blob: b4eb0c7e36c2e755cff2bf699562a19b8c5f4bc1 [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"
robertphillips2de59392015-02-11 13:18:14 -08009#include "SkPictureData.h"
10#include "SkPicturePlayback.h"
11#include "SkPictureRecord.h"
kkinnunencfdc0e32015-01-13 22:49:02 -080012#include <QListWidgetItem>
13#include <QtGui>
robertphillips3e5c2b12015-03-23 05:46:51 -070014#include "sk_tool_utils.h"
robertphillips@google.come174a8b2012-11-27 16:04:42 +000015
chudy@google.com902ebe52012-06-29 14:21:22 +000016SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000017 QMainWindow(parent)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000018 , fCentralSplitter(this)
chudy@google.com2d537a12012-07-31 12:49:52 +000019 , fStatusBar(this)
20 , fToolBar(this)
chudy@google.comc432f002012-07-10 13:19:25 +000021 , fActionOpen(this)
22 , fActionBreakpoint(this)
23 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000024 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000025 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000026 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000027 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000028 , fActionDelete(this)
29 , fActionDirectory(this)
30 , fActionGoToLine(this)
31 , fActionInspector(this)
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000032 , fActionSettings(this)
chudy@google.comc432f002012-07-10 13:19:25 +000033 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000034 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000035 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000036 , fActionSave(this)
37 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000038 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000039 , fActionStepBack(this)
40 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000041 , fActionZoomIn(this)
42 , fActionZoomOut(this)
43 , fMapper(this)
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +000044 , fListWidget(&fCentralSplitter)
45 , fDirectoryWidget(&fCentralSplitter)
chudy@google.com607357f2012-08-07 16:12:23 +000046 , fCanvasWidget(this, &fDebugger)
kkinnunen63a47022014-12-30 23:03:56 -080047 , fDrawCommandGeometryWidget(&fDebugger)
chudy@google.comc432f002012-07-10 13:19:25 +000048 , fMenuBar(this)
49 , fMenuFile(this)
50 , fMenuNavigate(this)
51 , fMenuView(this)
chudy@google.comd3058f52012-07-19 13:41:27 +000052 , fLoading(false)
chudy@google.comc432f002012-07-10 13:19:25 +000053{
chudy@google.com902ebe52012-06-29 14:21:22 +000054 setupUi(this);
robertphillips@google.comdd4b7452013-01-22 19:38:46 +000055 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
kkinnunen0cfeaf32015-01-07 07:33:46 -080056 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this,
57 SLOT(updateDrawCommandInfo()));
chudy@google.comc432f002012-07-10 13:19:25 +000058 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.comea5488b2012-07-26 19:38:22 +000059 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory()));
60 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000061 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000062 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000063 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
64 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
65 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000066 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
67 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
68 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +000069 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings()));
chudy@google.comea5488b2012-07-26 19:38:22 +000070 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
chudy@google.comc432f002012-07-10 13:19:25 +000071 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000072 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
73 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000074 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000075#if SK_SUPPORT_GPU
kkinnunen41c79cc2014-12-30 22:49:58 -080076 connect(&fSettingsWidget, SIGNAL(glSettingsChanged()), this, SLOT(actionGLSettingsChanged()));
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +000077#endif
kkinnunen41c79cc2014-12-30 22:49:58 -080078 connect(&fSettingsWidget, SIGNAL(rasterSettingsChanged()), this, SLOT(actionRasterSettingsChanged()));
79 connect(&fSettingsWidget, SIGNAL(visualizationsChanged()), this, SLOT(actionVisualizationsChanged()));
robertphillips@google.com32bbcf82013-10-17 17:56:10 +000080 connect(&fSettingsWidget, SIGNAL(texFilterSettingsChanged()), this, SLOT(actionTextureFilter()));
chudy@google.comea5488b2012-07-26 19:38:22 +000081 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000082 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000083 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000084 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
kkinnunen41c79cc2014-12-30 22:49:58 -080085 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(updateHit(int)));
chudy@google.comea5488b2012-07-26 19:38:22 +000086 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
kkinnunen63a47022014-12-30 23:03:56 -080087
chudy@google.com0ab03392012-07-28 20:16:11 +000088 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
89 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000090
bungeman@google.come8cc6e82013-01-17 16:30:56 +000091 fMapper.setMapping(&fActionZoomIn, SkCanvasWidget::kIn_ZoomCommand);
92 fMapper.setMapping(&fActionZoomOut, SkCanvasWidget::kOut_ZoomCommand);
chudy@google.coma1226312012-07-26 20:26:44 +000093
94 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
95 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
bungeman@google.come8cc6e82013-01-17 16:30:56 +000096 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(zoom(int)));
chudy@google.coma1226312012-07-26 20:26:44 +000097
kkinnunen41c79cc2014-12-30 22:49:58 -080098 fViewStateFrame.setDisabled(true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000099 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +0000100 fMenuEdit.setDisabled(true);
101 fMenuNavigate.setDisabled(true);
102 fMenuView.setDisabled(true);
chudy@google.combbad34d2012-08-13 14:26:36 +0000103}
chudy@google.com902ebe52012-06-29 14:21:22 +0000104
105void SkDebuggerGUI::actionBreakpoints() {
kkinnunenf3a9e992015-01-05 01:14:11 -0800106 bool breakpointsActivated = fActionBreakpoint.isChecked();
chudy@google.comc432f002012-07-10 13:19:25 +0000107 for (int row = 0; row < fListWidget.count(); row++) {
108 QListWidgetItem *item = fListWidget.item(row);
kkinnunenf3a9e992015-01-05 01:14:11 -0800109 item->setHidden(item->checkState() == Qt::Unchecked && breakpointsActivated);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000110 }
111}
chudy@google.com902ebe52012-06-29 14:21:22 +0000112
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000113void SkDebuggerGUI::showDeletes() {
kkinnunenf3a9e992015-01-05 01:14:11 -0800114 bool deletesActivated = fActionShowDeletes.isChecked();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000115 for (int row = 0; row < fListWidget.count(); row++) {
116 QListWidgetItem *item = fListWidget.item(row);
kkinnunenf3a9e992015-01-05 01:14:11 -0800117 item->setHidden(fDebugger.isCommandVisible(row) && deletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000118 }
119}
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000120
chudy@google.com902ebe52012-06-29 14:21:22 +0000121void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000122 for (int row = 0; row < fListWidget.count(); row++) {
123 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000124 }
125}
126
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000127void SkDebuggerGUI::actionClearBreakpoints() {
128 for (int row = 0; row < fListWidget.count(); row++) {
129 QListWidgetItem* item = fListWidget.item(row);
130 item->setCheckState(Qt::Unchecked);
131 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000132 QPixmap(":/blank.png"));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000133 }
134}
135
136void SkDebuggerGUI::actionClearDeletes() {
137 for (int row = 0; row < fListWidget.count(); row++) {
138 QListWidgetItem* item = fListWidget.item(row);
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000139 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
chudy@google.com607357f2012-08-07 16:12:23 +0000140 fDebugger.setCommandVisible(row, true);
robertphillips@google.com5f971142012-12-07 20:48:56 +0000141 fSkipCommands[row] = false;
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000142 }
kkinnunencfdc0e32015-01-13 22:49:02 -0800143 this->updateImage();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000144}
145
chudy@google.com902ebe52012-06-29 14:21:22 +0000146void SkDebuggerGUI::actionClose() {
147 this->close();
148}
149
150void SkDebuggerGUI::actionDelete() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000151
robertphillips@google.comdd4b7452013-01-22 19:38:46 +0000152 for (int row = 0; row < fListWidget.count(); ++row) {
153 QListWidgetItem* item = fListWidget.item(row);
154
155 if (!item->isSelected()) {
156 continue;
157 }
158
159 if (fDebugger.isCommandVisible(row)) {
160 item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
161 fDebugger.setCommandVisible(row, false);
162 fSkipCommands[row] = true;
163 } else {
164 item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
165 fDebugger.setCommandVisible(row, true);
166 fSkipCommands[row] = false;
167 }
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000168 }
169
kkinnunencfdc0e32015-01-13 22:49:02 -0800170 this->updateImage();
chudy@google.com902ebe52012-06-29 14:21:22 +0000171}
172
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000173#if SK_SUPPORT_GPU
kkinnunen41c79cc2014-12-30 22:49:58 -0800174void SkDebuggerGUI::actionGLSettingsChanged() {
commit-bot@chromium.orgfde1e7c2013-08-02 13:59:50 +0000175 bool isToggled = fSettingsWidget.isGLActive();
176 if (isToggled) {
177 fCanvasWidget.setGLSampleCount(fSettingsWidget.getGLSampleCount());
178 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000179 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
180}
robertphillips@google.come8fe4bc2013-02-13 13:26:13 +0000181#endif
chudy@google.comea5488b2012-07-26 19:38:22 +0000182
chudy@google.com902ebe52012-06-29 14:21:22 +0000183void SkDebuggerGUI::actionInspector() {
kkinnunen41c79cc2014-12-30 22:49:58 -0800184 bool newState = !fInspectorWidget.isHidden();
185
186 fInspectorWidget.setHidden(newState);
187 fViewStateFrame.setHidden(newState);
kkinnunen63a47022014-12-30 23:03:56 -0800188 fDrawCommandGeometryWidget.setHidden(newState);
chudy@google.com902ebe52012-06-29 14:21:22 +0000189}
190
191void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000192 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000193 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000194 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000195 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000196 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000197 return;
198 }
199 }
chudy@google.comc432f002012-07-10 13:19:25 +0000200 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000201}
202
kkinnunen41c79cc2014-12-30 22:49:58 -0800203void SkDebuggerGUI::actionRasterSettingsChanged() {
204 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType,
205 !fSettingsWidget.isRasterEnabled());
206 fDebugger.setOverdrawViz(fSettingsWidget.isOverdrawVizEnabled());
kkinnunencfdc0e32015-01-13 22:49:02 -0800207 this->updateImage();
robertphillips@google.comf4741c12013-02-06 20:13:54 +0000208}
209
kkinnunen41c79cc2014-12-30 22:49:58 -0800210void SkDebuggerGUI::actionVisualizationsChanged() {
211 fDebugger.setMegaViz(fSettingsWidget.isMegaVizEnabled());
212 fDebugger.setPathOps(fSettingsWidget.isPathOpsEnabled());
213 fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled());
kkinnunencfdc0e32015-01-13 22:49:02 -0800214 this->updateImage();
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000215}
216
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000217void SkDebuggerGUI::actionTextureFilter() {
reede7903c72015-03-16 10:26:13 -0700218 SkFilterQuality quality;
219 bool enabled = fSettingsWidget.getFilterOverride(&quality);
220 fDebugger.setTexFilterOverride(enabled, quality);
robertphillips@google.com32bbcf82013-10-17 17:56:10 +0000221 fCanvasWidget.update();
222}
223
chudy@google.com902ebe52012-06-29 14:21:22 +0000224void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000225 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000226}
227
chudy@google.com0ab03392012-07-28 20:16:11 +0000228void SkDebuggerGUI::actionSave() {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000229 fFileName = fPath.toAscii().data();
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000230 fFileName.append("/");
robertphillips@google.come219baf2013-01-28 19:25:43 +0000231 fFileName.append(fDirectoryWidget.currentItem()->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000232 saveToFile(fFileName);
chudy@google.com0ab03392012-07-28 20:16:11 +0000233}
234
235void SkDebuggerGUI::actionSaveAs() {
236 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
237 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000238 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000239 filename.append(".skp");
240 }
djsollen@google.comc3c82162012-11-13 18:35:10 +0000241 saveToFile(SkString(filename.toAscii().data()));
chudy@google.com0ab03392012-07-28 20:16:11 +0000242}
243
chudy@google.com7dcae672012-07-09 20:26:53 +0000244void SkDebuggerGUI::actionScale(float scaleFactor) {
kkinnunen41c79cc2014-12-30 22:49:58 -0800245 fZoomBox.setText(QString::number(scaleFactor * 100, 'f', 0).append("%"));
chudy@google.com7dcae672012-07-09 20:26:53 +0000246}
247
chudy@google.com902ebe52012-06-29 14:21:22 +0000248void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000249 if (fSettingsWidget.isHidden()) {
250 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000251 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000252 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000253 }
254}
255
256void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000257 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000258 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000259 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000260 }
261}
262
263void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000264 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000265 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000266 QString curCount = QString::number(fListWidget.count());
267 if (currentRow < fListWidget.count() - 1) {
268 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000269 }
270}
271
chudy@google.coma9e937c2012-08-03 17:32:05 +0000272void SkDebuggerGUI::drawComplete() {
kkinnunencfdc0e32015-01-13 22:49:02 -0800273 SkString clipStack;
274 fDebugger.getClipStackText(&clipStack);
275 fInspectorWidget.setText(clipStack.c_str(), SkInspectorWidget::kClipStack_TabType);
276
chudy@google.com607357f2012-08-07 16:12:23 +0000277 fInspectorWidget.setMatrix(fDebugger.getCurrentMatrix());
278 fInspectorWidget.setClip(fDebugger.getCurrentClip());
chudy@google.coma9e937c2012-08-03 17:32:05 +0000279}
280
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000281void SkDebuggerGUI::saveToFile(const SkString& filename) {
282 SkFILEWStream file(filename.c_str());
robertphillips@google.com25bc2f82013-01-22 18:03:56 +0000283 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
284
robertphillips3e5c2b12015-03-23 05:46:51 -0700285 sk_tool_utils::PngPixelSerializer serializer;
286 copy->serialize(&file, &serializer);
chudy@google.com0ab03392012-07-28 20:16:11 +0000287}
288
chudy@google.com902ebe52012-06-29 14:21:22 +0000289void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
290 if (fDirectoryWidgetActive) {
robertphillips@google.come219baf2013-01-28 19:25:43 +0000291 fFileName = fPath.toAscii().data();
jvanverth@google.com0ac6f162013-02-05 19:44:07 +0000292 // don't add a '/' to files in the local directory
293 if (fFileName.size() > 0) {
294 fFileName.append("/");
295 }
robertphillips@google.come219baf2013-01-28 19:25:43 +0000296 fFileName.append(item->text().toAscii().data());
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000297 loadPicture(fFileName);
chudy@google.com902ebe52012-06-29 14:21:22 +0000298 }
299}
300
301void SkDebuggerGUI::openFile() {
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000302 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
chudy@google.com7dcae672012-07-09 20:26:53 +0000303 tr("Files (*.*)"));
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000304 openFile(temp);
305}
306
307void SkDebuggerGUI::openFile(const QString &filename) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000308 fDirectoryWidgetActive = false;
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000309 if (!filename.isEmpty()) {
310 QFileInfo pathInfo(filename);
311 loadPicture(SkString(filename.toAscii().data()));
312 setupDirectoryWidget(pathInfo.path());
chudy@google.com902ebe52012-06-29 14:21:22 +0000313 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000314 fDirectoryWidgetActive = true;
315}
316
chudy@google.comc432f002012-07-10 13:19:25 +0000317void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com607357f2012-08-07 16:12:23 +0000318 fPausedRow = fListWidget.currentRow();
kkinnunencfdc0e32015-01-13 22:49:02 -0800319 this->updateDrawCommandInfo();
chudy@google.com7dcae672012-07-09 20:26:53 +0000320}
321
kkinnunen0cfeaf32015-01-07 07:33:46 -0800322void SkDebuggerGUI::updateDrawCommandInfo() {
323 int currentRow = -1;
324 if (!fLoading) {
325 currentRow = fListWidget.currentRow();
326 }
327 if (currentRow == -1) {
328 fInspectorWidget.setText("", SkInspectorWidget::kDetail_TabType);
329 fInspectorWidget.setText("", SkInspectorWidget::kClipStack_TabType);
330 fCurrentCommandBox.setText("");
331 fDrawCommandGeometryWidget.setDrawCommandIndex(-1);
332 } else {
kkinnunencfdc0e32015-01-13 22:49:02 -0800333 this->updateImage();
334
kkinnunen0cfeaf32015-01-07 07:33:46 -0800335 const SkTDArray<SkString*> *currInfo = fDebugger.getCommandInfo(currentRow);
chudy@google.comd3058f52012-07-19 13:41:27 +0000336
kkinnunen0cfeaf32015-01-07 07:33:46 -0800337 /* TODO(chudy): Add command type before parameters. Rename v
338 * to something more informative. */
339 if (currInfo) {
340 QString info;
341 info.append("<b>Parameters: </b><br/>");
342 for (int i = 0; i < currInfo->count(); i++) {
343 info.append(QString((*currInfo)[i]->c_str()));
344 info.append("<br/>");
chudy@google.comd3058f52012-07-19 13:41:27 +0000345 }
kkinnunen0cfeaf32015-01-07 07:33:46 -0800346 fInspectorWidget.setText(info, SkInspectorWidget::kDetail_TabType);
chudy@google.comd3058f52012-07-19 13:41:27 +0000347 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000348
kkinnunen0cfeaf32015-01-07 07:33:46 -0800349 fCurrentCommandBox.setText(QString::number(currentRow));
350
351 fDrawCommandGeometryWidget.setDrawCommandIndex(currentRow);
352
353 fInspectorWidget.setDisabled(false);
354 fViewStateFrame.setDisabled(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000355 }
356}
357
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000358void SkDebuggerGUI::selectCommand(int command) {
kkinnunenf3a9e992015-01-05 01:14:11 -0800359 if (this->isPaused()) {
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000360 fListWidget.setCurrentRow(command);
361 }
362}
363
chudy@google.com902ebe52012-06-29 14:21:22 +0000364void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000365 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000366 if (item->checkState() == Qt::Unchecked) {
367 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000368 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000369 QPixmap(":/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000370 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000371 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000372 item->setData(Qt::DecorationRole,
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000373 QPixmap(":/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000374 }
375}
376
377void SkDebuggerGUI::toggleDirectory() {
chudy@google.com607357f2012-08-07 16:12:23 +0000378 fDirectoryWidget.setHidden(!fDirectoryWidget.isHidden());
chudy@google.com902ebe52012-06-29 14:21:22 +0000379}
380
381void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000382 for (int row = 0; row < fListWidget.count(); row++) {
383 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com607357f2012-08-07 16:12:23 +0000384 item->setHidden(item->text() != string);
chudy@google.com902ebe52012-06-29 14:21:22 +0000385 }
386}
387
388void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
389 QIcon windowIcon;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000390 windowIcon.addFile(QString::fromUtf8(":/skia.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000391 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000392 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
393 SkDebuggerGUI->resize(1200, 1000);
394 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000395 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000396
chudy@google.come504de02012-07-16 18:35:23 +0000397 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000398 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000399
400 QIcon breakpoint;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000401 breakpoint.addFile(QString::fromUtf8(":/breakpoint.png"),
chudy@google.com7dcae672012-07-09 20:26:53 +0000402 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000403 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000404 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000405 fActionBreakpoint.setText("Breakpoints");
kkinnunenf3a9e992015-01-05 01:14:11 -0800406 fActionBreakpoint.setCheckable(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000407
408 QIcon cancel;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000409 cancel.addFile(QString::fromUtf8(":/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000410 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000411 fActionCancel.setIcon(cancel);
412 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000413
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000414 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
415 fActionClearBreakpoints.setText("Clear Breakpoints");
416
417 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
418 fActionClearDeletes.setText("Clear Deletes");
419
chudy@google.come504de02012-07-16 18:35:23 +0000420 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000421 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000422
chudy@google.come504de02012-07-16 18:35:23 +0000423 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
424 fActionCreateBreakpoint.setText("Set Breakpoint");
425
426 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000427 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000428
chudy@google.come504de02012-07-16 18:35:23 +0000429 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
430 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000431
chudy@google.comc432f002012-07-10 13:19:25 +0000432 QIcon inspector;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000433 inspector.addFile(QString::fromUtf8(":/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000434 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000435 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000436 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000437 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000438
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000439 QIcon settings;
440 settings.addFile(QString::fromUtf8(":/inspector.png"),
441 QSize(), QIcon::Normal, QIcon::Off);
442 fActionSettings.setShortcut(QKeySequence(tr("Ctrl+G")));
443 fActionSettings.setIcon(settings);
444 fActionSettings.setText("Settings");
skia.committer@gmail.com0d55dd72013-07-02 07:00:59 +0000445
chudy@google.comc432f002012-07-10 13:19:25 +0000446 QIcon play;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000447 play.addFile(QString::fromUtf8(":/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000448 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000449 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000450 fActionPlay.setIcon(play);
451 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000452
chudy@google.come504de02012-07-16 18:35:23 +0000453 QIcon pause;
robertphillips@google.comd1636362012-11-19 18:25:09 +0000454 pause.addFile(QString::fromUtf8(":/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000455 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000456 fActionPause.setShortcut(QKeySequence(tr("Space")));
457 fActionPause.setCheckable(true);
458 fActionPause.setIcon(pause);
459 fActionPause.setText("Pause");
460
chudy@google.comc432f002012-07-10 13:19:25 +0000461 QIcon rewind;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000462 rewind.addFile(QString::fromUtf8(":/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000463 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000464 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000465 fActionRewind.setIcon(rewind);
466 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000467
chudy@google.com0ab03392012-07-28 20:16:11 +0000468 fActionSave.setShortcut(QKeySequence::Save);
469 fActionSave.setText("Save");
470 fActionSave.setDisabled(true);
471 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
472 fActionSaveAs.setText("Save As");
473 fActionSaveAs.setDisabled(true);
474
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000475 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
476 fActionShowDeletes.setText("Deleted Commands");
kkinnunenf3a9e992015-01-05 01:14:11 -0800477 fActionShowDeletes.setCheckable(true);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000478
chudy@google.comc432f002012-07-10 13:19:25 +0000479 QIcon stepBack;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000480 stepBack.addFile(QString::fromUtf8(":/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000481 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000482 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000483 fActionStepBack.setIcon(stepBack);
484 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000485
chudy@google.comc432f002012-07-10 13:19:25 +0000486 QIcon stepForward;
robertphillips@google.com8e41a162012-11-19 17:39:18 +0000487 stepForward.addFile(QString::fromUtf8(":/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000488 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000489 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000490 fActionStepForward.setIcon(stepForward);
491 fActionStepForward.setText("Step Forward");
492
chudy@google.coma1226312012-07-26 20:26:44 +0000493 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
494 fActionZoomIn.setText("Zoom In");
495 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
496 fActionZoomOut.setText("Zoom Out");
497
chudy@google.comc432f002012-07-10 13:19:25 +0000498 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
499 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000500 fListWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000501
502 fFilter.addItem("--Filter By Available Commands--");
503
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000504 fDirectoryWidget.setMinimumWidth(250);
chudy@google.comc432f002012-07-10 13:19:25 +0000505 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
506
507 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000508 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000509
kkinnunen63a47022014-12-30 23:03:56 -0800510 fDrawCommandGeometryWidget.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000511
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000512 fSettingsAndImageLayout.addWidget(&fSettingsWidget);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000513
kkinnunen41c79cc2014-12-30 22:49:58 -0800514 // View state group, part of inspector.
515 fViewStateFrame.setFrameStyle(QFrame::Panel);
516 fViewStateFrame.setLayout(&fViewStateFrameLayout);
517 fViewStateFrameLayout.addWidget(&fViewStateGroup);
kkinnunen63a47022014-12-30 23:03:56 -0800518 fViewStateGroup.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
kkinnunen41c79cc2014-12-30 22:49:58 -0800519 fViewStateGroup.setTitle("View");
520 fViewStateLayout.addRow("Zoom Level", &fZoomBox);
521 fZoomBox.setText("100%");
522 fZoomBox.setMinimumSize(QSize(50,25));
523 fZoomBox.setMaximumSize(QSize(50,25));
524 fZoomBox.setAlignment(Qt::AlignRight);
525 fZoomBox.setReadOnly(true);
526 fViewStateLayout.addRow("Command HitBox", &fCommandHitBox);
527 fCommandHitBox.setText("0");
528 fCommandHitBox.setMinimumSize(QSize(50,25));
529 fCommandHitBox.setMaximumSize(QSize(50,25));
530 fCommandHitBox.setAlignment(Qt::AlignRight);
531 fCommandHitBox.setReadOnly(true);
532 fViewStateLayout.addRow("Current Command", &fCurrentCommandBox);
533 fCurrentCommandBox.setText("0");
534 fCurrentCommandBox.setMinimumSize(QSize(50,25));
535 fCurrentCommandBox.setMaximumSize(QSize(50,25));
536 fCurrentCommandBox.setAlignment(Qt::AlignRight);
537 fCurrentCommandBox.setReadOnly(true);
538 fViewStateGroup.setLayout(&fViewStateLayout);
539 fSettingsAndImageLayout.addWidget(&fViewStateFrame);
540
kkinnunen63a47022014-12-30 23:03:56 -0800541 fDrawCommandGeometryWidget.setToolTip("Current Command Geometry");
542 fSettingsAndImageLayout.addWidget(&fDrawCommandGeometryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000543
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000544 fLeftColumnSplitter.addWidget(&fListWidget);
545 fLeftColumnSplitter.addWidget(&fDirectoryWidget);
546 fLeftColumnSplitter.setOrientation(Qt::Vertical);
chudy@google.com902ebe52012-06-29 14:21:22 +0000547
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000548 fCanvasSettingsAndImageLayout.setSpacing(6);
kkinnunen41c79cc2014-12-30 22:49:58 -0800549 fCanvasSettingsAndImageLayout.addWidget(&fCanvasWidget, 1);
550 fCanvasSettingsAndImageLayout.addLayout(&fSettingsAndImageLayout, 0);
robertphillips@google.com6dec8fc2012-11-21 17:11:02 +0000551
chudy@google.comc432f002012-07-10 13:19:25 +0000552 fMainAndRightColumnLayout.setSpacing(6);
kkinnunen7c339ae2015-01-02 06:35:43 -0800553 fMainAndRightColumnLayout.addLayout(&fCanvasSettingsAndImageLayout, 1);
554 fMainAndRightColumnLayout.addWidget(&fInspectorWidget, 0);
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000555 fMainAndRightColumnWidget.setLayout(&fMainAndRightColumnLayout);
chudy@google.com902ebe52012-06-29 14:21:22 +0000556
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000557 fCentralSplitter.addWidget(&fLeftColumnSplitter);
558 fCentralSplitter.addWidget(&fMainAndRightColumnWidget);
559 fCentralSplitter.setStretchFactor(0, 0);
560 fCentralSplitter.setStretchFactor(1, 1);
chudy@google.comc432f002012-07-10 13:19:25 +0000561
commit-bot@chromium.orgbcd431e2013-11-21 13:41:37 +0000562 SkDebuggerGUI->setCentralWidget(&fCentralSplitter);
chudy@google.comc432f002012-07-10 13:19:25 +0000563 SkDebuggerGUI->setStatusBar(&fStatusBar);
564
chudy@google.come504de02012-07-16 18:35:23 +0000565 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000566 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
567 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000568
chudy@google.com0ab03392012-07-28 20:16:11 +0000569 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000570
chudy@google.comc432f002012-07-10 13:19:25 +0000571 fToolBar.addAction(&fActionRewind);
572 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000573 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000574 fToolBar.addAction(&fActionStepForward);
575 fToolBar.addAction(&fActionPlay);
576 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000577 fToolBar.addAction(&fActionInspector);
bungeman@google.com2ff6d1d2013-07-01 14:24:12 +0000578 fToolBar.addAction(&fActionSettings);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000579
580 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000581 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000582 fToolBar.addWidget(&fFilter);
583 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000584
585 // TODO(chudy): Remove static call.
586 fDirectoryWidgetActive = false;
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000587 fFileName = "";
robertphillips@google.comff6e6ba2013-01-28 17:43:26 +0000588 setupDirectoryWidget("");
chudy@google.com902ebe52012-06-29 14:21:22 +0000589 fDirectoryWidgetActive = true;
590
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;
638 QDir dir(path);
chudy@google.com902ebe52012-06-29 14:21:22 +0000639 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000640 fDirectoryWidget.clear();
641 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000642 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000643 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000644 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000645 }
646}
647
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000648void SkDebuggerGUI::loadPicture(const SkString& fileName) {
649 fFileName = fileName;
chudy@google.comd3058f52012-07-19 13:41:27 +0000650 fLoading = true;
halcanary385fe4d2015-08-26 13:07:48 -0700651 SkAutoTDelete<SkStream> stream(new SkFILEStream(fileName.c_str()));
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000652
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000653 SkPicture* picture = SkPicture::CreateFromStream(stream);
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000654
halcanary96fcdcc2015-08-27 07:41:13 -0700655 if (nullptr == picture) {
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000656 QMessageBox::critical(this, "Error loading file", "Couldn't read file, sorry.");
robertphillips@google.com2d40ec42013-02-07 20:39:40 +0000657 return;
658 }
robertphillips@google.com2bde91d2012-11-15 14:57:57 +0000659
chudy@google.com686e6802012-08-14 16:00:32 +0000660 fCanvasWidget.resetWidgetTransform();
chudy@google.com607357f2012-08-07 16:12:23 +0000661 fDebugger.loadPicture(picture);
chudy@google.com4c7962e2012-08-14 19:38:31 +0000662
robertphillips@google.com6d9c92b2013-05-23 13:21:18 +0000663 fSkipCommands.setCount(fDebugger.getSize());
664 for (int i = 0; i < fSkipCommands.count(); ++i) {
robertphillips@google.com5f971142012-12-07 20:48:56 +0000665 fSkipCommands[i] = false;
666 }
667
chudy@google.com607357f2012-08-07 16:12:23 +0000668 SkSafeUnref(picture);
669
chudy@google.com7dcae672012-07-09 20:26:53 +0000670 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
chudy@google.com607357f2012-08-07 16:12:23 +0000671 * of the visibility filter.
672 * TODO(chudy): This should be deprecated since fDebugger is not
673 * recreated.
674 * */
kkinnunen41c79cc2014-12-30 22:49:58 -0800675 fDebugger.highlightCurrentCommand(fSettingsWidget.isVisibilityFilterEnabled());
chudy@google.com607357f2012-08-07 16:12:23 +0000676
kkinnunen5037e9d2014-12-30 07:22:58 -0800677 this->setupListWidget();
678 this->setupComboBox();
halcanary96fcdcc2015-08-27 07:41:13 -0700679 this->setupOverviewText(nullptr, 0.0, 1);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000680 fInspectorWidget.setDisabled(false);
kkinnunen41c79cc2014-12-30 22:49:58 -0800681 fViewStateFrame.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000682 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000683 fMenuEdit.setDisabled(false);
684 fMenuNavigate.setDisabled(false);
685 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000686 fActionSave.setDisabled(false);
687 fActionSaveAs.setDisabled(false);
kkinnunenf3a9e992015-01-05 01:14:11 -0800688 fActionPause.setChecked(false);
kkinnunen0cfeaf32015-01-07 07:33:46 -0800689 fDrawCommandGeometryWidget.setDrawCommandIndex(-1);
690
chudy@google.comd3058f52012-07-19 13:41:27 +0000691 fLoading = false;
692 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000693}
694
kkinnunen5037e9d2014-12-30 07:22:58 -0800695void SkDebuggerGUI::setupListWidget() {
robertphillips546db462015-03-26 10:08:04 -0700696
697 SkASSERT(!strcmp("Save",
698 SkDrawCommand::GetCommandString(SkDrawCommand::kSave_OpType)));
699 SkASSERT(!strcmp("SaveLayer",
700 SkDrawCommand::GetCommandString(SkDrawCommand::kSaveLayer_OpType)));
701 SkASSERT(!strcmp("Restore",
702 SkDrawCommand::GetCommandString(SkDrawCommand::kRestore_OpType)));
fmalita160ebb22015-04-01 20:58:37 -0700703 SkASSERT(!strcmp("BeginDrawPicture",
704 SkDrawCommand::GetCommandString(SkDrawCommand::kBeginDrawPicture_OpType)));
705 SkASSERT(!strcmp("EndDrawPicture",
706 SkDrawCommand::GetCommandString(SkDrawCommand::kEndDrawPicture_OpType)));
robertphillips546db462015-03-26 10:08:04 -0700707
chudy@google.comc432f002012-07-10 13:19:25 +0000708 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000709 int counter = 0;
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000710 int indent = 0;
kkinnunen5037e9d2014-12-30 07:22:58 -0800711 for (int i = 0; i < fDebugger.getSize(); i++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000712 QListWidgetItem *item = new QListWidgetItem();
kkinnunen5037e9d2014-12-30 07:22:58 -0800713 SkDrawCommand* command = fDebugger.getDrawCommandAt(i);
714 SkString commandString = command->toString();
715 item->setData(Qt::DisplayRole, commandString.c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000716 item->setData(Qt::UserRole + 1, counter++);
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000717
kkinnunen5037e9d2014-12-30 07:22:58 -0800718 if (0 == strcmp("Restore", commandString.c_str()) ||
fmalita160ebb22015-04-01 20:58:37 -0700719 0 == strcmp("EndDrawPicture", commandString.c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000720 indent -= 10;
721 }
722
723 item->setData(Qt::UserRole + 3, indent);
724
kkinnunen5037e9d2014-12-30 07:22:58 -0800725 if (0 == strcmp("Save", commandString.c_str()) ||
robertphillips546db462015-03-26 10:08:04 -0700726 0 == strcmp("SaveLayer", commandString.c_str()) ||
fmalita160ebb22015-04-01 20:58:37 -0700727 0 == strcmp("BeginDrawPicture", commandString.c_str())) {
robertphillips@google.com30d35f22012-11-06 16:45:36 +0000728 indent += 10;
729 }
730
commit-bot@chromium.org57f74e02014-03-25 23:31:33 +0000731 item->setData(Qt::UserRole + 4, -1);
robertphillips@google.comd26c7062012-11-12 20:42:12 +0000732
chudy@google.comc432f002012-07-10 13:19:25 +0000733 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000734 }
735}
736
skia.committer@gmail.com91274b92013-03-13 07:01:04 +0000737void SkDebuggerGUI::setupOverviewText(const SkTDArray<double>* typeTimes,
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000738 double totTime,
739 int numRuns) {
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000740 SkString overview;
robertphillips@google.come428f9b2013-03-12 15:33:40 +0000741 fDebugger.getOverviewText(typeTimes, totTime, &overview, numRuns);
borenet@google.com2d9dbd42013-03-12 13:07:40 +0000742 fInspectorWidget.setText(overview.c_str(), SkInspectorWidget::kOverview_TabType);
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000743}
744
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +0000745
kkinnunen5037e9d2014-12-30 07:22:58 -0800746void SkDebuggerGUI::setupComboBox() {
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000747 fFilter.clear();
748 fFilter.addItem("--Filter By Available Commands--");
749
750 std::map<std::string, int> map;
kkinnunen5037e9d2014-12-30 07:22:58 -0800751 for (int i = 0; i < fDebugger.getSize(); i++) {
752 map[fDebugger.getDrawCommandAt(i)->toString().c_str()]++;
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000753 }
754
skia.committer@gmail.com34587162012-11-20 02:01:23 +0000755 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
robertphillips@google.com8a1cdae2012-11-19 20:44:29 +0000756 ++it) {
757 fFilter.addItem((it->first).c_str());
758 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000759
760 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000761 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000762 fFilter.model());
763 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
764 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000765 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
766 firstItem->setSelectable(false);
767}
kkinnunen41c79cc2014-12-30 22:49:58 -0800768
kkinnunencfdc0e32015-01-13 22:49:02 -0800769void SkDebuggerGUI::updateImage() {
770 if (this->isPaused()) {
771 fCanvasWidget.drawTo(fPausedRow);
772 } else {
773 fCanvasWidget.drawTo(fListWidget.currentRow());
774 }
775}
776
kkinnunen41c79cc2014-12-30 22:49:58 -0800777void SkDebuggerGUI::updateHit(int newHit) {
778 fCommandHitBox.setText(QString::number(newHit));
779}
780