blob: 12c3bdc9c382f422995960cac8781cfac5e2d6bc [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);
131 fCanvasWidget.drawTo(currentRow);
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;
225 } else {
226 fPause = false;
chudy@google.comc432f002012-07-10 13:19:25 +0000227 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com7dcae672012-07-09 20:26:53 +0000228 }
229}
230
chudy@google.com902ebe52012-06-29 14:21:22 +0000231void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comc432f002012-07-10 13:19:25 +0000232 int currentRow = fListWidget.currentRow();
chudy@google.com7dcae672012-07-09 20:26:53 +0000233 if (!fPause) {
chudy@google.comc432f002012-07-10 13:19:25 +0000234 fCanvasWidget.drawTo(currentRow);
chudy@google.com7dcae672012-07-09 20:26:53 +0000235 }
chudy@google.comc432f002012-07-10 13:19:25 +0000236 std::vector<std::string> *v = fCanvasWidget.getCurrentCommandInfo(
chudy@google.com7dcae672012-07-09 20:26:53 +0000237 currentRow);
chudy@google.com902ebe52012-06-29 14:21:22 +0000238
chudy@google.com7dcae672012-07-09 20:26:53 +0000239 /* TODO(chudy): Add command type before parameters. Rename v
240 * to something more informative. */
241 if (v) {
242 std::vector<std::string>::iterator it;
chudy@google.com902ebe52012-06-29 14:21:22 +0000243
chudy@google.com7dcae672012-07-09 20:26:53 +0000244 QString info;
245 info.append("<b>Parameters: </b><br/>");
246 for (it = v->begin(); it != v->end(); ++it) {
247 info.append(QString((*it).c_str()));
248 info.append("<br/>");
chudy@google.com902ebe52012-06-29 14:21:22 +0000249 }
chudy@google.comc432f002012-07-10 13:19:25 +0000250 fInspectorWidget.setDetailText(info);
251 fInspectorWidget.setDisabled(false);
252 fInspectorWidget.setMatrix(fCanvasWidget.getCurrentMatrix());
253 fInspectorWidget.setClip(fCanvasWidget.getCurrentClip());
chudy@google.com902ebe52012-06-29 14:21:22 +0000254 }
255}
256
257void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000258 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000259 if (item->checkState() == Qt::Unchecked) {
260 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000261 item->setData(Qt::DecorationRole,
262 QPixmap(":/images/Icons/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000263 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000264 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000265 item->setData(Qt::DecorationRole,
266 QPixmap(":/images/Icons/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000267 }
268}
269
270void SkDebuggerGUI::toggleDirectory() {
chudy@google.comc432f002012-07-10 13:19:25 +0000271 if (fDirectoryWidget.isHidden()) {
272 fDirectoryWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000273 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000274 fDirectoryWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000275 }
276}
277
278void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000279 for (int row = 0; row < fListWidget.count(); row++) {
280 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000281 if (item->text() == string) {
282 item->setHidden(false);
283 } else {
284 item->setHidden(true);
285 }
286 }
287}
288
289void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
290 QIcon windowIcon;
chudy@google.com7dcae672012-07-09 20:26:53 +0000291 windowIcon.addFile(QString::fromUtf8(":/images/Icons/skia.png"), QSize(),
292 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000293 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
294 SkDebuggerGUI->resize(1200, 1000);
295 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000296 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000297
298 QIcon open;
chudy@google.com7dcae672012-07-09 20:26:53 +0000299 open.addFile(QString::fromUtf8(":/images/Icons/package-br32.png"), QSize(),
300 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000301 fActionOpen.setIcon(open);
302 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000303
304 QIcon breakpoint;
chudy@google.com7dcae672012-07-09 20:26:53 +0000305 breakpoint.addFile(QString::fromUtf8(":/images/Icons/breakpoint.png"),
306 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000307 fActionBreakpoint.setIcon(breakpoint);
308 fActionBreakpoint.setText("Show Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000309
310 QIcon cancel;
chudy@google.com7dcae672012-07-09 20:26:53 +0000311 cancel.addFile(QString::fromUtf8(":/images/Icons/reset.png"), QSize(),
312 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000313 fActionCancel.setIcon(cancel);
314 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000315
chudy@google.comc432f002012-07-10 13:19:25 +0000316 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000317
chudy@google.comc432f002012-07-10 13:19:25 +0000318 QIcon deleteIcon;
319 deleteIcon.addFile(QString::fromUtf8(":/images/Icons/delete.png"), QSize(),
320 QIcon::Normal, QIcon::Off);
321 fActionDelete.setIcon(deleteIcon);
322 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000323
chudy@google.comc432f002012-07-10 13:19:25 +0000324 QIcon directory;
325 directory.addFile(QString::fromUtf8(":/images/Icons/drawer-open-icon.png"),
326 QSize(), QIcon::Normal, QIcon::Off);
327 fActionDirectory.setIcon(directory);
328 fActionDirectory.setText("Toggle Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000329
chudy@google.comc432f002012-07-10 13:19:25 +0000330 QIcon inspector;
331 inspector.addFile(QString::fromUtf8(":/images/Icons/inspector.png"),
332 QSize(), QIcon::Normal, QIcon::Off);
333 fActionInspector.setIcon(inspector);
334 fActionInspector.setText("Toggle Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000335
chudy@google.comc432f002012-07-10 13:19:25 +0000336 QIcon play;
337 play.addFile(QString::fromUtf8(":/images/Icons/play.png"), QSize(),
338 QIcon::Normal, QIcon::Off);
339 fActionPlay.setIcon(play);
340 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000341
chudy@google.comc432f002012-07-10 13:19:25 +0000342 QIcon reload;
343 reload.addFile(QString::fromUtf8(":/images/Icons/reload.png"), QSize(),
344 QIcon::Normal, QIcon::Off);
345 fActionReload.setIcon(reload);
346 fActionReload.setText("Reset Picture");
chudy@google.com902ebe52012-06-29 14:21:22 +0000347
chudy@google.comc432f002012-07-10 13:19:25 +0000348 QIcon rewind;
349 rewind.addFile(QString::fromUtf8(":/images/Icons/rewind.png"), QSize(),
350 QIcon::Normal, QIcon::Off);
351 fActionRewind.setIcon(rewind);
352 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000353
chudy@google.comc432f002012-07-10 13:19:25 +0000354 QIcon settings;
355 settings.addFile(QString::fromUtf8(":/images/Icons/settings.png"), QSize(),
356 QIcon::Normal, QIcon::Off);
357 fActionSettings.setIcon(settings);
358 fActionSettings.setText("Settings");
chudy@google.com902ebe52012-06-29 14:21:22 +0000359
chudy@google.comc432f002012-07-10 13:19:25 +0000360 QIcon stepBack;
361 stepBack.addFile(QString::fromUtf8(":/images/Icons/back.png"), QSize(),
362 QIcon::Normal, QIcon::Off);
363 fActionStepBack.setIcon(stepBack);
364 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000365
chudy@google.comc432f002012-07-10 13:19:25 +0000366 QIcon stepForward;
367 stepForward.addFile(QString::fromUtf8(":/images/Icons/go-next.png"),
368 QSize(), QIcon::Normal, QIcon::Off);
369 fActionStepForward.setIcon(stepForward);
370 fActionStepForward.setText("Step Forward");
371
372 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
373 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
374 fListWidget.setMaximumWidth(250);
375
376 fFilter.addItem("--Filter By Available Commands--");
377
378 fDirectoryWidget.setMaximumWidth(250);
379 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
380
381 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000382 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000383
chudy@google.comc432f002012-07-10 13:19:25 +0000384 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000385 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000386 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000387
chudy@google.comc432f002012-07-10 13:19:25 +0000388 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
389 QSizePolicy::Expanding);
390 fSettingsWidget.setMaximumWidth(250);
391 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000392
chudy@google.comc432f002012-07-10 13:19:25 +0000393 fLeftColumnLayout.setSpacing(6);
394 fLeftColumnLayout.addWidget(&fListWidget);
395 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000396
chudy@google.comc432f002012-07-10 13:19:25 +0000397 fCanvasAndSettingsLayout.setSpacing(6);
398 fCanvasAndSettingsLayout.addWidget(&fCanvasWidget);
399 fCanvasAndSettingsLayout.addWidget(&fSettingsWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000400
chudy@google.comc432f002012-07-10 13:19:25 +0000401 fMainAndRightColumnLayout.setSpacing(6);
402 fMainAndRightColumnLayout.addLayout(&fCanvasAndSettingsLayout);
403 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000404
chudy@google.comc432f002012-07-10 13:19:25 +0000405 fContainerLayout.setSpacing(6);
406 fContainerLayout.setContentsMargins(11, 11, 11, 11);
407 fContainerLayout.addLayout(&fLeftColumnLayout);
408 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
409
410 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
411 SkDebuggerGUI->setStatusBar(&fStatusBar);
412
413 fToolBar.setIconSize(QSize(24, 24));
414 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
415 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000416
417 QWidget *spacer = new QWidget();
418 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
419
chudy@google.comc432f002012-07-10 13:19:25 +0000420 fToolBar.addAction(&fActionRewind);
421 fToolBar.addAction(&fActionStepBack);
422 fToolBar.addAction(&fActionStepForward);
423 fToolBar.addAction(&fActionPlay);
424 fToolBar.addSeparator();
425 fToolBar.addAction(&fActionBreakpoint);
426 fToolBar.addSeparator();
427 fToolBar.addAction(&fActionDelete);
428 fToolBar.addAction(&fActionReload);
429 fToolBar.addSeparator();
430 fToolBar.addAction(&fActionSettings);
431 fToolBar.addWidget(spacer);
432 fToolBar.addWidget(&fFilter);
433 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000434
435 // TODO(chudy): Remove static call.
436 fDirectoryWidgetActive = false;
chudy@google.com7dcae672012-07-09 20:26:53 +0000437 fPath = "/usr/local/google/home/chudy/trunk-linux/debugger/skp";
chudy@google.com902ebe52012-06-29 14:21:22 +0000438 setupDirectoryWidget();
439 fDirectoryWidgetActive = true;
440
chudy@google.com902ebe52012-06-29 14:21:22 +0000441 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000442 fMenuFile.setTitle("File");
443 fMenuFile.addAction(&fActionOpen);
444 fMenuFile.addAction(&fActionClose);
445 fMenuNavigate.setTitle("Navigate");
446 fMenuNavigate.addAction(&fActionGoToLine);
447 fMenuView.setTitle("View");
448 fMenuView.addAction(&fActionInspector);
449 fMenuView.addAction(&fActionDirectory);
450
451 fActionGoToLine.setText("Go to Line...");
452 fActionGoToLine.setDisabled(true);
453 fMenuBar.addAction(fMenuFile.menuAction());
454 fMenuBar.addAction(fMenuView.menuAction());
455 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000456
chudy@google.com7dcae672012-07-09 20:26:53 +0000457 fPause = false;
458
chudy@google.comc432f002012-07-10 13:19:25 +0000459 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000460 QMetaObject::connectSlotsByName(SkDebuggerGUI);
461}
462
463void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000464 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000465 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000466 fDirectoryWidget.clear();
467 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000468 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000469 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000470 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000471 }
472}
473
chudy@google.com902ebe52012-06-29 14:21:22 +0000474void SkDebuggerGUI::loadPicture(QString fileName) {
chudy@google.comc432f002012-07-10 13:19:25 +0000475 fCanvasWidget.loadPicture(fileName);
476 std::vector<std::string> *cv = fCanvasWidget.getDrawCommands();
chudy@google.com7dcae672012-07-09 20:26:53 +0000477 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
478 * of the visibility filter. */
chudy@google.comc432f002012-07-10 13:19:25 +0000479 fCanvasWidget.toggleCurrentCommandFilter(
480 fSettingsWidget.getVisibilityButton()->isChecked());
chudy@google.com902ebe52012-06-29 14:21:22 +0000481 setupListWidget(cv);
482 setupComboBox(cv);
chudy@google.come606d6e2012-07-12 14:31:25 +0000483 fSettingsWidget.setDisabled(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000484}
485
486void SkDebuggerGUI::setupListWidget(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000487 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000488 int counter = 0;
489 for (unsigned int i = 0; i < cv->size(); i++) {
490 QListWidgetItem *item = new QListWidgetItem();
491 item->setData(Qt::DisplayRole, (*cv)[i].c_str());
492 item->setData(Qt::UserRole + 1, counter++);
493 item->setData(Qt::UserRole + 2, true);
chudy@google.comc432f002012-07-10 13:19:25 +0000494 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000495 }
496}
497
498void SkDebuggerGUI::setupComboBox(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000499 fFilter.clear();
500 fFilter.addItem("--Filter By Available Commands--");
chudy@google.com902ebe52012-06-29 14:21:22 +0000501
502 std::map<std::string, int> map;
503 for (unsigned int i = 0; i < cv->size(); i++) {
504 map[(*cv)[i]]++;
505 }
506
507 QString overview;
508 int counter;
chudy@google.com7dcae672012-07-09 20:26:53 +0000509 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
510 ++it) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000511 overview.append((it->first).c_str());
512 overview.append(": ");
513 overview.append(QString::number(it->second));
514 overview.append("<br/>");
chudy@google.com7dcae672012-07-09 20:26:53 +0000515 counter += it->second;
chudy@google.comc432f002012-07-10 13:19:25 +0000516 fFilter.addItem((it->first).c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000517 }
518 QString total;
519 total.append("Total Draw Commands: ");
520 total.append(QString::number(counter));
521 total.append("<br/>");
522 overview.insert(0, total);
523
524 overview.append("<br/>");
525 overview.append("SkBitmap Width: ");
526 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.comc432f002012-07-10 13:19:25 +0000527 overview.append(QString::number(fCanvasWidget.getBitmapWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000528 overview.append("px<br/>");
529 overview.append("SkBitmap Height: ");
chudy@google.comc432f002012-07-10 13:19:25 +0000530 overview.append(QString::number(fCanvasWidget.getBitmapHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000531 overview.append("px");
chudy@google.comc432f002012-07-10 13:19:25 +0000532 fInspectorWidget.setOverviewText(overview);
chudy@google.com902ebe52012-06-29 14:21:22 +0000533
534 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000535 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000536 fFilter.model());
537 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
538 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000539 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
540 firstItem->setSelectable(false);
541}