blob: 1c5b48c2df7bf111c575638297971e200471660e [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)
chudy@google.come504de02012-07-16 18:35:23 +000017 , fActionClearDeletes(this)
chudy@google.comc432f002012-07-10 13:19:25 +000018 , fActionClose(this)
chudy@google.come504de02012-07-16 18:35:23 +000019 , fActionCreateBreakpoint(this)
chudy@google.comc432f002012-07-10 13:19:25 +000020 , fActionDelete(this)
21 , fActionDirectory(this)
22 , fActionGoToLine(this)
23 , fActionInspector(this)
24 , fActionPlay(this)
chudy@google.come504de02012-07-16 18:35:23 +000025 , fActionPause(this)
chudy@google.comc432f002012-07-10 13:19:25 +000026 , fActionReload(this)
27 , fActionRewind(this)
chudy@google.comc432f002012-07-10 13:19:25 +000028 , fActionStepBack(this)
29 , fActionStepForward(this)
30 , fCentralWidget(this)
31 , fFilter(&fCentralWidget)
32 , fContainerLayout(&fCentralWidget)
33 , fListWidget(&fCentralWidget)
34 , fDirectoryWidget(&fCentralWidget)
35 , fCanvasWidget(&fCentralWidget)
36 , fSettingsWidget(&fCentralWidget)
37 , fStatusBar(this)
38 , fMenuBar(this)
39 , fMenuFile(this)
40 , fMenuNavigate(this)
41 , fMenuView(this)
42 , fToolBar(this)
43{
chudy@google.com902ebe52012-06-29 14:21:22 +000044 setupUi(this);
chudy@google.comc432f002012-07-10 13:19:25 +000045 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*,
chudy@google.com7dcae672012-07-09 20:26:53 +000046 QListWidgetItem*)), this,
47 SLOT(registerListClick(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000048 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
49 connect(&fActionDirectory, SIGNAL(triggered()), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000050 SLOT(toggleDirectory()));
chudy@google.comc432f002012-07-10 13:19:25 +000051 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*,
chudy@google.com7dcae672012-07-09 20:26:53 +000052 QListWidgetItem*)), this,
53 SLOT(loadFile(QListWidgetItem *)));
chudy@google.comc432f002012-07-10 13:19:25 +000054 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
55 connect(&fActionReload, SIGNAL(triggered()), this, SLOT(actionReload()));
56 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000057 SLOT(toggleBreakpoint()));
chudy@google.comc432f002012-07-10 13:19:25 +000058 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
59 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
60 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
61 connect(&fActionStepForward, SIGNAL(triggered()), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000062 SLOT(actionStepForward()));
chudy@google.comc432f002012-07-10 13:19:25 +000063 connect(&fActionBreakpoint, SIGNAL(triggered()), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000064 SLOT(actionBreakpoints()));
chudy@google.comc432f002012-07-10 13:19:25 +000065 connect(&fActionInspector, SIGNAL(triggered()), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000066 SLOT(actionInspector()));
chudy@google.come504de02012-07-16 18:35:23 +000067 connect(&fActionInspector, SIGNAL(triggered()), this,
68 SLOT(actionSettings()));
chudy@google.comc432f002012-07-10 13:19:25 +000069 connect(&fFilter, SIGNAL(activated(QString)), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000070 SLOT(toggleFilter(QString)));
chudy@google.comc432f002012-07-10 13:19:25 +000071 connect(&fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
72 connect(&fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
chudy@google.comc432f002012-07-10 13:19:25 +000073 connect(fSettingsWidget.getVisibilityButton(), SIGNAL(toggled(bool)), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000074 SLOT(actionCommandFilter()));
chudy@google.comc432f002012-07-10 13:19:25 +000075 connect(&fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this,
chudy@google.com7dcae672012-07-09 20:26:53 +000076 SLOT(actionScale(float)));
chudy@google.come504de02012-07-16 18:35:23 +000077 connect(&fActionPause, SIGNAL(toggled(bool)),
chudy@google.comf927f442012-07-10 14:36:14 +000078 this, SLOT(pauseDrawing(bool)));
chudy@google.comc432f002012-07-10 13:19:25 +000079 connect(&fCanvasWidget, SIGNAL(commandChanged(int)), &fSettingsWidget,
chudy@google.com7dcae672012-07-09 20:26:53 +000080 SLOT(updateCommand(int)));
chudy@google.com9ca9bfe2012-07-12 21:58:14 +000081 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), this, SLOT(selectCommand(int)));
chudy@google.come606d6e2012-07-12 14:31:25 +000082 connect(&fCanvasWidget, SIGNAL(hitChanged(int)), &fSettingsWidget,
83 SLOT(updateHit(int)));
chudy@google.come504de02012-07-16 18:35:23 +000084 connect(&fActionCreateBreakpoint, SIGNAL(activated()), this, SLOT(toggleBreakpoint()));
chudy@google.com902ebe52012-06-29 14:21:22 +000085}
86
87SkDebuggerGUI::~SkDebuggerGUI() {
88}
89
90void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7dcae672012-07-09 20:26:53 +000091 if (!fBreakpointsActivated) {
chudy@google.com902ebe52012-06-29 14:21:22 +000092 fBreakpointsActivated = true;
93 } else {
94 fBreakpointsActivated = false;
95 }
96
chudy@google.comc432f002012-07-10 13:19:25 +000097 for (int row = 0; row < fListWidget.count(); row++) {
98 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +000099
100 if (item->checkState() == Qt::Unchecked && fBreakpointsActivated) {
101 item->setHidden(true);
102 } else {
103 item->setHidden(false);
104 }
105 }
106}
107
108void SkDebuggerGUI::actionCancel() {
chudy@google.comc432f002012-07-10 13:19:25 +0000109 for (int row = 0; row < fListWidget.count(); row++) {
110 fListWidget.item(row)->setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000111 }
112}
113
114void SkDebuggerGUI::actionCommandFilter() {
chudy@google.comc432f002012-07-10 13:19:25 +0000115 fCanvasWidget.toggleCurrentCommandFilter(
116 fSettingsWidget.getVisibilityButton()->isChecked());
117 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000118}
119
120void SkDebuggerGUI::actionClose() {
121 this->close();
122}
123
124void SkDebuggerGUI::actionDelete() {
chudy@google.comc432f002012-07-10 13:19:25 +0000125 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com7dcae672012-07-09 20:26:53 +0000126 if (item->data(Qt::UserRole + 2) == true) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000127 item->setData(Qt::UserRole + 2, false);
chudy@google.come565de42012-07-12 14:15:54 +0000128 item->setData(Qt::UserRole + 3, QPixmap(":/images/Icons/delete.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000129 } else {
130 item->setData(Qt::UserRole + 2, true);
chudy@google.come565de42012-07-12 14:15:54 +0000131 item->setData(Qt::UserRole + 3, QPixmap(":/images/Icons/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000132 }
chudy@google.comc432f002012-07-10 13:19:25 +0000133 int currentRow = fListWidget.currentRow();
chudy@google.comc432f002012-07-10 13:19:25 +0000134 fCanvasWidget.toggleCommand(currentRow);
chudy@google.come504de02012-07-16 18:35:23 +0000135 if (fPause) {
136 fCanvasWidget.drawTo(fPausedRow);
137 } else {
138 fCanvasWidget.drawTo(currentRow);
139 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000140}
141
142void SkDebuggerGUI::actionInspector() {
chudy@google.comc432f002012-07-10 13:19:25 +0000143 if (fInspectorWidget.isHidden()) {
144 fInspectorWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000145 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000146 fInspectorWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000147 }
148}
149
150void SkDebuggerGUI::actionPlay() {
chudy@google.comc432f002012-07-10 13:19:25 +0000151 for (int row = fListWidget.currentRow() + 1; row < fListWidget.count();
chudy@google.com7dcae672012-07-09 20:26:53 +0000152 row++) {
chudy@google.comc432f002012-07-10 13:19:25 +0000153 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000154 if (item->checkState() == Qt::Checked) {
chudy@google.comc432f002012-07-10 13:19:25 +0000155 fListWidget.setCurrentItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000156 return;
157 }
158 }
chudy@google.comc432f002012-07-10 13:19:25 +0000159 fListWidget.setCurrentRow(fListWidget.count() - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000160}
161
162void SkDebuggerGUI::actionReload() {
chudy@google.comc432f002012-07-10 13:19:25 +0000163 for (int row = 0; row < fListWidget.count(); row++) {
164 QListWidgetItem* item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000165 item->setData(Qt::UserRole + 2, true);
chudy@google.com7dcae672012-07-09 20:26:53 +0000166 item->setData(Qt::DecorationRole, QPixmap(":/images/Icons/blank.png"));
chudy@google.comc432f002012-07-10 13:19:25 +0000167 fCanvasWidget.toggleCommand(row, true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000168 }
chudy@google.comc432f002012-07-10 13:19:25 +0000169 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +0000170}
171
172void SkDebuggerGUI::actionRewind() {
chudy@google.come504de02012-07-16 18:35:23 +0000173 fListWidget.setCurrentRow(0);
chudy@google.com902ebe52012-06-29 14:21:22 +0000174}
175
chudy@google.com7dcae672012-07-09 20:26:53 +0000176void SkDebuggerGUI::actionScale(float scaleFactor) {
chudy@google.comc432f002012-07-10 13:19:25 +0000177 fSettingsWidget.setZoomText(scaleFactor);
chudy@google.com7dcae672012-07-09 20:26:53 +0000178}
179
chudy@google.com902ebe52012-06-29 14:21:22 +0000180void SkDebuggerGUI::actionSettings() {
chudy@google.comc432f002012-07-10 13:19:25 +0000181 if (fSettingsWidget.isHidden()) {
182 fSettingsWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000183 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000184 fSettingsWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000185 }
186}
187
188void SkDebuggerGUI::actionStepBack() {
chudy@google.comc432f002012-07-10 13:19:25 +0000189 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000190 if (currentRow != 0) {
chudy@google.comc432f002012-07-10 13:19:25 +0000191 fListWidget.setCurrentRow(currentRow - 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000192 }
193}
194
195void SkDebuggerGUI::actionStepForward() {
chudy@google.comc432f002012-07-10 13:19:25 +0000196 int currentRow = fListWidget.currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000197 QString curRow = QString::number(currentRow);
chudy@google.comc432f002012-07-10 13:19:25 +0000198 QString curCount = QString::number(fListWidget.count());
199 if (currentRow < fListWidget.count() - 1) {
200 fListWidget.setCurrentRow(currentRow + 1);
chudy@google.com902ebe52012-06-29 14:21:22 +0000201 }
202}
203
204void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
205 if (fDirectoryWidgetActive) {
206 QString fileName;
207 fileName.append(fPath);
208 fileName.append("/");
209 fileName.append(item->text());
210 loadPicture(fileName);
211 }
212}
213
214void SkDebuggerGUI::openFile() {
chudy@google.com7dcae672012-07-09 20:26:53 +0000215 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
216 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000217 fDirectoryWidgetActive = false;
218 if (!fileName.isNull()) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000219 QFileInfo pathInfo(fileName);
220 fPath = pathInfo.path();
221 loadPicture(fileName);
222 setupDirectoryWidget();
223 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000224 fDirectoryWidgetActive = true;
225}
226
chudy@google.comc432f002012-07-10 13:19:25 +0000227void SkDebuggerGUI::pauseDrawing(bool isPaused) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000228 // Qt uses 0 for unchecked, 1 for partially enabled and 2 for checked.
chudy@google.comc432f002012-07-10 13:19:25 +0000229 if (isPaused) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000230 fPause = true;
chudy@google.com233e4b82012-07-12 14:38:49 +0000231 fPausedRow = fListWidget.currentRow();
chudy@google.com7dcae672012-07-09 20:26:53 +0000232 } else {
233 fPause = false;
chudy@google.comc432f002012-07-10 13:19:25 +0000234 fCanvasWidget.drawTo(fListWidget.currentRow());
chudy@google.com7dcae672012-07-09 20:26:53 +0000235 }
236}
237
chudy@google.com902ebe52012-06-29 14:21:22 +0000238void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
chudy@google.comc432f002012-07-10 13:19:25 +0000239 int currentRow = fListWidget.currentRow();
chudy@google.com7dcae672012-07-09 20:26:53 +0000240 if (!fPause) {
chudy@google.comc432f002012-07-10 13:19:25 +0000241 fCanvasWidget.drawTo(currentRow);
chudy@google.com7dcae672012-07-09 20:26:53 +0000242 }
chudy@google.comc432f002012-07-10 13:19:25 +0000243 std::vector<std::string> *v = fCanvasWidget.getCurrentCommandInfo(
chudy@google.com7dcae672012-07-09 20:26:53 +0000244 currentRow);
chudy@google.com902ebe52012-06-29 14:21:22 +0000245
chudy@google.com7dcae672012-07-09 20:26:53 +0000246 /* TODO(chudy): Add command type before parameters. Rename v
247 * to something more informative. */
248 if (v) {
249 std::vector<std::string>::iterator it;
chudy@google.com902ebe52012-06-29 14:21:22 +0000250
chudy@google.com7dcae672012-07-09 20:26:53 +0000251 QString info;
252 info.append("<b>Parameters: </b><br/>");
253 for (it = v->begin(); it != v->end(); ++it) {
254 info.append(QString((*it).c_str()));
255 info.append("<br/>");
chudy@google.com902ebe52012-06-29 14:21:22 +0000256 }
chudy@google.comc432f002012-07-10 13:19:25 +0000257 fInspectorWidget.setDetailText(info);
258 fInspectorWidget.setDisabled(false);
259 fInspectorWidget.setMatrix(fCanvasWidget.getCurrentMatrix());
260 fInspectorWidget.setClip(fCanvasWidget.getCurrentClip());
chudy@google.com902ebe52012-06-29 14:21:22 +0000261 }
262}
263
chudy@google.com9ca9bfe2012-07-12 21:58:14 +0000264void SkDebuggerGUI::selectCommand(int command) {
265 if (fPause) {
266 fListWidget.setCurrentRow(command);
267 }
268}
269
chudy@google.com902ebe52012-06-29 14:21:22 +0000270void SkDebuggerGUI::toggleBreakpoint() {
chudy@google.comc432f002012-07-10 13:19:25 +0000271 QListWidgetItem* item = fListWidget.currentItem();
chudy@google.com902ebe52012-06-29 14:21:22 +0000272 if (item->checkState() == Qt::Unchecked) {
273 item->setCheckState(Qt::Checked);
chudy@google.come565de42012-07-12 14:15:54 +0000274 item->setData(Qt::DecorationRole,
275 QPixmap(":/images/Icons/breakpoint_16x16.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000276 } else {
chudy@google.com902ebe52012-06-29 14:21:22 +0000277 item->setCheckState(Qt::Unchecked);
chudy@google.come565de42012-07-12 14:15:54 +0000278 item->setData(Qt::DecorationRole,
279 QPixmap(":/images/Icons/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000280 }
281}
282
283void SkDebuggerGUI::toggleDirectory() {
chudy@google.comc432f002012-07-10 13:19:25 +0000284 if (fDirectoryWidget.isHidden()) {
285 fDirectoryWidget.setHidden(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000286 } else {
chudy@google.comc432f002012-07-10 13:19:25 +0000287 fDirectoryWidget.setHidden(true);
chudy@google.com902ebe52012-06-29 14:21:22 +0000288 }
289}
290
291void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.comc432f002012-07-10 13:19:25 +0000292 for (int row = 0; row < fListWidget.count(); row++) {
293 QListWidgetItem *item = fListWidget.item(row);
chudy@google.com902ebe52012-06-29 14:21:22 +0000294 if (item->text() == string) {
295 item->setHidden(false);
296 } else {
297 item->setHidden(true);
298 }
299 }
300}
301
302void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
303 QIcon windowIcon;
chudy@google.com7dcae672012-07-09 20:26:53 +0000304 windowIcon.addFile(QString::fromUtf8(":/images/Icons/skia.png"), QSize(),
305 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000306 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
307 SkDebuggerGUI->resize(1200, 1000);
308 SkDebuggerGUI->setWindowIcon(windowIcon);
chudy@google.comc432f002012-07-10 13:19:25 +0000309 SkDebuggerGUI->setWindowTitle("Skia Debugger");
chudy@google.com902ebe52012-06-29 14:21:22 +0000310
chudy@google.come504de02012-07-16 18:35:23 +0000311 fActionOpen.setShortcuts(QKeySequence::Open);
chudy@google.comc432f002012-07-10 13:19:25 +0000312 fActionOpen.setText("Open");
chudy@google.com902ebe52012-06-29 14:21:22 +0000313
314 QIcon breakpoint;
chudy@google.com7dcae672012-07-09 20:26:53 +0000315 breakpoint.addFile(QString::fromUtf8(":/images/Icons/breakpoint.png"),
316 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000317 fActionBreakpoint.setShortcut(QKeySequence(tr("Ctrl+B")));
chudy@google.comc432f002012-07-10 13:19:25 +0000318 fActionBreakpoint.setIcon(breakpoint);
319 fActionBreakpoint.setText("Show Breakpoints");
chudy@google.com902ebe52012-06-29 14:21:22 +0000320
321 QIcon cancel;
chudy@google.come504de02012-07-16 18:35:23 +0000322 cancel.addFile(QString::fromUtf8(":/images/Ico/reload.png"), QSize(),
chudy@google.com7dcae672012-07-09 20:26:53 +0000323 QIcon::Normal, QIcon::Off);
chudy@google.comc432f002012-07-10 13:19:25 +0000324 fActionCancel.setIcon(cancel);
325 fActionCancel.setText("Clear Filter");
chudy@google.com902ebe52012-06-29 14:21:22 +0000326
chudy@google.come504de02012-07-16 18:35:23 +0000327 fActionClose.setShortcuts(QKeySequence::Quit);
chudy@google.comc432f002012-07-10 13:19:25 +0000328 fActionClose.setText("Exit");
chudy@google.com902ebe52012-06-29 14:21:22 +0000329
chudy@google.come504de02012-07-16 18:35:23 +0000330 fActionCreateBreakpoint.setShortcut(QKeySequence(tr("B")));
331 fActionCreateBreakpoint.setText("Set Breakpoint");
332
333 fActionDelete.setShortcut(QKeySequence(tr("X")));
chudy@google.comc432f002012-07-10 13:19:25 +0000334 fActionDelete.setText("Delete Command");
chudy@google.com902ebe52012-06-29 14:21:22 +0000335
chudy@google.come504de02012-07-16 18:35:23 +0000336 fActionDirectory.setShortcut(QKeySequence(tr("Ctrl+D")));
337 fActionDirectory.setText("Directory");
chudy@google.com902ebe52012-06-29 14:21:22 +0000338
chudy@google.comc432f002012-07-10 13:19:25 +0000339 QIcon inspector;
chudy@google.come504de02012-07-16 18:35:23 +0000340 inspector.addFile(QString::fromUtf8(":/images/Ico/inspector.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000341 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000342 fActionInspector.setShortcut(QKeySequence(tr("Ctrl+I")));
chudy@google.comc432f002012-07-10 13:19:25 +0000343 fActionInspector.setIcon(inspector);
chudy@google.come504de02012-07-16 18:35:23 +0000344 fActionInspector.setText("Inspector");
chudy@google.com902ebe52012-06-29 14:21:22 +0000345
chudy@google.comc432f002012-07-10 13:19:25 +0000346 QIcon play;
chudy@google.come504de02012-07-16 18:35:23 +0000347 play.addFile(QString::fromUtf8(":/images/Ico/play.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000348 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000349 fActionPlay.setShortcut(QKeySequence(tr("Ctrl+P")));
chudy@google.comc432f002012-07-10 13:19:25 +0000350 fActionPlay.setIcon(play);
351 fActionPlay.setText("Play");
chudy@google.com902ebe52012-06-29 14:21:22 +0000352
chudy@google.come504de02012-07-16 18:35:23 +0000353 QIcon pause;
354 pause.addFile(QString::fromUtf8(":/images/Ico/pause.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000355 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000356 fActionPause.setShortcut(QKeySequence(tr("Space")));
357 fActionPause.setCheckable(true);
358 fActionPause.setIcon(pause);
359 fActionPause.setText("Pause");
360
chudy@google.comc432f002012-07-10 13:19:25 +0000361 fActionReload.setText("Reset Picture");
chudy@google.com902ebe52012-06-29 14:21:22 +0000362
chudy@google.comc432f002012-07-10 13:19:25 +0000363 QIcon rewind;
chudy@google.come504de02012-07-16 18:35:23 +0000364 rewind.addFile(QString::fromUtf8(":/images/Ico/rewind.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000365 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000366 fActionRewind.setShortcut(QKeySequence(tr("Ctrl+R")));
chudy@google.comc432f002012-07-10 13:19:25 +0000367 fActionRewind.setIcon(rewind);
368 fActionRewind.setText("Rewind");
chudy@google.com902ebe52012-06-29 14:21:22 +0000369
chudy@google.comc432f002012-07-10 13:19:25 +0000370 QIcon stepBack;
chudy@google.come504de02012-07-16 18:35:23 +0000371 stepBack.addFile(QString::fromUtf8(":/images/Ico/previous.png"), QSize(),
chudy@google.comc432f002012-07-10 13:19:25 +0000372 QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000373 fActionStepBack.setShortcut(QKeySequence(tr("[")));
chudy@google.comc432f002012-07-10 13:19:25 +0000374 fActionStepBack.setIcon(stepBack);
375 fActionStepBack.setText("Step Back");
chudy@google.com902ebe52012-06-29 14:21:22 +0000376
chudy@google.comc432f002012-07-10 13:19:25 +0000377 QIcon stepForward;
chudy@google.come504de02012-07-16 18:35:23 +0000378 stepForward.addFile(QString::fromUtf8(":/images/Ico/next.png"),
chudy@google.comc432f002012-07-10 13:19:25 +0000379 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.come504de02012-07-16 18:35:23 +0000380 fActionStepForward.setShortcut(QKeySequence(tr("]")));
chudy@google.comc432f002012-07-10 13:19:25 +0000381 fActionStepForward.setIcon(stepForward);
382 fActionStepForward.setText("Step Forward");
383
384 fListWidget.setItemDelegate(new SkListWidget(&fListWidget));
385 fListWidget.setObjectName(QString::fromUtf8("listWidget"));
386 fListWidget.setMaximumWidth(250);
387
388 fFilter.addItem("--Filter By Available Commands--");
389
390 fDirectoryWidget.setMaximumWidth(250);
391 fDirectoryWidget.setStyleSheet("QListWidget::Item {padding: 5px;}");
392
393 fCanvasWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000394 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000395
chudy@google.comc432f002012-07-10 13:19:25 +0000396 fInspectorWidget.setSizePolicy(QSizePolicy::Expanding,
chudy@google.com7dcae672012-07-09 20:26:53 +0000397 QSizePolicy::Expanding);
chudy@google.comc432f002012-07-10 13:19:25 +0000398 fInspectorWidget.setMaximumHeight(300);
chudy@google.com902ebe52012-06-29 14:21:22 +0000399
chudy@google.comc432f002012-07-10 13:19:25 +0000400 fSettingsWidget.setSizePolicy(QSizePolicy::Expanding,
401 QSizePolicy::Expanding);
402 fSettingsWidget.setMaximumWidth(250);
chudy@google.com902ebe52012-06-29 14:21:22 +0000403
chudy@google.comc432f002012-07-10 13:19:25 +0000404 fLeftColumnLayout.setSpacing(6);
405 fLeftColumnLayout.addWidget(&fListWidget);
406 fLeftColumnLayout.addWidget(&fDirectoryWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000407
chudy@google.comc432f002012-07-10 13:19:25 +0000408 fCanvasAndSettingsLayout.setSpacing(6);
409 fCanvasAndSettingsLayout.addWidget(&fCanvasWidget);
410 fCanvasAndSettingsLayout.addWidget(&fSettingsWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000411
chudy@google.comc432f002012-07-10 13:19:25 +0000412 fMainAndRightColumnLayout.setSpacing(6);
413 fMainAndRightColumnLayout.addLayout(&fCanvasAndSettingsLayout);
414 fMainAndRightColumnLayout.addWidget(&fInspectorWidget);
chudy@google.com902ebe52012-06-29 14:21:22 +0000415
chudy@google.comc432f002012-07-10 13:19:25 +0000416 fContainerLayout.setSpacing(6);
417 fContainerLayout.setContentsMargins(11, 11, 11, 11);
418 fContainerLayout.addLayout(&fLeftColumnLayout);
419 fContainerLayout.addLayout(&fMainAndRightColumnLayout);
420
421 SkDebuggerGUI->setCentralWidget(&fCentralWidget);
422 SkDebuggerGUI->setStatusBar(&fStatusBar);
423
chudy@google.come504de02012-07-16 18:35:23 +0000424 fToolBar.setIconSize(QSize(32, 32));
chudy@google.comc432f002012-07-10 13:19:25 +0000425 fToolBar.setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
426 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, &fToolBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000427
428 QWidget *spacer = new QWidget();
429 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
430
chudy@google.comc432f002012-07-10 13:19:25 +0000431 fToolBar.addAction(&fActionRewind);
432 fToolBar.addAction(&fActionStepBack);
chudy@google.come504de02012-07-16 18:35:23 +0000433 fToolBar.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000434 fToolBar.addAction(&fActionStepForward);
435 fToolBar.addAction(&fActionPlay);
436 fToolBar.addSeparator();
chudy@google.come504de02012-07-16 18:35:23 +0000437 fToolBar.addAction(&fActionInspector);
chudy@google.comc432f002012-07-10 13:19:25 +0000438 fToolBar.addSeparator();
chudy@google.comc432f002012-07-10 13:19:25 +0000439 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);
chudy@google.come504de02012-07-16 18:35:23 +0000453
454 fMenuEdit.setTitle("Edit");
455 fMenuEdit.addAction(&fActionDelete);
456 fMenuEdit.addAction(&fActionCreateBreakpoint);
457
chudy@google.comc432f002012-07-10 13:19:25 +0000458 fMenuNavigate.setTitle("Navigate");
chudy@google.come504de02012-07-16 18:35:23 +0000459 fMenuNavigate.addAction(&fActionRewind);
460 fMenuNavigate.addAction(&fActionStepBack);
461 fMenuNavigate.addAction(&fActionStepForward);
462 fMenuNavigate.addAction(&fActionPlay);
463 fMenuNavigate.addAction(&fActionPause);
chudy@google.comc432f002012-07-10 13:19:25 +0000464 fMenuNavigate.addAction(&fActionGoToLine);
chudy@google.come504de02012-07-16 18:35:23 +0000465
chudy@google.comc432f002012-07-10 13:19:25 +0000466 fMenuView.setTitle("View");
chudy@google.come504de02012-07-16 18:35:23 +0000467 fMenuView.addAction(&fActionBreakpoint);
468
469 fMenuWindows.setTitle("Window");
470 fMenuWindows.addAction(&fActionInspector);
471 fMenuWindows.addAction(&fActionDirectory);
chudy@google.comc432f002012-07-10 13:19:25 +0000472
473 fActionGoToLine.setText("Go to Line...");
474 fActionGoToLine.setDisabled(true);
475 fMenuBar.addAction(fMenuFile.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000476 fMenuBar.addAction(fMenuEdit.menuAction());
chudy@google.comc432f002012-07-10 13:19:25 +0000477 fMenuBar.addAction(fMenuView.menuAction());
478 fMenuBar.addAction(fMenuNavigate.menuAction());
chudy@google.come504de02012-07-16 18:35:23 +0000479 fMenuBar.addAction(fMenuWindows.menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000480
chudy@google.com7dcae672012-07-09 20:26:53 +0000481 fPause = false;
482
chudy@google.comc432f002012-07-10 13:19:25 +0000483 SkDebuggerGUI->setMenuBar(&fMenuBar);
chudy@google.com902ebe52012-06-29 14:21:22 +0000484 QMetaObject::connectSlotsByName(SkDebuggerGUI);
485}
486
487void SkDebuggerGUI::setupDirectoryWidget() {
chudy@google.comc432f002012-07-10 13:19:25 +0000488 QDir dir(fPath);
chudy@google.com902ebe52012-06-29 14:21:22 +0000489 QRegExp r(".skp");
chudy@google.comc432f002012-07-10 13:19:25 +0000490 fDirectoryWidget.clear();
491 const QStringList files = dir.entryList();
chudy@google.com902ebe52012-06-29 14:21:22 +0000492 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000493 if (f.contains(r))
chudy@google.comc432f002012-07-10 13:19:25 +0000494 fDirectoryWidget.addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000495 }
496}
497
chudy@google.com902ebe52012-06-29 14:21:22 +0000498void SkDebuggerGUI::loadPicture(QString fileName) {
chudy@google.comc432f002012-07-10 13:19:25 +0000499 fCanvasWidget.loadPicture(fileName);
500 std::vector<std::string> *cv = fCanvasWidget.getDrawCommands();
chudy@google.com7dcae672012-07-09 20:26:53 +0000501 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
502 * of the visibility filter. */
chudy@google.comc432f002012-07-10 13:19:25 +0000503 fCanvasWidget.toggleCurrentCommandFilter(
504 fSettingsWidget.getVisibilityButton()->isChecked());
chudy@google.com902ebe52012-06-29 14:21:22 +0000505 setupListWidget(cv);
506 setupComboBox(cv);
chudy@google.come606d6e2012-07-12 14:31:25 +0000507 fSettingsWidget.setDisabled(false);
chudy@google.com902ebe52012-06-29 14:21:22 +0000508}
509
510void SkDebuggerGUI::setupListWidget(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000511 fListWidget.clear();
chudy@google.com902ebe52012-06-29 14:21:22 +0000512 int counter = 0;
513 for (unsigned int i = 0; i < cv->size(); i++) {
514 QListWidgetItem *item = new QListWidgetItem();
515 item->setData(Qt::DisplayRole, (*cv)[i].c_str());
516 item->setData(Qt::UserRole + 1, counter++);
517 item->setData(Qt::UserRole + 2, true);
chudy@google.comc432f002012-07-10 13:19:25 +0000518 fListWidget.addItem(item);
chudy@google.com902ebe52012-06-29 14:21:22 +0000519 }
520}
521
522void SkDebuggerGUI::setupComboBox(std::vector<std::string>* cv) {
chudy@google.comc432f002012-07-10 13:19:25 +0000523 fFilter.clear();
524 fFilter.addItem("--Filter By Available Commands--");
chudy@google.com902ebe52012-06-29 14:21:22 +0000525
526 std::map<std::string, int> map;
527 for (unsigned int i = 0; i < cv->size(); i++) {
528 map[(*cv)[i]]++;
529 }
530
531 QString overview;
532 int counter;
chudy@google.com7dcae672012-07-09 20:26:53 +0000533 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
534 ++it) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000535 overview.append((it->first).c_str());
536 overview.append(": ");
537 overview.append(QString::number(it->second));
538 overview.append("<br/>");
chudy@google.com7dcae672012-07-09 20:26:53 +0000539 counter += it->second;
chudy@google.comc432f002012-07-10 13:19:25 +0000540 fFilter.addItem((it->first).c_str());
chudy@google.com902ebe52012-06-29 14:21:22 +0000541 }
542 QString total;
543 total.append("Total Draw Commands: ");
544 total.append(QString::number(counter));
545 total.append("<br/>");
546 overview.insert(0, total);
547
548 overview.append("<br/>");
549 overview.append("SkBitmap Width: ");
550 // NOTE(chudy): This is where we can pull out the SkPictures width.
chudy@google.comc432f002012-07-10 13:19:25 +0000551 overview.append(QString::number(fCanvasWidget.getBitmapWidth()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000552 overview.append("px<br/>");
553 overview.append("SkBitmap Height: ");
chudy@google.comc432f002012-07-10 13:19:25 +0000554 overview.append(QString::number(fCanvasWidget.getBitmapHeight()));
chudy@google.com902ebe52012-06-29 14:21:22 +0000555 overview.append("px");
chudy@google.comc432f002012-07-10 13:19:25 +0000556 fInspectorWidget.setOverviewText(overview);
chudy@google.com902ebe52012-06-29 14:21:22 +0000557
558 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000559 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
chudy@google.comc432f002012-07-10 13:19:25 +0000560 fFilter.model());
561 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
562 fFilter.rootModelIndex());
chudy@google.com902ebe52012-06-29 14:21:22 +0000563 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
564 firstItem->setSelectable(false);
565}