blob: 9863cc019183481da9689ebcd303ed705c305d44 [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include <iostream>
9#include "SkDebuggerGUI.h"
10#include <QListWidgetItem>
11
12SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000013 QMainWindow(parent)
chudy@google.com2d537a12012-07-31 12:49:52 +000014 , fCentralWidget(this)
15 , fStatusBar(this)
16 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000017 , fActionOpen(this)
18 , fActionBreakpoint(this)
19 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000020 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000021 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000022 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000023 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000024 , fActionDelete(this)
25 , fActionDirectory(this)
26 , fActionGoToLine(this)
27 , fActionInspector(this)
28 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000029 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000030 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000031 , fActionSave(this)
32 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000033 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000034 , fActionStepBack(this)
35 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000036 , fActionZoomIn(this)
37 , fActionZoomOut(this)
38 , fMapper(this)
chudy@google.comc432f002012-07-10 13:19:25 +000039 , fListWidget(&fCentralWidget)
40 , fDirectoryWidget(&fCentralWidget)
chudy@google.com607357f2012-08-07 16:12:23 +000041 , fCanvasWidget(this, &fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000042 , fMenuBar(this)
43 , fMenuFile(this)
44 , fMenuNavigate(this)
45 , fMenuView(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000046 , fBreakpointsActivated(false)
47 , fDeletesActivated(false)
48 , fPause(false)
chudy@google.comd3058f52012-07-19 13:41:27 +000049 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000050{
chudy@google.com902ebe52012-06-29 14:21:22 +000051 setupUi(this);
chudy@google.comea5488b2012-07-26 19:38:22 +000052 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000053 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000054 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
55 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000056 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000057 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000058 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
59 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
60 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000061 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
62 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
63 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
64 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionSettings()));
65 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
chudy@google.comc432f002012-07-10 13:19:25 +000066 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000067 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
68 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000069 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
chudy@google.comea5488b2012-07-26 19:38:22 +000070 connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this, SLOT(actionCommandFilter()));
71 connect(fSettingsWidget.getGLCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionGLWidget(bool)));
72 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
73 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000074 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000075 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000076 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
77 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
78 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
79 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +000080 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
81 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000082
chudy@google.coma1226312012-07-26 20:26:44 +000083 fMapper.setMapping(&fActionZoomIn, 1);
84 fMapper.setMapping(&fActionZoomOut, -1);
85
86 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
87 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
88 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(keyZoom(int)));
89
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000090 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +000091 fMenuEdit.setDisabled(true);
92 fMenuNavigate.setDisabled(true);
93 fMenuView.setDisabled(true);
chudy@google.com902ebe52012-06-29 14:21:22 +000094}
95
chudy@google.com2d537a12012-07-31 12:49:52 +000096SkDebuggerGUI::~SkDebuggerGUI() {}
chudy@google.com902ebe52012-06-29 14:21:22 +000097
98void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000099 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000100 for (int row = 0; row < fListWidget.count(); row++) {
101 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000102 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
103 }
104}
chudy@google.com902ebe52012-06-29 14:21:22 +0000105
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000106void SkDebuggerGUI::showDeletes() {
107 fDeletesActivated = !fDeletesActivated;
108 for (int row = 0; row < fListWidget.count(); row++) {
109 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000110 item->setHidden(fDebugger.isCommandVisible(row)
111 && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000112 }
113}
114
115void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000116 for (int row = 0; row < fListWidget.count(); row++) {
117 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000118 }
119}
120
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000121void SkDebuggerGUI::actionClearBreakpoints() {
122 for (int row = 0; row < fListWidget.count(); row++) {
123 QListWidgetItem* item = fListWidget.item(row);
124 item->setCheckState(Qt::Unchecked);
125 item->setData(Qt::DecorationRole,
126 QPixmap(":/images/Icons/blank.png"));
127 }
128}
129
130void SkDebuggerGUI::actionClearDeletes() {
131 for (int row = 0; row < fListWidget.count(); row++) {
132 QListWidgetItem* item = fListWidget.item(row);
133 item->setData(Qt::UserRole + 2, QPixmap(":/images/Icons/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000134 fDebugger.setCommandVisible(row, true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000135 }
136 if (fPause) {
137 fCanvasWidget.drawTo(fPausedRow);
138 } else {
139 fCanvasWidget.drawTo(fListWidget.currentRow());
140 }
141}
142
chudy@google.com902ebe52012-06-29 14:21:22 +0000143void SkDebuggerGUI::actionCommandFilter() {
chudy@google.com607357f2012-08-07 16:12:23 +0000144 fDebugger.highlightCurrentCommand(
chudy@google.comc432f002012-07-10 13:19:25 +0000145 fSettingsWidget.getVisibilityButton()->isChecked());
146 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000147}
148
149void SkDebuggerGUI::actionClose() {
150 this->close();
151}
152
153void SkDebuggerGUI::actionDelete() {
chudy@google.comc432f002012-07-10 13:19:25 +0000154 int currentRow = fListWidget.currentRow();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000155 QListWidgetItem* item = fListWidget.currentItem();
156
chudy@google.com607357f2012-08-07 16:12:23 +0000157 if (fDebugger.isCommandVisible(currentRow)) {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000158 item->setData(Qt::UserRole + 2, QPixmap(":/images/Icons/delete.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000159 fDebugger.setCommandVisible(currentRow, false);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000160 } else {
161 item->setData(Qt::UserRole + 2, QPixmap(":/images/Icons/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000162 fDebugger.setCommandVisible(currentRow, true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000163 }
164
chudy@google.come504de02012-07-16 18:35:23 +0000165 if (fPause) {
166 fCanvasWidget.drawTo(fPausedRow);
167 } else {
168 fCanvasWidget.drawTo(currentRow);
169 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000170}
171
chudy@google.comea5488b2012-07-26 19:38:22 +0000172void SkDebuggerGUI::actionGLWidget(bool isToggled) {
173 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
174}
175
chudy@google.com902ebe52012-06-29 14:21:22 +0000176void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000177 if (fInspectorWidget.isHidden()) {
178 fInspectorWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000179 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000180 fInspectorWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000181 }
182}
183
184void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000185 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000186 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000187 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000188 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000189 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000190 return;
191 }
192 }
chudy@google.comc432f002012-07-10 13:19:25 +0000193 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000194}
195
chudy@google.comea5488b2012-07-26 19:38:22 +0000196void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
197 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
198}
199
chudy@google.com902ebe52012-06-29 14:21:22 +0000200void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000201 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000202}
203
chudy@google.com0ab03392012-07-28 20:16:11 +0000204void SkDebuggerGUI::actionSave() {
205 QString filename;
206 filename.append(fPath);
207 filename.append("/");
208 filename.append(fDirectoryWidget.currentItem()->text());
209 saveToFile(filename);
210}
211
212void SkDebuggerGUI::actionSaveAs() {
213 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
214 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000215 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000216 filename.append(".skp");
217 }
218 saveToFile(filename);
219}
220
chudy@google.com7dcae672012-07-09 20:26:53 +0000221void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000222 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000223}
224
chudy@google.com902ebe52012-06-29 14:21:22 +0000225void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000226 if (fSettingsWidget.isHidden()) {
227 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000228 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000229 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000230 }
231}
232
233void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000234 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000235 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000236 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000237 }
238}
239
240void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000241 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000242 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000243 QString curCount = QString::number(fListWidget.count());
244 if (currentRow < fListWidget.count() - 1) {
245 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000246 }
247}
248
chudy@google.coma9e937c2012-08-03 17:32:05 +0000249void SkDebuggerGUI::drawComplete() {
chudy@google.com607357f2012-08-07 16:12:23 +0000250 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
251 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000252}
253
chudy@google.com0ab03392012-07-28 20:16:11 +0000254void SkDebuggerGUI::saveToFile(QString filename) {
255 SkFILEWStream file(filename.toAscii());
chudy@google.com607357f2012-08-07 16:12:23 +0000256 fDebugger.makePicture()->serialize(&file);
chudy@google.com0ab03392012-07-28 20:16:11 +0000257}
258
chudy@google.com902ebe52012-06-29 14:21:22 +0000259void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
260 if (fDirectoryWidgetActive) {
261 QString fileName;
262 fileName.append(fPath);
263 fileName.append("/");
264 fileName.append(item->text());
265 loadPicture(fileName);
266 }
267}
268
269void SkDebuggerGUI::openFile() {
chudy@google.com7dcae672012-07-09 20:26:53 +0000270 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
271 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000272 fDirectoryWidgetActive = false;
273 if (!fileName.isNull()) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000274 QFileInfo pathInfo(fileName);
275 fPath = pathInfo.path();
276 loadPicture(fileName);
277 setupDirectoryWidget();
278 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000279 fDirectoryWidgetActive = true;
280}
281
chudy@google.comc432f002012-07-10 13:19:25 +0000282void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000283 fPause = isPaused;
284 fPausedRow = fListWidget.currentRow();
285 fCanvasWidget.drawTo(fPausedRow);
chudy@google.com7dcae672012-07-09 20:26:53 +0000286}
287
chudy@google.com902ebe52012-06-29 14:21:22 +0000288void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000289 if(!fLoading) {
290 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000291
chudy@google.comea5488b2012-07-26 19:38:22 +0000292 if (currentRow != -1) {
293 if (!fPause) {
294 fCanvasWidget.drawTo(currentRow);
chudy@google.comd3058f52012-07-19 13:41:27 +0000295 }
chudy@google.com607357f2012-08-07 16:12:23 +0000296 std::vector<std::string> *cuffInfo = fDebugger.getCommandInfo(
chudy@google.comea5488b2012-07-26 19:38:22 +0000297 currentRow);
298
299 /* TODO(chudy): Add command type before parameters. Rename v
300 * to something more informative. */
301 if (cuffInfo) {
302 std::vector<std::string>::iterator it;
303
304 QString info;
305 info.append("<b>Parameters: </b><br/>");
306 for (it = cuffInfo->begin(); it != cuffInfo->end(); ++it) {
307 info.append(QString((*it).c_str()));
308 info.append("<br/>");
309 }
310 fInspectorWidget.setDetailText(info);
311 fInspectorWidget.setDisabled(false);
chudy@google.comea5488b2012-07-26 19:38:22 +0000312 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000313 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000314
chudy@google.com902ebe52012-06-29 14:21:22 +0000315 }
316}
317
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000318void SkDebuggerGUI::selectCommand(int command) {
319 if (fPause) {
320 fListWidget.setCurrentRow(command);
321 }
322}
323
chudy@google.com902ebe52012-06-29 14:21:22 +0000324void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000325 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000326 if (item->checkState() == Qt::Unchecked) {
327 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000328 item->setData(Qt::DecorationRole,
329 QPixmap(":/images/Icons/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000330 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000331 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000332 item->setData(Qt::DecorationRole,
333 QPixmap(":/images/Icons/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000334 }
335}
336
337void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000338 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000339}
340
341void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000342 for (int row = 0; row < fListWidget.count(); row++) {
343 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000344 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000345 }
346}
347
348void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
349 QIcon windowIcon;
chudy@google.com7dcae672012-07-09 20:26:53 +0000350 windowIcon.addFile(QString::fromUtf8(":/images/Icons/skia.png"), QSize(),
351 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000352 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
353 SkDebuggerGUI->resize(1200, 1000);
354 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000355 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000356
chudy@google.come504de02012-07-16 18:35:23 +0000357 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000358 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000359
360 QIcon breakpoint;
chudy@google.com7dcae672012-07-09 20:26:53 +0000361 breakpoint.addFile(QString::fromUtf8(":/images/Icons/breakpoint.png"),
362 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000363 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000364 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000365 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000366
367 QIcon cancel;
chudy@google.come504de02012-07-16 18:35:23 +0000368 cancel.addFile(QString::fromUtf8(":/images/Ico/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000369 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000370 fActionCancel.setIcon(cancel);
371 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000372
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000373 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
374 fActionClearBreakpoints.setText("Clear Breakpoints");
375
376 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
377 fActionClearDeletes.setText("Clear Deletes");
378
chudy@google.come504de02012-07-16 18:35:23 +0000379 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000380 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000381
chudy@google.come504de02012-07-16 18:35:23 +0000382 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
383 fActionCreateBreakpoint.setText("Set Breakpoint");
384
385 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000386 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000387
chudy@google.come504de02012-07-16 18:35:23 +0000388 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
389 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000390
chudy@google.comc432f002012-07-10 13:19:25 +0000391 QIcon inspector;
chudy@google.come504de02012-07-16 18:35:23 +0000392 inspector.addFile(QString::fromUtf8(":/images/Ico/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000393 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000394 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000395 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000396 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000397
chudy@google.comc432f002012-07-10 13:19:25 +0000398 QIcon play;
chudy@google.come504de02012-07-16 18:35:23 +0000399 play.addFile(QString::fromUtf8(":/images/Ico/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000400 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000401 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000402 fActionPlay.setIcon(play);
403 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000404
chudy@google.come504de02012-07-16 18:35:23 +0000405 QIcon pause;
406 pause.addFile(QString::fromUtf8(":/images/Ico/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000407 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000408 fActionPause.setShortcut(QKeySequence(tr("Space")));
409 fActionPause.setCheckable(true);
410 fActionPause.setIcon(pause);
411 fActionPause.setText("Pause");
412
chudy@google.comc432f002012-07-10 13:19:25 +0000413 QIcon rewind;
chudy@google.come504de02012-07-16 18:35:23 +0000414 rewind.addFile(QString::fromUtf8(":/images/Ico/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000415 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000416 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000417 fActionRewind.setIcon(rewind);
418 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000419
chudy@google.com0ab03392012-07-28 20:16:11 +0000420 fActionSave.setShortcut(QKeySequence::Save);
421 fActionSave.setText("Save");
422 fActionSave.setDisabled(true);
423 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
424 fActionSaveAs.setText("Save As");
425 fActionSaveAs.setDisabled(true);
426
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000427 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
428 fActionShowDeletes.setText("Deleted Commands");
429
chudy@google.comc432f002012-07-10 13:19:25 +0000430 QIcon stepBack;
chudy@google.come504de02012-07-16 18:35:23 +0000431 stepBack.addFile(QString::fromUtf8(":/images/Ico/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000432 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000433 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000434 fActionStepBack.setIcon(stepBack);
435 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000436
chudy@google.comc432f002012-07-10 13:19:25 +0000437 QIcon stepForward;
chudy@google.come504de02012-07-16 18:35:23 +0000438 stepForward.addFile(QString::fromUtf8(":/images/Ico/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000439 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000440 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000441 fActionStepForward.setIcon(stepForward);
442 fActionStepForward.setText("Step Forward");
443
chudy@google.coma1226312012-07-26 20:26:44 +0000444 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
445 fActionZoomIn.setText("Zoom In");
446 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
447 fActionZoomOut.setText("Zoom Out");
448
chudy@google.comc432f002012-07-10 13:19:25 +0000449 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
450 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
451 fListWidget.setMaximumWidth(250);
452
453 fFilter.addItem("--Filter By Available Commands--");
454
455 fDirectoryWidget.setMaximumWidth(250);
456 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
457
458 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000459 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000460
chudy@google.comc432f002012-07-10 13:19:25 +0000461 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000462 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000463 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000464
chudy@google.comc432f002012-07-10 13:19:25 +0000465 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
466 QSizePolicy::Expanding);
467 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000468
chudy@google.comc432f002012-07-10 13:19:25 +0000469 fLeftColumnLayout.setSpacing(6);
470 fLeftColumnLayout.addWidget(&fListWidget);
471 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000472
chudy@google.comc432f002012-07-10 13:19:25 +0000473 fCanvasAndSettingsLayout.setSpacing(6);
474 fCanvasAndSettingsLayout.addWidget(&fCanvasWidget);
475 fCanvasAndSettingsLayout.addWidget(&fSettingsWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000476
chudy@google.comc432f002012-07-10 13:19:25 +0000477 fMainAndRightColumnLayout.setSpacing(6);
478 fMainAndRightColumnLayout.addLayout(&fCanvasAndSettingsLayout);
479 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000480
chudy@google.com2d537a12012-07-31 12:49:52 +0000481 fCentralWidget.setLayout(&fContainerLayout);
chudy@google.comc432f002012-07-10 13:19:25 +0000482 fContainerLayout.setSpacing(6);
483 fContainerLayout.setContentsMargins(11, 11, 11, 11);
484 fContainerLayout.addLayout(&fLeftColumnLayout);
485 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
486
487 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
488 SkDebuggerGUI->setStatusBar(&fStatusBar);
489
chudy@google.come504de02012-07-16 18:35:23 +0000490 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000491 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
492 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000493
chudy@google.com0ab03392012-07-28 20:16:11 +0000494 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000495
chudy@google.comc432f002012-07-10 13:19:25 +0000496 fToolBar.addAction(&fActionRewind);
497 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000498 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000499 fToolBar.addAction(&fActionStepForward);
500 fToolBar.addAction(&fActionPlay);
501 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000502 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000503 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000504 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000505 fToolBar.addWidget(&fFilter);
506 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000507
508 // TODO(chudy): Remove static call.
509 fDirectoryWidgetActive = false;
chudy@google.comea5488b2012-07-26 19:38:22 +0000510 fPath = "/usr/local/google/home/chudy/trunk-git/trunk/skp";
chudy@google.com902ebe52012-06-29 14:21:22 +0000511 setupDirectoryWidget();
512 fDirectoryWidgetActive = true;
513
chudy@google.com902ebe52012-06-29 14:21:22 +0000514 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000515 fMenuFile.setTitle("File");
516 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000517 fMenuFile.addAction(&fActionSave);
518 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000519 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000520
521 fMenuEdit.setTitle("Edit");
522 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000523 fMenuEdit.addAction(&fActionClearDeletes);
524 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000525 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000526 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000527
chudy@google.comc432f002012-07-10 13:19:25 +0000528 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000529 fMenuNavigate.addAction(&fActionRewind);
530 fMenuNavigate.addAction(&fActionStepBack);
531 fMenuNavigate.addAction(&fActionStepForward);
532 fMenuNavigate.addAction(&fActionPlay);
533 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000534 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000535
chudy@google.comc432f002012-07-10 13:19:25 +0000536 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000537 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000538 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000539 fMenuView.addAction(&fActionZoomIn);
540 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000541
542 fMenuWindows.setTitle("Window");
543 fMenuWindows.addAction(&fActionInspector);
544 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000545
546 fActionGoToLine.setText("Go to Line...");
547 fActionGoToLine.setDisabled(true);
548 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000549 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000550 fMenuBar.addAction(fMenuView.menuAction());
551 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000552 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000553
chudy@google.com7dcae672012-07-09 20:26:53 +0000554 fPause = false;
555
chudy@google.comc432f002012-07-10 13:19:25 +0000556 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000557 QMetaObject::connectSlotsByName(SkDebuggerGUI);
558}
559
560void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000561 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000562 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000563 fDirectoryWidget.clear();
564 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000565 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000566 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000567 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000568 }
569}
570
chudy@google.com902ebe52012-06-29 14:21:22 +0000571void SkDebuggerGUI::loadPicture(QString fileName) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000572 fLoading = true;
chudy@google.com607357f2012-08-07 16:12:23 +0000573 SkStream* stream = new SkFILEStream(fileName.toAscii());
574 SkPicture* picture = new SkPicture(stream);
575 fDebugger.loadPicture(picture);
576 SkSafeUnref(stream);
577 SkSafeUnref(picture);
578
579 std::vector<std::string> *cv = fDebugger.getDrawCommands();
580
chudy@google.com7dcae672012-07-09 20:26:53 +0000581 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000582 * of the visibility filter.
583 * TODO(chudy): This should be deprecated since fDebugger is not
584 * recreated.
585 * */
586 fDebugger.highlightCurrentCommand(fSettingsWidget.getVisibilityButton()->isChecked());
587
chudy@google.com902ebe52012-06-29 14:21:22 +0000588 setupListWidget(cv);
589 setupComboBox(cv);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000590 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000591 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000592 fMenuEdit.setDisabled(false);
593 fMenuNavigate.setDisabled(false);
594 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000595 fActionSave.setDisabled(false);
596 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000597 fLoading = false;
598 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000599}
600
601void SkDebuggerGUI::setupListWidget(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000602 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000603 int counter = 0;
604 for (unsigned int i = 0; i < cv->size(); i++) {
605 QListWidgetItem *item = new QListWidgetItem();
606 item->setData(Qt::DisplayRole, (*cv)[i].c_str());
607 item->setData(Qt::UserRole + 1, counter++);
chudy@google.comc432f002012-07-10 13:19:25 +0000608 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000609 }
610}
611
612void SkDebuggerGUI::setupComboBox(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000613 fFilter.clear();
614 fFilter.addItem("--Filter By Available Commands--");
chudy@google.com902ebe52012-06-29 14:21:22 +0000615
616 std::map<std::string, int> map;
617 for (unsigned int i = 0; i < cv->size(); i++) {
618 map[(*cv)[i]]++;
619 }
620
621 QString overview;
chudy@google.com607357f2012-08-07 16:12:23 +0000622 int counter = 0;
chudy@google.com7dcae672012-07-09 20:26:53 +0000623 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
624 ++it) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000625 overview.append((it->first).c_str());
626 overview.append(": ");
627 overview.append(QString::number(it->second));
628 overview.append("<br/>");
chudy@google.com7dcae672012-07-09 20:26:53 +0000629 counter += it->second;
chudy@google.comc432f002012-07-10 13:19:25 +0000630 fFilter.addItem((it->first).c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000631 }
632 QString total;
633 total.append("Total Draw Commands: ");
634 total.append(QString::number(counter));
635 total.append("<br/>");
636 overview.insert(0, total);
637
638 overview.append("<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +0000639 overview.append("SkPicture Width: ");
chudy@google.com902ebe52012-06-29 14:21:22 +0000640 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.com607357f2012-08-07 16:12:23 +0000641 overview.append(QString::number(fDebugger.pictureWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000642 overview.append("px<br/>");
chudy@google.com607357f2012-08-07 16:12:23 +0000643 overview.append("SkPicture Height: ");
644 overview.append(QString::number(fDebugger.pictureHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000645 overview.append("px");
chudy@google.comc432f002012-07-10 13:19:25 +0000646 fInspectorWidget.setOverviewText(overview);
chudy@google.com902ebe52012-06-29 14:21:22 +0000647
648 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000649 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000650 fFilter.model());
651 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
652 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000653 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
654 firstItem->setSelectable(false);
655}