blob: 766dd6dd8384c1acbe5b367781fe970c111d50c2 [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.com9ca9bfe2012-07-12 21:58:14 +000078 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
chudy@google.come606d6e2012-07-12 14:31:25 +000079 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget,
80 SLOT(updateHit(int)));
chudy@google.com902ebe52012-06-29 14:21:22 +000081}
82
83SkDebuggerGUI::~SkDebuggerGUI() {
84}
85
86void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7dcae672012-07-09 20:26:53 +000087 if (!fBreakpointsActivated) {
chudy@google.com902ebe52012-06-29 14:21:22 +000088 fBreakpointsActivated = true;
89 } else {
90 fBreakpointsActivated = false;
91 }
92
chudy@google.comc432f002012-07-10 13:19:25 +000093 for (int row = 0; row < fListWidget.count(); row++) {
94 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +000095
96 if (item->checkState() == Qt::Unchecked && fBreakpointsActivated) {
97 item->setHidden(true);
98 } else {
99 item->setHidden(false);
100 }
101 }
102}
103
104void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000105 for (int row = 0; row < fListWidget.count(); row++) {
106 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000107 }
108}
109
110void SkDebuggerGUI::actionCommandFilter() {
chudy@google.comc432f002012-07-10 13:19:25 +0000111 fCanvasWidget.toggleCurrentCommandFilter(
112 fSettingsWidget.getVisibilityButton()->isChecked());
113 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000114}
115
116void SkDebuggerGUI::actionClose() {
117 this->close();
118}
119
120void SkDebuggerGUI::actionDelete() {
chudy@google.comc432f002012-07-10 13:19:25 +0000121 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com7dcae672012-07-09 20:26:53 +0000122 if (item->data(Qt::UserRole + 2) == true) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000123 item->setData(Qt::UserRole + 2, false);
chudy@google.come565de42012-07-12 14:15:54 +0000124 item->setData(Qt::UserRole + 3, QPixmap(":/images/Icons/delete.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000125 } else {
126 item->setData(Qt::UserRole + 2, true);
chudy@google.come565de42012-07-12 14:15:54 +0000127 item->setData(Qt::UserRole + 3, QPixmap(":/images/Icons/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000128 }
chudy@google.comc432f002012-07-10 13:19:25 +0000129 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000130 // NOTE(chudy): Forces a redraw up to current selected command.
chudy@google.comc432f002012-07-10 13:19:25 +0000131 fCanvasWidget.toggleCommand(currentRow);
chudy@google.com233e4b82012-07-12 14:38:49 +0000132 fCanvasWidget.drawTo(fPausedRow);
chudy@google.com902ebe52012-06-29 14:21:22 +0000133}
134
135void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000136 if (fInspectorWidget.isHidden()) {
137 fInspectorWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000138 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000139 fInspectorWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000140 }
141}
142
143void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000144 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000145 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000146 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000147 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000148 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000149 return;
150 }
151 }
chudy@google.comc432f002012-07-10 13:19:25 +0000152 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000153}
154
155void SkDebuggerGUI::actionReload() {
chudy@google.comc432f002012-07-10 13:19:25 +0000156 for (int row = 0; row < fListWidget.count(); row++) {
157 QListWidgetItem* item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000158 item->setData(Qt::UserRole + 2, true);
chudy@google.com7dcae672012-07-09 20:26:53 +0000159 item->setData(Qt::DecorationRole, QPixmap(":/images/Icons/blank.png"));
chudy@google.comc432f002012-07-10 13:19:25 +0000160 fCanvasWidget.toggleCommand(row, true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000161 }
chudy@google.comc432f002012-07-10 13:19:25 +0000162 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000163}
164
165void SkDebuggerGUI::actionRewind() {
166 /* NOTE(chudy): Hack. All skps opened so far start with save and concat
167 * commands that don't clear or reset the canvas. */
chudy@google.comc432f002012-07-10 13:19:25 +0000168 fListWidget.setCurrentRow(2);
chudy@google.com902ebe52012-06-29 14:21:22 +0000169}
170
chudy@google.com7dcae672012-07-09 20:26:53 +0000171void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000172 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000173}
174
chudy@google.com902ebe52012-06-29 14:21:22 +0000175void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000176 if (fSettingsWidget.isHidden()) {
177 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000178 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000179 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000180 }
181}
182
183void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000184 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000185 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000186 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000187 }
188}
189
190void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000191 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000192 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000193 QString curCount = QString::number(fListWidget.count());
194 if (currentRow < fListWidget.count() - 1) {
195 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000196 }
197}
198
199void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
200 if (fDirectoryWidgetActive) {
201 QString fileName;
202 fileName.append(fPath);
203 fileName.append("/");
204 fileName.append(item->text());
205 loadPicture(fileName);
206 }
207}
208
209void SkDebuggerGUI::openFile() {
chudy@google.com7dcae672012-07-09 20:26:53 +0000210 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
211 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000212 fDirectoryWidgetActive = false;
213 if (!fileName.isNull()) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000214 QFileInfo pathInfo(fileName);
215 fPath = pathInfo.path();
216 loadPicture(fileName);
217 setupDirectoryWidget();
218 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000219 fDirectoryWidgetActive = true;
220}
221
chudy@google.comc432f002012-07-10 13:19:25 +0000222void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000223 // Qt uses 0 for unchecked, 1 for partially enabled and 2 for checked.
chudy@google.comc432f002012-07-10 13:19:25 +0000224 if (isPaused) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000225 fPause = true;
chudy@google.com233e4b82012-07-12 14:38:49 +0000226 fPausedRow = fListWidget.currentRow();
chudy@google.com7dcae672012-07-09 20:26:53 +0000227 } else {
228 fPause = false;
chudy@google.comc432f002012-07-10 13:19:25 +0000229 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com7dcae672012-07-09 20:26:53 +0000230 }
231}
232
chudy@google.com902ebe52012-06-29 14:21:22 +0000233void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comc432f002012-07-10 13:19:25 +0000234 int currentRow = fListWidget.currentRow();
chudy@google.com7dcae672012-07-09 20:26:53 +0000235 if (!fPause) {
chudy@google.comc432f002012-07-10 13:19:25 +0000236 fCanvasWidget.drawTo(currentRow);
chudy@google.com7dcae672012-07-09 20:26:53 +0000237 }
chudy@google.comc432f002012-07-10 13:19:25 +0000238 std::vector<std::string> *v = fCanvasWidget.getCurrentCommandInfo(
chudy@google.com7dcae672012-07-09 20:26:53 +0000239 currentRow);
chudy@google.com902ebe52012-06-29 14:21:22 +0000240
chudy@google.com7dcae672012-07-09 20:26:53 +0000241 /* TODO(chudy): Add command type before parameters. Rename v
242 * to something more informative. */
243 if (v) {
244 std::vector<std::string>::iterator it;
chudy@google.com902ebe52012-06-29 14:21:22 +0000245
chudy@google.com7dcae672012-07-09 20:26:53 +0000246 QString info;
247 info.append("<b>Parameters: </b><br/>");
248 for (it = v->begin(); it != v->end(); ++it) {
249 info.append(QString((*it).c_str()));
250 info.append("<br/>");
chudy@google.com902ebe52012-06-29 14:21:22 +0000251 }
chudy@google.comc432f002012-07-10 13:19:25 +0000252 fInspectorWidget.setDetailText(info);
253 fInspectorWidget.setDisabled(false);
254 fInspectorWidget.setMatrix(fCanvasWidget.getCurrentMatrix());
255 fInspectorWidget.setClip(fCanvasWidget.getCurrentClip());
chudy@google.com902ebe52012-06-29 14:21:22 +0000256 }
257}
258
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000259void SkDebuggerGUI::selectCommand(int command) {
260 if (fPause) {
261 fListWidget.setCurrentRow(command);
262 }
263}
264
chudy@google.com902ebe52012-06-29 14:21:22 +0000265void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000266 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000267 if (item->checkState() == Qt::Unchecked) {
268 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000269 item->setData(Qt::DecorationRole,
270 QPixmap(":/images/Icons/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000271 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000272 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000273 item->setData(Qt::DecorationRole,
274 QPixmap(":/images/Icons/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000275 }
276}
277
278void SkDebuggerGUI::toggleDirectory() {
chudy@google.comc432f002012-07-10 13:19:25 +0000279 if (fDirectoryWidget.isHidden()) {
280 fDirectoryWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000281 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000282 fDirectoryWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000283 }
284}
285
286void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000287 for (int row = 0; row < fListWidget.count(); row++) {
288 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000289 if (item->text() == string) {
290 item->setHidden(false);
291 } else {
292 item->setHidden(true);
293 }
294 }
295}
296
297void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
298 QIcon windowIcon;
chudy@google.com7dcae672012-07-09 20:26:53 +0000299 windowIcon.addFile(QString::fromUtf8(":/images/Icons/skia.png"), QSize(),
300 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000301 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
302 SkDebuggerGUI->resize(1200, 1000);
303 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000304 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000305
306 QIcon open;
chudy@google.com7dcae672012-07-09 20:26:53 +0000307 open.addFile(QString::fromUtf8(":/images/Icons/package-br32.png"), QSize(),
308 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000309 fActionOpen.setIcon(open);
310 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000311
312 QIcon breakpoint;
chudy@google.com7dcae672012-07-09 20:26:53 +0000313 breakpoint.addFile(QString::fromUtf8(":/images/Icons/breakpoint.png"),
314 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000315 fActionBreakpoint.setIcon(breakpoint);
316 fActionBreakpoint.setText("Show Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000317
318 QIcon cancel;
chudy@google.com7dcae672012-07-09 20:26:53 +0000319 cancel.addFile(QString::fromUtf8(":/images/Icons/reset.png"), QSize(),
320 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000321 fActionCancel.setIcon(cancel);
322 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000323
chudy@google.comc432f002012-07-10 13:19:25 +0000324 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000325
chudy@google.comc432f002012-07-10 13:19:25 +0000326 QIcon deleteIcon;
327 deleteIcon.addFile(QString::fromUtf8(":/images/Icons/delete.png"), QSize(),
328 QIcon::Normal, QIcon::Off);
329 fActionDelete.setIcon(deleteIcon);
330 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000331
chudy@google.comc432f002012-07-10 13:19:25 +0000332 QIcon directory;
333 directory.addFile(QString::fromUtf8(":/images/Icons/drawer-open-icon.png"),
334 QSize(), QIcon::Normal, QIcon::Off);
335 fActionDirectory.setIcon(directory);
336 fActionDirectory.setText("Toggle Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000337
chudy@google.comc432f002012-07-10 13:19:25 +0000338 QIcon inspector;
339 inspector.addFile(QString::fromUtf8(":/images/Icons/inspector.png"),
340 QSize(), QIcon::Normal, QIcon::Off);
341 fActionInspector.setIcon(inspector);
342 fActionInspector.setText("Toggle Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000343
chudy@google.comc432f002012-07-10 13:19:25 +0000344 QIcon play;
345 play.addFile(QString::fromUtf8(":/images/Icons/play.png"), QSize(),
346 QIcon::Normal, QIcon::Off);
347 fActionPlay.setIcon(play);
348 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000349
chudy@google.comc432f002012-07-10 13:19:25 +0000350 QIcon reload;
351 reload.addFile(QString::fromUtf8(":/images/Icons/reload.png"), QSize(),
352 QIcon::Normal, QIcon::Off);
353 fActionReload.setIcon(reload);
354 fActionReload.setText("Reset Picture");
chudy@google.com902ebe52012-06-29 14:21:22 +0000355
chudy@google.comc432f002012-07-10 13:19:25 +0000356 QIcon rewind;
357 rewind.addFile(QString::fromUtf8(":/images/Icons/rewind.png"), QSize(),
358 QIcon::Normal, QIcon::Off);
359 fActionRewind.setIcon(rewind);
360 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000361
chudy@google.comc432f002012-07-10 13:19:25 +0000362 QIcon settings;
363 settings.addFile(QString::fromUtf8(":/images/Icons/settings.png"), QSize(),
364 QIcon::Normal, QIcon::Off);
365 fActionSettings.setIcon(settings);
366 fActionSettings.setText("Settings");
chudy@google.com902ebe52012-06-29 14:21:22 +0000367
chudy@google.comc432f002012-07-10 13:19:25 +0000368 QIcon stepBack;
369 stepBack.addFile(QString::fromUtf8(":/images/Icons/back.png"), QSize(),
370 QIcon::Normal, QIcon::Off);
371 fActionStepBack.setIcon(stepBack);
372 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000373
chudy@google.comc432f002012-07-10 13:19:25 +0000374 QIcon stepForward;
375 stepForward.addFile(QString::fromUtf8(":/images/Icons/go-next.png"),
376 QSize(), QIcon::Normal, QIcon::Off);
377 fActionStepForward.setIcon(stepForward);
378 fActionStepForward.setText("Step Forward");
379
380 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
381 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
382 fListWidget.setMaximumWidth(250);
383
384 fFilter.addItem("--Filter By Available Commands--");
385
386 fDirectoryWidget.setMaximumWidth(250);
387 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
388
389 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000390 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000391
chudy@google.comc432f002012-07-10 13:19:25 +0000392 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000393 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000394 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000395
chudy@google.comc432f002012-07-10 13:19:25 +0000396 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
397 QSizePolicy::Expanding);
398 fSettingsWidget.setMaximumWidth(250);
399 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000400
chudy@google.comc432f002012-07-10 13:19:25 +0000401 fLeftColumnLayout.setSpacing(6);
402 fLeftColumnLayout.addWidget(&fListWidget);
403 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000404
chudy@google.comc432f002012-07-10 13:19:25 +0000405 fCanvasAndSettingsLayout.setSpacing(6);
406 fCanvasAndSettingsLayout.addWidget(&fCanvasWidget);
407 fCanvasAndSettingsLayout.addWidget(&fSettingsWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000408
chudy@google.comc432f002012-07-10 13:19:25 +0000409 fMainAndRightColumnLayout.setSpacing(6);
410 fMainAndRightColumnLayout.addLayout(&fCanvasAndSettingsLayout);
411 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000412
chudy@google.comc432f002012-07-10 13:19:25 +0000413 fContainerLayout.setSpacing(6);
414 fContainerLayout.setContentsMargins(11, 11, 11, 11);
415 fContainerLayout.addLayout(&fLeftColumnLayout);
416 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
417
418 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
419 SkDebuggerGUI->setStatusBar(&fStatusBar);
420
421 fToolBar.setIconSize(QSize(24, 24));
422 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
423 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000424
425 QWidget *spacer = new QWidget();
426 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
427
chudy@google.comc432f002012-07-10 13:19:25 +0000428 fToolBar.addAction(&fActionRewind);
429 fToolBar.addAction(&fActionStepBack);
430 fToolBar.addAction(&fActionStepForward);
431 fToolBar.addAction(&fActionPlay);
432 fToolBar.addSeparator();
433 fToolBar.addAction(&fActionBreakpoint);
434 fToolBar.addSeparator();
435 fToolBar.addAction(&fActionDelete);
436 fToolBar.addAction(&fActionReload);
437 fToolBar.addSeparator();
438 fToolBar.addAction(&fActionSettings);
439 fToolBar.addWidget(spacer);
440 fToolBar.addWidget(&fFilter);
441 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000442
443 // TODO(chudy): Remove static call.
444 fDirectoryWidgetActive = false;
chudy@google.com7dcae672012-07-09 20:26:53 +0000445 fPath = "/usr/local/google/home/chudy/trunk-linux/debugger/skp";
chudy@google.com902ebe52012-06-29 14:21:22 +0000446 setupDirectoryWidget();
447 fDirectoryWidgetActive = true;
448
chudy@google.com902ebe52012-06-29 14:21:22 +0000449 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000450 fMenuFile.setTitle("File");
451 fMenuFile.addAction(&fActionOpen);
452 fMenuFile.addAction(&fActionClose);
453 fMenuNavigate.setTitle("Navigate");
454 fMenuNavigate.addAction(&fActionGoToLine);
455 fMenuView.setTitle("View");
456 fMenuView.addAction(&fActionInspector);
457 fMenuView.addAction(&fActionDirectory);
458
459 fActionGoToLine.setText("Go to Line...");
460 fActionGoToLine.setDisabled(true);
461 fMenuBar.addAction(fMenuFile.menuAction());
462 fMenuBar.addAction(fMenuView.menuAction());
463 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000464
chudy@google.com7dcae672012-07-09 20:26:53 +0000465 fPause = false;
466
chudy@google.comc432f002012-07-10 13:19:25 +0000467 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000468 QMetaObject::connectSlotsByName(SkDebuggerGUI);
469}
470
471void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000472 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000473 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000474 fDirectoryWidget.clear();
475 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000476 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000477 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000478 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000479 }
480}
481
chudy@google.com902ebe52012-06-29 14:21:22 +0000482void SkDebuggerGUI::loadPicture(QString fileName) {
chudy@google.comc432f002012-07-10 13:19:25 +0000483 fCanvasWidget.loadPicture(fileName);
484 std::vector<std::string> *cv = fCanvasWidget.getDrawCommands();
chudy@google.com7dcae672012-07-09 20:26:53 +0000485 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
486 * of the visibility filter. */
chudy@google.comc432f002012-07-10 13:19:25 +0000487 fCanvasWidget.toggleCurrentCommandFilter(
488 fSettingsWidget.getVisibilityButton()->isChecked());
chudy@google.com902ebe52012-06-29 14:21:22 +0000489 setupListWidget(cv);
490 setupComboBox(cv);
chudy@google.come606d6e2012-07-12 14:31:25 +0000491 fSettingsWidget.setDisabled(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000492}
493
494void SkDebuggerGUI::setupListWidget(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000495 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000496 int counter = 0;
497 for (unsigned int i = 0; i < cv->size(); i++) {
498 QListWidgetItem *item = new QListWidgetItem();
499 item->setData(Qt::DisplayRole, (*cv)[i].c_str());
500 item->setData(Qt::UserRole + 1, counter++);
501 item->setData(Qt::UserRole + 2, true);
chudy@google.comc432f002012-07-10 13:19:25 +0000502 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000503 }
504}
505
506void SkDebuggerGUI::setupComboBox(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000507 fFilter.clear();
508 fFilter.addItem("--Filter By Available Commands--");
chudy@google.com902ebe52012-06-29 14:21:22 +0000509
510 std::map<std::string, int> map;
511 for (unsigned int i = 0; i < cv->size(); i++) {
512 map[(*cv)[i]]++;
513 }
514
515 QString overview;
516 int counter;
chudy@google.com7dcae672012-07-09 20:26:53 +0000517 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
518 ++it) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000519 overview.append((it->first).c_str());
520 overview.append(": ");
521 overview.append(QString::number(it->second));
522 overview.append("<br/>");
chudy@google.com7dcae672012-07-09 20:26:53 +0000523 counter += it->second;
chudy@google.comc432f002012-07-10 13:19:25 +0000524 fFilter.addItem((it->first).c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000525 }
526 QString total;
527 total.append("Total Draw Commands: ");
528 total.append(QString::number(counter));
529 total.append("<br/>");
530 overview.insert(0, total);
531
532 overview.append("<br/>");
533 overview.append("SkBitmap Width: ");
534 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.comc432f002012-07-10 13:19:25 +0000535 overview.append(QString::number(fCanvasWidget.getBitmapWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000536 overview.append("px<br/>");
537 overview.append("SkBitmap Height: ");
chudy@google.comc432f002012-07-10 13:19:25 +0000538 overview.append(QString::number(fCanvasWidget.getBitmapHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000539 overview.append("px");
chudy@google.comc432f002012-07-10 13:19:25 +0000540 fInspectorWidget.setOverviewText(overview);
chudy@google.com902ebe52012-06-29 14:21:22 +0000541
542 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000543 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000544 fFilter.model());
545 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
546 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000547 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
548 firstItem->setSelectable(false);
549}