blob: e497ff77fdfe7ca2cc15b1e1690159890e687bb9 [file] [log] [blame]
chudy@google.com902ebe52012-06-29 14:21:22 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include <iostream>
9#include "SkDebuggerGUI.h"
10#include <QListWidgetItem>
11
12SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) :
chudy@google.comc432f002012-07-10 13:19:25 +000013 QMainWindow(parent)
14 , fActionOpen(this)
15 , fActionBreakpoint(this)
16 , fActionCancel(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000017 , fActionClearBreakpoints(this)
chudy@google.come504de02012-07-16 18:35:23 +000018 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000019 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000020 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000021 , fActionDelete(this)
22 , fActionDirectory(this)
23 , fActionGoToLine(this)
24 , fActionInspector(this)
25 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000026 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000027 , fActionRewind(this)
chudy@google.com0ab03392012-07-28 20:16:11 +000028 , fActionSave(this)
29 , fActionSaveAs(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000030 , fActionShowDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000031 , fActionStepBack(this)
32 , fActionStepForward(this)
chudy@google.coma1226312012-07-26 20:26:44 +000033 , fActionZoomIn(this)
34 , fActionZoomOut(this)
35 , fMapper(this)
chudy@google.comc432f002012-07-10 13:19:25 +000036 , fCentralWidget(this)
37 , fFilter(&fCentralWidget)
38 , fContainerLayout(&fCentralWidget)
39 , fListWidget(&fCentralWidget)
40 , fDirectoryWidget(&fCentralWidget)
41 , fCanvasWidget(&fCentralWidget)
42 , fSettingsWidget(&fCentralWidget)
43 , fStatusBar(this)
44 , fMenuBar(this)
45 , fMenuFile(this)
46 , fMenuNavigate(this)
47 , fMenuView(this)
48 , fToolBar(this)
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000049 , fBreakpointsActivated(false)
50 , fDeletesActivated(false)
51 , fPause(false)
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);
chudy@google.comea5488b2012-07-26 19:38:22 +000055 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *)));
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 *)));
chudy@google.comc432f002012-07-10 13:19:25 +000059 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
chudy@google.comea5488b2012-07-26 19:38:22 +000060 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000061 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
62 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
63 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.comea5488b2012-07-26 19:38:22 +000064 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward()));
65 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints()));
66 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector()));
67 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionSettings()));
68 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString)));
chudy@google.comc432f002012-07-10 13:19:25 +000069 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000070 connect(&fActionClearBreakpoints, SIGNAL(triggered()), this, SLOT(actionClearBreakpoints()));
71 connect(&fActionClearDeletes, SIGNAL(triggered()), this, SLOT(actionClearDeletes()));
chudy@google.comc432f002012-07-10 13:19:25 +000072 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
chudy@google.comea5488b2012-07-26 19:38:22 +000073 connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this, SLOT(actionCommandFilter()));
74 connect(fSettingsWidget.getGLCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionGLWidget(bool)));
75 connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
76 connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
chudy@google.come504de02012-07-16 18:35:23 +000077 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000078 connect(&fActionShowDeletes, SIGNAL(triggered()), this, SLOT(showDeletes()));
chudy@google.comea5488b2012-07-26 19:38:22 +000079 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
80 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget, SLOT(updateHit(int)));
81 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this, SLOT(actionScale(float)));
82 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget, SLOT(updateCommand(int)));
chudy@google.com0ab03392012-07-28 20:16:11 +000083 connect(&fActionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
84 connect(&fActionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000085
chudy@google.coma1226312012-07-26 20:26:44 +000086 fMapper.setMapping(&fActionZoomIn, 1);
87 fMapper.setMapping(&fActionZoomOut, -1);
88
89 connect(&fActionZoomIn, SIGNAL(triggered()), &fMapper, SLOT(map()));
90 connect(&fActionZoomOut, SIGNAL(triggered()), &fMapper, SLOT(map()));
91 connect(&fMapper, SIGNAL(mapped(int)), &fCanvasWidget, SLOT(keyZoom(int)));
92
chudy@google.com7e4cfbf2012-07-17 15:40:51 +000093 fInspectorWidget.setDisabled(true);
chudy@google.comd3058f52012-07-19 13:41:27 +000094 fMenuEdit.setDisabled(true);
95 fMenuNavigate.setDisabled(true);
96 fMenuView.setDisabled(true);
97
chudy@google.com902ebe52012-06-29 14:21:22 +000098}
99
100SkDebuggerGUI::~SkDebuggerGUI() {
101}
102
103void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000104 fBreakpointsActivated = !fBreakpointsActivated;
chudy@google.comc432f002012-07-10 13:19:25 +0000105 for (int row = 0; row < fListWidget.count(); row++) {
106 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000107 item->setHidden(item->checkState() == Qt::Unchecked && fBreakpointsActivated);
108 }
109}
chudy@google.com902ebe52012-06-29 14:21:22 +0000110
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000111void SkDebuggerGUI::showDeletes() {
112 fDeletesActivated = !fDeletesActivated;
113 for (int row = 0; row < fListWidget.count(); row++) {
114 QListWidgetItem *item = fListWidget.item(row);
115 bool isVisible = fCanvasWidget.commandIsVisibleAtIndex(row);
116 item->setHidden(isVisible && fDeletesActivated);
chudy@google.com902ebe52012-06-29 14:21:22 +0000117 }
118}
119
120void 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,
131 QPixmap(":/images/Icons/blank.png"));
132 }
133}
134
135void SkDebuggerGUI::actionClearDeletes() {
136 for (int row = 0; row < fListWidget.count(); row++) {
137 QListWidgetItem* item = fListWidget.item(row);
138 item->setData(Qt::UserRole + 2, QPixmap(":/images/Icons/blank.png"));
139 fCanvasWidget.setCommandVisibliltyAtIndex(row, true);
140 }
141 if (fPause) {
142 fCanvasWidget.drawTo(fPausedRow);
143 } else {
144 fCanvasWidget.drawTo(fListWidget.currentRow());
145 }
146}
147
chudy@google.com902ebe52012-06-29 14:21:22 +0000148void SkDebuggerGUI::actionCommandFilter() {
chudy@google.comc432f002012-07-10 13:19:25 +0000149 fCanvasWidget.toggleCurrentCommandFilter(
150 fSettingsWidget.getVisibilityButton()->isChecked());
151 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000152}
153
154void SkDebuggerGUI::actionClose() {
155 this->close();
156}
157
158void SkDebuggerGUI::actionDelete() {
chudy@google.comc432f002012-07-10 13:19:25 +0000159 int currentRow = fListWidget.currentRow();
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000160 QListWidgetItem* item = fListWidget.currentItem();
161
162 if (fCanvasWidget.commandIsVisibleAtIndex(currentRow)) {
163 item->setData(Qt::UserRole + 2, QPixmap(":/images/Icons/delete.png"));
164 fCanvasWidget.setCommandVisibliltyAtIndex(currentRow, false);
165 } else {
166 item->setData(Qt::UserRole + 2, QPixmap(":/images/Icons/blank.png"));
167 fCanvasWidget.setCommandVisibliltyAtIndex(currentRow, true);
168 }
169
chudy@google.come504de02012-07-16 18:35:23 +0000170 if (fPause) {
171 fCanvasWidget.drawTo(fPausedRow);
172 } else {
173 fCanvasWidget.drawTo(currentRow);
174 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000175}
176
chudy@google.comea5488b2012-07-26 19:38:22 +0000177void SkDebuggerGUI::actionGLWidget(bool isToggled) {
178 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kGPU_WidgetType, !isToggled);
179}
180
chudy@google.com902ebe52012-06-29 14:21:22 +0000181void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000182 if (fInspectorWidget.isHidden()) {
183 fInspectorWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000184 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000185 fInspectorWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000186 }
187}
188
189void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000190 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000191 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000192 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000193 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000194 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000195 return;
196 }
197 }
chudy@google.comc432f002012-07-10 13:19:25 +0000198 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000199}
200
chudy@google.comea5488b2012-07-26 19:38:22 +0000201void SkDebuggerGUI::actionRasterWidget(bool isToggled) {
202 fCanvasWidget.setWidgetVisibility(SkCanvasWidget::kRaster_8888_WidgetType, !isToggled);
203}
204
chudy@google.com902ebe52012-06-29 14:21:22 +0000205void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000206 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000207}
208
chudy@google.com0ab03392012-07-28 20:16:11 +0000209void SkDebuggerGUI::actionSave() {
210 QString filename;
211 filename.append(fPath);
212 filename.append("/");
213 filename.append(fDirectoryWidget.currentItem()->text());
214 saveToFile(filename);
215}
216
217void SkDebuggerGUI::actionSaveAs() {
218 QString filename = QFileDialog::getSaveFileName(this, "Save File", "",
219 "Skia Picture (*skp)");
chudy@google.com38b08ce2012-07-28 23:26:10 +0000220 if (!filename.endsWith(".skp", Qt::CaseInsensitive)) {
chudy@google.com0ab03392012-07-28 20:16:11 +0000221 filename.append(".skp");
222 }
223 saveToFile(filename);
224}
225
chudy@google.com7dcae672012-07-09 20:26:53 +0000226void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000227 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000228}
229
chudy@google.com902ebe52012-06-29 14:21:22 +0000230void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000231 if (fSettingsWidget.isHidden()) {
232 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000233 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000234 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000235 }
236}
237
238void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000239 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000240 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000241 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000242 }
243}
244
245void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000246 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000247 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000248 QString curCount = QString::number(fListWidget.count());
249 if (currentRow < fListWidget.count() - 1) {
250 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000251 }
252}
253
chudy@google.com0ab03392012-07-28 20:16:11 +0000254void SkDebuggerGUI::saveToFile(QString filename) {
255 SkFILEWStream file(filename.toAscii());
256 SkPicture picture;
257 SkCanvas* canvas = picture.beginRecording(100,100);
258 fCanvasWidget.getCurrentDebugCanvas()->draw(canvas);
259 picture.endRecording();
260 picture.serialize(&file);
261}
262
chudy@google.com902ebe52012-06-29 14:21:22 +0000263void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
264 if (fDirectoryWidgetActive) {
265 QString fileName;
266 fileName.append(fPath);
267 fileName.append("/");
268 fileName.append(item->text());
269 loadPicture(fileName);
270 }
271}
272
273void SkDebuggerGUI::openFile() {
chudy@google.com7dcae672012-07-09 20:26:53 +0000274 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
275 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000276 fDirectoryWidgetActive = false;
277 if (!fileName.isNull()) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000278 QFileInfo pathInfo(fileName);
279 fPath = pathInfo.path();
280 loadPicture(fileName);
281 setupDirectoryWidget();
282 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000283 fDirectoryWidgetActive = true;
284}
285
chudy@google.comc432f002012-07-10 13:19:25 +0000286void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000287 // Qt uses 0 for unchecked, 1 for partially enabled and 2 for checked.
chudy@google.comc432f002012-07-10 13:19:25 +0000288 if (isPaused) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000289 fPause = true;
chudy@google.com233e4b82012-07-12 14:38:49 +0000290 fPausedRow = fListWidget.currentRow();
chudy@google.com7dcae672012-07-09 20:26:53 +0000291 } else {
292 fPause = false;
chudy@google.comc432f002012-07-10 13:19:25 +0000293 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com7dcae672012-07-09 20:26:53 +0000294 }
295}
296
chudy@google.com902ebe52012-06-29 14:21:22 +0000297void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000298 if(!fLoading) {
299 int currentRow = fListWidget.currentRow();
chudy@google.comd3058f52012-07-19 13:41:27 +0000300
chudy@google.comea5488b2012-07-26 19:38:22 +0000301 if (currentRow != -1) {
302 if (!fPause) {
303 fCanvasWidget.drawTo(currentRow);
chudy@google.comd3058f52012-07-19 13:41:27 +0000304 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000305 std::vector<std::string> *cuffInfo = fCanvasWidget.getCurrentCommandInfo(
306 currentRow);
307
308 /* TODO(chudy): Add command type before parameters. Rename v
309 * to something more informative. */
310 if (cuffInfo) {
311 std::vector<std::string>::iterator it;
312
313 QString info;
314 info.append("<b>Parameters: </b><br/>");
315 for (it = cuffInfo->begin(); it != cuffInfo->end(); ++it) {
316 info.append(QString((*it).c_str()));
317 info.append("<br/>");
318 }
319 fInspectorWidget.setDetailText(info);
320 fInspectorWidget.setDisabled(false);
321 fInspectorWidget.setMatrix(fCanvasWidget.getCurrentMatrix());
322 fInspectorWidget.setClip(fCanvasWidget.getCurrentClip());
323 }
chudy@google.comd3058f52012-07-19 13:41:27 +0000324 }
chudy@google.comea5488b2012-07-26 19:38:22 +0000325
chudy@google.com902ebe52012-06-29 14:21:22 +0000326 }
327}
328
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000329void SkDebuggerGUI::selectCommand(int command) {
330 if (fPause) {
331 fListWidget.setCurrentRow(command);
332 }
333}
334
chudy@google.com902ebe52012-06-29 14:21:22 +0000335void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000336 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000337 if (item->checkState() == Qt::Unchecked) {
338 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000339 item->setData(Qt::DecorationRole,
340 QPixmap(":/images/Icons/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000341 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000342 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000343 item->setData(Qt::DecorationRole,
344 QPixmap(":/images/Icons/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000345 }
346}
347
348void SkDebuggerGUI::toggleDirectory() {
chudy@google.comc432f002012-07-10 13:19:25 +0000349 if (fDirectoryWidget.isHidden()) {
350 fDirectoryWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000351 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000352 fDirectoryWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000353 }
354}
355
356void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000357 for (int row = 0; row < fListWidget.count(); row++) {
358 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000359 if (item->text() == string) {
360 item->setHidden(false);
361 } else {
362 item->setHidden(true);
363 }
364 }
365}
366
367void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
368 QIcon windowIcon;
chudy@google.com7dcae672012-07-09 20:26:53 +0000369 windowIcon.addFile(QString::fromUtf8(":/images/Icons/skia.png"), QSize(),
370 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000371 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
372 SkDebuggerGUI->resize(1200, 1000);
373 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000374 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000375
chudy@google.come504de02012-07-16 18:35:23 +0000376 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000377 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000378
379 QIcon breakpoint;
chudy@google.com7dcae672012-07-09 20:26:53 +0000380 breakpoint.addFile(QString::fromUtf8(":/images/Icons/breakpoint.png"),
381 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000382 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000383 fActionBreakpoint.setIcon(breakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000384 fActionBreakpoint.setText("Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000385
386 QIcon cancel;
chudy@google.come504de02012-07-16 18:35:23 +0000387 cancel.addFile(QString::fromUtf8(":/images/Ico/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000388 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000389 fActionCancel.setIcon(cancel);
390 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000391
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000392 fActionClearBreakpoints.setShortcut(QKeySequence(tr("Alt+B")));
393 fActionClearBreakpoints.setText("Clear Breakpoints");
394
395 fActionClearDeletes.setShortcut(QKeySequence(tr("Alt+X")));
396 fActionClearDeletes.setText("Clear Deletes");
397
chudy@google.come504de02012-07-16 18:35:23 +0000398 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000399 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000400
chudy@google.come504de02012-07-16 18:35:23 +0000401 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
402 fActionCreateBreakpoint.setText("Set Breakpoint");
403
404 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000405 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000406
chudy@google.come504de02012-07-16 18:35:23 +0000407 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
408 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000409
chudy@google.comc432f002012-07-10 13:19:25 +0000410 QIcon inspector;
chudy@google.come504de02012-07-16 18:35:23 +0000411 inspector.addFile(QString::fromUtf8(":/images/Ico/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000412 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000413 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000414 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000415 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000416
chudy@google.comc432f002012-07-10 13:19:25 +0000417 QIcon play;
chudy@google.come504de02012-07-16 18:35:23 +0000418 play.addFile(QString::fromUtf8(":/images/Ico/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000419 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000420 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000421 fActionPlay.setIcon(play);
422 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000423
chudy@google.come504de02012-07-16 18:35:23 +0000424 QIcon pause;
425 pause.addFile(QString::fromUtf8(":/images/Ico/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000426 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000427 fActionPause.setShortcut(QKeySequence(tr("Space")));
428 fActionPause.setCheckable(true);
429 fActionPause.setIcon(pause);
430 fActionPause.setText("Pause");
431
chudy@google.comc432f002012-07-10 13:19:25 +0000432 QIcon rewind;
chudy@google.come504de02012-07-16 18:35:23 +0000433 rewind.addFile(QString::fromUtf8(":/images/Ico/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000434 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000435 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000436 fActionRewind.setIcon(rewind);
437 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000438
chudy@google.com0ab03392012-07-28 20:16:11 +0000439 fActionSave.setShortcut(QKeySequence::Save);
440 fActionSave.setText("Save");
441 fActionSave.setDisabled(true);
442 fActionSaveAs.setShortcut(QKeySequence::SaveAs);
443 fActionSaveAs.setText("Save As");
444 fActionSaveAs.setDisabled(true);
445
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000446 fActionShowDeletes.setShortcut(QKeySequence(tr("Ctrl+X")));
447 fActionShowDeletes.setText("Deleted Commands");
448
chudy@google.comc432f002012-07-10 13:19:25 +0000449 QIcon stepBack;
chudy@google.come504de02012-07-16 18:35:23 +0000450 stepBack.addFile(QString::fromUtf8(":/images/Ico/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000451 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000452 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000453 fActionStepBack.setIcon(stepBack);
454 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000455
chudy@google.comc432f002012-07-10 13:19:25 +0000456 QIcon stepForward;
chudy@google.come504de02012-07-16 18:35:23 +0000457 stepForward.addFile(QString::fromUtf8(":/images/Ico/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000458 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000459 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000460 fActionStepForward.setIcon(stepForward);
461 fActionStepForward.setText("Step Forward");
462
chudy@google.coma1226312012-07-26 20:26:44 +0000463 fActionZoomIn.setShortcut(QKeySequence(tr("Ctrl+=")));
464 fActionZoomIn.setText("Zoom In");
465 fActionZoomOut.setShortcut(QKeySequence(tr("Ctrl+-")));
466 fActionZoomOut.setText("Zoom Out");
467
chudy@google.comc432f002012-07-10 13:19:25 +0000468 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
469 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
470 fListWidget.setMaximumWidth(250);
471
472 fFilter.addItem("--Filter By Available Commands--");
473
474 fDirectoryWidget.setMaximumWidth(250);
475 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
476
477 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000478 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000479
chudy@google.comc432f002012-07-10 13:19:25 +0000480 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000481 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000482 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000483
chudy@google.comc432f002012-07-10 13:19:25 +0000484 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
485 QSizePolicy::Expanding);
486 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000487
chudy@google.comc432f002012-07-10 13:19:25 +0000488 fLeftColumnLayout.setSpacing(6);
489 fLeftColumnLayout.addWidget(&fListWidget);
490 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000491
chudy@google.comc432f002012-07-10 13:19:25 +0000492 fCanvasAndSettingsLayout.setSpacing(6);
493 fCanvasAndSettingsLayout.addWidget(&fCanvasWidget);
494 fCanvasAndSettingsLayout.addWidget(&fSettingsWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000495
chudy@google.comc432f002012-07-10 13:19:25 +0000496 fMainAndRightColumnLayout.setSpacing(6);
497 fMainAndRightColumnLayout.addLayout(&fCanvasAndSettingsLayout);
498 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000499
chudy@google.comc432f002012-07-10 13:19:25 +0000500 fContainerLayout.setSpacing(6);
501 fContainerLayout.setContentsMargins(11, 11, 11, 11);
502 fContainerLayout.addLayout(&fLeftColumnLayout);
503 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
504
505 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
506 SkDebuggerGUI->setStatusBar(&fStatusBar);
507
chudy@google.come504de02012-07-16 18:35:23 +0000508 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000509 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
510 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000511
chudy@google.com0ab03392012-07-28 20:16:11 +0000512 fSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000513
chudy@google.comc432f002012-07-10 13:19:25 +0000514 fToolBar.addAction(&fActionRewind);
515 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000516 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000517 fToolBar.addAction(&fActionStepForward);
518 fToolBar.addAction(&fActionPlay);
519 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000520 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000521 fToolBar.addSeparator();
chudy@google.com0ab03392012-07-28 20:16:11 +0000522 fToolBar.addWidget(&fSpacer);
chudy@google.comc432f002012-07-10 13:19:25 +0000523 fToolBar.addWidget(&fFilter);
524 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000525
526 // TODO(chudy): Remove static call.
527 fDirectoryWidgetActive = false;
chudy@google.comea5488b2012-07-26 19:38:22 +0000528 fPath = "/usr/local/google/home/chudy/trunk-git/trunk/skp";
chudy@google.com902ebe52012-06-29 14:21:22 +0000529 setupDirectoryWidget();
530 fDirectoryWidgetActive = true;
531
chudy@google.com902ebe52012-06-29 14:21:22 +0000532 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000533 fMenuFile.setTitle("File");
534 fMenuFile.addAction(&fActionOpen);
chudy@google.com0ab03392012-07-28 20:16:11 +0000535 fMenuFile.addAction(&fActionSave);
536 fMenuFile.addAction(&fActionSaveAs);
chudy@google.comc432f002012-07-10 13:19:25 +0000537 fMenuFile.addAction(&fActionClose);
chudy@google.come504de02012-07-16 18:35:23 +0000538
539 fMenuEdit.setTitle("Edit");
540 fMenuEdit.addAction(&fActionDelete);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000541 fMenuEdit.addAction(&fActionClearDeletes);
542 fMenuEdit.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000543 fMenuEdit.addAction(&fActionCreateBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000544 fMenuEdit.addAction(&fActionClearBreakpoints);
chudy@google.come504de02012-07-16 18:35:23 +0000545
chudy@google.comc432f002012-07-10 13:19:25 +0000546 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000547 fMenuNavigate.addAction(&fActionRewind);
548 fMenuNavigate.addAction(&fActionStepBack);
549 fMenuNavigate.addAction(&fActionStepForward);
550 fMenuNavigate.addAction(&fActionPlay);
551 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000552 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000553
chudy@google.comc432f002012-07-10 13:19:25 +0000554 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000555 fMenuView.addAction(&fActionBreakpoint);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000556 fMenuView.addAction(&fActionShowDeletes);
chudy@google.coma1226312012-07-26 20:26:44 +0000557 fMenuView.addAction(&fActionZoomIn);
558 fMenuView.addAction(&fActionZoomOut);
chudy@google.come504de02012-07-16 18:35:23 +0000559
560 fMenuWindows.setTitle("Window");
561 fMenuWindows.addAction(&fActionInspector);
562 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000563
564 fActionGoToLine.setText("Go to Line...");
565 fActionGoToLine.setDisabled(true);
566 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000567 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000568 fMenuBar.addAction(fMenuView.menuAction());
569 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000570 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000571
chudy@google.com7dcae672012-07-09 20:26:53 +0000572 fPause = false;
573
chudy@google.comc432f002012-07-10 13:19:25 +0000574 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000575 QMetaObject::connectSlotsByName(SkDebuggerGUI);
576}
577
578void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000579 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000580 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000581 fDirectoryWidget.clear();
582 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000583 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000584 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000585 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000586 }
587}
588
chudy@google.com902ebe52012-06-29 14:21:22 +0000589void SkDebuggerGUI::loadPicture(QString fileName) {
chudy@google.comd3058f52012-07-19 13:41:27 +0000590 fLoading = true;
chudy@google.comc432f002012-07-10 13:19:25 +0000591 fCanvasWidget.loadPicture(fileName);
592 std::vector<std::string> *cv = fCanvasWidget.getDrawCommands();
chudy@google.com7dcae672012-07-09 20:26:53 +0000593 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
594 * of the visibility filter. */
chudy@google.comc432f002012-07-10 13:19:25 +0000595 fCanvasWidget.toggleCurrentCommandFilter(
596 fSettingsWidget.getVisibilityButton()->isChecked());
chudy@google.com902ebe52012-06-29 14:21:22 +0000597 setupListWidget(cv);
598 setupComboBox(cv);
chudy@google.com7e4cfbf2012-07-17 15:40:51 +0000599 fInspectorWidget.setDisabled(false);
chudy@google.come606d6e2012-07-12 14:31:25 +0000600 fSettingsWidget.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000601 fMenuEdit.setDisabled(false);
602 fMenuNavigate.setDisabled(false);
603 fMenuView.setDisabled(false);
chudy@google.com0ab03392012-07-28 20:16:11 +0000604 fActionSave.setDisabled(false);
605 fActionSaveAs.setDisabled(false);
chudy@google.comd3058f52012-07-19 13:41:27 +0000606 fLoading = false;
607 actionPlay();
chudy@google.com902ebe52012-06-29 14:21:22 +0000608}
609
610void SkDebuggerGUI::setupListWidget(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000611 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000612 int counter = 0;
613 for (unsigned int i = 0; i < cv->size(); i++) {
614 QListWidgetItem *item = new QListWidgetItem();
615 item->setData(Qt::DisplayRole, (*cv)[i].c_str());
616 item->setData(Qt::UserRole + 1, counter++);
chudy@google.comc432f002012-07-10 13:19:25 +0000617 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000618 }
619}
620
621void SkDebuggerGUI::setupComboBox(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000622 fFilter.clear();
623 fFilter.addItem("--Filter By Available Commands--");
chudy@google.com902ebe52012-06-29 14:21:22 +0000624
625 std::map<std::string, int> map;
626 for (unsigned int i = 0; i < cv->size(); i++) {
627 map[(*cv)[i]]++;
628 }
629
630 QString overview;
631 int counter;
chudy@google.com7dcae672012-07-09 20:26:53 +0000632 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
633 ++it) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000634 overview.append((it->first).c_str());
635 overview.append(": ");
636 overview.append(QString::number(it->second));
637 overview.append("<br/>");
chudy@google.com7dcae672012-07-09 20:26:53 +0000638 counter += it->second;
chudy@google.comc432f002012-07-10 13:19:25 +0000639 fFilter.addItem((it->first).c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000640 }
641 QString total;
642 total.append("Total Draw Commands: ");
643 total.append(QString::number(counter));
644 total.append("<br/>");
645 overview.insert(0, total);
646
647 overview.append("<br/>");
648 overview.append("SkBitmap Width: ");
649 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.comc432f002012-07-10 13:19:25 +0000650 overview.append(QString::number(fCanvasWidget.getBitmapWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000651 overview.append("px<br/>");
652 overview.append("SkBitmap Height: ");
chudy@google.comc432f002012-07-10 13:19:25 +0000653 overview.append(QString::number(fCanvasWidget.getBitmapHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000654 overview.append("px");
chudy@google.comc432f002012-07-10 13:19:25 +0000655 fInspectorWidget.setOverviewText(overview);
chudy@google.com902ebe52012-06-29 14:21:22 +0000656
657 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000658 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000659 fFilter.model());
660 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
661 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000662 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
663 firstItem->setSelectable(false);
664}