blob: 0729ac9b297eaad43d0a878d46a78e0798b8ddd5 [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.com7dcae672012-07-09 20:26:53 +000013 QMainWindow(parent) {
chudy@google.com902ebe52012-06-29 14:21:22 +000014
15 setupUi(this);
16 connect(fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*,
chudy@google.com7dcae672012-07-09 20:26:53 +000017 QListWidgetItem*)), this,
18 SLOT(registerListClick(QListWidgetItem *)));
chudy@google.com902ebe52012-06-29 14:21:22 +000019 connect(fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
chudy@google.com7dcae672012-07-09 20:26:53 +000020 connect(fActionDirectory, SIGNAL(triggered()), this,
21 SLOT(toggleDirectory()));
chudy@google.com902ebe52012-06-29 14:21:22 +000022 connect(fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*,
chudy@google.com7dcae672012-07-09 20:26:53 +000023 QListWidgetItem*)), this,
24 SLOT(loadFile(QListWidgetItem *)));
chudy@google.com902ebe52012-06-29 14:21:22 +000025 connect(fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
26 connect(fActionReload, SIGNAL(triggered()), this, SLOT(actionReload()));
chudy@google.com7dcae672012-07-09 20:26:53 +000027 connect(fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this,
28 SLOT(toggleBreakpoint()));
chudy@google.com902ebe52012-06-29 14:21:22 +000029 connect(fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
30 connect(fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
31 connect(fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack()));
chudy@google.com7dcae672012-07-09 20:26:53 +000032 connect(fActionStepForward, SIGNAL(triggered()), this,
33 SLOT(actionStepForward()));
34 connect(fActionBreakpoint, SIGNAL(triggered()), this,
35 SLOT(actionBreakpoints()));
36 connect(fActionInspector, SIGNAL(triggered()), this,
37 SLOT(actionInspector()));
38 connect(fFilter, SIGNAL(activated(QString)), this,
39 SLOT(toggleFilter(QString)));
chudy@google.com902ebe52012-06-29 14:21:22 +000040 connect(fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel()));
41 connect(fActionClose, SIGNAL(triggered()), this, SLOT(actionClose()));
42 connect(fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings()));
chudy@google.com7dcae672012-07-09 20:26:53 +000043 connect(fSettingsWidget->getVisibilityButton(), SIGNAL(toggled(bool)), this,
44 SLOT(actionCommandFilter()));
45 connect(fCanvasWidget, SIGNAL(scaleFactorChanged(float)), this,
46 SLOT(actionScale(float)));
47 connect(fSettingsWidget->getCommandCheckBox(), SIGNAL(stateChanged(int)),
48 this, SLOT(pauseDrawing(int)));
49 connect(fCanvasWidget, SIGNAL(commandChanged(int)), fSettingsWidget,
50 SLOT(updateCommand(int)));
chudy@google.com902ebe52012-06-29 14:21:22 +000051}
52
53SkDebuggerGUI::~SkDebuggerGUI() {
54}
55
56void SkDebuggerGUI::actionBreakpoints() {
chudy@google.com7dcae672012-07-09 20:26:53 +000057 if (!fBreakpointsActivated) {
chudy@google.com902ebe52012-06-29 14:21:22 +000058 fBreakpointsActivated = true;
59 } else {
60 fBreakpointsActivated = false;
61 }
62
chudy@google.com7dcae672012-07-09 20:26:53 +000063 for (int row = 0; row < fListWidget->count(); row++) {
chudy@google.com902ebe52012-06-29 14:21:22 +000064 QListWidgetItem *item = fListWidget->item(row);
65
66 if (item->checkState() == Qt::Unchecked && fBreakpointsActivated) {
67 item->setHidden(true);
68 } else {
69 item->setHidden(false);
70 }
71 }
72}
73
74void SkDebuggerGUI::actionCancel() {
chudy@google.com7dcae672012-07-09 20:26:53 +000075 for (int row = 0; row < fListWidget->count(); row++) {
chudy@google.com902ebe52012-06-29 14:21:22 +000076 fListWidget->item(row)->setHidden(false);
77 }
78}
79
80void SkDebuggerGUI::actionCommandFilter() {
chudy@google.com7dcae672012-07-09 20:26:53 +000081 fCanvasWidget->toggleCurrentCommandFilter(fSettingsWidget->getVisibilityButton()->isChecked());
chudy@google.com902ebe52012-06-29 14:21:22 +000082 fCanvasWidget->drawTo(fListWidget->currentRow());
chudy@google.com902ebe52012-06-29 14:21:22 +000083}
84
85void SkDebuggerGUI::actionClose() {
86 this->close();
87}
88
89void SkDebuggerGUI::actionDelete() {
90 QListWidgetItem* item = fListWidget->currentItem();
chudy@google.com7dcae672012-07-09 20:26:53 +000091 if (item->data(Qt::UserRole + 2) == true) {
chudy@google.com902ebe52012-06-29 14:21:22 +000092 item->setData(Qt::UserRole + 2, false);
chudy@google.com7dcae672012-07-09 20:26:53 +000093 item->setData(Qt::DecorationRole, QPixmap(":/images/Icons/delete.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +000094 } else {
95 item->setData(Qt::UserRole + 2, true);
chudy@google.com7dcae672012-07-09 20:26:53 +000096 if (item->checkState() == Qt::Unchecked) {
chudy@google.com902ebe52012-06-29 14:21:22 +000097 item->setData(Qt::DecorationRole,
98 QPixmap(":/images/Icons/blank.png"));
99 } else {
100 item->setData(Qt::DecorationRole,
101 QPixmap(":/images/Icons/breakpoint_16x16.png"));
102 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000103 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000104 int currentRow = fListWidget->currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000105 // NOTE(chudy): Forces a redraw up to current selected command.
106 if (fCanvasWidget) {
107 fCanvasWidget->toggleCommand(currentRow);
108 fCanvasWidget->drawTo(currentRow);
109 }
110}
111
112void SkDebuggerGUI::actionInspector() {
113 if (fInspectorWidget->isHidden()) {
114 fInspectorWidget->setHidden(false);
115 } else {
116 fInspectorWidget->setHidden(true);
117 }
118}
119
120void SkDebuggerGUI::actionPlay() {
chudy@google.com7dcae672012-07-09 20:26:53 +0000121 for (int row = fListWidget->currentRow() + 1; row < fListWidget->count();
122 row++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000123 QListWidgetItem *item = fListWidget->item(row);
124 if (item->checkState() == Qt::Checked) {
125 fListWidget->setCurrentItem(item);
126 return;
127 }
128 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000129 fListWidget->setCurrentRow(fListWidget->count() - 1);
130}
131
132void SkDebuggerGUI::actionReload() {
chudy@google.com7dcae672012-07-09 20:26:53 +0000133 for (int row = 0; row < fListWidget->count(); row++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000134 QListWidgetItem* item = fListWidget->item(row);
135 item->setData(Qt::UserRole + 2, true);
chudy@google.com7dcae672012-07-09 20:26:53 +0000136 item->setData(Qt::DecorationRole, QPixmap(":/images/Icons/blank.png"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000137 fCanvasWidget->toggleCommand(row, true);
138 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000139 fCanvasWidget->drawTo(fListWidget->currentRow());
140}
141
142void SkDebuggerGUI::actionRewind() {
143 /* NOTE(chudy): Hack. All skps opened so far start with save and concat
144 * commands that don't clear or reset the canvas. */
145 fListWidget->setCurrentRow(2);
146}
147
chudy@google.com7dcae672012-07-09 20:26:53 +0000148void SkDebuggerGUI::actionScale(float scaleFactor) {
149 fSettingsWidget->setZoomText(scaleFactor);
150}
151
chudy@google.com902ebe52012-06-29 14:21:22 +0000152void SkDebuggerGUI::actionSettings() {
153 if (fSettingsWidget->isHidden()) {
154 fSettingsWidget->setHidden(false);
155 } else {
156 fSettingsWidget->setHidden(true);
157 }
158}
159
160void SkDebuggerGUI::actionStepBack() {
161 int currentRow = fListWidget->currentRow();
162 if (currentRow != 0) {
163 fListWidget->setCurrentRow(currentRow - 1);
164 }
165}
166
167void SkDebuggerGUI::actionStepForward() {
168 int currentRow = fListWidget->currentRow();
chudy@google.com902ebe52012-06-29 14:21:22 +0000169 QString curRow = QString::number(currentRow);
170 QString curCount = QString::number(fListWidget->count());
chudy@google.com902ebe52012-06-29 14:21:22 +0000171 if (currentRow < fListWidget->count() - 1) {
172 fListWidget->setCurrentRow(currentRow + 1);
173 }
174}
175
176void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
177 if (fDirectoryWidgetActive) {
178 QString fileName;
179 fileName.append(fPath);
180 fileName.append("/");
181 fileName.append(item->text());
182 loadPicture(fileName);
183 }
184}
185
186void SkDebuggerGUI::openFile() {
chudy@google.com7dcae672012-07-09 20:26:53 +0000187 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
188 tr("Files (*.*)"));
chudy@google.com902ebe52012-06-29 14:21:22 +0000189 fDirectoryWidgetActive = false;
190 if (!fileName.isNull()) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000191 QFileInfo pathInfo(fileName);
192 fPath = pathInfo.path();
193 loadPicture(fileName);
194 setupDirectoryWidget();
195 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000196 fDirectoryWidgetActive = true;
197}
198
chudy@google.com7dcae672012-07-09 20:26:53 +0000199void SkDebuggerGUI::pauseDrawing(int state) {
200 // Qt uses 0 for unchecked, 1 for partially enabled and 2 for checked.
201 if (state == 2) {
202 fPause = true;
203 } else {
204 fPause = false;
205 fCanvasWidget->drawTo(fListWidget->currentRow());
206 }
207}
208
chudy@google.com902ebe52012-06-29 14:21:22 +0000209void SkDebuggerGUI::registerListClick(QListWidgetItem *item) {
210 int currentRow = fListWidget->currentRow();
chudy@google.com7dcae672012-07-09 20:26:53 +0000211 if (!fPause) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000212 fCanvasWidget->drawTo(currentRow);
chudy@google.com7dcae672012-07-09 20:26:53 +0000213 }
214 std::vector<std::string> *v = fCanvasWidget->getCurrentCommandInfo(
215 currentRow);
chudy@google.com902ebe52012-06-29 14:21:22 +0000216
chudy@google.com7dcae672012-07-09 20:26:53 +0000217 /* TODO(chudy): Add command type before parameters. Rename v
218 * to something more informative. */
219 if (v) {
220 std::vector<std::string>::iterator it;
chudy@google.com902ebe52012-06-29 14:21:22 +0000221
chudy@google.com7dcae672012-07-09 20:26:53 +0000222 QString info;
223 info.append("<b>Parameters: </b><br/>");
224 for (it = v->begin(); it != v->end(); ++it) {
225 info.append(QString((*it).c_str()));
226 info.append("<br/>");
chudy@google.com902ebe52012-06-29 14:21:22 +0000227 }
chudy@google.com7dcae672012-07-09 20:26:53 +0000228 fInspectorWidget->setDetailText(info);
229 fInspectorWidget->setDisabled(false);
230 fInspectorWidget->setMatrix(fCanvasWidget->getCurrentMatrix());
231 fInspectorWidget->setClip(fCanvasWidget->getCurrentClip());
chudy@google.com902ebe52012-06-29 14:21:22 +0000232 }
233}
234
235void SkDebuggerGUI::toggleBreakpoint() {
236 QListWidgetItem* item = fListWidget->currentItem();
237 if (item->checkState() == Qt::Unchecked) {
238 item->setCheckState(Qt::Checked);
239
chudy@google.com902ebe52012-06-29 14:21:22 +0000240 /* NOTE(chudy): If the command is toggled as hidden that takes
241 * precendence over the breakpoint icon.
242 */
chudy@google.com7dcae672012-07-09 20:26:53 +0000243 if (item->data(Qt::UserRole + 2) == false) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000244 item->setData(Qt::DecorationRole,
245 QPixmap(":/images/Icons/delete.png"));
246 } else {
247 item->setData(Qt::DecorationRole,
248 QPixmap(":/images/Icons/breakpoint_16x16.png"));
249 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000250 } else {
251
252 /* NOTE(chudy): When untoggling as a breakpoint if the command
253 * is hidden then the portraying icon should remain the delete icon.
254 */
255 item->setCheckState(Qt::Unchecked);
256
chudy@google.com7dcae672012-07-09 20:26:53 +0000257 if (item->data(Qt::UserRole + 2) == false) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000258 item->setData(Qt::DecorationRole,
259 QPixmap(":/images/Icons/delete.png"));
260 } else {
261 item->setData(Qt::DecorationRole,
262 QPixmap(":/images/Icons/blank.png"));
263 }
chudy@google.com902ebe52012-06-29 14:21:22 +0000264 }
265}
266
267void SkDebuggerGUI::toggleDirectory() {
268 if (fDirectoryWidget->isHidden()) {
269 fDirectoryWidget->setHidden(false);
270 } else {
271 fDirectoryWidget->setHidden(true);
272 }
273}
274
275void SkDebuggerGUI::toggleFilter(QString string) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000276 for (int row = 0; row < fListWidget->count(); row++) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000277 QListWidgetItem *item = fListWidget->item(row);
278 if (item->text() == string) {
279 item->setHidden(false);
280 } else {
281 item->setHidden(true);
282 }
283 }
284}
285
286void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) {
287 QIcon windowIcon;
chudy@google.com7dcae672012-07-09 20:26:53 +0000288 windowIcon.addFile(QString::fromUtf8(":/images/Icons/skia.png"), QSize(),
289 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000290 SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI"));
291 SkDebuggerGUI->resize(1200, 1000);
292 SkDebuggerGUI->setWindowIcon(windowIcon);
293
294 QIcon open;
chudy@google.com7dcae672012-07-09 20:26:53 +0000295 open.addFile(QString::fromUtf8(":/images/Icons/package-br32.png"), QSize(),
296 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000297 fActionOpen = new QAction(SkDebuggerGUI);
298 fActionOpen->setObjectName(QString::fromUtf8("actionOpen"));
299 fActionOpen->setIcon(open);
300
301 QIcon directory;
chudy@google.com7dcae672012-07-09 20:26:53 +0000302 directory.addFile(QString::fromUtf8(":/images/Icons/drawer-open-icon.png"),
303 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000304 fActionDirectory = new QAction(SkDebuggerGUI);
305 fActionDirectory->setObjectName(QString::fromUtf8("actionDirectory"));
306 fActionDirectory->setIcon(directory);
307 fActionDirectory->setText("Toggle Directory");
308
309 QIcon rewind;
chudy@google.com7dcae672012-07-09 20:26:53 +0000310 rewind.addFile(QString::fromUtf8(":/images/Icons/rewind.png"), QSize(),
311 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000312 fActionRewind = new QAction(SkDebuggerGUI);
313 fActionRewind->setObjectName(QString::fromUtf8("actionRewind"));
314 fActionRewind->setIcon(rewind);
315 fActionRewind->setText("Rewind");
316
317 QIcon stepBack;
chudy@google.com7dcae672012-07-09 20:26:53 +0000318 stepBack.addFile(QString::fromUtf8(":/images/Icons/back.png"), QSize(),
319 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000320 fActionStepBack = new QAction(SkDebuggerGUI);
321 fActionStepBack->setObjectName(QString::fromUtf8("actionStepBack"));
322 fActionStepBack->setIcon(stepBack);
323 fActionStepBack->setText("Step Back");
324
325 QIcon stepForward;
chudy@google.com7dcae672012-07-09 20:26:53 +0000326 stepForward.addFile(QString::fromUtf8(":/images/Icons/go-next.png"),
327 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000328 fActionStepForward = new QAction(SkDebuggerGUI);
329 fActionStepForward->setObjectName(QString::fromUtf8("actionStepBack"));
330 fActionStepForward->setIcon(stepForward);
331 fActionStepForward->setText("Step Forward");
332
333 QIcon play;
chudy@google.com7dcae672012-07-09 20:26:53 +0000334 play.addFile(QString::fromUtf8(":/images/Icons/play.png"), QSize(),
335 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000336 fActionPlay = new QAction(SkDebuggerGUI);
337 fActionPlay->setObjectName(QString::fromUtf8("actionPlay"));
338 fActionPlay->setIcon(play);
339 fActionPlay->setText("Play");
340
341 QIcon breakpoint;
chudy@google.com7dcae672012-07-09 20:26:53 +0000342 breakpoint.addFile(QString::fromUtf8(":/images/Icons/breakpoint.png"),
343 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000344 fActionBreakpoint = new QAction(SkDebuggerGUI);
345 fActionBreakpoint->setObjectName(QString::fromUtf8("actionBreakpoint"));
346 fActionBreakpoint->setIcon(breakpoint);
347 fActionBreakpoint->setText("Show Breakpoints");
348
349 QIcon inspector;
chudy@google.com7dcae672012-07-09 20:26:53 +0000350 inspector.addFile(QString::fromUtf8(":/images/Icons/inspector.png"),
351 QSize(), QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000352 fActionInspector = new QAction(SkDebuggerGUI);
353 fActionInspector->setObjectName(QString::fromUtf8("actionInspector"));
354 fActionInspector->setIcon(inspector);
355 fActionInspector->setText("Inspector");
356
357 QIcon deleteIcon;
chudy@google.com7dcae672012-07-09 20:26:53 +0000358 deleteIcon.addFile(QString::fromUtf8(":/images/Icons/delete.png"), QSize(),
359 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000360 fActionDelete = new QAction(SkDebuggerGUI);
361 fActionDelete->setObjectName(QString::fromUtf8("actionDelete"));
362 fActionDelete->setIcon(deleteIcon);
363 fActionDelete->setText("Delete Command");
364
365 QIcon reload;
chudy@google.com7dcae672012-07-09 20:26:53 +0000366 reload.addFile(QString::fromUtf8(":/images/Icons/reload.png"), QSize(),
367 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000368 fActionReload = new QAction(SkDebuggerGUI);
369 fActionReload->setObjectName(QString::fromUtf8("actionReload"));
370 fActionReload->setIcon(reload);
371 fActionReload->setText("Reset Picture");
372
373 QIcon settings;
chudy@google.com7dcae672012-07-09 20:26:53 +0000374 settings.addFile(QString::fromUtf8(":/images/Icons/settings.png"), QSize(),
375 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000376 fActionSettings = new QAction(SkDebuggerGUI);
377 fActionSettings->setObjectName(QString::fromUtf8("actionSettings"));
378 fActionSettings->setIcon(settings);
379 fActionSettings->setText("Settings");
380
381 QIcon cancel;
chudy@google.com7dcae672012-07-09 20:26:53 +0000382 cancel.addFile(QString::fromUtf8(":/images/Icons/reset.png"), QSize(),
383 QIcon::Normal, QIcon::Off);
chudy@google.com902ebe52012-06-29 14:21:22 +0000384 fActionCancel = new QAction(SkDebuggerGUI);
385 fActionCancel->setObjectName(QString::fromUtf8("actionCancel"));
386 fActionCancel->setIcon(cancel);
387 fActionCancel->setText("Clear Filter");
388
389 fCentralWidget = new QWidget(SkDebuggerGUI);
390 fCentralWidget->setObjectName(QString::fromUtf8("centralWidget"));
391
392 fHorizontalLayout = new QHBoxLayout(fCentralWidget);
393 fHorizontalLayout->setSpacing(6);
394 fHorizontalLayout->setContentsMargins(11, 11, 11, 11);
395 fHorizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
396
397 fVerticalLayout = new QVBoxLayout();
398 fVerticalLayout->setSpacing(6);
399 fVerticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
400
401 fVerticalLayout_2 = new QVBoxLayout();
402 fVerticalLayout_2->setSpacing(6);
403 fVerticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
404
405 fListWidget = new QListWidget(fCentralWidget);
406 fListWidget->setItemDelegate(new SkListWidget(fListWidget));
407 fListWidget->setObjectName(QString::fromUtf8("listWidget"));
408 fListWidget->setMaximumWidth(250);
409
410 fInspectorWidget = new SkInspectorWidget();
411 fInspectorWidget->setObjectName(QString::fromUtf8("inspectorWidget"));
chudy@google.com7dcae672012-07-09 20:26:53 +0000412 fInspectorWidget->setSizePolicy(QSizePolicy::Expanding,
413 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000414 fInspectorWidget->setMaximumHeight(300);
415
416 fFilter = new QComboBox(fCentralWidget);
417 fFilter->setObjectName(QString::fromUtf8("comboBox"));
418 fFilter->addItem("--Filter By Available Commands--");
419
420 fDirectoryWidget = new QListWidget(fCentralWidget);
421 fDirectoryWidget->setObjectName(QString::fromUtf8("listWidget_2"));
422 fDirectoryWidget->setMaximumWidth(250);
423 fDirectoryWidget->setStyleSheet("QListWidget::Item {padding: 5px;}");
424
425 fVerticalLayout_2->addWidget(fListWidget);
426 fVerticalLayout_2->addWidget(fDirectoryWidget);
427
428 fCanvasWidget = new SkCanvasWidget(fCentralWidget);
chudy@google.com7dcae672012-07-09 20:26:53 +0000429 fCanvasWidget->setSizePolicy(QSizePolicy::Expanding,
430 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000431
432 fSettingsWidget = new SkSettingsWidget(fCentralWidget);
chudy@google.com7dcae672012-07-09 20:26:53 +0000433 fSettingsWidget->setSizePolicy(QSizePolicy::Expanding,
434 QSizePolicy::Expanding);
chudy@google.com902ebe52012-06-29 14:21:22 +0000435 fSettingsWidget->setMaximumWidth(250);
436 fSettingsWidget->setHidden(true);
437
438 fHorizontalLayout_2 = new QHBoxLayout();
439 fHorizontalLayout_2->setSpacing(6);
440
441 fHorizontalLayout_2->addWidget(fCanvasWidget);
442 fHorizontalLayout_2->addWidget(fSettingsWidget);
443
444 fVerticalLayout->addLayout(fHorizontalLayout_2);
445 fVerticalLayout->addWidget(fInspectorWidget);
446
447 fHorizontalLayout->addLayout(fVerticalLayout_2);
448 fHorizontalLayout->addLayout(fVerticalLayout);
449
450 SkDebuggerGUI->setCentralWidget(fCentralWidget);
451 fStatusBar = new QStatusBar(SkDebuggerGUI);
452 fStatusBar->setObjectName(QString::fromUtf8("statusBar"));
453 SkDebuggerGUI->setStatusBar(fStatusBar);
454 fToolBar = new QToolBar(SkDebuggerGUI);
455 fToolBar->setObjectName(QString::fromUtf8("toolBar"));
456 fToolBar->setIconSize(QSize(24, 24));
457 //fToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
458 SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, fToolBar);
459
460 QWidget *spacer = new QWidget();
461 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
462
463 fToolBar->addAction(fActionOpen);
464 fToolBar->addSeparator();
465 fToolBar->addAction(fActionDirectory);
466 fToolBar->addSeparator();
467 fToolBar->addAction(fActionRewind);
468 fToolBar->addAction(fActionStepBack);
469 fToolBar->addAction(fActionStepForward);
470 fToolBar->addAction(fActionPlay);
471 fToolBar->addSeparator();
472 fToolBar->addAction(fActionBreakpoint);
473 fToolBar->addAction(fActionInspector);
474 fToolBar->addSeparator();
475 fToolBar->addAction(fActionDelete);
476 fToolBar->addAction(fActionReload);
477 fToolBar->addSeparator();
478 fToolBar->addAction(fActionSettings);
479 fToolBar->addWidget(spacer);
480 fToolBar->addWidget(fFilter);
481 fToolBar->addAction(fActionCancel);
482
483 // TODO(chudy): Remove static call.
484 fDirectoryWidgetActive = false;
chudy@google.com7dcae672012-07-09 20:26:53 +0000485 fPath = "/usr/local/google/home/chudy/trunk-linux/debugger/skp";
chudy@google.com902ebe52012-06-29 14:21:22 +0000486 setupDirectoryWidget();
487 fDirectoryWidgetActive = true;
488
489 fMenuBar = new QMenuBar(SkDebuggerGUI);
490
491 // File
492 fMenuFile = new QMenu(SkDebuggerGUI);
493 fMenuFile->setTitle("File");
494
495 fActionClose = new QAction(SkDebuggerGUI);
496 fActionClose->setText("Close");
497
498 fMenuFile->addAction(fActionOpen);
499 fMenuFile->addAction(fActionClose);
500
chudy@google.com902ebe52012-06-29 14:21:22 +0000501 // Navigate
502 fMenuNavigate = new QMenu(SkDebuggerGUI);
503 fMenuNavigate->setTitle("Navigate");
504
505 fActionGoToLine = new QAction(SkDebuggerGUI);
506 fActionGoToLine->setText("Go to Line...");
507 fActionGoToLine->setDisabled(true);
508
509 fMenuNavigate->addAction(fActionGoToLine);
510
511 // Menu Bar
512 fMenuBar->addAction(fMenuFile->menuAction());
chudy@google.com902ebe52012-06-29 14:21:22 +0000513 fMenuBar->addAction(fMenuNavigate->menuAction());
514
chudy@google.com7dcae672012-07-09 20:26:53 +0000515 fPause = false;
516
chudy@google.com902ebe52012-06-29 14:21:22 +0000517 SkDebuggerGUI->setMenuBar(fMenuBar);
518
519 retranslateUi(SkDebuggerGUI);
520 QMetaObject::connectSlotsByName(SkDebuggerGUI);
521}
522
523void SkDebuggerGUI::setupDirectoryWidget() {
524 fDir = new QDir(fPath);
525 QRegExp r(".skp");
526 fDirectoryWidget->clear();
527 const QStringList files = fDir->entryList();
528 foreach (QString f, files) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000529 if (f.contains(r))
530 fDirectoryWidget->addItem(f);
chudy@google.com902ebe52012-06-29 14:21:22 +0000531 }
532}
533
534// TODO(chudy): Is this necessary?
535void SkDebuggerGUI::retranslateUi(QMainWindow *SkDebuggerGUI) {
chudy@google.com7dcae672012-07-09 20:26:53 +0000536 SkDebuggerGUI->setWindowTitle(
537 QApplication::translate("SkDebuggerGUI", "SkDebuggerGUI", 0,
538 QApplication::UnicodeUTF8));
539 fActionOpen->setText(
540 QApplication::translate("SkDebuggerGUI", "Open", 0,
541 QApplication::UnicodeUTF8));
542 fToolBar->setWindowTitle(
543 QApplication::translate("SkDebuggerGUI", "toolBar", 0,
544 QApplication::UnicodeUTF8));
chudy@google.com902ebe52012-06-29 14:21:22 +0000545}
546
547void SkDebuggerGUI::loadPicture(QString fileName) {
548 fCanvasWidget->loadPicture(fileName);
549 std::vector<std::string> *cv = fCanvasWidget->getDrawCommands();
chudy@google.com7dcae672012-07-09 20:26:53 +0000550 /* fDebugCanvas is reinitialized every load picture. Need it to retain value
551 * of the visibility filter. */
552 actionCommandFilter();
553
554 fCanvasWidget->toggleCurrentCommandFilter(fSettingsWidget->getVisibilityButton()->isChecked());
555
556
557
558
chudy@google.com902ebe52012-06-29 14:21:22 +0000559 setupListWidget(cv);
560 setupComboBox(cv);
561}
562
563void SkDebuggerGUI::setupListWidget(std::vector<std::string>* cv) {
564 fListWidget->clear();
565 int counter = 0;
566 for (unsigned int i = 0; i < cv->size(); i++) {
567 QListWidgetItem *item = new QListWidgetItem();
568 item->setData(Qt::DisplayRole, (*cv)[i].c_str());
569 item->setData(Qt::UserRole + 1, counter++);
570 item->setData(Qt::UserRole + 2, true);
571 fListWidget->addItem(item);
572 }
573}
574
575void SkDebuggerGUI::setupComboBox(std::vector<std::string>* cv) {
576 fFilter->clear();
577 fFilter->addItem("--Filter By Available Commands--");
578
579 std::map<std::string, int> map;
580 for (unsigned int i = 0; i < cv->size(); i++) {
581 map[(*cv)[i]]++;
582 }
583
584 QString overview;
585 int counter;
chudy@google.com7dcae672012-07-09 20:26:53 +0000586 for (std::map<std::string, int>::iterator it = map.begin(); it != map.end();
587 ++it) {
chudy@google.com902ebe52012-06-29 14:21:22 +0000588 overview.append((it->first).c_str());
589 overview.append(": ");
590 overview.append(QString::number(it->second));
591 overview.append("<br/>");
chudy@google.com7dcae672012-07-09 20:26:53 +0000592 counter += it->second;
chudy@google.com902ebe52012-06-29 14:21:22 +0000593 fFilter->addItem((it->first).c_str());
594 }
595 QString total;
596 total.append("Total Draw Commands: ");
597 total.append(QString::number(counter));
598 total.append("<br/>");
599 overview.insert(0, total);
600
601 overview.append("<br/>");
602 overview.append("SkBitmap Width: ");
603 // NOTE(chudy): This is where we can pull out the SkPictures width.
604 overview.append(QString::number(fCanvasWidget->getBitmapWidth()));
605 overview.append("px<br/>");
606 overview.append("SkBitmap Height: ");
607 overview.append(QString::number(fCanvasWidget->getBitmapHeight()));
608 overview.append("px");
609 fInspectorWidget->setOverviewText(overview);
610
611 // NOTE(chudy): Makes first item unselectable.
chudy@google.com7dcae672012-07-09 20:26:53 +0000612 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
613 fFilter->model());
chudy@google.com902ebe52012-06-29 14:21:22 +0000614 QModelIndex firstIndex = model->index(0, fFilter->modelColumn(),
615 fFilter->rootModelIndex());
616 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
617 firstItem->setSelectable(false);
618}