| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include <iostream> |
| 10 | #include "SkDebuggerGUI.h" |
| 11 | #include <QListWidgetItem> |
| 12 | |
| 13 | SkDebuggerGUI::SkDebuggerGUI(QWidget *parent) : |
| 14 | QMainWindow(parent) { |
| 15 | |
| 16 | setupUi(this); |
| 17 | connect(fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, |
| 18 | QListWidgetItem*)), this, SLOT(registerListClick(QListWidgetItem *))); |
| 19 | connect(fActionOpen, SIGNAL(triggered()), this, SLOT(openFile())); |
| 20 | connect(fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory())); |
| 21 | connect(fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, |
| 22 | QListWidgetItem*)), this, SLOT(loadFile(QListWidgetItem *))); |
| 23 | connect(fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete())); |
| 24 | connect(fActionReload, SIGNAL(triggered()), this, SLOT(actionReload())); |
| 25 | connect(fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(toggleBreakpoint())); |
| 26 | connect(fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind())); |
| 27 | connect(fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay())); |
| 28 | connect(fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack())); |
| 29 | connect(fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForward())); |
| 30 | connect(fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoints())); |
| 31 | connect(fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector())); |
| 32 | connect(fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QString))); |
| 33 | connect(fActionCancel, SIGNAL(triggered()), this, SLOT(actionCancel())); |
| 34 | connect(fActionClose, SIGNAL(triggered()), this, SLOT(actionClose())); |
| 35 | connect(fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings())); |
| 36 | connect(fActionToggleCurrentCommand, SIGNAL(triggered()), this, SLOT(actionCommandFilter())); |
| 37 | } |
| 38 | |
| 39 | SkDebuggerGUI::~SkDebuggerGUI() { |
| 40 | } |
| 41 | |
| 42 | void SkDebuggerGUI::actionBreakpoints() { |
| 43 | if(!fBreakpointsActivated) { |
| 44 | fBreakpointsActivated = true; |
| 45 | } else { |
| 46 | fBreakpointsActivated = false; |
| 47 | } |
| 48 | |
| 49 | for(int row=0; row<fListWidget->count(); row++) { |
| 50 | QListWidgetItem *item = fListWidget->item(row); |
| 51 | |
| 52 | if (item->checkState() == Qt::Unchecked && fBreakpointsActivated) { |
| 53 | item->setHidden(true); |
| 54 | } else { |
| 55 | item->setHidden(false); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void SkDebuggerGUI::actionCancel() { |
| 61 | for(int row=0; row<fListWidget->count(); row++) { |
| 62 | fListWidget->item(row)->setHidden(false); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | void SkDebuggerGUI::actionCommandFilter() { |
| 67 | if (fActionToggleCurrentCommand->text() == "Show Filter") { |
| 68 | fCanvasWidget->toggleCurrentCommandFilter(true); |
| 69 | fActionToggleCurrentCommand->setText("Hide Filter"); |
| 70 | } else { |
| 71 | fActionToggleCurrentCommand->setText("Show Filter"); |
| 72 | fCanvasWidget->toggleCurrentCommandFilter(false); |
| 73 | } |
| 74 | |
| 75 | fCanvasWidget->drawTo(fListWidget->currentRow()); |
| 76 | |
| 77 | } |
| 78 | |
| 79 | void SkDebuggerGUI::actionClose() { |
| 80 | this->close(); |
| 81 | } |
| 82 | |
| 83 | void SkDebuggerGUI::actionDelete() { |
| 84 | QListWidgetItem* item = fListWidget->currentItem(); |
| 85 | |
| 86 | if(item->data(Qt::UserRole + 2) == true) { |
| 87 | item->setData(Qt::UserRole + 2, false); |
| 88 | item->setData(Qt::DecorationRole, |
| 89 | QPixmap(":/images/Icons/delete.png")); |
| 90 | |
| 91 | } else { |
| 92 | item->setData(Qt::UserRole + 2, true); |
| 93 | if(item->checkState() == Qt::Unchecked) { |
| 94 | item->setData(Qt::DecorationRole, |
| 95 | QPixmap(":/images/Icons/blank.png")); |
| 96 | } else { |
| 97 | item->setData(Qt::DecorationRole, |
| 98 | QPixmap(":/images/Icons/breakpoint_16x16.png")); |
| 99 | } |
| 100 | |
| 101 | } |
| 102 | |
| 103 | int currentRow = fListWidget->currentRow(); |
| 104 | |
| 105 | // NOTE(chudy): Forces a redraw up to current selected command. |
| 106 | if (fCanvasWidget) { |
| 107 | fCanvasWidget->toggleCommand(currentRow); |
| 108 | fCanvasWidget->drawTo(currentRow); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | void SkDebuggerGUI::actionInspector() { |
| 113 | if (fInspectorWidget->isHidden()) { |
| 114 | fInspectorWidget->setHidden(false); |
| 115 | } else { |
| 116 | fInspectorWidget->setHidden(true); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | void SkDebuggerGUI::actionPlay() { |
| 121 | for(int row=fListWidget->currentRow()+1; row<fListWidget->count(); row++) { |
| 122 | QListWidgetItem *item = fListWidget->item(row); |
| 123 | if (item->checkState() == Qt::Checked) { |
| 124 | fListWidget->setCurrentItem(item); |
| 125 | return; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | fListWidget->setCurrentRow(fListWidget->count() - 1); |
| 130 | } |
| 131 | |
| 132 | void SkDebuggerGUI::actionReload() { |
| 133 | for(int row=0; row<fListWidget->count(); row++) { |
| 134 | QListWidgetItem* item = fListWidget->item(row); |
| 135 | item->setData(Qt::UserRole + 2, true); |
| 136 | item->setData(Qt::DecorationRole, |
| 137 | QPixmap(":/images/Icons/blank.png")); |
| 138 | fCanvasWidget->toggleCommand(row, true); |
| 139 | } |
| 140 | |
| 141 | fCanvasWidget->drawTo(fListWidget->currentRow()); |
| 142 | } |
| 143 | |
| 144 | void SkDebuggerGUI::actionRewind() { |
| 145 | /* NOTE(chudy): Hack. All skps opened so far start with save and concat |
| 146 | * commands that don't clear or reset the canvas. */ |
| 147 | fListWidget->setCurrentRow(2); |
| 148 | } |
| 149 | |
| 150 | void SkDebuggerGUI::actionSettings() { |
| 151 | if (fSettingsWidget->isHidden()) { |
| 152 | fSettingsWidget->setHidden(false); |
| 153 | } else { |
| 154 | fSettingsWidget->setHidden(true); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | void SkDebuggerGUI::actionStepBack() { |
| 159 | int currentRow = fListWidget->currentRow(); |
| 160 | if (currentRow != 0) { |
| 161 | fListWidget->setCurrentRow(currentRow - 1); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | void SkDebuggerGUI::actionStepForward() { |
| 166 | int currentRow = fListWidget->currentRow(); |
| 167 | |
| 168 | QString curRow = QString::number(currentRow); |
| 169 | QString curCount = QString::number(fListWidget->count()); |
| 170 | |
| 171 | |
| 172 | if (currentRow < fListWidget->count() - 1) { |
| 173 | fListWidget->setCurrentRow(currentRow + 1); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | void SkDebuggerGUI::loadFile(QListWidgetItem *item) { |
| 178 | if (fDirectoryWidgetActive) { |
| 179 | QString fileName; |
| 180 | fileName.append(fPath); |
| 181 | fileName.append("/"); |
| 182 | fileName.append(item->text()); |
| 183 | loadPicture(fileName); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | void SkDebuggerGUI::openFile() { |
| 188 | QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), |
| 189 | "", |
| 190 | tr("Files (*.*)")); |
| 191 | fDirectoryWidgetActive = false; |
| 192 | if (!fileName.isNull()) { |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 193 | QFileInfo pathInfo(fileName); |
| 194 | fPath = pathInfo.path(); |
| 195 | loadPicture(fileName); |
| 196 | setupDirectoryWidget(); |
| 197 | } |
| 198 | /* TODO(chudy): Need something here that sets the active directory |
| 199 | * widget selection to what was opened. OR we can just add a new function |
| 200 | * to change the directory (would be much easier). |
| 201 | */ |
| 202 | fDirectoryWidgetActive = true; |
| 203 | } |
| 204 | |
| 205 | void SkDebuggerGUI::registerListClick(QListWidgetItem *item) { |
| 206 | int currentRow = fListWidget->currentRow(); |
| 207 | |
| 208 | // NOTE(chudy): Prevents initialization errors. |
| 209 | if (fCanvasWidget) { |
| 210 | fCanvasWidget->drawTo(currentRow); |
| 211 | std::vector<std::string> *v = |
| 212 | fCanvasWidget->getCurrentCommandInfo(currentRow); |
| 213 | |
| 214 | |
| 215 | /* TODO(chudy): Add command type before parameters. Rename v |
| 216 | * to something more informative. */ |
| 217 | if (v) { |
| 218 | std::vector<std::string>::iterator it; |
| 219 | |
| 220 | QString info; |
| 221 | info.append("<b>Parameters: </b><br/>"); |
| 222 | for (it = v->begin(); it != v->end(); ++it) { |
| 223 | info.append(QString((*it).c_str())); |
| 224 | info.append("<br/>"); |
| 225 | } |
| 226 | fInspectorWidget->setDetailText(info); |
| chudy@google.com | 2f89179 | 2012-07-03 16:05:59 +0000 | [diff] [blame^] | 227 | fInspectorWidget->setDisabled(false); |
| 228 | fInspectorWidget->setMatrix(fCanvasWidget->getCurrentMatrix()); |
| 229 | fInspectorWidget->setClip(fCanvasWidget->getCurrentClip()); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | void SkDebuggerGUI::toggleBreakpoint() { |
| 235 | QListWidgetItem* item = fListWidget->currentItem(); |
| 236 | if (item->checkState() == Qt::Unchecked) { |
| 237 | item->setCheckState(Qt::Checked); |
| 238 | |
| 239 | |
| 240 | /* NOTE(chudy): If the command is toggled as hidden that takes |
| 241 | * precendence over the breakpoint icon. |
| 242 | */ |
| 243 | if(item->data(Qt::UserRole + 2) == false) { |
| 244 | 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 | } |
| 250 | |
| 251 | } else { |
| 252 | |
| 253 | /* NOTE(chudy): When untoggling as a breakpoint if the command |
| 254 | * is hidden then the portraying icon should remain the delete icon. |
| 255 | */ |
| 256 | item->setCheckState(Qt::Unchecked); |
| 257 | |
| 258 | if(item->data(Qt::UserRole + 2) == false) { |
| 259 | item->setData(Qt::DecorationRole, |
| 260 | QPixmap(":/images/Icons/delete.png")); |
| 261 | } else { |
| 262 | item->setData(Qt::DecorationRole, |
| 263 | QPixmap(":/images/Icons/blank.png")); |
| 264 | } |
| 265 | |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | void SkDebuggerGUI::toggleDirectory() { |
| 270 | if (fDirectoryWidget->isHidden()) { |
| 271 | fDirectoryWidget->setHidden(false); |
| 272 | } else { |
| 273 | fDirectoryWidget->setHidden(true); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | void SkDebuggerGUI::toggleFilter(QString string) { |
| 278 | for(int row=0; row<fListWidget->count(); row++) { |
| 279 | QListWidgetItem *item = fListWidget->item(row); |
| 280 | if (item->text() == string) { |
| 281 | item->setHidden(false); |
| 282 | } else { |
| 283 | item->setHidden(true); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | void SkDebuggerGUI::setupUi(QMainWindow *SkDebuggerGUI) { |
| 289 | QIcon windowIcon; |
| 290 | windowIcon.addFile(QString::fromUtf8(":/images/Icons/skia.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 291 | SkDebuggerGUI->setObjectName(QString::fromUtf8("SkDebuggerGUI")); |
| 292 | SkDebuggerGUI->resize(1200, 1000); |
| 293 | SkDebuggerGUI->setWindowIcon(windowIcon); |
| 294 | |
| 295 | QIcon open; |
| 296 | open.addFile(QString::fromUtf8(":/images/Icons/package-br32.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 297 | fActionOpen = new QAction(SkDebuggerGUI); |
| 298 | fActionOpen->setObjectName(QString::fromUtf8("actionOpen")); |
| 299 | fActionOpen->setIcon(open); |
| 300 | |
| 301 | QIcon directory; |
| 302 | directory.addFile(QString::fromUtf8(":/images/Icons/drawer-open-icon.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 303 | fActionDirectory = new QAction(SkDebuggerGUI); |
| 304 | fActionDirectory->setObjectName(QString::fromUtf8("actionDirectory")); |
| 305 | fActionDirectory->setIcon(directory); |
| 306 | fActionDirectory->setText("Toggle Directory"); |
| 307 | |
| 308 | QIcon rewind; |
| 309 | rewind.addFile(QString::fromUtf8(":/images/Icons/rewind.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 310 | fActionRewind = new QAction(SkDebuggerGUI); |
| 311 | fActionRewind->setObjectName(QString::fromUtf8("actionRewind")); |
| 312 | fActionRewind->setIcon(rewind); |
| 313 | fActionRewind->setText("Rewind"); |
| 314 | |
| 315 | QIcon stepBack; |
| 316 | stepBack.addFile(QString::fromUtf8(":/images/Icons/back.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 317 | fActionStepBack = new QAction(SkDebuggerGUI); |
| 318 | fActionStepBack->setObjectName(QString::fromUtf8("actionStepBack")); |
| 319 | fActionStepBack->setIcon(stepBack); |
| 320 | fActionStepBack->setText("Step Back"); |
| 321 | |
| 322 | QIcon stepForward; |
| 323 | stepForward.addFile(QString::fromUtf8(":/images/Icons/go-next.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 324 | fActionStepForward = new QAction(SkDebuggerGUI); |
| 325 | fActionStepForward->setObjectName(QString::fromUtf8("actionStepBack")); |
| 326 | fActionStepForward->setIcon(stepForward); |
| 327 | fActionStepForward->setText("Step Forward"); |
| 328 | |
| 329 | QIcon play; |
| 330 | play.addFile(QString::fromUtf8(":/images/Icons/play.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 331 | fActionPlay = new QAction(SkDebuggerGUI); |
| 332 | fActionPlay->setObjectName(QString::fromUtf8("actionPlay")); |
| 333 | fActionPlay->setIcon(play); |
| 334 | fActionPlay->setText("Play"); |
| 335 | |
| 336 | QIcon breakpoint; |
| 337 | breakpoint.addFile(QString::fromUtf8(":/images/Icons/breakpoint.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 338 | fActionBreakpoint = new QAction(SkDebuggerGUI); |
| 339 | fActionBreakpoint->setObjectName(QString::fromUtf8("actionBreakpoint")); |
| 340 | fActionBreakpoint->setIcon(breakpoint); |
| 341 | fActionBreakpoint->setText("Show Breakpoints"); |
| 342 | |
| 343 | QIcon inspector; |
| 344 | inspector.addFile(QString::fromUtf8(":/images/Icons/inspector.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 345 | fActionInspector = new QAction(SkDebuggerGUI); |
| 346 | fActionInspector->setObjectName(QString::fromUtf8("actionInspector")); |
| 347 | fActionInspector->setIcon(inspector); |
| 348 | fActionInspector->setText("Inspector"); |
| 349 | |
| 350 | QIcon deleteIcon; |
| 351 | deleteIcon.addFile(QString::fromUtf8(":/images/Icons/delete.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 352 | fActionDelete = new QAction(SkDebuggerGUI); |
| 353 | fActionDelete->setObjectName(QString::fromUtf8("actionDelete")); |
| 354 | fActionDelete->setIcon(deleteIcon); |
| 355 | fActionDelete->setText("Delete Command"); |
| 356 | |
| 357 | QIcon reload; |
| 358 | reload.addFile(QString::fromUtf8(":/images/Icons/reload.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 359 | fActionReload = new QAction(SkDebuggerGUI); |
| 360 | fActionReload->setObjectName(QString::fromUtf8("actionReload")); |
| 361 | fActionReload->setIcon(reload); |
| 362 | fActionReload->setText("Reset Picture"); |
| 363 | |
| 364 | QIcon settings; |
| 365 | settings.addFile(QString::fromUtf8(":/images/Icons/settings.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 366 | fActionSettings = new QAction(SkDebuggerGUI); |
| 367 | fActionSettings->setObjectName(QString::fromUtf8("actionSettings")); |
| 368 | fActionSettings->setIcon(settings); |
| 369 | fActionSettings->setText("Settings"); |
| 370 | |
| 371 | QIcon cancel; |
| 372 | cancel.addFile(QString::fromUtf8(":/images/Icons/reset.png"), QSize(), QIcon::Normal, QIcon::Off); |
| 373 | fActionCancel = new QAction(SkDebuggerGUI); |
| 374 | fActionCancel->setObjectName(QString::fromUtf8("actionCancel")); |
| 375 | fActionCancel->setIcon(cancel); |
| 376 | fActionCancel->setText("Clear Filter"); |
| 377 | |
| 378 | fCentralWidget = new QWidget(SkDebuggerGUI); |
| 379 | fCentralWidget->setObjectName(QString::fromUtf8("centralWidget")); |
| 380 | |
| 381 | fHorizontalLayout = new QHBoxLayout(fCentralWidget); |
| 382 | fHorizontalLayout->setSpacing(6); |
| 383 | fHorizontalLayout->setContentsMargins(11, 11, 11, 11); |
| 384 | fHorizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); |
| 385 | |
| 386 | fVerticalLayout = new QVBoxLayout(); |
| 387 | fVerticalLayout->setSpacing(6); |
| 388 | fVerticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); |
| 389 | |
| 390 | fVerticalLayout_2 = new QVBoxLayout(); |
| 391 | fVerticalLayout_2->setSpacing(6); |
| 392 | fVerticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2")); |
| 393 | |
| 394 | fListWidget = new QListWidget(fCentralWidget); |
| 395 | fListWidget->setItemDelegate(new SkListWidget(fListWidget)); |
| 396 | fListWidget->setObjectName(QString::fromUtf8("listWidget")); |
| 397 | fListWidget->setMaximumWidth(250); |
| 398 | |
| 399 | fInspectorWidget = new SkInspectorWidget(); |
| 400 | fInspectorWidget->setObjectName(QString::fromUtf8("inspectorWidget")); |
| 401 | fInspectorWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| 402 | fInspectorWidget->setMaximumHeight(300); |
| 403 | |
| 404 | fFilter = new QComboBox(fCentralWidget); |
| 405 | fFilter->setObjectName(QString::fromUtf8("comboBox")); |
| 406 | fFilter->addItem("--Filter By Available Commands--"); |
| 407 | |
| 408 | fDirectoryWidget = new QListWidget(fCentralWidget); |
| 409 | fDirectoryWidget->setObjectName(QString::fromUtf8("listWidget_2")); |
| 410 | fDirectoryWidget->setMaximumWidth(250); |
| 411 | fDirectoryWidget->setStyleSheet("QListWidget::Item {padding: 5px;}"); |
| 412 | |
| 413 | fVerticalLayout_2->addWidget(fListWidget); |
| 414 | fVerticalLayout_2->addWidget(fDirectoryWidget); |
| 415 | |
| 416 | fCanvasWidget = new SkCanvasWidget(fCentralWidget); |
| 417 | fCanvasWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| 418 | |
| 419 | fSettingsWidget = new SkSettingsWidget(fCentralWidget); |
| 420 | fSettingsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| 421 | fSettingsWidget->setMaximumWidth(250); |
| 422 | fSettingsWidget->setHidden(true); |
| 423 | |
| 424 | fHorizontalLayout_2 = new QHBoxLayout(); |
| 425 | fHorizontalLayout_2->setSpacing(6); |
| 426 | |
| 427 | fHorizontalLayout_2->addWidget(fCanvasWidget); |
| 428 | fHorizontalLayout_2->addWidget(fSettingsWidget); |
| 429 | |
| 430 | fVerticalLayout->addLayout(fHorizontalLayout_2); |
| 431 | fVerticalLayout->addWidget(fInspectorWidget); |
| 432 | |
| 433 | fHorizontalLayout->addLayout(fVerticalLayout_2); |
| 434 | fHorizontalLayout->addLayout(fVerticalLayout); |
| 435 | |
| 436 | SkDebuggerGUI->setCentralWidget(fCentralWidget); |
| 437 | fStatusBar = new QStatusBar(SkDebuggerGUI); |
| 438 | fStatusBar->setObjectName(QString::fromUtf8("statusBar")); |
| 439 | SkDebuggerGUI->setStatusBar(fStatusBar); |
| 440 | fToolBar = new QToolBar(SkDebuggerGUI); |
| 441 | fToolBar->setObjectName(QString::fromUtf8("toolBar")); |
| 442 | fToolBar->setIconSize(QSize(24, 24)); |
| 443 | //fToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); |
| 444 | SkDebuggerGUI->addToolBar(Qt::TopToolBarArea, fToolBar); |
| 445 | |
| 446 | QWidget *spacer = new QWidget(); |
| 447 | spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| 448 | |
| 449 | fToolBar->addAction(fActionOpen); |
| 450 | fToolBar->addSeparator(); |
| 451 | fToolBar->addAction(fActionDirectory); |
| 452 | fToolBar->addSeparator(); |
| 453 | fToolBar->addAction(fActionRewind); |
| 454 | fToolBar->addAction(fActionStepBack); |
| 455 | fToolBar->addAction(fActionStepForward); |
| 456 | fToolBar->addAction(fActionPlay); |
| 457 | fToolBar->addSeparator(); |
| 458 | fToolBar->addAction(fActionBreakpoint); |
| 459 | fToolBar->addAction(fActionInspector); |
| 460 | fToolBar->addSeparator(); |
| 461 | fToolBar->addAction(fActionDelete); |
| 462 | fToolBar->addAction(fActionReload); |
| 463 | fToolBar->addSeparator(); |
| 464 | fToolBar->addAction(fActionSettings); |
| 465 | fToolBar->addWidget(spacer); |
| 466 | fToolBar->addWidget(fFilter); |
| 467 | fToolBar->addAction(fActionCancel); |
| 468 | |
| 469 | // TODO(chudy): Remove static call. |
| 470 | fDirectoryWidgetActive = false; |
| 471 | fPath= "/usr/local/google/home/chudy/trunk-linux/debugger/skp"; |
| 472 | setupDirectoryWidget(); |
| 473 | fDirectoryWidgetActive = true; |
| 474 | |
| 475 | fMenuBar = new QMenuBar(SkDebuggerGUI); |
| 476 | |
| 477 | // File |
| 478 | fMenuFile = new QMenu(SkDebuggerGUI); |
| 479 | fMenuFile->setTitle("File"); |
| 480 | |
| 481 | fActionClose = new QAction(SkDebuggerGUI); |
| 482 | fActionClose->setText("Close"); |
| 483 | |
| 484 | fMenuFile->addAction(fActionOpen); |
| 485 | fMenuFile->addAction(fActionClose); |
| 486 | |
| 487 | // View |
| 488 | fMenuView = new QMenu(SkDebuggerGUI); |
| 489 | fMenuView->setTitle("View"); |
| 490 | |
| 491 | fActionToggleCurrentCommand = new QAction(SkDebuggerGUI); |
| 492 | fActionToggleCurrentCommand->setText("Show Filter"); |
| 493 | |
| 494 | fMenuView->addAction(fActionToggleCurrentCommand); |
| 495 | |
| 496 | // Navigate |
| 497 | fMenuNavigate = new QMenu(SkDebuggerGUI); |
| 498 | fMenuNavigate->setTitle("Navigate"); |
| 499 | |
| 500 | fActionGoToLine = new QAction(SkDebuggerGUI); |
| 501 | fActionGoToLine->setText("Go to Line..."); |
| 502 | fActionGoToLine->setDisabled(true); |
| 503 | |
| 504 | fMenuNavigate->addAction(fActionGoToLine); |
| 505 | |
| 506 | // Menu Bar |
| 507 | fMenuBar->addAction(fMenuFile->menuAction()); |
| 508 | fMenuBar->addAction(fMenuView->menuAction()); |
| 509 | fMenuBar->addAction(fMenuNavigate->menuAction()); |
| 510 | |
| 511 | SkDebuggerGUI->setMenuBar(fMenuBar); |
| 512 | |
| 513 | retranslateUi(SkDebuggerGUI); |
| 514 | QMetaObject::connectSlotsByName(SkDebuggerGUI); |
| 515 | } |
| 516 | |
| 517 | void SkDebuggerGUI::setupDirectoryWidget() { |
| 518 | fDir = new QDir(fPath); |
| 519 | QRegExp r(".skp"); |
| 520 | fDirectoryWidget->clear(); |
| 521 | const QStringList files = fDir->entryList(); |
| 522 | foreach (QString f, files) { |
| 523 | if (f.contains(r)) fDirectoryWidget->addItem(f); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | // TODO(chudy): Is this necessary? |
| 528 | void SkDebuggerGUI::retranslateUi(QMainWindow *SkDebuggerGUI) { |
| 529 | SkDebuggerGUI->setWindowTitle(QApplication::translate("SkDebuggerGUI", "SkDebuggerGUI", 0, QApplication::UnicodeUTF8)); |
| 530 | fActionOpen->setText(QApplication::translate("SkDebuggerGUI", "Open", 0, QApplication::UnicodeUTF8)); |
| 531 | fToolBar->setWindowTitle(QApplication::translate("SkDebuggerGUI", "toolBar", 0, QApplication::UnicodeUTF8)); |
| 532 | } |
| 533 | |
| 534 | void SkDebuggerGUI::loadPicture(QString fileName) { |
| 535 | fCanvasWidget->loadPicture(fileName); |
| 536 | std::vector<std::string> *cv = fCanvasWidget->getDrawCommands(); |
| 537 | setupListWidget(cv); |
| 538 | setupComboBox(cv); |
| 539 | } |
| 540 | |
| 541 | void SkDebuggerGUI::setupListWidget(std::vector<std::string>* cv) { |
| 542 | fListWidget->clear(); |
| 543 | int counter = 0; |
| 544 | for (unsigned int i = 0; i < cv->size(); i++) { |
| 545 | QListWidgetItem *item = new QListWidgetItem(); |
| 546 | item->setData(Qt::DisplayRole, (*cv)[i].c_str()); |
| 547 | item->setData(Qt::UserRole + 1, counter++); |
| 548 | item->setData(Qt::UserRole + 2, true); |
| 549 | fListWidget->addItem(item); |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | void SkDebuggerGUI::setupComboBox(std::vector<std::string>* cv) { |
| 554 | fFilter->clear(); |
| 555 | fFilter->addItem("--Filter By Available Commands--"); |
| 556 | |
| 557 | std::map<std::string, int> map; |
| 558 | for (unsigned int i = 0; i < cv->size(); i++) { |
| 559 | map[(*cv)[i]]++; |
| 560 | } |
| 561 | |
| 562 | QString overview; |
| 563 | int counter; |
| 564 | for(std::map<std::string, int>::iterator it = map.begin(); it != map.end(); ++it) { |
| 565 | overview.append((it->first).c_str()); |
| 566 | overview.append(": "); |
| 567 | overview.append(QString::number(it->second)); |
| 568 | overview.append("<br/>"); |
| 569 | counter+=it->second; |
| 570 | fFilter->addItem((it->first).c_str()); |
| 571 | } |
| 572 | QString total; |
| 573 | total.append("Total Draw Commands: "); |
| 574 | total.append(QString::number(counter)); |
| 575 | total.append("<br/>"); |
| 576 | overview.insert(0, total); |
| 577 | |
| 578 | overview.append("<br/>"); |
| 579 | overview.append("SkBitmap Width: "); |
| 580 | // NOTE(chudy): This is where we can pull out the SkPictures width. |
| 581 | overview.append(QString::number(fCanvasWidget->getBitmapWidth())); |
| 582 | overview.append("px<br/>"); |
| 583 | overview.append("SkBitmap Height: "); |
| 584 | overview.append(QString::number(fCanvasWidget->getBitmapHeight())); |
| 585 | overview.append("px"); |
| 586 | fInspectorWidget->setOverviewText(overview); |
| 587 | |
| 588 | // NOTE(chudy): Makes first item unselectable. |
| 589 | QStandardItemModel* model = |
| 590 | qobject_cast<QStandardItemModel*>(fFilter->model()); |
| 591 | QModelIndex firstIndex = model->index(0, fFilter->modelColumn(), |
| 592 | fFilter->rootModelIndex()); |
| 593 | QStandardItem* firstItem = model->itemFromIndex(firstIndex); |
| 594 | firstItem->setSelectable(false); |
| 595 | } |