blob: 1cca0ba9536fe317e024a2efd1cb05ba6e4a13a3 [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.come606d6e2012-07-12 14:31:25 +000074 connect(fSettingsWidget.getCommandCheckBox(), SIGNAL(toggled(bool)),
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.come606d6e2012-07-12 14:31:25 +000078 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget,
79 SLOT(updateHit(int)));
chudy@google.com902ebe52012-06-29 14:21:22 +000080}
81
82SkDebuggerGUI::~SkDebuggerGUI() {
83}
84
85void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7dcae672012-07-09 20:26:53 +000086 if (!fBreakpointsActivated) {
chudy@google.com902ebe52012-06-29 14:21:22 +000087 fBreakpointsActivated = true;
88 } else {
89 fBreakpointsActivated = false;
90 }
91
chudy@google.comc432f002012-07-10 13:19:25 +000092 for (int row = 0; row < fListWidget.count(); row++) {
93 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +000094
95 if (item->checkState() == Qt::Unchecked && fBreakpointsActivated) {
96 item->setHidden(true);
97 } else {
98 item->setHidden(false);
99 }
100 }
101}
102
103void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000104 for (int row = 0; row < fListWidget.count(); row++) {
105 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000106 }
107}
108
109void SkDebuggerGUI::actionCommandFilter() {
chudy@google.comc432f002012-07-10 13:19:25 +0000110 fCanvasWidget.toggleCurrentCommandFilter(
111 fSettingsWidget.getVisibilityButton()->isChecked());
112 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000113}
114
115void SkDebuggerGUI::actionClose() {
116 this->close();
117}
118
119void SkDebuggerGUI::actionDelete() {
chudy@google.comc432f002012-07-10 13:19:25 +0000120 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com7dcae672012-07-09 20:26:53 +0000121 if (item->data(Qt::UserRole + 2) == true) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000122 item->setData(Qt::UserRole + 2, false);
chudy@google.come565de42012-07-12 14:15:54 +0000123 item->setData(Qt::UserRole + 3, QPixmap(":/images/Icons/delete.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000124 } else {
125 item->setData(Qt::UserRole + 2, true);
chudy@google.come565de42012-07-12 14:15:54 +0000126 item->setData(Qt::UserRole + 3, QPixmap(":/images/Icons/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000127 }
chudy@google.comc432f002012-07-10 13:19:25 +0000128 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000129 // NOTE(chudy): Forces a redraw up to current selected command.
chudy@google.comc432f002012-07-10 13:19:25 +0000130 fCanvasWidget.toggleCommand(currentRow);
chudy@google.com233e4b82012-07-12 14:38:49 +0000131 fCanvasWidget.drawTo(fPausedRow);
chudy@google.com902ebe52012-06-29 14:21:22 +0000132}
133
134void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000135 if (fInspectorWidget.isHidden()) {
136 fInspectorWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000137 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000138 fInspectorWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000139 }
140}
141
142void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000143 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000144 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000145 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000146 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000147 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000148 return;
149 }
150 }
chudy@google.comc432f002012-07-10 13:19:25 +0000151 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000152}
153
154void SkDebuggerGUI::actionReload() {
chudy@google.comc432f002012-07-10 13:19:25 +0000155 for (int row = 0; row < fListWidget.count(); row++) {
156 QListWidgetItem* item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000157 item->setData(Qt::UserRole + 2, true);
chudy@google.com7dcae672012-07-09 20:26:53 +0000158 item->setData(Qt::DecorationRole, QPixmap(":/images/Icons/blank.png"));
chudy@google.comc432f002012-07-10 13:19:25 +0000159 fCanvasWidget.toggleCommand(row, true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000160 }
chudy@google.comc432f002012-07-10 13:19:25 +0000161 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000162}
163
164void SkDebuggerGUI::actionRewind() {
165 /* NOTE(chudy): Hack. All skps opened so far start with save and concat
166 * commands that don't clear or reset the canvas. */
chudy@google.comc432f002012-07-10 13:19:25 +0000167 fListWidget.setCurrentRow(2);
chudy@google.com902ebe52012-06-29 14:21:22 +0000168}
169
chudy@google.com7dcae672012-07-09 20:26:53 +0000170void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000171 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000172}
173
chudy@google.com902ebe52012-06-29 14:21:22 +0000174void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000175 if (fSettingsWidget.isHidden()) {
176 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000177 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000178 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000179 }
180}
181
182void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000183 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000184 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000185 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000186 }
187}
188
189void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000190 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000191 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000192 QString curCount = QString::number(fListWidget.count());
193 if (currentRow < fListWidget.count() - 1) {
194 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000195 }
196}
197
198void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
199 if (fDirectoryWidgetActive) {
200 QString fileName;
201 fileName.append(fPath);
202 fileName.append("/");
203 fileName.append(item->text());
204 loadPicture(fileName);
205 }
206}
207
208void SkDebuggerGUI::openFile() {
chudy@google.com7dcae672012-07-09 20:26:53 +0000209 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
210 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000211 fDirectoryWidgetActive = false;
212 if (!fileName.isNull()) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000213 QFileInfo pathInfo(fileName);
214 fPath = pathInfo.path();
215 loadPicture(fileName);
216 setupDirectoryWidget();
217 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000218 fDirectoryWidgetActive = true;
219}
220
chudy@google.comc432f002012-07-10 13:19:25 +0000221void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000222 // Qt uses 0 for unchecked, 1 for partially enabled and 2 for checked.
chudy@google.comc432f002012-07-10 13:19:25 +0000223 if (isPaused) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000224 fPause = true;
chudy@google.com233e4b82012-07-12 14:38:49 +0000225 fPausedRow = fListWidget.currentRow();
chudy@google.com7dcae672012-07-09 20:26:53 +0000226 } else {
227 fPause = false;
chudy@google.comc432f002012-07-10 13:19:25 +0000228 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com7dcae672012-07-09 20:26:53 +0000229 }
230}
231
chudy@google.com902ebe52012-06-29 14:21:22 +0000232void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comc432f002012-07-10 13:19:25 +0000233 int currentRow = fListWidget.currentRow();
chudy@google.com7dcae672012-07-09 20:26:53 +0000234 if (!fPause) {
chudy@google.comc432f002012-07-10 13:19:25 +0000235 fCanvasWidget.drawTo(currentRow);
chudy@google.com7dcae672012-07-09 20:26:53 +0000236 }
chudy@google.comc432f002012-07-10 13:19:25 +0000237 std::vector<std::string> *v = fCanvasWidget.getCurrentCommandInfo(
chudy@google.com7dcae672012-07-09 20:26:53 +0000238 currentRow);
chudy@google.com902ebe52012-06-29 14:21:22 +0000239
chudy@google.com7dcae672012-07-09 20:26:53 +0000240 /* TODO(chudy): Add command type before parameters. Rename v
241 * to something more informative. */
242 if (v) {
243 std::vector<std::string>::iterator it;
chudy@google.com902ebe52012-06-29 14:21:22 +0000244
chudy@google.com7dcae672012-07-09 20:26:53 +0000245 QString info;
246 info.append("<b>Parameters: </b><br/>");
247 for (it = v->begin(); it != v->end(); ++it) {
248 info.append(QString((*it).c_str()));
249 info.append("<br/>");
chudy@google.com902ebe52012-06-29 14:21:22 +0000250 }
chudy@google.comc432f002012-07-10 13:19:25 +0000251 fInspectorWidget.setDetailText(info);
252 fInspectorWidget.setDisabled(false);
253 fInspectorWidget.setMatrix(fCanvasWidget.getCurrentMatrix());
254 fInspectorWidget.setClip(fCanvasWidget.getCurrentClip());
chudy@google.com902ebe52012-06-29 14:21:22 +0000255 }
256}
257
258void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000259 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000260 if (item->checkState() == Qt::Unchecked) {
261 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000262 item->setData(Qt::DecorationRole,
263 QPixmap(":/images/Icons/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000264 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000265 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000266 item->setData(Qt::DecorationRole,
267 QPixmap(":/images/Icons/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000268 }
269}
270
271void SkDebuggerGUI::toggleDirectory() {
chudy@google.comc432f002012-07-10 13:19:25 +0000272 if (fDirectoryWidget.isHidden()) {
273 fDirectoryWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000274 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000275 fDirectoryWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000276 }
277}
278
279void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000280 for (int row = 0; row < fListWidget.count(); row++) {
281 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000282 if (item->text() == string) {
283 item->setHidden(false);
284 } else {
285 item->setHidden(true);
286 }
287 }
288}
289
290void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
291 QIcon windowIcon;
chudy@google.com7dcae672012-07-09 20:26:53 +0000292 windowIcon.addFile(QString::fromUtf8(":/images/Icons/skia.png"), QSize(),
293 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000294 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
295 SkDebuggerGUI->resize(1200, 1000);
296 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000297 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000298
299 QIcon open;
chudy@google.com7dcae672012-07-09 20:26:53 +0000300 open.addFile(QString::fromUtf8(":/images/Icons/package-br32.png"), QSize(),
301 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000302 fActionOpen.setIcon(open);
303 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000304
305 QIcon breakpoint;
chudy@google.com7dcae672012-07-09 20:26:53 +0000306 breakpoint.addFile(QString::fromUtf8(":/images/Icons/breakpoint.png"),
307 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000308 fActionBreakpoint.setIcon(breakpoint);
309 fActionBreakpoint.setText("Show Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000310
311 QIcon cancel;
chudy@google.com7dcae672012-07-09 20:26:53 +0000312 cancel.addFile(QString::fromUtf8(":/images/Icons/reset.png"), QSize(),
313 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000314 fActionCancel.setIcon(cancel);
315 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000316
chudy@google.comc432f002012-07-10 13:19:25 +0000317 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000318
chudy@google.comc432f002012-07-10 13:19:25 +0000319 QIcon deleteIcon;
320 deleteIcon.addFile(QString::fromUtf8(":/images/Icons/delete.png"), QSize(),
321 QIcon::Normal, QIcon::Off);
322 fActionDelete.setIcon(deleteIcon);
323 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000324
chudy@google.comc432f002012-07-10 13:19:25 +0000325 QIcon directory;
326 directory.addFile(QString::fromUtf8(":/images/Icons/drawer-open-icon.png"),
327 QSize(), QIcon::Normal, QIcon::Off);
328 fActionDirectory.setIcon(directory);
329 fActionDirectory.setText("Toggle Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000330
chudy@google.comc432f002012-07-10 13:19:25 +0000331 QIcon inspector;
332 inspector.addFile(QString::fromUtf8(":/images/Icons/inspector.png"),
333 QSize(), QIcon::Normal, QIcon::Off);
334 fActionInspector.setIcon(inspector);
335 fActionInspector.setText("Toggle Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000336
chudy@google.comc432f002012-07-10 13:19:25 +0000337 QIcon play;
338 play.addFile(QString::fromUtf8(":/images/Icons/play.png"), QSize(),
339 QIcon::Normal, QIcon::Off);
340 fActionPlay.setIcon(play);
341 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000342
chudy@google.comc432f002012-07-10 13:19:25 +0000343 QIcon reload;
344 reload.addFile(QString::fromUtf8(":/images/Icons/reload.png"), QSize(),
345 QIcon::Normal, QIcon::Off);
346 fActionReload.setIcon(reload);
347 fActionReload.setText("Reset Picture");
chudy@google.com902ebe52012-06-29 14:21:22 +0000348
chudy@google.comc432f002012-07-10 13:19:25 +0000349 QIcon rewind;
350 rewind.addFile(QString::fromUtf8(":/images/Icons/rewind.png"), QSize(),
351 QIcon::Normal, QIcon::Off);
352 fActionRewind.setIcon(rewind);
353 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000354
chudy@google.comc432f002012-07-10 13:19:25 +0000355 QIcon settings;
356 settings.addFile(QString::fromUtf8(":/images/Icons/settings.png"), QSize(),
357 QIcon::Normal, QIcon::Off);
358 fActionSettings.setIcon(settings);
359 fActionSettings.setText("Settings");
chudy@google.com902ebe52012-06-29 14:21:22 +0000360
chudy@google.comc432f002012-07-10 13:19:25 +0000361 QIcon stepBack;
362 stepBack.addFile(QString::fromUtf8(":/images/Icons/back.png"), QSize(),
363 QIcon::Normal, QIcon::Off);
364 fActionStepBack.setIcon(stepBack);
365 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000366
chudy@google.comc432f002012-07-10 13:19:25 +0000367 QIcon stepForward;
368 stepForward.addFile(QString::fromUtf8(":/images/Icons/go-next.png"),
369 QSize(), QIcon::Normal, QIcon::Off);
370 fActionStepForward.setIcon(stepForward);
371 fActionStepForward.setText("Step Forward");
372
373 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
374 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
375 fListWidget.setMaximumWidth(250);
376
377 fFilter.addItem("--Filter By Available Commands--");
378
379 fDirectoryWidget.setMaximumWidth(250);
380 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
381
382 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000383 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000384
chudy@google.comc432f002012-07-10 13:19:25 +0000385 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000386 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000387 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000388
chudy@google.comc432f002012-07-10 13:19:25 +0000389 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
390 QSizePolicy::Expanding);
391 fSettingsWidget.setMaximumWidth(250);
392 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000393
chudy@google.comc432f002012-07-10 13:19:25 +0000394 fLeftColumnLayout.setSpacing(6);
395 fLeftColumnLayout.addWidget(&fListWidget);
396 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000397
chudy@google.comc432f002012-07-10 13:19:25 +0000398 fCanvasAndSettingsLayout.setSpacing(6);
399 fCanvasAndSettingsLayout.addWidget(&fCanvasWidget);
400 fCanvasAndSettingsLayout.addWidget(&fSettingsWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000401
chudy@google.comc432f002012-07-10 13:19:25 +0000402 fMainAndRightColumnLayout.setSpacing(6);
403 fMainAndRightColumnLayout.addLayout(&fCanvasAndSettingsLayout);
404 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000405
chudy@google.comc432f002012-07-10 13:19:25 +0000406 fContainerLayout.setSpacing(6);
407 fContainerLayout.setContentsMargins(11, 11, 11, 11);
408 fContainerLayout.addLayout(&fLeftColumnLayout);
409 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
410
411 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
412 SkDebuggerGUI->setStatusBar(&fStatusBar);
413
414 fToolBar.setIconSize(QSize(24, 24));
415 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
416 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000417
418 QWidget *spacer = new QWidget();
419 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
420
chudy@google.comc432f002012-07-10 13:19:25 +0000421 fToolBar.addAction(&fActionRewind);
422 fToolBar.addAction(&fActionStepBack);
423 fToolBar.addAction(&fActionStepForward);
424 fToolBar.addAction(&fActionPlay);
425 fToolBar.addSeparator();
426 fToolBar.addAction(&fActionBreakpoint);
427 fToolBar.addSeparator();
428 fToolBar.addAction(&fActionDelete);
429 fToolBar.addAction(&fActionReload);
430 fToolBar.addSeparator();
431 fToolBar.addAction(&fActionSettings);
432 fToolBar.addWidget(spacer);
433 fToolBar.addWidget(&fFilter);
434 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000435
436 // TODO(chudy): Remove static call.
437 fDirectoryWidgetActive = false;
chudy@google.com7dcae672012-07-09 20:26:53 +0000438 fPath = "/usr/local/google/home/chudy/trunk-linux/debugger/skp";
chudy@google.com902ebe52012-06-29 14:21:22 +0000439 setupDirectoryWidget();
440 fDirectoryWidgetActive = true;
441
chudy@google.com902ebe52012-06-29 14:21:22 +0000442 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000443 fMenuFile.setTitle("File");
444 fMenuFile.addAction(&fActionOpen);
445 fMenuFile.addAction(&fActionClose);
446 fMenuNavigate.setTitle("Navigate");
447 fMenuNavigate.addAction(&fActionGoToLine);
448 fMenuView.setTitle("View");
449 fMenuView.addAction(&fActionInspector);
450 fMenuView.addAction(&fActionDirectory);
451
452 fActionGoToLine.setText("Go to Line...");
453 fActionGoToLine.setDisabled(true);
454 fMenuBar.addAction(fMenuFile.menuAction());
455 fMenuBar.addAction(fMenuView.menuAction());
456 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000457
chudy@google.com7dcae672012-07-09 20:26:53 +0000458 fPause = false;
459
chudy@google.comc432f002012-07-10 13:19:25 +0000460 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000461 QMetaObject::connectSlotsByName(SkDebuggerGUI);
462}
463
464void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000465 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000466 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000467 fDirectoryWidget.clear();
468 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000469 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000470 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000471 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000472 }
473}
474
chudy@google.com902ebe52012-06-29 14:21:22 +0000475void SkDebuggerGUI::loadPicture(QString fileName) {
chudy@google.comc432f002012-07-10 13:19:25 +0000476 fCanvasWidget.loadPicture(fileName);
477 std::vector<std::string> *cv = fCanvasWidget.getDrawCommands();
chudy@google.com7dcae672012-07-09 20:26:53 +0000478 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
479 * of the visibility filter. */
chudy@google.comc432f002012-07-10 13:19:25 +0000480 fCanvasWidget.toggleCurrentCommandFilter(
481 fSettingsWidget.getVisibilityButton()->isChecked());
chudy@google.com902ebe52012-06-29 14:21:22 +0000482 setupListWidget(cv);
483 setupComboBox(cv);
chudy@google.come606d6e2012-07-12 14:31:25 +0000484 fSettingsWidget.setDisabled(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000485}
486
487void SkDebuggerGUI::setupListWidget(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000488 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000489 int counter = 0;
490 for (unsigned int i = 0; i < cv->size(); i++) {
491 QListWidgetItem *item = new QListWidgetItem();
492 item->setData(Qt::DisplayRole, (*cv)[i].c_str());
493 item->setData(Qt::UserRole + 1, counter++);
494 item->setData(Qt::UserRole + 2, true);
chudy@google.comc432f002012-07-10 13:19:25 +0000495 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000496 }
497}
498
499void SkDebuggerGUI::setupComboBox(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000500 fFilter.clear();
501 fFilter.addItem("--Filter By Available Commands--");
chudy@google.com902ebe52012-06-29 14:21:22 +0000502
503 std::map<std::string, int> map;
504 for (unsigned int i = 0; i < cv->size(); i++) {
505 map[(*cv)[i]]++;
506 }
507
508 QString overview;
509 int counter;
chudy@google.com7dcae672012-07-09 20:26:53 +0000510 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
511 ++it) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000512 overview.append((it->first).c_str());
513 overview.append(": ");
514 overview.append(QString::number(it->second));
515 overview.append("<br/>");
chudy@google.com7dcae672012-07-09 20:26:53 +0000516 counter += it->second;
chudy@google.comc432f002012-07-10 13:19:25 +0000517 fFilter.addItem((it->first).c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000518 }
519 QString total;
520 total.append("Total Draw Commands: ");
521 total.append(QString::number(counter));
522 total.append("<br/>");
523 overview.insert(0, total);
524
525 overview.append("<br/>");
526 overview.append("SkBitmap Width: ");
527 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.comc432f002012-07-10 13:19:25 +0000528 overview.append(QString::number(fCanvasWidget.getBitmapWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000529 overview.append("px<br/>");
530 overview.append("SkBitmap Height: ");
chudy@google.comc432f002012-07-10 13:19:25 +0000531 overview.append(QString::number(fCanvasWidget.getBitmapHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000532 overview.append("px");
chudy@google.comc432f002012-07-10 13:19:25 +0000533 fInspectorWidget.setOverviewText(overview);
chudy@google.com902ebe52012-06-29 14:21:22 +0000534
535 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000536 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000537 fFilter.model());
538 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
539 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000540 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
541 firstItem->setSelectable(false);
542}