blob: 96e155167ed6b9e324caaf9908389bb90c1f7680 [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)
17 , fActionClose(this)
18 , fActionDelete(this)
19 , fActionDirectory(this)
20 , fActionGoToLine(this)
21 , fActionInspector(this)
22 , fActionPlay(this)
23 , fActionReload(this)
24 , fActionRewind(this)
25 , fActionSettings(this)
26 , fActionStepBack(this)
27 , fActionStepForward(this)
28 , fCentralWidget(this)
29 , fFilter(&fCentralWidget)
30 , fContainerLayout(&fCentralWidget)
31 , fListWidget(&fCentralWidget)
32 , fDirectoryWidget(&fCentralWidget)
33 , fCanvasWidget(&fCentralWidget)
34 , fSettingsWidget(&fCentralWidget)
35 , fStatusBar(this)
36 , fMenuBar(this)
37 , fMenuFile(this)
38 , fMenuNavigate(this)
39 , fMenuView(this)
40 , fToolBar(this)
41{
chudy@google.com902ebe52012-06-29 14:21:22 +000042 setupUi(this);
chudy@google.comc432f002012-07-10 13:19:25 +000043 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*,
chudy@google.com7dcae672012-07-09 20:26:53 +000044 QListWidgetItem*)), this,
45 SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000046 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
47 connect(&fActionDirectory, SIGNAL(triggered()), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000048 SLOT(toggleDirectory()));
chudy@google.comc432f002012-07-10 13:19:25 +000049 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*,
chudy@google.com7dcae672012-07-09 20:26:53 +000050 QListWidgetItem*)), this,
51 SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000052 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
53 connect(&fActionReload, SIGNAL(triggered()), this, SLOT(actionReload()));
54 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000055 SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000056 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
57 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
58 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
59 connect(&fActionStepForward, SIGNAL(triggered()), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000060 SLOT(actionStepForward()));
chudy@google.comc432f002012-07-10 13:19:25 +000061 connect(&fActionBreakpoint, SIGNAL(triggered()), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000062 SLOT(actionBreakpoints()));
chudy@google.comc432f002012-07-10 13:19:25 +000063 connect(&fActionInspector, SIGNAL(triggered()), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000064 SLOT(actionInspector()));
chudy@google.comc432f002012-07-10 13:19:25 +000065 connect(&fFilter, SIGNAL(activated(QString)), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000066 SLOT(toggleFilter(QString)));
chudy@google.comc432f002012-07-10 13:19:25 +000067 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
68 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
69 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings()));
70 connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000071 SLOT(actionCommandFilter()));
chudy@google.comc432f002012-07-10 13:19:25 +000072 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000073 SLOT(actionScale(float)));
chudy@google.comc432f002012-07-10 13:19:25 +000074 connect(fSettingsWidget.getCommandCheckBox(), SIGNAL(stateChanged(int)),
chudy@google.comf927f442012-07-10 14:36:14 +000075 this, SLOT(pauseDrawing(bool)));
chudy@google.comc432f002012-07-10 13:19:25 +000076 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget,
chudy@google.com7dcae672012-07-09 20:26:53 +000077 SLOT(updateCommand(int)));
chudy@google.com902ebe52012-06-29 14:21:22 +000078}
79
80SkDebuggerGUI::~SkDebuggerGUI() {
81}
82
83void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7dcae672012-07-09 20:26:53 +000084 if (!fBreakpointsActivated) {
chudy@google.com902ebe52012-06-29 14:21:22 +000085 fBreakpointsActivated = true;
86 } else {
87 fBreakpointsActivated = false;
88 }
89
chudy@google.comc432f002012-07-10 13:19:25 +000090 for (int row = 0; row < fListWidget.count(); row++) {
91 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +000092
93 if (item->checkState() == Qt::Unchecked && fBreakpointsActivated) {
94 item->setHidden(true);
95 } else {
96 item->setHidden(false);
97 }
98 }
99}
100
101void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000102 for (int row = 0; row < fListWidget.count(); row++) {
103 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000104 }
105}
106
107void SkDebuggerGUI::actionCommandFilter() {
chudy@google.comc432f002012-07-10 13:19:25 +0000108 fCanvasWidget.toggleCurrentCommandFilter(
109 fSettingsWidget.getVisibilityButton()->isChecked());
110 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000111}
112
113void SkDebuggerGUI::actionClose() {
114 this->close();
115}
116
117void SkDebuggerGUI::actionDelete() {
chudy@google.comc432f002012-07-10 13:19:25 +0000118 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com7dcae672012-07-09 20:26:53 +0000119 if (item->data(Qt::UserRole + 2) == true) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000120 item->setData(Qt::UserRole + 2, false);
chudy@google.come565de42012-07-12 14:15:54 +0000121 item->setData(Qt::UserRole + 3, QPixmap(":/images/Icons/delete.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000122 } else {
123 item->setData(Qt::UserRole + 2, true);
chudy@google.come565de42012-07-12 14:15:54 +0000124 item->setData(Qt::UserRole + 3, QPixmap(":/images/Icons/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000125 }
chudy@google.comc432f002012-07-10 13:19:25 +0000126 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000127 // NOTE(chudy): Forces a redraw up to current selected command.
chudy@google.comc432f002012-07-10 13:19:25 +0000128 fCanvasWidget.toggleCommand(currentRow);
129 fCanvasWidget.drawTo(currentRow);
chudy@google.com902ebe52012-06-29 14:21:22 +0000130}
131
132void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000133 if (fInspectorWidget.isHidden()) {
134 fInspectorWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000135 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000136 fInspectorWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000137 }
138}
139
140void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000141 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000142 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000143 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000144 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000145 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000146 return;
147 }
148 }
chudy@google.comc432f002012-07-10 13:19:25 +0000149 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000150}
151
152void SkDebuggerGUI::actionReload() {
chudy@google.comc432f002012-07-10 13:19:25 +0000153 for (int row = 0; row < fListWidget.count(); row++) {
154 QListWidgetItem* item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000155 item->setData(Qt::UserRole + 2, true);
chudy@google.com7dcae672012-07-09 20:26:53 +0000156 item->setData(Qt::DecorationRole, QPixmap(":/images/Icons/blank.png"));
chudy@google.comc432f002012-07-10 13:19:25 +0000157 fCanvasWidget.toggleCommand(row, true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000158 }
chudy@google.comc432f002012-07-10 13:19:25 +0000159 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000160}
161
162void SkDebuggerGUI::actionRewind() {
163 /* NOTE(chudy): Hack. All skps opened so far start with save and concat
164 * commands that don't clear or reset the canvas. */
chudy@google.comc432f002012-07-10 13:19:25 +0000165 fListWidget.setCurrentRow(2);
chudy@google.com902ebe52012-06-29 14:21:22 +0000166}
167
chudy@google.com7dcae672012-07-09 20:26:53 +0000168void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000169 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000170}
171
chudy@google.com902ebe52012-06-29 14:21:22 +0000172void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000173 if (fSettingsWidget.isHidden()) {
174 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000175 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000176 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000177 }
178}
179
180void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000181 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000182 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000183 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000184 }
185}
186
187void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000188 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000189 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000190 QString curCount = QString::number(fListWidget.count());
191 if (currentRow < fListWidget.count() - 1) {
192 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000193 }
194}
195
196void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
197 if (fDirectoryWidgetActive) {
198 QString fileName;
199 fileName.append(fPath);
200 fileName.append("/");
201 fileName.append(item->text());
202 loadPicture(fileName);
203 }
204}
205
206void SkDebuggerGUI::openFile() {
chudy@google.com7dcae672012-07-09 20:26:53 +0000207 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
208 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000209 fDirectoryWidgetActive = false;
210 if (!fileName.isNull()) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000211 QFileInfo pathInfo(fileName);
212 fPath = pathInfo.path();
213 loadPicture(fileName);
214 setupDirectoryWidget();
215 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000216 fDirectoryWidgetActive = true;
217}
218
chudy@google.comc432f002012-07-10 13:19:25 +0000219void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000220 // Qt uses 0 for unchecked, 1 for partially enabled and 2 for checked.
chudy@google.comc432f002012-07-10 13:19:25 +0000221 if (isPaused) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000222 fPause = true;
223 } else {
224 fPause = false;
chudy@google.comc432f002012-07-10 13:19:25 +0000225 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com7dcae672012-07-09 20:26:53 +0000226 }
227}
228
chudy@google.com902ebe52012-06-29 14:21:22 +0000229void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comc432f002012-07-10 13:19:25 +0000230 int currentRow = fListWidget.currentRow();
chudy@google.com7dcae672012-07-09 20:26:53 +0000231 if (!fPause) {
chudy@google.comc432f002012-07-10 13:19:25 +0000232 fCanvasWidget.drawTo(currentRow);
chudy@google.com7dcae672012-07-09 20:26:53 +0000233 }
chudy@google.comc432f002012-07-10 13:19:25 +0000234 std::vector<std::string> *v = fCanvasWidget.getCurrentCommandInfo(
chudy@google.com7dcae672012-07-09 20:26:53 +0000235 currentRow);
chudy@google.com902ebe52012-06-29 14:21:22 +0000236
chudy@google.com7dcae672012-07-09 20:26:53 +0000237 /* TODO(chudy): Add command type before parameters. Rename v
238 * to something more informative. */
239 if (v) {
240 std::vector<std::string>::iterator it;
chudy@google.com902ebe52012-06-29 14:21:22 +0000241
chudy@google.com7dcae672012-07-09 20:26:53 +0000242 QString info;
243 info.append("<b>Parameters: </b><br/>");
244 for (it = v->begin(); it != v->end(); ++it) {
245 info.append(QString((*it).c_str()));
246 info.append("<br/>");
chudy@google.com902ebe52012-06-29 14:21:22 +0000247 }
chudy@google.comc432f002012-07-10 13:19:25 +0000248 fInspectorWidget.setDetailText(info);
249 fInspectorWidget.setDisabled(false);
250 fInspectorWidget.setMatrix(fCanvasWidget.getCurrentMatrix());
251 fInspectorWidget.setClip(fCanvasWidget.getCurrentClip());
chudy@google.com902ebe52012-06-29 14:21:22 +0000252 }
253}
254
255void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000256 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000257 if (item->checkState() == Qt::Unchecked) {
258 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000259 item->setData(Qt::DecorationRole,
260 QPixmap(":/images/Icons/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000261 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000262 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000263 item->setData(Qt::DecorationRole,
264 QPixmap(":/images/Icons/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000265 }
266}
267
268void SkDebuggerGUI::toggleDirectory() {
chudy@google.comc432f002012-07-10 13:19:25 +0000269 if (fDirectoryWidget.isHidden()) {
270 fDirectoryWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000271 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000272 fDirectoryWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000273 }
274}
275
276void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000277 for (int row = 0; row < fListWidget.count(); row++) {
278 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000279 if (item->text() == string) {
280 item->setHidden(false);
281 } else {
282 item->setHidden(true);
283 }
284 }
285}
286
287void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
288 QIcon windowIcon;
chudy@google.com7dcae672012-07-09 20:26:53 +0000289 windowIcon.addFile(QString::fromUtf8(":/images/Icons/skia.png"), QSize(),
290 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000291 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
292 SkDebuggerGUI->resize(1200, 1000);
293 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000294 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000295
296 QIcon open;
chudy@google.com7dcae672012-07-09 20:26:53 +0000297 open.addFile(QString::fromUtf8(":/images/Icons/package-br32.png"), QSize(),
298 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000299 fActionOpen.setIcon(open);
300 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000301
302 QIcon breakpoint;
chudy@google.com7dcae672012-07-09 20:26:53 +0000303 breakpoint.addFile(QString::fromUtf8(":/images/Icons/breakpoint.png"),
304 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000305 fActionBreakpoint.setIcon(breakpoint);
306 fActionBreakpoint.setText("Show Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000307
308 QIcon cancel;
chudy@google.com7dcae672012-07-09 20:26:53 +0000309 cancel.addFile(QString::fromUtf8(":/images/Icons/reset.png"), QSize(),
310 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000311 fActionCancel.setIcon(cancel);
312 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000313
chudy@google.comc432f002012-07-10 13:19:25 +0000314 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000315
chudy@google.comc432f002012-07-10 13:19:25 +0000316 QIcon deleteIcon;
317 deleteIcon.addFile(QString::fromUtf8(":/images/Icons/delete.png"), QSize(),
318 QIcon::Normal, QIcon::Off);
319 fActionDelete.setIcon(deleteIcon);
320 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000321
chudy@google.comc432f002012-07-10 13:19:25 +0000322 QIcon directory;
323 directory.addFile(QString::fromUtf8(":/images/Icons/drawer-open-icon.png"),
324 QSize(), QIcon::Normal, QIcon::Off);
325 fActionDirectory.setIcon(directory);
326 fActionDirectory.setText("Toggle Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000327
chudy@google.comc432f002012-07-10 13:19:25 +0000328 QIcon inspector;
329 inspector.addFile(QString::fromUtf8(":/images/Icons/inspector.png"),
330 QSize(), QIcon::Normal, QIcon::Off);
331 fActionInspector.setIcon(inspector);
332 fActionInspector.setText("Toggle Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000333
chudy@google.comc432f002012-07-10 13:19:25 +0000334 QIcon play;
335 play.addFile(QString::fromUtf8(":/images/Icons/play.png"), QSize(),
336 QIcon::Normal, QIcon::Off);
337 fActionPlay.setIcon(play);
338 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000339
chudy@google.comc432f002012-07-10 13:19:25 +0000340 QIcon reload;
341 reload.addFile(QString::fromUtf8(":/images/Icons/reload.png"), QSize(),
342 QIcon::Normal, QIcon::Off);
343 fActionReload.setIcon(reload);
344 fActionReload.setText("Reset Picture");
chudy@google.com902ebe52012-06-29 14:21:22 +0000345
chudy@google.comc432f002012-07-10 13:19:25 +0000346 QIcon rewind;
347 rewind.addFile(QString::fromUtf8(":/images/Icons/rewind.png"), QSize(),
348 QIcon::Normal, QIcon::Off);
349 fActionRewind.setIcon(rewind);
350 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000351
chudy@google.comc432f002012-07-10 13:19:25 +0000352 QIcon settings;
353 settings.addFile(QString::fromUtf8(":/images/Icons/settings.png"), QSize(),
354 QIcon::Normal, QIcon::Off);
355 fActionSettings.setIcon(settings);
356 fActionSettings.setText("Settings");
chudy@google.com902ebe52012-06-29 14:21:22 +0000357
chudy@google.comc432f002012-07-10 13:19:25 +0000358 QIcon stepBack;
359 stepBack.addFile(QString::fromUtf8(":/images/Icons/back.png"), QSize(),
360 QIcon::Normal, QIcon::Off);
361 fActionStepBack.setIcon(stepBack);
362 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000363
chudy@google.comc432f002012-07-10 13:19:25 +0000364 QIcon stepForward;
365 stepForward.addFile(QString::fromUtf8(":/images/Icons/go-next.png"),
366 QSize(), QIcon::Normal, QIcon::Off);
367 fActionStepForward.setIcon(stepForward);
368 fActionStepForward.setText("Step Forward");
369
370 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
371 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
372 fListWidget.setMaximumWidth(250);
373
374 fFilter.addItem("--Filter By Available Commands--");
375
376 fDirectoryWidget.setMaximumWidth(250);
377 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
378
379 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000380 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000381
chudy@google.comc432f002012-07-10 13:19:25 +0000382 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000383 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000384 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000385
chudy@google.comc432f002012-07-10 13:19:25 +0000386 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
387 QSizePolicy::Expanding);
388 fSettingsWidget.setMaximumWidth(250);
389 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000390
chudy@google.comc432f002012-07-10 13:19:25 +0000391 fLeftColumnLayout.setSpacing(6);
392 fLeftColumnLayout.addWidget(&fListWidget);
393 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000394
chudy@google.comc432f002012-07-10 13:19:25 +0000395 fCanvasAndSettingsLayout.setSpacing(6);
396 fCanvasAndSettingsLayout.addWidget(&fCanvasWidget);
397 fCanvasAndSettingsLayout.addWidget(&fSettingsWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000398
chudy@google.comc432f002012-07-10 13:19:25 +0000399 fMainAndRightColumnLayout.setSpacing(6);
400 fMainAndRightColumnLayout.addLayout(&fCanvasAndSettingsLayout);
401 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000402
chudy@google.comc432f002012-07-10 13:19:25 +0000403 fContainerLayout.setSpacing(6);
404 fContainerLayout.setContentsMargins(11, 11, 11, 11);
405 fContainerLayout.addLayout(&fLeftColumnLayout);
406 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
407
408 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
409 SkDebuggerGUI->setStatusBar(&fStatusBar);
410
411 fToolBar.setIconSize(QSize(24, 24));
412 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
413 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000414
415 QWidget *spacer = new QWidget();
416 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
417
chudy@google.comc432f002012-07-10 13:19:25 +0000418 fToolBar.addAction(&fActionRewind);
419 fToolBar.addAction(&fActionStepBack);
420 fToolBar.addAction(&fActionStepForward);
421 fToolBar.addAction(&fActionPlay);
422 fToolBar.addSeparator();
423 fToolBar.addAction(&fActionBreakpoint);
424 fToolBar.addSeparator();
425 fToolBar.addAction(&fActionDelete);
426 fToolBar.addAction(&fActionReload);
427 fToolBar.addSeparator();
428 fToolBar.addAction(&fActionSettings);
429 fToolBar.addWidget(spacer);
430 fToolBar.addWidget(&fFilter);
431 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000432
433 // TODO(chudy): Remove static call.
434 fDirectoryWidgetActive = false;
chudy@google.com7dcae672012-07-09 20:26:53 +0000435 fPath = "/usr/local/google/home/chudy/trunk-linux/debugger/skp";
chudy@google.com902ebe52012-06-29 14:21:22 +0000436 setupDirectoryWidget();
437 fDirectoryWidgetActive = true;
438
chudy@google.com902ebe52012-06-29 14:21:22 +0000439 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000440 fMenuFile.setTitle("File");
441 fMenuFile.addAction(&fActionOpen);
442 fMenuFile.addAction(&fActionClose);
443 fMenuNavigate.setTitle("Navigate");
444 fMenuNavigate.addAction(&fActionGoToLine);
445 fMenuView.setTitle("View");
446 fMenuView.addAction(&fActionInspector);
447 fMenuView.addAction(&fActionDirectory);
448
449 fActionGoToLine.setText("Go to Line...");
450 fActionGoToLine.setDisabled(true);
451 fMenuBar.addAction(fMenuFile.menuAction());
452 fMenuBar.addAction(fMenuView.menuAction());
453 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000454
chudy@google.com7dcae672012-07-09 20:26:53 +0000455 fPause = false;
456
chudy@google.comc432f002012-07-10 13:19:25 +0000457 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000458 QMetaObject::connectSlotsByName(SkDebuggerGUI);
459}
460
461void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000462 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000463 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000464 fDirectoryWidget.clear();
465 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000466 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000467 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000468 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000469 }
470}
471
chudy@google.com902ebe52012-06-29 14:21:22 +0000472void SkDebuggerGUI::loadPicture(QString fileName) {
chudy@google.comc432f002012-07-10 13:19:25 +0000473 fCanvasWidget.loadPicture(fileName);
474 std::vector<std::string> *cv = fCanvasWidget.getDrawCommands();
chudy@google.com7dcae672012-07-09 20:26:53 +0000475 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
476 * of the visibility filter. */
chudy@google.comc432f002012-07-10 13:19:25 +0000477 fCanvasWidget.toggleCurrentCommandFilter(
478 fSettingsWidget.getVisibilityButton()->isChecked());
chudy@google.com902ebe52012-06-29 14:21:22 +0000479 setupListWidget(cv);
480 setupComboBox(cv);
481}
482
483void SkDebuggerGUI::setupListWidget(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000484 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000485 int counter = 0;
486 for (unsigned int i = 0; i < cv->size(); i++) {
487 QListWidgetItem *item = new QListWidgetItem();
488 item->setData(Qt::DisplayRole, (*cv)[i].c_str());
489 item->setData(Qt::UserRole + 1, counter++);
490 item->setData(Qt::UserRole + 2, true);
chudy@google.comc432f002012-07-10 13:19:25 +0000491 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000492 }
493}
494
495void SkDebuggerGUI::setupComboBox(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000496 fFilter.clear();
497 fFilter.addItem("--Filter By Available Commands--");
chudy@google.com902ebe52012-06-29 14:21:22 +0000498
499 std::map<std::string, int> map;
500 for (unsigned int i = 0; i < cv->size(); i++) {
501 map[(*cv)[i]]++;
502 }
503
504 QString overview;
505 int counter;
chudy@google.com7dcae672012-07-09 20:26:53 +0000506 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
507 ++it) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000508 overview.append((it->first).c_str());
509 overview.append(": ");
510 overview.append(QString::number(it->second));
511 overview.append("<br/>");
chudy@google.com7dcae672012-07-09 20:26:53 +0000512 counter += it->second;
chudy@google.comc432f002012-07-10 13:19:25 +0000513 fFilter.addItem((it->first).c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000514 }
515 QString total;
516 total.append("Total Draw Commands: ");
517 total.append(QString::number(counter));
518 total.append("<br/>");
519 overview.insert(0, total);
520
521 overview.append("<br/>");
522 overview.append("SkBitmap Width: ");
523 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.comc432f002012-07-10 13:19:25 +0000524 overview.append(QString::number(fCanvasWidget.getBitmapWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000525 overview.append("px<br/>");
526 overview.append("SkBitmap Height: ");
chudy@google.comc432f002012-07-10 13:19:25 +0000527 overview.append(QString::number(fCanvasWidget.getBitmapHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000528 overview.append("px");
chudy@google.comc432f002012-07-10 13:19:25 +0000529 fInspectorWidget.setOverviewText(overview);
chudy@google.com902ebe52012-06-29 14:21:22 +0000530
531 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000532 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000533 fFilter.model());
534 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
535 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000536 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
537 firstItem->setSelectable(false);
538}