blob: 09e7f702161193dd5af16d25f6f4631cca6d6fec [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"
chudy@google.com902ebe52012-06-29 14:21:22 +000020#include "SkSettingsWidget.h"
21#include <QtCore/QVariant>
22#include <QtGui/QAction>
23#include <QtGui/QApplication>
24#include <QtGui/QButtonGroup>
25#include <QtGui/QHBoxLayout>
26#include <QtGui/QHeaderView>
27#include <QtGui/QListView>
28#include <QtGui/QListWidget>
29#include <QtGui/QMainWindow>
30#include <QtGui/QStatusBar>
31#include <QtGui/QToolBar>
32#include <QtGui/QVBoxLayout>
33#include <QtGui/QWidget>
34#include <QtGui/QMenu>
35#include <QtGui/QMenuBar>
36#include <vector>
37
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +000038class SkTimedPicture;
39namespace sk_tools {
40 class PictureRenderer;
41}
42
chudy@google.com902ebe52012-06-29 14:21:22 +000043/** \class SkDebuggerGUI
44
45 Container for the UI and it's functions.
46 */
47class SkDebuggerGUI : public QMainWindow {
48 Q_OBJECT
49
50public:
51 /**
52 Constructs the view of the application.
53 @param parent The parent container of this widget.
54 */
55 SkDebuggerGUI(QWidget *parent = 0);
56
57 ~SkDebuggerGUI();
58
chudy@google.com7dcae672012-07-09 20:26:53 +000059signals:
60 void commandChanged(int command);
61
chudy@google.com902ebe52012-06-29 14:21:22 +000062private slots:
63 /**
64 Toggles breakpoint view in the list widget.
65 */
66 void actionBreakpoints();
67
68 /**
robertphillips@google.comd26c7062012-11-12 20:42:12 +000069 Profile the commands
70 */
71 void actionProfile();
72
73 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000074 Cancels the command filter in the list widget.
75 */
76 void actionCancel();
77
78 /**
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000079 Clears the breakpoint state off of all commands marked as breakpoints.
80 */
81 void actionClearBreakpoints();
82
83 /**
84 Clears the deleted state off of all commands marked as deleted.
85 */
86 void actionClearDeletes();
87
88 /**
chudy@google.com902ebe52012-06-29 14:21:22 +000089 Applies a visible filter to all drawing commands other than the previous.
90 */
91 void actionCommandFilter();
92
93 /**
94 Closes the application.
95 */
96 void actionClose();
97
98 /**
99 Deletes the command in question.
100 */
101 void actionDelete();
102
103 /**
chudy@google.comea5488b2012-07-26 19:38:22 +0000104 Toggles the visibility of the GL canvas widget.
105 */
106 void actionGLWidget(bool isToggled);
107
108 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000109 Toggles the visibility of the inspector widget.
110 */
111 void actionInspector();
112
113 /**
114 Plays from the current step to the next breakpoint if it exists, otherwise
115 executes all remaining draw commands.
116 */
117 void actionPlay();
118
119 /**
chudy@google.comea5488b2012-07-26 19:38:22 +0000120 Toggles the visibility of the raster canvas widget.
121 */
122 void actionRasterWidget(bool isToggled);
123
124 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000125 Rewinds from the current step back to the start of the commands.
126 */
127 void actionRewind();
128
129 /**
chudy@google.com0ab03392012-07-28 20:16:11 +0000130 Saves the current SKP with all modifications.
131 */
132 void actionSave();
133
134 /**
135 Saves the current SKP under a different name and/or location.
136 */
137 void actionSaveAs();
138
139 /**
chudy@google.com7dcae672012-07-09 20:26:53 +0000140 Sends the scale factor information to the settings widget.
141 */
142 void actionScale(float scaleFactor);
143
144 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000145 Toggles the settings widget visibility.
146 */
147 void actionSettings();
148
149 /**
150 Steps forward to the next draw command.
151 */
152 void actionStepBack();
153
154 /**
155 Steps backwards to the next draw command.
156 */
157 void actionStepForward();
158
159 /**
chudy@google.coma9e937c2012-08-03 17:32:05 +0000160 Called when the canvas is done being drawn to by SkCanvasWidget.
161 */
162 void drawComplete();
163
164 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000165 Loads an skpicture selected from the directory.
166 */
167 void loadFile(QListWidgetItem *item);
168
169 /**
170 Toggles a dialog with a file browser for navigating to a skpicture. Loads
171 the seleced file.
172 */
173 void openFile();
174
175 /**
chudy@google.com7dcae672012-07-09 20:26:53 +0000176 Toggles whether drawing to a new command requires a double click
177 or simple focus.
178 */
chudy@google.come504de02012-07-16 18:35:23 +0000179 void pauseDrawing(bool isPaused = true);
chudy@google.com7dcae672012-07-09 20:26:53 +0000180
181 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000182 Executes draw commands up to the selected command
183 */
184 void registerListClick(QListWidgetItem *item);
185
186 /**
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000187 Sets the command to active in the list widget.
188 */
189 void selectCommand(int command);
190
191 /**
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000192 Toggles the exclusive listing of commands set as deleted.
193 */
194 void showDeletes();
195
196 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000197 Toggles a breakpoint on the current step in the list widget.
198 */
199 void toggleBreakpoint();
200
201 /**
202 Toggles the visibility of the directory widget.
203 */
204 void toggleDirectory();
205
206 /**
207 Filters the list widgets command visibility based on the currently
208 active selection.
209 */
210 void toggleFilter(QString string);
211
212private:
chudy@google.com2d537a12012-07-31 12:49:52 +0000213 QWidget fCentralWidget;
214 QStatusBar fStatusBar;
215 QToolBar fToolBar;
216
chudy@google.comc432f002012-07-10 13:19:25 +0000217 QAction fActionOpen;
218 QAction fActionBreakpoint;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000219 QAction fActionProfile;
chudy@google.comc432f002012-07-10 13:19:25 +0000220 QAction fActionCancel;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000221 QAction fActionClearBreakpoints;
chudy@google.come504de02012-07-16 18:35:23 +0000222 QAction fActionClearDeletes;
chudy@google.comc432f002012-07-10 13:19:25 +0000223 QAction fActionClose;
chudy@google.come504de02012-07-16 18:35:23 +0000224 QAction fActionCreateBreakpoint;
chudy@google.comc432f002012-07-10 13:19:25 +0000225 QAction fActionDelete;
226 QAction fActionDirectory;
227 QAction fActionGoToLine;
228 QAction fActionInspector;
229 QAction fActionPlay;
chudy@google.come504de02012-07-16 18:35:23 +0000230 QAction fActionPause;
chudy@google.comc432f002012-07-10 13:19:25 +0000231 QAction fActionRewind;
chudy@google.com0ab03392012-07-28 20:16:11 +0000232 QAction fActionSave;
233 QAction fActionSaveAs;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000234 QAction fActionShowDeletes;
chudy@google.comc432f002012-07-10 13:19:25 +0000235 QAction fActionStepBack;
236 QAction fActionStepForward;
chudy@google.coma1226312012-07-26 20:26:44 +0000237 QAction fActionZoomIn;
238 QAction fActionZoomOut;
239 QSignalMapper fMapper;
chudy@google.com2d537a12012-07-31 12:49:52 +0000240
chudy@google.com0ab03392012-07-28 20:16:11 +0000241 QWidget fSpacer;
chudy@google.comc432f002012-07-10 13:19:25 +0000242 QComboBox fFilter;
chudy@google.com902ebe52012-06-29 14:21:22 +0000243
chudy@google.com2d537a12012-07-31 12:49:52 +0000244 QHBoxLayout fContainerLayout;
chudy@google.comc432f002012-07-10 13:19:25 +0000245 QVBoxLayout fLeftColumnLayout;
246 QVBoxLayout fMainAndRightColumnLayout;
chudy@google.comc432f002012-07-10 13:19:25 +0000247 QHBoxLayout fCanvasAndSettingsLayout;
chudy@google.com902ebe52012-06-29 14:21:22 +0000248
chudy@google.comc432f002012-07-10 13:19:25 +0000249 QListWidget fListWidget;
250 QListWidget fDirectoryWidget;
chudy@google.com902ebe52012-06-29 14:21:22 +0000251
chudy@google.com607357f2012-08-07 16:12:23 +0000252 SkDebugger fDebugger;
chudy@google.comc432f002012-07-10 13:19:25 +0000253 SkCanvasWidget fCanvasWidget;
254 SkInspectorWidget fInspectorWidget;
255 SkSettingsWidget fSettingsWidget;
chudy@google.comc432f002012-07-10 13:19:25 +0000256
chudy@google.com902ebe52012-06-29 14:21:22 +0000257 QString fPath;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000258 SkString fFileName;
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000259 SkTDArray<size_t> fOffsets; // the offset of each command in the SkPicture
chudy@google.com902ebe52012-06-29 14:21:22 +0000260 bool fDirectoryWidgetActive;
chudy@google.com902ebe52012-06-29 14:21:22 +0000261
chudy@google.comc432f002012-07-10 13:19:25 +0000262 QMenuBar fMenuBar;
263 QMenu fMenuFile;
chudy@google.come504de02012-07-16 18:35:23 +0000264 QMenu fMenuEdit;
chudy@google.comc432f002012-07-10 13:19:25 +0000265 QMenu fMenuNavigate;
266 QMenu fMenuView;
chudy@google.come504de02012-07-16 18:35:23 +0000267 QMenu fMenuWindows;
chudy@google.com902ebe52012-06-29 14:21:22 +0000268
269 bool fBreakpointsActivated;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000270 bool fDeletesActivated;
chudy@google.com7dcae672012-07-09 20:26:53 +0000271 bool fPause;
chudy@google.comd3058f52012-07-19 13:41:27 +0000272 bool fLoading;
chudy@google.com2d537a12012-07-31 12:49:52 +0000273 int fPausedRow;
chudy@google.com902ebe52012-06-29 14:21:22 +0000274
275 /**
276 Creates the entire UI.
277 */
278 void setupUi(QMainWindow *SkDebuggerGUI);
279
280 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000281 Pipes a QString in with the location of the filename, proceeds to updating
282 the listwidget, combowidget and inspectorwidget.
283 */
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000284 void loadPicture(const SkString& fileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000285
286 /**
chudy@google.com0ab03392012-07-28 20:16:11 +0000287 Creates a picture of the current canvas.
288 */
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000289 void saveToFile(const SkString& filename);
chudy@google.com0ab03392012-07-28 20:16:11 +0000290
291 /**
chudy@google.com902ebe52012-06-29 14:21:22 +0000292 Populates the list widget with the vector of strings passed in.
293 */
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000294 void setupListWidget(SkTArray<SkString>* command);
chudy@google.com902ebe52012-06-29 14:21:22 +0000295
296 /**
297 Populates the combo box widget with the vector of strings passed in.
298 */
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000299 void setupComboBox(SkTArray<SkString>* command);
300
301 /**
302 Fills in the overview pane with text
303 */
304 void setupOverviewText(const SkTDArray<double>* typeTimes, double totTime);
chudy@google.com902ebe52012-06-29 14:21:22 +0000305
306 /**
307 Updates the directory widget with the latest directory path stored in
308 the global class variable fPath.
309 */
310 void setupDirectoryWidget();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000311
312 /**
313 Render the supplied picture several times tracking the time consumed
314 by each command.
315 */
316 void run(SkTimedPicture* pict,
317 sk_tools::PictureRenderer* renderer,
318 int repeats);
chudy@google.com902ebe52012-06-29 14:21:22 +0000319};
320
321#endif // SKDEBUGGERUI_H