+ dialog.exec();
+}
+
+void MainWindow::openHelp(const QUrl &url)
+{
+ QDesktopServices::openUrl(url);
+}
+
+void MainWindow::showSurfacesMenu(const QPoint &pos)
+{
+ QTreeWidget *tree = m_ui.surfacesTreeWidget;
+ QTreeWidgetItem *item = tree->itemAt(pos);
+ if (!item)
+ return;
+
+ QMenu menu(tr("Surfaces"), this);
+
+ QAction *act = menu.addAction(tr("View Image"));
+ act->setStatusTip(tr("View the currently selected surface"));
+ connect(act, SIGNAL(triggered()),
+ SLOT(showSelectedSurface()));
+
+ act = menu.addAction(tr("Save Image"));
+ act->setStatusTip(tr("Save the currently selected surface"));
+ connect(act, SIGNAL(triggered()),
+ SLOT(saveSelectedSurface()));
+
+ menu.exec(tree->viewport()->mapToGlobal(pos));
+}
+
+void MainWindow::showSelectedSurface()
+{
+ QTreeWidgetItem *item =
+ m_ui.surfacesTreeWidget->currentItem();
+
+ if (!item)
+ return;
+
+ QVariant var = item->data(0, Qt::UserRole);
+ QImage img = var.value<QImage>();
+ ImageViewer *viewer = new ImageViewer(this);
+
+ QString title;
+ if (currentCall()) {
+ title = tr("QApiTrace - Surface at %1 (%2)")
+ .arg(currentCall()->name())
+ .arg(currentCall()->index());
+ } else {
+ title = tr("QApiTrace - Surface Viewer");
+ }
+ viewer->setWindowTitle(title);
+ viewer->setAttribute(Qt::WA_DeleteOnClose, true);
+ viewer->setImage(img);
+ QRect screenRect = QApplication::desktop()->availableGeometry();
+ viewer->resize(qMin(int(0.75 * screenRect.width()), img.width()) + 40,
+ qMin(int(0.75 * screenRect.height()), img.height()) + 40);
+ viewer->show();
+ viewer->raise();
+ viewer->activateWindow();
+}
+
+void MainWindow::initObjects()
+{
+ m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder);
+ m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder);
+
+ m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab);
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(m_sourcesWidget);
+ m_ui.shadersTab->setLayout(layout);
+
+ m_trace = new ApiTrace();
+ m_retracer = new Retracer(this);
+
+ m_vdataInterpreter = new VertexDataInterpreter(this);
+ m_vdataInterpreter->setListWidget(m_ui.vertexDataListWidget);
+ m_vdataInterpreter->setStride(
+ m_ui.vertexStrideSB->value());
+ m_vdataInterpreter->setComponents(
+ m_ui.vertexComponentsSB->value());
+ m_vdataInterpreter->setStartingOffset(
+ m_ui.startingOffsetSB->value());
+ m_vdataInterpreter->setTypeFromString(
+ m_ui.vertexTypeCB->currentText());
+
+ m_model = new ApiTraceModel();
+ m_model->setApiTrace(m_trace);
+ m_proxyModel = new ApiTraceFilter();
+ m_proxyModel->setSourceModel(m_model);
+ m_ui.callView->setModel(m_proxyModel);
+ m_ui.callView->setItemDelegate(
+ new ApiCallDelegate(m_ui.callView));
+ m_ui.callView->resizeColumnToContents(0);
+ m_ui.callView->header()->swapSections(0, 1);
+ m_ui.callView->setColumnWidth(1, 42);
+ m_ui.callView->setContextMenuPolicy(Qt::CustomContextMenu);
+
+ m_progressBar = new QProgressBar();
+ m_progressBar->setRange(0, 100);
+ statusBar()->addPermanentWidget(m_progressBar);
+ m_progressBar->hide();
+
+ m_argsEditor = new ArgumentsEditor(this);
+
+ m_ui.detailsDock->hide();
+ m_ui.errorsDock->hide();
+ m_ui.vertexDataDock->hide();
+ m_ui.stateDock->hide();
+ setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
+
+ tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
+ tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
+
+ m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
+
+ m_ui.detailsWebView->page()->setLinkDelegationPolicy(
+ QWebPage::DelegateExternalLinks);
+
+ m_jumpWidget = new JumpWidget(this);
+ m_ui.centralLayout->addWidget(m_jumpWidget);
+ m_jumpWidget->hide();
+
+ m_searchWidget = new SearchWidget(this);
+ m_ui.centralLayout->addWidget(m_searchWidget);
+ m_searchWidget->hide();
+
+ m_traceProcess = new TraceProcess(this);
+}
+
+void MainWindow::initConnections()
+{
+ connect(m_trace, SIGNAL(startedLoadingTrace()),
+ this, SLOT(startedLoadingTrace()));
+ connect(m_trace, SIGNAL(loaded(int)),
+ this, SLOT(loadProgess(int)));
+ connect(m_trace, SIGNAL(finishedLoadingTrace()),
+ this, SLOT(finishedLoadingTrace()));
+ connect(m_trace, SIGNAL(startedSaving()),
+ this, SLOT(slotStartedSaving()));
+ connect(m_trace, SIGNAL(saved()),
+ this, SLOT(slotSaved()));
+ connect(m_trace, SIGNAL(changed(ApiTraceCall*)),
+ this, SLOT(slotTraceChanged(ApiTraceCall*)));
+
+ connect(m_retracer, SIGNAL(finished(const QString&)),
+ this, SLOT(replayFinished(const QString&)));
+ connect(m_retracer, SIGNAL(error(const QString&)),
+ this, SLOT(replayError(const QString&)));
+ connect(m_retracer, SIGNAL(foundState(ApiTraceState*)),
+ this, SLOT(replayStateFound(ApiTraceState*)));
+ connect(m_retracer, SIGNAL(retraceErrors(const QList<RetraceError>&)),
+ this, SLOT(slotRetraceErrors(const QList<RetraceError>&)));
+
+ connect(m_ui.vertexInterpretButton, SIGNAL(clicked()),
+ m_vdataInterpreter, SLOT(interpretData()));
+ connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)),
+ m_vdataInterpreter, SLOT(setTypeFromString(const QString&)));
+ connect(m_ui.vertexStrideSB, SIGNAL(valueChanged(int)),
+ m_vdataInterpreter, SLOT(setStride(int)));
+ connect(m_ui.vertexComponentsSB, SIGNAL(valueChanged(int)),
+ m_vdataInterpreter, SLOT(setComponents(int)));
+ connect(m_ui.startingOffsetSB, SIGNAL(valueChanged(int)),
+ m_vdataInterpreter, SLOT(setStartingOffset(int)));
+
+
+ connect(m_ui.actionNew, SIGNAL(triggered()),
+ this, SLOT(createTrace()));
+ connect(m_ui.actionOpen, SIGNAL(triggered()),
+ this, SLOT(openTrace()));
+ connect(m_ui.actionQuit, SIGNAL(triggered()),
+ this, SLOT(close()));
+
+ connect(m_ui.actionFind, SIGNAL(triggered()),
+ this, SLOT(slotSearch()));
+ connect(m_ui.actionGo, SIGNAL(triggered()),
+ this, SLOT(slotGoTo()));
+ connect(m_ui.actionGoFrameStart, SIGNAL(triggered()),
+ this, SLOT(slotGoFrameStart()));
+ connect(m_ui.actionGoFrameEnd, SIGNAL(triggered()),
+ this, SLOT(slotGoFrameEnd()));
+
+ connect(m_ui.actionReplay, SIGNAL(triggered()),
+ this, SLOT(replayStart()));
+ connect(m_ui.actionStop, SIGNAL(triggered()),
+ this, SLOT(replayStop()));
+ connect(m_ui.actionLookupState, SIGNAL(triggered()),
+ this, SLOT(lookupState()));
+ connect(m_ui.actionOptions, SIGNAL(triggered()),
+ this, SLOT(showSettings()));
+
+ connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
+ this, SLOT(callItemSelected(const QModelIndex &)));
+ connect(m_ui.callView, SIGNAL(customContextMenuRequested(QPoint)),
+ this, SLOT(customContextMenuRequested(QPoint)));
+
+ connect(m_ui.surfacesTreeWidget,
+ SIGNAL(customContextMenuRequested(const QPoint &)),
+ SLOT(showSurfacesMenu(const QPoint &)));
+ connect(m_ui.surfacesTreeWidget,
+ SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
+ SLOT(showSelectedSurface()));
+
+ connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
+ this, SLOT(openHelp(const QUrl&)));
+
+ connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
+ this, SLOT(fillState(bool)));
+
+ connect(m_jumpWidget, SIGNAL(jumpTo(int)),
+ SLOT(slotJumpTo(int)));
+
+ connect(m_searchWidget,
+ SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
+ SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
+ connect(m_searchWidget,
+ SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
+ SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
+
+ connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
+ SLOT(createdTrace(const QString&)));
+ connect(m_traceProcess, SIGNAL(error(const QString&)),
+ SLOT(traceError(const QString&)));
+
+ connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)),
+ m_ui.actionShowErrorsDock, SLOT(setChecked(bool)));
+ connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)),
+ m_ui.errorsDock, SLOT(setVisible(bool)));
+ connect(m_ui.errorsTreeWidget,
+ SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
+ this, SLOT(slotErrorSelected(QTreeWidgetItem*)));
+}
+
+void MainWindow::replayStateFound(ApiTraceState *state)
+{
+ m_stateEvent->setState(state);
+ m_model->stateSetOnEvent(m_stateEvent);
+ if (m_selectedEvent == m_stateEvent ||
+ m_nonDefaultsLookupEvent == m_selectedEvent) {
+ fillStateForFrame();
+ } else {
+ m_ui.stateDock->hide();