blob: 601318334a02a5c61c3102bdbf73c269cbbb71cd [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
chudy@google.com902ebe52012-06-29 14:21:22 +00008#include "SkDebuggerGUI.h"
fmalita3f0424f2015-11-02 09:32:54 -08009#include "SkPicture.h"
kkinnunencfdc0e32015-01-13 22:49:02 -080010#include <QListWidgetItem>
11#include <QtGui>
robertphillips3e5c2b12015-03-23 05:46:51 -070012#include "sk_tool_utils.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000013
chudy@google.com902ebe52012-06-29 14:21:22 +000014SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000015 QMainWindow(parent)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000016 , fCentralSplitter(this)
chudy@google.com2d537a12012-07-31 12:49:52 +000017 , fStatusBar(this)
18 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000019 , fActionOpen(this)
20 , fActionBreakpoint(this)
21 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000022 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000023 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000024 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000025 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000026 , fActionDelete(this)
27 , fActionDirectory(this)
28 , fActionGoToLine(this)
29 , fActionInspector(this)
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000030 , fActionSettings(this)
chudy@google.comc432f002012-07-10 13:19:25 +000031 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000032 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000033 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000034 , fActionSave(this)
35 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000036 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000037 , fActionStepBack(this)
38 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000039 , fActionZoomIn(this)
40 , fActionZoomOut(this)
41 , fMapper(this)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000042 , fListWidget(&fCentralSplitter)
43 , fDirectoryWidget(&fCentralSplitter)
chudy@google.com607357f2012-08-07 16:12:23 +000044 , fCanvasWidget(this, &fDebugger)
kkinnunen63a47022014-12-30 23:03:56 -080045 , fDrawCommandGeometryWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000046 , fMenuBar(this)
47 , fMenuFile(this)
48 , fMenuNavigate(this)
49 , fMenuView(this)
chudy@google.comd3058f52012-07-19 13:41:27 +000050 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000051{
chudy@google.com902ebe52012-06-29 14:21:22 +000052 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000053 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
kkinnunen0cfeaf32015-01-07 07:33:46 -080054 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this,
55 SLOT(updateDrawCommandInfo()));
chudy@google.comc432f002012-07-10 13:19:25 +000056 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000057 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
58 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
djsollena7451862015-11-18 13:00:21 -080059 connect(&fDirectoryWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(populateDirectoryWidget()));
chudy@google.comc432f002012-07-10 13:19:25 +000060 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000061 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000062 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
63 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
64 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000065 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
66 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
67 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000068 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings()));
chudy@google.comea5488b2012-07-26 19:38:22 +000069 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
chudy@google.comc432f002012-07-10 13:19:25 +000070 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000071 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
72 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000073 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000074#if SK_SUPPORT_GPU
kkinnunen41c79cc2014-12-30 22:49:58 -080075 connect(&fSettingsWidget, SIGNAL(glSettingsChanged()), this, SLOT(actionGLSettingsChanged()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000076#endif
kkinnunen41c79cc2014-12-30 22:49:58 -080077 connect(&fSettingsWidget, SIGNAL(rasterSettingsChanged()), this, SLOT(actionRasterSettingsChanged()));
78 connect(&fSettingsWidget, SIGNAL(visualizationsChanged()), this, SLOT(actionVisualizationsChanged()));
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000079 connect(&fSettingsWidget, SIGNAL(texFilterSettingsChanged()), this, SLOT(actionTextureFilter()));
chudy@google.comea5488b2012-07-26 19:38:22 +000080 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000081 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000082 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000083 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
kkinnunen41c79cc2014-12-30 22:49:58 -080084 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(updateHit(int)));
chudy@google.comea5488b2012-07-26 19:38:22 +000085 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
kkinnunen63a47022014-12-30 23:03:56 -080086
chudy@google.com0ab03392012-07-28 20:16:11 +000087 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
88 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000089
bungeman@google.come8cc6e82013-01-17 16:30:56 +000090 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
91 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +000092
93 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
94 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +000095 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +000096
kkinnunen41c79cc2014-12-30 22:49:58 -080097 fViewStateFrame.setDisabled(true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000098 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +000099 fMenuEdit.setDisabled(true);
100 fMenuNavigate.setDisabled(true);
101 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000102}
chudy@google.com902ebe52012-06-29 14:21:22 +0000103
104void SkDebuggerGUI::actionBreakpoints() {
kkinnunenf3a9e992015-01-05 01:14:11 -0800105 bool breakpointsActivated = fActionBreakpoint.isChecked();
chudy@google.comc432f002012-07-10 13:19:25 +0000106 for (int row = 0; row < fListWidget.count(); row++) {
107 QListWidgetItem *item = fListWidget.item(row);
kkinnunenf3a9e992015-01-05 01:14:11 -0800108 item->setHidden(item->checkState() == Qt::Unchecked && breakpointsActivated);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000109 }
110}
chudy@google.com902ebe52012-06-29 14:21:22 +0000111
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000112void SkDebuggerGUI::showDeletes() {
kkinnunenf3a9e992015-01-05 01:14:11 -0800113 bool deletesActivated = fActionShowDeletes.isChecked();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000114 for (int row = 0; row < fListWidget.count(); row++) {
115 QListWidgetItem *item = fListWidget.item(row);
kkinnunenf3a9e992015-01-05 01:14:11 -0800116 item->setHidden(fDebugger.isCommandVisible(row) && deletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000117 }
118}
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000119
chudy@google.com902ebe52012-06-29 14:21:22 +0000120void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000121 for (int row = 0; row < fListWidget.count(); row++) {
122 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000123 }
124}
125
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000126void SkDebuggerGUI::actionClearBreakpoints() {
127 for (int row = 0; row < fListWidget.count(); row++) {
128 QListWidgetItem* item = fListWidget.item(row);
129 item->setCheckState(Qt::Unchecked);
130 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000131 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000132 }
133}
134
135void SkDebuggerGUI::actionClearDeletes() {
136 for (int row = 0; row < fListWidget.count(); row++) {
137 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000138 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000139 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000140 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000141 }
kkinnunencfdc0e32015-01-13 22:49:02 -0800142 this->updateImage();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000143}
144
chudy@google.com902ebe52012-06-29 14:21:22 +0000145void SkDebuggerGUI::actionClose() {
146 this->close();
147}
148
149void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000150
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000151 for (int row = 0; row < fListWidget.count(); ++row) {
152 QListWidgetItem* item = fListWidget.item(row);
153
154 if (!item->isSelected()) {
155 continue;
156 }
157
158 if (fDebugger.isCommandVisible(row)) {
159 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
160 fDebugger.setCommandVisible(row, false);
161 fSkipCommands[row] = true;
162 } else {
163 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
164 fDebugger.setCommandVisible(row, true);
165 fSkipCommands[row] = false;
166 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000167 }
168
kkinnunencfdc0e32015-01-13 22:49:02 -0800169 this->updateImage();
chudy@google.com902ebe52012-06-29 14:21:22 +0000170}
171
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000172#if SK_SUPPORT_GPU
kkinnunen41c79cc2014-12-30 22:49:58 -0800173void SkDebuggerGUI::actionGLSettingsChanged() {
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000174 bool isToggled = fSettingsWidget.isGLActive();
175 if (isToggled) {
176 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
177 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000178 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
179}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000180#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000181
chudy@google.com902ebe52012-06-29 14:21:22 +0000182void SkDebuggerGUI::actionInspector() {
kkinnunen41c79cc2014-12-30 22:49:58 -0800183 bool newState = !fInspectorWidget.isHidden();
184
185 fInspectorWidget.setHidden(newState);
186 fViewStateFrame.setHidden(newState);
kkinnunen63a47022014-12-30 23:03:56 -0800187 fDrawCommandGeometryWidget.setHidden(newState);
chudy@google.com902ebe52012-06-29 14:21:22 +0000188}
189
190void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000191 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000192 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000193 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000194 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000195 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000196 return;
197 }
198 }
chudy@google.comc432f002012-07-10 13:19:25 +0000199 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000200}
201
kkinnunen41c79cc2014-12-30 22:49:58 -0800202void SkDebuggerGUI::actionRasterSettingsChanged() {
203 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType,
204 !fSettingsWidget.isRasterEnabled());
kkinnunencfdc0e32015-01-13 22:49:02 -0800205 this->updateImage();
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000206}
207
kkinnunen41c79cc2014-12-30 22:49:58 -0800208void SkDebuggerGUI::actionVisualizationsChanged() {
209 fDebugger.setMegaViz(fSettingsWidget.isMegaVizEnabled());
210 fDebugger.setPathOps(fSettingsWidget.isPathOpsEnabled());
211 fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled());
robertphillipsf42fca42016-01-27 05:00:04 -0800212 fDebugger.setOverdrawViz(fSettingsWidget.isOverdrawVizEnabled());
kkinnunencfdc0e32015-01-13 22:49:02 -0800213 this->updateImage();
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000214}
215
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000216void SkDebuggerGUI::actionTextureFilter() {
reede7903c72015-03-16 10:26:13 -0700217 SkFilterQuality quality;
218 bool enabled = fSettingsWidget.getFilterOverride(&quality);
219 fDebugger.setTexFilterOverride(enabled, quality);
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000220 fCanvasWidget.update();
221}
222
chudy@google.com902ebe52012-06-29 14:21:22 +0000223void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000224 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000225}
226
chudy@google.com0ab03392012-07-28 20:16:11 +0000227void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000228 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000229 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000230 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000231 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000232}
233
234void SkDebuggerGUI::actionSaveAs() {
235 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
236 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000237 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000238 filename.append(".skp");
239 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000240 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000241}
242
chudy@google.com7dcae672012-07-09 20:26:53 +0000243void SkDebuggerGUI::actionScale(float scaleFactor) {
kkinnunen41c79cc2014-12-30 22:49:58 -0800244 fZoomBox.setText(QString::number(scaleFactor * 100, 'f', 0).append("%"));
chudy@google.com7dcae672012-07-09 20:26:53 +0000245}
246
chudy@google.com902ebe52012-06-29 14:21:22 +0000247void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000248 if (fSettingsWidget.isHidden()) {
249 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000250 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000251 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000252 }
253}
254
255void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000256 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000257 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000258 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000259 }
260}
261
262void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000263 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000264 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000265 QString curCount = QString::number(fListWidget.count());
266 if (currentRow < fListWidget.count() - 1) {
267 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000268 }
269}
270
chudy@google.coma9e937c2012-08-03 17:32:05 +0000271void SkDebuggerGUI::drawComplete() {
kkinnunencfdc0e32015-01-13 22:49:02 -0800272 SkString clipStack;
273 fDebugger.getClipStackText(&clipStack);
274 fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType);
275
chudy@google.com607357f2012-08-07 16:12:23 +0000276 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
277 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000278}
279
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000280void SkDebuggerGUI::saveToFile(const SkString& filename) {
281 SkFILEWStream file(filename.c_str());
robertphillips587ea712016-03-25 07:04:35 -0700282 sk_sp<SkPicture> copy(fDebugger.copyPicture());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000283
Hal Canarydb683012016-11-23 08:55:18 -0700284 sk_sp<SkPixelSerializer> serializer(sk_tool_utils::MakePixelSerializer());
Florin Malitaf5305862016-11-15 10:03:32 -0500285 copy->serialize(&file, serializer.get());
chudy@google.com0ab03392012-07-28 20:16:11 +0000286}
287
chudy@google.com902ebe52012-06-29 14:21:22 +0000288void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
djsollena7451862015-11-18 13:00:21 -0800289 if (item == nullptr) {
290 return;
291 }
292
293 SkString fileName(fPath.toAscii().data());
294 // don't add a '/' to files in the local directory
295 if (fileName.size() > 0) {
296 fileName.append("/");
297 }
298 fileName.append(item->text().toAscii().data());
299
300 if (!fileName.equals(fFileName)) {
301 fFileName = fileName;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000302 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000303 }
304}
305
306void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000307 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000308 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000309 openFile(temp);
310}
311
312void SkDebuggerGUI::openFile(const QString &filename) {
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000313 if (!filename.isEmpty()) {
314 QFileInfo pathInfo(filename);
315 loadPicture(SkString(filename.toAscii().data()));
316 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000317 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000318}
319
chudy@google.comc432f002012-07-10 13:19:25 +0000320void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000321 fPausedRow = fListWidget.currentRow();
kkinnunencfdc0e32015-01-13 22:49:02 -0800322 this->updateDrawCommandInfo();
chudy@google.com7dcae672012-07-09 20:26:53 +0000323}
324
kkinnunen0cfeaf32015-01-07 07:33:46 -0800325void SkDebuggerGUI::updateDrawCommandInfo() {
326 int currentRow = -1;
327 if (!fLoading) {
328 currentRow = fListWidget.currentRow();
329 }
330 if (currentRow == -1) {
331 fInspectorWidget.setText("", SkInspectorWidget::kDetail_TabType);
332 fInspectorWidget.setText("", SkInspectorWidget::kClipStack_TabType);
333 fCurrentCommandBox.setText("");
334 fDrawCommandGeometryWidget.setDrawCommandIndex(-1);
335 } else {
kkinnunencfdc0e32015-01-13 22:49:02 -0800336 this->updateImage();
337
kkinnunen0cfeaf32015-01-07 07:33:46 -0800338 const SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(currentRow);
chudy@google.comd3058f52012-07-19 13:41:27 +0000339
kkinnunen0cfeaf32015-01-07 07:33:46 -0800340 /* TODO(chudy): Add command type before parameters. Rename v
341 * to something more informative. */
342 if (currInfo) {
343 QString info;
344 info.append("<b>Parameters: </b><br/>");
345 for (int i = 0; i < currInfo->count(); i++) {
346 info.append(QString((*currInfo)[i]->c_str()));
347 info.append("<br/>");
chudy@google.comd3058f52012-07-19 13:41:27 +0000348 }
kkinnunen0cfeaf32015-01-07 07:33:46 -0800349 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comd3058f52012-07-19 13:41:27 +0000350 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000351
kkinnunen0cfeaf32015-01-07 07:33:46 -0800352 fCurrentCommandBox.setText(QString::number(currentRow));
353
354 fDrawCommandGeometryWidget.setDrawCommandIndex(currentRow);
355
356 fInspectorWidget.setDisabled(false);
357 fViewStateFrame.setDisabled(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000358 }
359}
360
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000361void SkDebuggerGUI::selectCommand(int command) {
kkinnunenf3a9e992015-01-05 01:14:11 -0800362 if (this->isPaused()) {
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000363 fListWidget.setCurrentRow(command);
364 }
365}
366
chudy@google.com902ebe52012-06-29 14:21:22 +0000367void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000368 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000369 if (item->checkState() == Qt::Unchecked) {
370 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000371 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000372 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000373 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000374 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000375 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000376 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000377 }
378}
379
380void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000381 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000382}
383
384void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000385 for (int row = 0; row < fListWidget.count(); row++) {
386 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000387 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000388 }
389}
390
391void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
392 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000393 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000394 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000395 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
396 SkDebuggerGUI->resize(1200, 1000);
397 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000398 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000399
chudy@google.come504de02012-07-16 18:35:23 +0000400 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000401 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000402
403 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000404 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000405 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000406 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000407 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000408 fActionBreakpoint.setText("Breakpoints");
kkinnunenf3a9e992015-01-05 01:14:11 -0800409 fActionBreakpoint.setCheckable(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000410
411 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000412 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000413 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000414 fActionCancel.setIcon(cancel);
415 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000416
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000417 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
418 fActionClearBreakpoints.setText("Clear Breakpoints");
419
420 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
421 fActionClearDeletes.setText("Clear Deletes");
422
chudy@google.come504de02012-07-16 18:35:23 +0000423 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000424 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000425
chudy@google.come504de02012-07-16 18:35:23 +0000426 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
427 fActionCreateBreakpoint.setText("Set Breakpoint");
428
429 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000430 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000431
chudy@google.come504de02012-07-16 18:35:23 +0000432 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
433 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000434
chudy@google.comc432f002012-07-10 13:19:25 +0000435 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000436 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000437 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000438 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000439 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000440 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000441
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000442 QIcon settings;
443 settings.addFile(QString::fromUtf8(":/inspector.png"),
444 QSize(), QIcon::Normal, QIcon::Off);
445 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
446 fActionSettings.setIcon(settings);
447 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000448
chudy@google.comc432f002012-07-10 13:19:25 +0000449 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000450 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000451 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000452 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000453 fActionPlay.setIcon(play);
454 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000455
chudy@google.come504de02012-07-16 18:35:23 +0000456 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000457 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000458 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000459 fActionPause.setShortcut(QKeySequence(tr("Space")));
460 fActionPause.setCheckable(true);
461 fActionPause.setIcon(pause);
462 fActionPause.setText("Pause");
463
chudy@google.comc432f002012-07-10 13:19:25 +0000464 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000465 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000466 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000467 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000468 fActionRewind.setIcon(rewind);
469 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000470
chudy@google.com0ab03392012-07-28 20:16:11 +0000471 fActionSave.setShortcut(QKeySequence::Save);
472 fActionSave.setText("Save");
473 fActionSave.setDisabled(true);
474 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
475 fActionSaveAs.setText("Save As");
476 fActionSaveAs.setDisabled(true);
477
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000478 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
479 fActionShowDeletes.setText("Deleted Commands");
kkinnunenf3a9e992015-01-05 01:14:11 -0800480 fActionShowDeletes.setCheckable(true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000481
chudy@google.comc432f002012-07-10 13:19:25 +0000482 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000483 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000484 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000485 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000486 fActionStepBack.setIcon(stepBack);
487 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000488
chudy@google.comc432f002012-07-10 13:19:25 +0000489 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000490 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000491 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000492 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000493 fActionStepForward.setIcon(stepForward);
494 fActionStepForward.setText("Step Forward");
495
chudy@google.coma1226312012-07-26 20:26:44 +0000496 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
497 fActionZoomIn.setText("Zoom In");
498 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
499 fActionZoomOut.setText("Zoom Out");
500
chudy@google.comc432f002012-07-10 13:19:25 +0000501 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
502 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000503 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000504
505 fFilter.addItem("--Filter By Available Commands--");
506
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000507 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000508 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
509
510 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000511 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000512
kkinnunen63a47022014-12-30 23:03:56 -0800513 fDrawCommandGeometryWidget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000514
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000515 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000516
kkinnunen41c79cc2014-12-30 22:49:58 -0800517 // View state group, part of inspector.
518 fViewStateFrame.setFrameStyle(QFrame::Panel);
519 fViewStateFrame.setLayout(&fViewStateFrameLayout);
520 fViewStateFrameLayout.addWidget(&fViewStateGroup);
kkinnunen63a47022014-12-30 23:03:56 -0800521 fViewStateGroup.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
kkinnunen41c79cc2014-12-30 22:49:58 -0800522 fViewStateGroup.setTitle("View");
523 fViewStateLayout.addRow("Zoom Level", &fZoomBox);
524 fZoomBox.setText("100%");
525 fZoomBox.setMinimumSize(QSize(50,25));
526 fZoomBox.setMaximumSize(QSize(50,25));
527 fZoomBox.setAlignment(Qt::AlignRight);
528 fZoomBox.setReadOnly(true);
529 fViewStateLayout.addRow("Command HitBox", &fCommandHitBox);
530 fCommandHitBox.setText("0");
531 fCommandHitBox.setMinimumSize(QSize(50,25));
532 fCommandHitBox.setMaximumSize(QSize(50,25));
533 fCommandHitBox.setAlignment(Qt::AlignRight);
534 fCommandHitBox.setReadOnly(true);
535 fViewStateLayout.addRow("Current Command", &fCurrentCommandBox);
536 fCurrentCommandBox.setText("0");
537 fCurrentCommandBox.setMinimumSize(QSize(50,25));
538 fCurrentCommandBox.setMaximumSize(QSize(50,25));
539 fCurrentCommandBox.setAlignment(Qt::AlignRight);
540 fCurrentCommandBox.setReadOnly(true);
541 fViewStateGroup.setLayout(&fViewStateLayout);
542 fSettingsAndImageLayout.addWidget(&fViewStateFrame);
543
kkinnunen63a47022014-12-30 23:03:56 -0800544 fDrawCommandGeometryWidget.setToolTip("Current Command Geometry");
545 fSettingsAndImageLayout.addWidget(&fDrawCommandGeometryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000546
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000547 fLeftColumnSplitter.addWidget(&fListWidget);
548 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
549 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000550
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000551 fCanvasSettingsAndImageLayout.setSpacing(6);
kkinnunen41c79cc2014-12-30 22:49:58 -0800552 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget, 1);
553 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout, 0);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000554
chudy@google.comc432f002012-07-10 13:19:25 +0000555 fMainAndRightColumnLayout.setSpacing(6);
kkinnunen7c339ae2015-01-02 06:35:43 -0800556 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout, 1);
557 fMainAndRightColumnLayout.addWidget(&fInspectorWidget, 0);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000558 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000559
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000560 fCentralSplitter.addWidget(&fLeftColumnSplitter);
561 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
562 fCentralSplitter.setStretchFactor(0, 0);
563 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000564
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000565 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000566 SkDebuggerGUI->setStatusBar(&fStatusBar);
567
chudy@google.come504de02012-07-16 18:35:23 +0000568 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000569 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
570 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000571
chudy@google.com0ab03392012-07-28 20:16:11 +0000572 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000573
chudy@google.comc432f002012-07-10 13:19:25 +0000574 fToolBar.addAction(&fActionRewind);
575 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000576 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000577 fToolBar.addAction(&fActionStepForward);
578 fToolBar.addAction(&fActionPlay);
579 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000580 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000581 fToolBar.addAction(&fActionSettings);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000582
583 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000584 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000585 fToolBar.addWidget(&fFilter);
586 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000587
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000588 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000589 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000590
chudy@google.com902ebe52012-06-29 14:21:22 +0000591 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000592 fMenuFile.setTitle("File");
593 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000594 fMenuFile.addAction(&fActionSave);
595 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000596 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000597
598 fMenuEdit.setTitle("Edit");
599 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000600 fMenuEdit.addAction(&fActionClearDeletes);
601 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000602 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000603 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000604
chudy@google.comc432f002012-07-10 13:19:25 +0000605 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000606 fMenuNavigate.addAction(&fActionRewind);
607 fMenuNavigate.addAction(&fActionStepBack);
608 fMenuNavigate.addAction(&fActionStepForward);
609 fMenuNavigate.addAction(&fActionPlay);
610 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000611 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000612
chudy@google.comc432f002012-07-10 13:19:25 +0000613 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000614 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000615 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000616 fMenuView.addAction(&fActionZoomIn);
617 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000618
619 fMenuWindows.setTitle("Window");
620 fMenuWindows.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000621 fMenuWindows.addAction(&fActionSettings);
chudy@google.come504de02012-07-16 18:35:23 +0000622 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000623
624 fActionGoToLine.setText("Go to Line...");
625 fActionGoToLine.setDisabled(true);
626 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000627 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000628 fMenuBar.addAction(fMenuView.menuAction());
629 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000630 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000631
chudy@google.comc432f002012-07-10 13:19:25 +0000632 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000633 QMetaObject::connectSlotsByName(SkDebuggerGUI);
634}
635
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000636void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
637 fPath = path;
djsollena7451862015-11-18 13:00:21 -0800638 populateDirectoryWidget();
639
640 // clear the existing watched directory and setup a new directory to watch
641 if (!fDirectoryWatcher.directories().empty()) {
642 fDirectoryWatcher.removePaths(fDirectoryWatcher.directories());
643 }
644 if (!path.isEmpty()) {
645 fDirectoryWatcher.addPath(fPath);
646 }
647}
648
649void SkDebuggerGUI::populateDirectoryWidget() {
650 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000651 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000652 const QStringList files = dir.entryList();
djsollena7451862015-11-18 13:00:21 -0800653
654 // check if a file has been removed
655 for (int i = fDirectoryWidget.count() - 1; i >= 0; i--) {
656 QListWidgetItem* item = fDirectoryWidget.item(i);
657 if (!files.contains(item->text())) {
658 fDirectoryWidget.removeItemWidget(item);
659 delete item;
660 }
661 }
662
663 // add any new files
robertphillips9ea8acd2016-03-01 09:34:38 -0800664 Q_FOREACH (QString f, files) {
djsollena7451862015-11-18 13:00:21 -0800665 if (f.contains(r) && fDirectoryWidget.findItems(f, Qt::MatchExactly).size() == 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000666 fDirectoryWidget.addItem(f);
djsollena7451862015-11-18 13:00:21 -0800667 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000668 }
669}
670
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000671void SkDebuggerGUI::loadPicture(const SkString& fileName) {
672 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000673 fLoading = true;
Florin Malitaf5305862016-11-15 10:03:32 -0500674 SkFILEStream stream(fileName.c_str());
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000675
Florin Malitaf5305862016-11-15 10:03:32 -0500676 auto picture = SkPicture::MakeFromStream(&stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000677
halcanary96fcdcc2015-08-27 07:41:13 -0700678 if (nullptr == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000679 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000680 return;
681 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000682
chudy@google.com686e6802012-08-14 16:00:32 +0000683 fCanvasWidget.resetWidgetTransform();
reedca2622b2016-03-18 07:25:55 -0700684 fDebugger.loadPicture(picture.get());
chudy@google.com4c7962e2012-08-14 19:38:31 +0000685
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000686 fSkipCommands.setCount(fDebugger.getSize());
687 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000688 fSkipCommands[i] = false;
689 }
690
reedca2622b2016-03-18 07:25:55 -0700691 picture.reset();
chudy@google.com607357f2012-08-07 16:12:23 +0000692
chudy@google.com7dcae672012-07-09 20:26:53 +0000693 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000694 * of the visibility filter.
695 * TODO(chudy): This should be deprecated since fDebugger is not
696 * recreated.
697 * */
kkinnunen41c79cc2014-12-30 22:49:58 -0800698 fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled());
chudy@google.com607357f2012-08-07 16:12:23 +0000699
kkinnunen5037e9d2014-12-30 07:22:58 -0800700 this->setupListWidget();
701 this->setupComboBox();
halcanary96fcdcc2015-08-27 07:41:13 -0700702 this->setupOverviewText(nullptr, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000703 fInspectorWidget.setDisabled(false);
kkinnunen41c79cc2014-12-30 22:49:58 -0800704 fViewStateFrame.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000705 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000706 fMenuEdit.setDisabled(false);
707 fMenuNavigate.setDisabled(false);
708 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000709 fActionSave.setDisabled(false);
710 fActionSaveAs.setDisabled(false);
kkinnunenf3a9e992015-01-05 01:14:11 -0800711 fActionPause.setChecked(false);
kkinnunen0cfeaf32015-01-07 07:33:46 -0800712 fDrawCommandGeometryWidget.setDrawCommandIndex(-1);
713
chudy@google.comd3058f52012-07-19 13:41:27 +0000714 fLoading = false;
715 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000716}
717
kkinnunen5037e9d2014-12-30 07:22:58 -0800718void SkDebuggerGUI::setupListWidget() {
robertphillips546db462015-03-26 10:08:04 -0700719
720 SkASSERT(!strcmp("Save",
721 SkDrawCommand::GetCommandString(SkDrawCommand::kSave_OpType)));
722 SkASSERT(!strcmp("SaveLayer",
723 SkDrawCommand::GetCommandString(SkDrawCommand::kSaveLayer_OpType)));
724 SkASSERT(!strcmp("Restore",
725 SkDrawCommand::GetCommandString(SkDrawCommand::kRestore_OpType)));
fmalita160ebb22015-04-01 20:58:37 -0700726 SkASSERT(!strcmp("BeginDrawPicture",
727 SkDrawCommand::GetCommandString(SkDrawCommand::kBeginDrawPicture_OpType)));
728 SkASSERT(!strcmp("EndDrawPicture",
729 SkDrawCommand::GetCommandString(SkDrawCommand::kEndDrawPicture_OpType)));
robertphillips546db462015-03-26 10:08:04 -0700730
chudy@google.comc432f002012-07-10 13:19:25 +0000731 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000732 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000733 int indent = 0;
kkinnunen5037e9d2014-12-30 07:22:58 -0800734 for (int i = 0; i < fDebugger.getSize(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000735 QListWidgetItem *item = new QListWidgetItem();
kkinnunen5037e9d2014-12-30 07:22:58 -0800736 SkDrawCommand* command = fDebugger.getDrawCommandAt(i);
737 SkString commandString = command->toString();
738 item->setData(Qt::DisplayRole, commandString.c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000739 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000740
kkinnunen5037e9d2014-12-30 07:22:58 -0800741 if (0 == strcmp("Restore", commandString.c_str()) ||
fmalita160ebb22015-04-01 20:58:37 -0700742 0 == strcmp("EndDrawPicture", commandString.c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000743 indent -= 10;
744 }
745
746 item->setData(Qt::UserRole + 3, indent);
747
kkinnunen5037e9d2014-12-30 07:22:58 -0800748 if (0 == strcmp("Save", commandString.c_str()) ||
robertphillips546db462015-03-26 10:08:04 -0700749 0 == strcmp("SaveLayer", commandString.c_str()) ||
fmalita160ebb22015-04-01 20:58:37 -0700750 0 == strcmp("BeginDrawPicture", commandString.c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000751 indent += 10;
752 }
753
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000754 item->setData(Qt::UserRole + 4, -1);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000755
chudy@google.comc432f002012-07-10 13:19:25 +0000756 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000757 }
758}
759
skia.committer@gmail.com91274b92013-03-13 07:01:04 +0000760void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000761 double totTime,
762 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000763 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000764 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000765 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000766}
767
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000768
kkinnunen5037e9d2014-12-30 07:22:58 -0800769void SkDebuggerGUI::setupComboBox() {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000770 fFilter.clear();
771 fFilter.addItem("--Filter By Available Commands--");
772
773 std::map<std::string, int> map;
kkinnunen5037e9d2014-12-30 07:22:58 -0800774 for (int i = 0; i < fDebugger.getSize(); i++) {
775 map[fDebugger.getDrawCommandAt(i)->toString().c_str()]++;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000776 }
777
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000778 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000779 ++it) {
780 fFilter.addItem((it->first).c_str());
781 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000782
783 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000784 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000785 fFilter.model());
786 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
787 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000788 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
789 firstItem->setSelectable(false);
790}
kkinnunen41c79cc2014-12-30 22:49:58 -0800791
kkinnunencfdc0e32015-01-13 22:49:02 -0800792void SkDebuggerGUI::updateImage() {
793 if (this->isPaused()) {
794 fCanvasWidget.drawTo(fPausedRow);
795 } else {
796 fCanvasWidget.drawTo(fListWidget.currentRow());
797 }
798}
799
kkinnunen41c79cc2014-12-30 22:49:58 -0800800void SkDebuggerGUI::updateHit(int newHit) {
801 fCommandHitBox.setText(QString::number(newHit));
802}
803