blob: 33a7190099608bf1fc50f81838be90b248e1ec8d [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.com7dcae672012-07-09 20:26:53 +0000121 item->setData(Qt::DecorationRole, QPixmap(":/images/Icons/delete.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000122 } else {
123 item->setData(Qt::UserRole + 2, true);
chudy@google.com7dcae672012-07-09 20:26:53 +0000124 if (item->checkState() == Qt::Unchecked) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000125 item->setData(Qt::DecorationRole,
126 QPixmap(":/images/Icons/blank.png"));
127 } else {
128 item->setData(Qt::DecorationRole,
129 QPixmap(":/images/Icons/breakpoint_16x16.png"));
130 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000131 }
chudy@google.comc432f002012-07-10 13:19:25 +0000132 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000133 // NOTE(chudy): Forces a redraw up to current selected command.
chudy@google.comc432f002012-07-10 13:19:25 +0000134 fCanvasWidget.toggleCommand(currentRow);
135 fCanvasWidget.drawTo(currentRow);
chudy@google.com902ebe52012-06-29 14:21:22 +0000136}
137
138void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000139 if (fInspectorWidget.isHidden()) {
140 fInspectorWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000141 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000142 fInspectorWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000143 }
144}
145
146void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000147 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000148 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000149 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000150 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000151 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000152 return;
153 }
154 }
chudy@google.comc432f002012-07-10 13:19:25 +0000155 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000156}
157
158void SkDebuggerGUI::actionReload() {
chudy@google.comc432f002012-07-10 13:19:25 +0000159 for (int row = 0; row < fListWidget.count(); row++) {
160 QListWidgetItem* item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000161 item->setData(Qt::UserRole + 2, true);
chudy@google.com7dcae672012-07-09 20:26:53 +0000162 item->setData(Qt::DecorationRole, QPixmap(":/images/Icons/blank.png"));
chudy@google.comc432f002012-07-10 13:19:25 +0000163 fCanvasWidget.toggleCommand(row, true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000164 }
chudy@google.comc432f002012-07-10 13:19:25 +0000165 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000166}
167
168void SkDebuggerGUI::actionRewind() {
169 /* NOTE(chudy): Hack. All skps opened so far start with save and concat
170 * commands that don't clear or reset the canvas. */
chudy@google.comc432f002012-07-10 13:19:25 +0000171 fListWidget.setCurrentRow(2);
chudy@google.com902ebe52012-06-29 14:21:22 +0000172}
173
chudy@google.com7dcae672012-07-09 20:26:53 +0000174void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000175 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000176}
177
chudy@google.com902ebe52012-06-29 14:21:22 +0000178void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000179 if (fSettingsWidget.isHidden()) {
180 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000181 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000182 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000183 }
184}
185
186void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000187 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000188 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000189 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000190 }
191}
192
193void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000194 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000195 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000196 QString curCount = QString::number(fListWidget.count());
197 if (currentRow < fListWidget.count() - 1) {
198 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000199 }
200}
201
202void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
203 if (fDirectoryWidgetActive) {
204 QString fileName;
205 fileName.append(fPath);
206 fileName.append("/");
207 fileName.append(item->text());
208 loadPicture(fileName);
209 }
210}
211
212void SkDebuggerGUI::openFile() {
chudy@google.com7dcae672012-07-09 20:26:53 +0000213 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
214 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000215 fDirectoryWidgetActive = false;
216 if (!fileName.isNull()) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000217 QFileInfo pathInfo(fileName);
218 fPath = pathInfo.path();
219 loadPicture(fileName);
220 setupDirectoryWidget();
221 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000222 fDirectoryWidgetActive = true;
223}
224
chudy@google.comc432f002012-07-10 13:19:25 +0000225void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000226 // Qt uses 0 for unchecked, 1 for partially enabled and 2 for checked.
chudy@google.comc432f002012-07-10 13:19:25 +0000227 if (isPaused) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000228 fPause = true;
229 } else {
230 fPause = false;
chudy@google.comc432f002012-07-10 13:19:25 +0000231 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com7dcae672012-07-09 20:26:53 +0000232 }
233}
234
chudy@google.com902ebe52012-06-29 14:21:22 +0000235void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comc432f002012-07-10 13:19:25 +0000236 int currentRow = fListWidget.currentRow();
chudy@google.com7dcae672012-07-09 20:26:53 +0000237 if (!fPause) {
chudy@google.comc432f002012-07-10 13:19:25 +0000238 fCanvasWidget.drawTo(currentRow);
chudy@google.com7dcae672012-07-09 20:26:53 +0000239 }
chudy@google.comc432f002012-07-10 13:19:25 +0000240 std::vector<std::string> *v = fCanvasWidget.getCurrentCommandInfo(
chudy@google.com7dcae672012-07-09 20:26:53 +0000241 currentRow);
chudy@google.com902ebe52012-06-29 14:21:22 +0000242
chudy@google.com7dcae672012-07-09 20:26:53 +0000243 /* TODO(chudy): Add command type before parameters. Rename v
244 * to something more informative. */
245 if (v) {
246 std::vector<std::string>::iterator it;
chudy@google.com902ebe52012-06-29 14:21:22 +0000247
chudy@google.com7dcae672012-07-09 20:26:53 +0000248 QString info;
249 info.append("<b>Parameters: </b><br/>");
250 for (it = v->begin(); it != v->end(); ++it) {
251 info.append(QString((*it).c_str()));
252 info.append("<br/>");
chudy@google.com902ebe52012-06-29 14:21:22 +0000253 }
chudy@google.comc432f002012-07-10 13:19:25 +0000254 fInspectorWidget.setDetailText(info);
255 fInspectorWidget.setDisabled(false);
256 fInspectorWidget.setMatrix(fCanvasWidget.getCurrentMatrix());
257 fInspectorWidget.setClip(fCanvasWidget.getCurrentClip());
chudy@google.com902ebe52012-06-29 14:21:22 +0000258 }
259}
260
261void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000262 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000263 if (item->checkState() == Qt::Unchecked) {
264 item->setCheckState(Qt::Checked);
265
chudy@google.com902ebe52012-06-29 14:21:22 +0000266 /* NOTE(chudy): If the command is toggled as hidden that takes
267 * precendence over the breakpoint icon.
268 */
chudy@google.com7dcae672012-07-09 20:26:53 +0000269 if (item->data(Qt::UserRole + 2) == false) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000270 item->setData(Qt::DecorationRole,
271 QPixmap(":/images/Icons/delete.png"));
272 } else {
273 item->setData(Qt::DecorationRole,
274 QPixmap(":/images/Icons/breakpoint_16x16.png"));
275 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000276 } else {
277
278 /* NOTE(chudy): When untoggling as a breakpoint if the command
279 * is hidden then the portraying icon should remain the delete icon.
280 */
281 item->setCheckState(Qt::Unchecked);
282
chudy@google.com7dcae672012-07-09 20:26:53 +0000283 if (item->data(Qt::UserRole + 2) == false) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000284 item->setData(Qt::DecorationRole,
285 QPixmap(":/images/Icons/delete.png"));
286 } else {
287 item->setData(Qt::DecorationRole,
288 QPixmap(":/images/Icons/blank.png"));
289 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000290 }
291}
292
293void SkDebuggerGUI::toggleDirectory() {
chudy@google.comc432f002012-07-10 13:19:25 +0000294 if (fDirectoryWidget.isHidden()) {
295 fDirectoryWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000296 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000297 fDirectoryWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000298 }
299}
300
301void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000302 for (int row = 0; row < fListWidget.count(); row++) {
303 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000304 if (item->text() == string) {
305 item->setHidden(false);
306 } else {
307 item->setHidden(true);
308 }
309 }
310}
311
312void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
313 QIcon windowIcon;
chudy@google.com7dcae672012-07-09 20:26:53 +0000314 windowIcon.addFile(QString::fromUtf8(":/images/Icons/skia.png"), QSize(),
315 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000316 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
317 SkDebuggerGUI->resize(1200, 1000);
318 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000319 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000320
321 QIcon open;
chudy@google.com7dcae672012-07-09 20:26:53 +0000322 open.addFile(QString::fromUtf8(":/images/Icons/package-br32.png"), QSize(),
323 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000324 fActionOpen.setIcon(open);
325 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000326
327 QIcon breakpoint;
chudy@google.com7dcae672012-07-09 20:26:53 +0000328 breakpoint.addFile(QString::fromUtf8(":/images/Icons/breakpoint.png"),
329 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000330 fActionBreakpoint.setIcon(breakpoint);
331 fActionBreakpoint.setText("Show Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000332
333 QIcon cancel;
chudy@google.com7dcae672012-07-09 20:26:53 +0000334 cancel.addFile(QString::fromUtf8(":/images/Icons/reset.png"), QSize(),
335 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000336 fActionCancel.setIcon(cancel);
337 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000338
chudy@google.comc432f002012-07-10 13:19:25 +0000339 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000340
chudy@google.comc432f002012-07-10 13:19:25 +0000341 QIcon deleteIcon;
342 deleteIcon.addFile(QString::fromUtf8(":/images/Icons/delete.png"), QSize(),
343 QIcon::Normal, QIcon::Off);
344 fActionDelete.setIcon(deleteIcon);
345 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000346
chudy@google.comc432f002012-07-10 13:19:25 +0000347 QIcon directory;
348 directory.addFile(QString::fromUtf8(":/images/Icons/drawer-open-icon.png"),
349 QSize(), QIcon::Normal, QIcon::Off);
350 fActionDirectory.setIcon(directory);
351 fActionDirectory.setText("Toggle Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000352
chudy@google.comc432f002012-07-10 13:19:25 +0000353 QIcon inspector;
354 inspector.addFile(QString::fromUtf8(":/images/Icons/inspector.png"),
355 QSize(), QIcon::Normal, QIcon::Off);
356 fActionInspector.setIcon(inspector);
357 fActionInspector.setText("Toggle Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000358
chudy@google.comc432f002012-07-10 13:19:25 +0000359 QIcon play;
360 play.addFile(QString::fromUtf8(":/images/Icons/play.png"), QSize(),
361 QIcon::Normal, QIcon::Off);
362 fActionPlay.setIcon(play);
363 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000364
chudy@google.comc432f002012-07-10 13:19:25 +0000365 QIcon reload;
366 reload.addFile(QString::fromUtf8(":/images/Icons/reload.png"), QSize(),
367 QIcon::Normal, QIcon::Off);
368 fActionReload.setIcon(reload);
369 fActionReload.setText("Reset Picture");
chudy@google.com902ebe52012-06-29 14:21:22 +0000370
chudy@google.comc432f002012-07-10 13:19:25 +0000371 QIcon rewind;
372 rewind.addFile(QString::fromUtf8(":/images/Icons/rewind.png"), QSize(),
373 QIcon::Normal, QIcon::Off);
374 fActionRewind.setIcon(rewind);
375 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000376
chudy@google.comc432f002012-07-10 13:19:25 +0000377 QIcon settings;
378 settings.addFile(QString::fromUtf8(":/images/Icons/settings.png"), QSize(),
379 QIcon::Normal, QIcon::Off);
380 fActionSettings.setIcon(settings);
381 fActionSettings.setText("Settings");
chudy@google.com902ebe52012-06-29 14:21:22 +0000382
chudy@google.comc432f002012-07-10 13:19:25 +0000383 QIcon stepBack;
384 stepBack.addFile(QString::fromUtf8(":/images/Icons/back.png"), QSize(),
385 QIcon::Normal, QIcon::Off);
386 fActionStepBack.setIcon(stepBack);
387 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000388
chudy@google.comc432f002012-07-10 13:19:25 +0000389 QIcon stepForward;
390 stepForward.addFile(QString::fromUtf8(":/images/Icons/go-next.png"),
391 QSize(), QIcon::Normal, QIcon::Off);
392 fActionStepForward.setIcon(stepForward);
393 fActionStepForward.setText("Step Forward");
394
395 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
396 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
397 fListWidget.setMaximumWidth(250);
398
399 fFilter.addItem("--Filter By Available Commands--");
400
401 fDirectoryWidget.setMaximumWidth(250);
402 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
403
404 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000405 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000406
chudy@google.comc432f002012-07-10 13:19:25 +0000407 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000408 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000409 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000410
chudy@google.comc432f002012-07-10 13:19:25 +0000411 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
412 QSizePolicy::Expanding);
413 fSettingsWidget.setMaximumWidth(250);
414 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000415
chudy@google.comc432f002012-07-10 13:19:25 +0000416 fLeftColumnLayout.setSpacing(6);
417 fLeftColumnLayout.addWidget(&fListWidget);
418 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000419
chudy@google.comc432f002012-07-10 13:19:25 +0000420 fCanvasAndSettingsLayout.setSpacing(6);
421 fCanvasAndSettingsLayout.addWidget(&fCanvasWidget);
422 fCanvasAndSettingsLayout.addWidget(&fSettingsWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000423
chudy@google.comc432f002012-07-10 13:19:25 +0000424 fMainAndRightColumnLayout.setSpacing(6);
425 fMainAndRightColumnLayout.addLayout(&fCanvasAndSettingsLayout);
426 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000427
chudy@google.comc432f002012-07-10 13:19:25 +0000428 fContainerLayout.setSpacing(6);
429 fContainerLayout.setContentsMargins(11, 11, 11, 11);
430 fContainerLayout.addLayout(&fLeftColumnLayout);
431 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
432
433 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
434 SkDebuggerGUI->setStatusBar(&fStatusBar);
435
436 fToolBar.setIconSize(QSize(24, 24));
437 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
438 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000439
440 QWidget *spacer = new QWidget();
441 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
442
chudy@google.comc432f002012-07-10 13:19:25 +0000443 fToolBar.addAction(&fActionRewind);
444 fToolBar.addAction(&fActionStepBack);
445 fToolBar.addAction(&fActionStepForward);
446 fToolBar.addAction(&fActionPlay);
447 fToolBar.addSeparator();
448 fToolBar.addAction(&fActionBreakpoint);
449 fToolBar.addSeparator();
450 fToolBar.addAction(&fActionDelete);
451 fToolBar.addAction(&fActionReload);
452 fToolBar.addSeparator();
453 fToolBar.addAction(&fActionSettings);
454 fToolBar.addWidget(spacer);
455 fToolBar.addWidget(&fFilter);
456 fToolBar.addAction(&fActionCancel);
chudy@google.com902ebe52012-06-29 14:21:22 +0000457
458 // TODO(chudy): Remove static call.
459 fDirectoryWidgetActive = false;
chudy@google.com7dcae672012-07-09 20:26:53 +0000460 fPath = "/usr/local/google/home/chudy/trunk-linux/debugger/skp";
chudy@google.com902ebe52012-06-29 14:21:22 +0000461 setupDirectoryWidget();
462 fDirectoryWidgetActive = true;
463
chudy@google.com902ebe52012-06-29 14:21:22 +0000464 // Menu Bar
chudy@google.comc432f002012-07-10 13:19:25 +0000465 fMenuFile.setTitle("File");
466 fMenuFile.addAction(&fActionOpen);
467 fMenuFile.addAction(&fActionClose);
468 fMenuNavigate.setTitle("Navigate");
469 fMenuNavigate.addAction(&fActionGoToLine);
470 fMenuView.setTitle("View");
471 fMenuView.addAction(&fActionInspector);
472 fMenuView.addAction(&fActionDirectory);
473
474 fActionGoToLine.setText("Go to Line...");
475 fActionGoToLine.setDisabled(true);
476 fMenuBar.addAction(fMenuFile.menuAction());
477 fMenuBar.addAction(fMenuView.menuAction());
478 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000479
chudy@google.com7dcae672012-07-09 20:26:53 +0000480 fPause = false;
481
chudy@google.comc432f002012-07-10 13:19:25 +0000482 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000483 QMetaObject::connectSlotsByName(SkDebuggerGUI);
484}
485
486void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000487 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000488 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000489 fDirectoryWidget.clear();
490 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000491 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000492 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000493 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000494 }
495}
496
chudy@google.com902ebe52012-06-29 14:21:22 +0000497void SkDebuggerGUI::loadPicture(QString fileName) {
chudy@google.comc432f002012-07-10 13:19:25 +0000498 fCanvasWidget.loadPicture(fileName);
499 std::vector<std::string> *cv = fCanvasWidget.getDrawCommands();
chudy@google.com7dcae672012-07-09 20:26:53 +0000500 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
501 * of the visibility filter. */
chudy@google.comc432f002012-07-10 13:19:25 +0000502 fCanvasWidget.toggleCurrentCommandFilter(
503 fSettingsWidget.getVisibilityButton()->isChecked());
chudy@google.com902ebe52012-06-29 14:21:22 +0000504 setupListWidget(cv);
505 setupComboBox(cv);
506}
507
508void SkDebuggerGUI::setupListWidget(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000509 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000510 int counter = 0;
511 for (unsigned int i = 0; i < cv->size(); i++) {
512 QListWidgetItem *item = new QListWidgetItem();
513 item->setData(Qt::DisplayRole, (*cv)[i].c_str());
514 item->setData(Qt::UserRole + 1, counter++);
515 item->setData(Qt::UserRole + 2, true);
chudy@google.comc432f002012-07-10 13:19:25 +0000516 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000517 }
518}
519
520void SkDebuggerGUI::setupComboBox(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000521 fFilter.clear();
522 fFilter.addItem("--Filter By Available Commands--");
chudy@google.com902ebe52012-06-29 14:21:22 +0000523
524 std::map<std::string, int> map;
525 for (unsigned int i = 0; i < cv->size(); i++) {
526 map[(*cv)[i]]++;
527 }
528
529 QString overview;
530 int counter;
chudy@google.com7dcae672012-07-09 20:26:53 +0000531 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
532 ++it) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000533 overview.append((it->first).c_str());
534 overview.append(": ");
535 overview.append(QString::number(it->second));
536 overview.append("<br/>");
chudy@google.com7dcae672012-07-09 20:26:53 +0000537 counter += it->second;
chudy@google.comc432f002012-07-10 13:19:25 +0000538 fFilter.addItem((it->first).c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000539 }
540 QString total;
541 total.append("Total Draw Commands: ");
542 total.append(QString::number(counter));
543 total.append("<br/>");
544 overview.insert(0, total);
545
546 overview.append("<br/>");
547 overview.append("SkBitmap Width: ");
548 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.comc432f002012-07-10 13:19:25 +0000549 overview.append(QString::number(fCanvasWidget.getBitmapWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000550 overview.append("px<br/>");
551 overview.append("SkBitmap Height: ");
chudy@google.comc432f002012-07-10 13:19:25 +0000552 overview.append(QString::number(fCanvasWidget.getBitmapHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000553 overview.append("px");
chudy@google.comc432f002012-07-10 13:19:25 +0000554 fInspectorWidget.setOverviewText(overview);
chudy@google.com902ebe52012-06-29 14:21:22 +0000555
556 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000557 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000558 fFilter.model());
559 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
560 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000561 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
562 firstItem->setSelectable(false);
563}