1 
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"
14 #include "SkCanvasWidget.h"
15 #include "SkDebugger.h"
16 #include "SkGLWidget.h"
17 #include "SkListWidget.h"
18 #include "SkInspectorWidget.h"
19 #include "SkRasterWidget.h"
20 #include "SkDrawCommandGeometryWidget.h"
21 #include "SkSettingsWidget.h"
22 #include <QtCore/QSignalMapper>
23 #include <QtCore/QVariant>
24 #include <QtGui/QAction>
25 #include <QtGui/QApplication>
26 #include <QtGui/QButtonGroup>
27 #include <QtGui/QHBoxLayout>
28 #include <QtGui/QHeaderView>
29 #include <QtGui/QListView>
30 #include <QtGui/QListWidget>
31 #include <QtGui/QMainWindow>
32 #include <QtGui/QSplitter>
33 #include <QtGui/QStatusBar>
34 #include <QtGui/QToolBar>
35 #include <QtGui/QVBoxLayout>
36 #include <QtGui/QWidget>
37 #include <QtGui/QMenu>
38 #include <QtGui/QMenuBar>
39 #include <vector>
40 
41 class SkTimedPicture;
42 namespace sk_tools {
43     class PictureRenderer;
44 }
45 
46 /** \class SkDebuggerGUI
47 
48     Container for the UI and it's functions.
49  */
50 class SkDebuggerGUI : public QMainWindow {
51     Q_OBJECT
52 
53 public:
54     /**
55         Constructs the view of the application.
56         @param parent  The parent container of this widget.
57      */
58     SkDebuggerGUI(QWidget *parent = 0);
59 
60     /**
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 
71 signals:
72     void commandChanged(int command);
73 
74 private slots:
75     /**
76         Toggles breakpoint view in the list widget.
77      */
78     void actionBreakpoints();
79 
80     /**
81         Profile the commands
82      */
83     void actionProfile();
84 
85     /**
86         Cancels the command filter in the list widget.
87      */
88     void actionCancel();
89 
90     /**
91         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     /**
101         Closes the application.
102      */
103     void actionClose();
104 
105     /**
106         Deletes the command in question.
107      */
108     void actionDelete();
109 
110 #if SK_SUPPORT_GPU
111     /**
112         Updates the visibility of the GL canvas widget and sample count of the GL surface.
113      */
114     void actionGLSettingsChanged();
115 #endif
116 
117     /**
118         Toggles the visibility of the inspector widget.
119      */
120     void actionInspector();
121 
122     /**
123         Plays from the current step to the next breakpoint if it exists, otherwise
124         executes all remaining draw commands.
125      */
126     void actionPlay();
127 
128     /**
129         Sets the visibility of the raster canvas widget according to the settings widget.
130      */
131     void actionRasterSettingsChanged();
132 
133     /**
134         Sets the visualization settings according to the settings widget.
135      */
136     void actionVisualizationsChanged();
137 
138     /**
139         Applies the new texture filter override
140      */
141     void actionTextureFilter();
142 
143     /**
144         Rewinds from the current step back to the start of the commands.
145      */
146     void actionRewind();
147 
148     /**
149         Saves the current SKP with all modifications.
150      */
151     void actionSave();
152 
153     /**
154         Saves the current SKP under a different name and/or location.
155      */
156     void actionSaveAs();
157 
158     /**
159         Sends the scale factor information to the settings widget.
160      */
161     void actionScale(float scaleFactor);
162 
163     /**
164         Toggles the settings widget visibility.
165      */
166     void actionSettings();
167 
168     /**
169         Steps forward to the next draw command.
170      */
171     void actionStepBack();
172 
173     /**
174         Steps backwards to the next draw command.
175      */
176     void actionStepForward();
177 
178     /**
179         Called when the canvas is done being drawn to by SkCanvasWidget.
180      */
181     void drawComplete();
182 
183     /**
184         Loads an skpicture selected from the directory.
185      */
186     void loadFile(QListWidgetItem *item);
187 
188     /**
189         Toggles a dialog with a file browser for navigating to a skpicture. Loads
190         the selected file.
191      */
192     void openFile();
193 
194     /**
195         Toggles whether drawing to a new command requires a double click
196         or simple focus.
197      */
198     void pauseDrawing(bool isPaused = true);
199 
200     /**
201         Updates the UI based on the selected command.
202      */
203     void updateDrawCommandInfo();
204 
205     /**
206         Sets the command to active in the list widget.
207      */
208     void selectCommand(int command);
209 
210     /**
211         Toggles the exclusive listing of commands set as deleted.
212      */
213     void showDeletes();
214 
215     /**
216         Toggles a breakpoint on the current step in the list widget.
217      */
218     void toggleBreakpoint();
219 
220     /**
221         Toggles the visibility of the directory widget.
222      */
223     void toggleDirectory();
224 
225     /**
226         Filters the list widgets command visibility based on the currently
227         active selection.
228      */
229     void toggleFilter(QString string);
230 
231     void updateHit(int newHit);
232 
233     void updateImage();
234 private:
235     QSplitter fCentralSplitter;
236     QStatusBar fStatusBar;
237     QToolBar fToolBar;
238 
239     QAction fActionOpen;
240     QAction fActionBreakpoint;
241     QAction fActionProfile;
242     QAction fActionCancel;
243     QAction fActionClearBreakpoints;
244     QAction fActionClearDeletes;
245     QAction fActionClose;
246     QAction fActionCreateBreakpoint;
247     QAction fActionDelete;
248     QAction fActionDirectory;
249     QAction fActionGoToLine;
250     QAction fActionInspector;
251     QAction fActionSettings;
252     QAction fActionPlay;
253     QAction fActionPause;
254     QAction fActionRewind;
255     QAction fActionSave;
256     QAction fActionSaveAs;
257     QAction fActionShowDeletes;
258     QAction fActionStepBack;
259     QAction fActionStepForward;
260     QAction fActionZoomIn;
261     QAction fActionZoomOut;
262     QSignalMapper fMapper;
263 
264     QWidget fSpacer;
265     QComboBox fFilter;
266 
267     QSplitter fLeftColumnSplitter;
268     QWidget fMainAndRightColumnWidget;
269     QVBoxLayout fMainAndRightColumnLayout;
270     QHBoxLayout fCanvasSettingsAndImageLayout;
271     QVBoxLayout fSettingsAndImageLayout;
272 
273     QListWidget fListWidget;
274     QListWidget fDirectoryWidget;
275 
276     SkDebugger fDebugger;
277     SkCanvasWidget fCanvasWidget;
278 
279     SkInspectorWidget fInspectorWidget;
280     SkSettingsWidget fSettingsWidget;
281 
282     QFrame fViewStateFrame;
283     QVBoxLayout fViewStateFrameLayout;
284     QGroupBox fViewStateGroup;
285     QFormLayout fViewStateLayout;
286     QLineEdit fCurrentCommandBox;
287     QLineEdit fCommandHitBox;
288     QLineEdit fZoomBox;
289     SkDrawCommandGeometryWidget fDrawCommandGeometryWidget;
290 
291     QString fPath;
292     SkString fFileName;
293     SkTDArray<bool> fSkipCommands; // has a specific command been deleted?
294     bool fDirectoryWidgetActive;
295 
296     QMenuBar fMenuBar;
297     QMenu fMenuFile;
298     QMenu fMenuEdit;
299     QMenu fMenuNavigate;
300     QMenu fMenuView;
301     QMenu fMenuWindows;
302 
303     bool fLoading;
304     int fPausedRow;
305 
306     /**
307         Creates the entire UI.
308      */
309     void setupUi(QMainWindow *SkDebuggerGUI);
310 
311     /**
312         Pipes a QString in with the location of the filename, proceeds to updating
313         the listwidget, combowidget and inspectorwidget.
314      */
315     void loadPicture(const SkString& fileName);
316 
317     /**
318         Creates a picture of the current canvas.
319      */
320     void saveToFile(const SkString& filename);
321 
322     /**
323         Populates the list widget with the debugger draw command info.
324      */
325     void setupListWidget();
326 
327     /**
328         Populates the combo box widget with with the debugger draw command info.
329      */
330     void setupComboBox();
331 
332     /**
333         Fills in the overview pane with text
334      */
335     void setupOverviewText(const SkTDArray<double>* typeTimes, double totTime, int numRuns);
336 
337 
338     /**
339         Render the supplied picture several times tracking the time consumed
340         by each command.
341      */
342     void run(const SkPicture* pict,
343              sk_tools::PictureRenderer* renderer,
344              int repeats);
345 
isPaused()346     bool isPaused() const {
347         return fActionPause.isChecked();
348     }
349 };
350 
351 #endif // SKDEBUGGERUI_H
352