blob: 4130e962d1930046935d648ca0d8624dc89ecd87 [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef SKDEBUGGERUI_H
10#define SKDEBUGGERUI_H
11
12
13#include "SkCanvas.h"
chudy@google.comea5488b2012-07-26 19:38:22 +000014#include "SkCanvasWidget.h"
chudy@google.com607357f2012-08-07 16:12:23 +000015#include "SkDebugger.h"
chudy@google.comea5488b2012-07-26 19:38:22 +000016#include "SkGLWidget.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000017#include "SkListWidget.h"
18#include "SkInspectorWidget.h"
chudy@google.comea5488b2012-07-26 19:38:22 +000019#include "SkRasterWidget.h"
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +000020#include "SkImageWidget.h"
chudy@google.com902ebe52012-06-29 14:21:22 +000021#include "SkSettingsWidget.h"
22#include <QtCore/QVariant>
23#include <QtGui/QAction>
24#include <QtGui/QApplication>
25#include <QtGui/QButtonGroup>
26#include <QtGui/QHBoxLayout>
27#include <QtGui/QHeaderView>
28#include <QtGui/QListView>
29#include <QtGui/QListWidget>
30#include <QtGui/QMainWindow>
31#include <QtGui/QStatusBar>
32#include <QtGui/QToolBar>
33#include <QtGui/QVBoxLayout>
34#include <QtGui/QWidget>
35#include <QtGui/QMenu>
36#include <QtGui/QMenuBar>
37#include <vector>
38
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +000039class SkTimedPicture;
40namespace sk_tools {
41 class PictureRenderer;
42}
43
chudy@google.com902ebe52012-06-29 14:21:22 +000044/** \class SkDebuggerGUI
45
46 Container for the UI and it's functions.
47 */
48class SkDebuggerGUI : public QMainWindow {
49 Q_OBJECT
50
51public:
52 /**
53 Constructs the view of the application.
54 @param parent The parent container of this widget.
55 */
56 SkDebuggerGUI(QWidget *parent = 0);
57
58 ~SkDebuggerGUI();
59
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +000060 /**
61 Updates the directory widget with the latest directory path stored in
62 the global class variable fPath.
63 */
64 void setupDirectoryWidget(const QString& path);
65
66 /**
67 Loads the specified file.
68 */
69 void openFile(const QString& filename);
70
chudy@google.com7dcae672012-07-09 20:26:53 +000071signals:
72 void commandChanged(int command);
73
chudy@google.com902ebe52012-06-29 14:21:22 +000074private slots:
75 /**
76 Toggles breakpoint view in the list widget.
77 */
78 void actionBreakpoints();
79
80 /**
robertphillips@google.comd26c7062012-11-12 20:42:12 +000081 Profile the commands
82 */
83 void actionProfile();
84
85 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000086 Cancels the command filter in the list widget.
87 */
88 void actionCancel();
89
90 /**
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000091 Clears the breakpoint state off of all commands marked as breakpoints.
92 */
93 void actionClearBreakpoints();
94
95 /**
96 Clears the deleted state off of all commands marked as deleted.
97 */
98 void actionClearDeletes();
99
100 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000101 Applies a visible filter to all drawing commands other than the previous.
102 */
103 void actionCommandFilter();
104
105 /**
106 Closes the application.
107 */
108 void actionClose();
109
110 /**
111 Deletes the command in question.
112 */
113 void actionDelete();
114
115 /**
chudy@google.comea5488b2012-07-26 19:38:22 +0000116 Toggles the visibility of the GL canvas widget.
117 */
118 void actionGLWidget(bool isToggled);
119
120 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000121 Toggles the visibility of the inspector widget.
122 */
123 void actionInspector();
124
125 /**
126 Plays from the current step to the next breakpoint if it exists, otherwise
127 executes all remaining draw commands.
128 */
129 void actionPlay();
130
131 /**
chudy@google.comea5488b2012-07-26 19:38:22 +0000132 Toggles the visibility of the raster canvas widget.
133 */
134 void actionRasterWidget(bool isToggled);
135
136 /**
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000137 Toggles the the overdraw visualization on and off
138 */
139 void actionOverdrawVizWidget(bool isToggled);
140
141 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000142 Rewinds from the current step back to the start of the commands.
143 */
144 void actionRewind();
145
146 /**
chudy@google.com0ab03392012-07-28 20:16:11 +0000147 Saves the current SKP with all modifications.
148 */
149 void actionSave();
150
151 /**
152 Saves the current SKP under a different name and/or location.
153 */
154 void actionSaveAs();
155
156 /**
chudy@google.com7dcae672012-07-09 20:26:53 +0000157 Sends the scale factor information to the settings widget.
158 */
159 void actionScale(float scaleFactor);
160
161 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000162 Toggles the settings widget visibility.
163 */
164 void actionSettings();
165
166 /**
167 Steps forward to the next draw command.
168 */
169 void actionStepBack();
170
171 /**
172 Steps backwards to the next draw command.
173 */
174 void actionStepForward();
175
176 /**
chudy@google.coma9e937c2012-08-03 17:32:05 +0000177 Called when the canvas is done being drawn to by SkCanvasWidget.
178 */
179 void drawComplete();
180
181 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000182 Loads an skpicture selected from the directory.
183 */
184 void loadFile(QListWidgetItem *item);
185
186 /**
187 Toggles a dialog with a file browser for navigating to a skpicture. Loads
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000188 the selected file.
chudy@google.com902ebe52012-06-29 14:21:22 +0000189 */
190 void openFile();
191
192 /**
chudy@google.com7dcae672012-07-09 20:26:53 +0000193 Toggles whether drawing to a new command requires a double click
194 or simple focus.
195 */
chudy@google.come504de02012-07-16 18:35:23 +0000196 void pauseDrawing(bool isPaused = true);
chudy@google.com7dcae672012-07-09 20:26:53 +0000197
198 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000199 Executes draw commands up to the selected command
200 */
201 void registerListClick(QListWidgetItem *item);
202
203 /**
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000204 Sets the command to active in the list widget.
205 */
206 void selectCommand(int command);
207
208 /**
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000209 Toggles the exclusive listing of commands set as deleted.
210 */
211 void showDeletes();
212
213 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000214 Toggles a breakpoint on the current step in the list widget.
215 */
216 void toggleBreakpoint();
217
218 /**
219 Toggles the visibility of the directory widget.
220 */
221 void toggleDirectory();
222
223 /**
224 Filters the list widgets command visibility based on the currently
225 active selection.
226 */
227 void toggleFilter(QString string);
228
229private:
chudy@google.com2d537a12012-07-31 12:49:52 +0000230 QWidget fCentralWidget;
231 QStatusBar fStatusBar;
232 QToolBar fToolBar;
233
chudy@google.comc432f002012-07-10 13:19:25 +0000234 QAction fActionOpen;
235 QAction fActionBreakpoint;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000236 QAction fActionProfile;
chudy@google.comc432f002012-07-10 13:19:25 +0000237 QAction fActionCancel;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000238 QAction fActionClearBreakpoints;
chudy@google.come504de02012-07-16 18:35:23 +0000239 QAction fActionClearDeletes;
chudy@google.comc432f002012-07-10 13:19:25 +0000240 QAction fActionClose;
chudy@google.come504de02012-07-16 18:35:23 +0000241 QAction fActionCreateBreakpoint;
chudy@google.comc432f002012-07-10 13:19:25 +0000242 QAction fActionDelete;
243 QAction fActionDirectory;
244 QAction fActionGoToLine;
245 QAction fActionInspector;
246 QAction fActionPlay;
chudy@google.come504de02012-07-16 18:35:23 +0000247 QAction fActionPause;
chudy@google.comc432f002012-07-10 13:19:25 +0000248 QAction fActionRewind;
chudy@google.com0ab03392012-07-28 20:16:11 +0000249 QAction fActionSave;
250 QAction fActionSaveAs;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000251 QAction fActionShowDeletes;
chudy@google.comc432f002012-07-10 13:19:25 +0000252 QAction fActionStepBack;
253 QAction fActionStepForward;
chudy@google.coma1226312012-07-26 20:26:44 +0000254 QAction fActionZoomIn;
255 QAction fActionZoomOut;
256 QSignalMapper fMapper;
chudy@google.com2d537a12012-07-31 12:49:52 +0000257
chudy@google.com0ab03392012-07-28 20:16:11 +0000258 QWidget fSpacer;
chudy@google.comc432f002012-07-10 13:19:25 +0000259 QComboBox fFilter;
chudy@google.com902ebe52012-06-29 14:21:22 +0000260
chudy@google.com2d537a12012-07-31 12:49:52 +0000261 QHBoxLayout fContainerLayout;
chudy@google.comc432f002012-07-10 13:19:25 +0000262 QVBoxLayout fLeftColumnLayout;
263 QVBoxLayout fMainAndRightColumnLayout;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000264 QHBoxLayout fCanvasSettingsAndImageLayout;
265 QVBoxLayout fSettingsAndImageLayout;
chudy@google.com902ebe52012-06-29 14:21:22 +0000266
chudy@google.comc432f002012-07-10 13:19:25 +0000267 QListWidget fListWidget;
268 QListWidget fDirectoryWidget;
chudy@google.com902ebe52012-06-29 14:21:22 +0000269
chudy@google.com607357f2012-08-07 16:12:23 +0000270 SkDebugger fDebugger;
chudy@google.comc432f002012-07-10 13:19:25 +0000271 SkCanvasWidget fCanvasWidget;
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000272 SkImageWidget fImageWidget;
chudy@google.comc432f002012-07-10 13:19:25 +0000273 SkInspectorWidget fInspectorWidget;
274 SkSettingsWidget fSettingsWidget;
chudy@google.comc432f002012-07-10 13:19:25 +0000275
chudy@google.com902ebe52012-06-29 14:21:22 +0000276 QString fPath;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000277 SkString fFileName;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000278 SkTDArray<size_t> fOffsets; // the offset of each command in the SkPicture
robertphillips@google.com5f971142012-12-07 20:48:56 +0000279 SkTDArray<bool> fSkipCommands; // has a specific command been deleted?
chudy@google.com902ebe52012-06-29 14:21:22 +0000280 bool fDirectoryWidgetActive;
chudy@google.com902ebe52012-06-29 14:21:22 +0000281
chudy@google.comc432f002012-07-10 13:19:25 +0000282 QMenuBar fMenuBar;
283 QMenu fMenuFile;
chudy@google.come504de02012-07-16 18:35:23 +0000284 QMenu fMenuEdit;
chudy@google.comc432f002012-07-10 13:19:25 +0000285 QMenu fMenuNavigate;
286 QMenu fMenuView;
chudy@google.come504de02012-07-16 18:35:23 +0000287 QMenu fMenuWindows;
chudy@google.com902ebe52012-06-29 14:21:22 +0000288
289 bool fBreakpointsActivated;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000290 bool fDeletesActivated;
chudy@google.com7dcae672012-07-09 20:26:53 +0000291 bool fPause;
chudy@google.comd3058f52012-07-19 13:41:27 +0000292 bool fLoading;
chudy@google.com2d537a12012-07-31 12:49:52 +0000293 int fPausedRow;
chudy@google.com902ebe52012-06-29 14:21:22 +0000294
295 /**
296 Creates the entire UI.
297 */
298 void setupUi(QMainWindow *SkDebuggerGUI);
299
300 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000301 Pipes a QString in with the location of the filename, proceeds to updating
302 the listwidget, combowidget and inspectorwidget.
303 */
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000304 void loadPicture(const SkString& fileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000305
306 /**
chudy@google.com0ab03392012-07-28 20:16:11 +0000307 Creates a picture of the current canvas.
308 */
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000309 void saveToFile(const SkString& filename);
chudy@google.com0ab03392012-07-28 20:16:11 +0000310
311 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000312 Populates the list widget with the vector of strings passed in.
313 */
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000314 void setupListWidget(SkTArray<SkString>* command);
chudy@google.com902ebe52012-06-29 14:21:22 +0000315
316 /**
317 Populates the combo box widget with the vector of strings passed in.
318 */
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000319 void setupComboBox(SkTArray<SkString>* command);
320
321 /**
322 Fills in the overview pane with text
323 */
324 void setupOverviewText(const SkTDArray<double>* typeTimes, double totTime);
chudy@google.com902ebe52012-06-29 14:21:22 +0000325
326 /**
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000327 Render the supplied picture several times tracking the time consumed
328 by each command.
329 */
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000330 void run(SkTimedPicture* pict,
331 sk_tools::PictureRenderer* renderer,
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000332 int repeats);
chudy@google.com902ebe52012-06-29 14:21:22 +0000333};
334
335#endif // SKDEBUGGERUI_H