From 09ec4840eb1036a8b7719d1ed05390a7c451dc12 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Sun, 10 Apr 2011 01:57:17 -0400 Subject: [PATCH] Add a simple viewer for surfaces. --- gui/CMakeLists.txt | 2 ++ gui/mainwindow.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++- gui/mainwindow.h | 5 ++++ gui/ui/mainwindow.ui | 6 ++--- 4 files changed, 84 insertions(+), 4 deletions(-) diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index f1f1a7f..8da0f61 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -8,6 +8,7 @@ set(qapitrace_SRCS apitracecall.cpp apitracefilter.cpp apitracemodel.cpp + imageviewer.cpp loaderthread.cpp mainwindow.cpp main.cpp @@ -22,6 +23,7 @@ qt4_automoc(${qapitrace_SRCS}) qt4_add_resources(qapitrace_SRCS qapitrace.qrc) set(qapitrace_UIS + ui/imageviewer.ui ui/mainwindow.ui ui/retracerdialog.ui ui/settings.ui diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 57112e5..0838fcd 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -5,6 +5,7 @@ #include "apicalldelegate.h" #include "apitracemodel.h" #include "apitracefilter.h" +#include "imageviewer.h" #include "retracer.h" #include "settingsdialog.h" #include "shaderssourcewidget.h" @@ -65,6 +66,8 @@ MainWindow::MainWindow() m_vdataInterpreter->setTypeFromString( m_ui.vertexTypeCB->currentText()); + m_imageViewer = new ImageViewer(this); + connect(m_ui.vertexInterpretButton, SIGNAL(clicked()), m_vdataInterpreter, SLOT(interpretData())); connect(m_ui.vertexTypeCB, SIGNAL(currentIndexChanged(const QString&)), @@ -121,6 +124,14 @@ MainWindow::MainWindow() connect(m_filterEdit, SIGNAL(returnPressed()), this, SLOT(filterTrace())); + m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_ui.surfacesTreeWidget, + SIGNAL(customContextMenuRequested(const QPoint &)), + SLOT(showSurfacesMenu(const QPoint &))); + connect(m_ui.surfacesTreeWidget, + SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), + SLOT(showSelectedSurface())); + m_ui.detailsWebView->page()->setLinkDelegationPolicy( QWebPage::DelegateExternalLinks); connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)), @@ -411,7 +422,37 @@ void MainWindow::fillStateForFrame() m_sourcesWidget->setShaders(shaderSources); } - m_ui.surfacesTab->setEnabled(false); + const QList &textures = + state.textures(); + + if (textures.isEmpty()) { + m_ui.surfacesTreeWidget->clear(); + m_ui.surfacesTab->setDisabled(false); + } else { + QTreeWidgetItem *textureItem = + new QTreeWidgetItem(m_ui.surfacesTreeWidget); + m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64)); + textureItem->setText(0, tr("Textures")); + for (int i = 0; i < textures.count(); ++i) { + const ApiTexture &texture = + textures[i]; + QIcon icon(QPixmap::fromImage(texture.thumb())); + QTreeWidgetItem *item = new QTreeWidgetItem(textureItem); + item->setIcon(0, icon); + int width = texture.size().width(); + int height = texture.size().height(); + QString descr = + QString::fromLatin1("%1, %2 x %3") + .arg(texture.target()) + .arg(width) + .arg(height); + item->setText(1, descr); + + item->setData(0, Qt::UserRole, + texture.image()); + } + m_ui.surfacesTab->setEnabled(true); + } m_ui.stateDock->show(); } @@ -430,4 +471,36 @@ 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); + //add needed actions + QAction *act = menu.addAction(tr("View Image")); + act->setStatusTip(tr("View the currently selected surface")); + connect(act, SIGNAL(triggered()), + SLOT(showSelectedSurface())); + + 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); + m_imageViewer->setImage(var.value()); + m_imageViewer->show(); + m_imageViewer->raise(); + m_imageViewer->activateWindow(); +} + #include "mainwindow.moc" diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 19fffc2..d309ed2 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -11,6 +11,7 @@ class ApiTraceEvent; class ApiTraceFilter; class ApiTraceFrame; class ApiTraceModel; +class ImageViewer; class QLineEdit; class QModelIndex; class QProgressBar; @@ -46,6 +47,8 @@ private slots: void lookupState(); void showSettings(); void openHelp(const QUrl &url); + void showSurfacesMenu(const QPoint &pos); + void showSelectedSurface(); private: void newTraceFile(const QString &fileName); @@ -75,6 +78,8 @@ private: Retracer *m_retracer; VertexDataInterpreter *m_vdataInterpreter; + + ImageViewer *m_imageViewer; }; diff --git a/gui/ui/mainwindow.ui b/gui/ui/mainwindow.ui index 06988c7..89b5836 100644 --- a/gui/ui/mainwindow.ui +++ b/gui/ui/mainwindow.ui @@ -127,7 +127,7 @@ - 1 + 2 @@ -176,12 +176,12 @@ - Type + Thumbnail - Size + Description -- 2.7.4