]> git.cworth.org Git - apitrace/commitdiff
Allow saving of surface snapshots to png's.
authorZack Rusin <zack@kde.org>
Mon, 20 Jun 2011 23:46:17 +0000 (19:46 -0400)
committerZack Rusin <zack@kde.org>
Mon, 20 Jun 2011 23:46:17 +0000 (19:46 -0400)
idea from Terry Hendrix II

gui/mainwindow.cpp
gui/mainwindow.h

index 183ba401980034f1eda98deaa3b33c32b17f8d96..057168b1d76ba3e6793c017fbfcd475205640eb4 100644 (file)
@@ -562,12 +562,17 @@ void MainWindow::showSurfacesMenu(const QPoint &pos)
         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()));
 
+    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));
 }
 
@@ -1097,4 +1102,57 @@ ApiTraceCall * MainWindow::currentCall() const
     return NULL;
 }
 
+void MainWindow::saveSelectedSurface()
+{
+    QTreeWidgetItem *item =
+        m_ui.surfacesTreeWidget->currentItem();
+
+    if (!item || !m_trace)
+        return;
+
+    QVariant var = item->data(0, Qt::UserRole);
+    QImage img = var.value<QImage>();
+
+    QString imageIndex;
+    if (currentCall()) {
+        imageIndex = tr("_call_%1")
+                     .arg(currentCall()->index());
+    } else if (currentFrame()) {
+        ApiTraceCall *firstCall = currentFrame()->call(0);
+        if (firstCall) {
+            imageIndex = tr("_frame_%1")
+                         .arg(firstCall->index());
+        } else {
+            qDebug()<<"unknown frame number";
+            imageIndex = tr("_frame_%1")
+                         .arg(firstCall->index());
+        }
+    }
+
+    //which of the surfaces are we saving
+    QTreeWidgetItem *parent = item->parent();
+    int parentIndex =
+        m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent);
+    if (parentIndex < 0) {
+        parentIndex = 0;
+    }
+    int childIndex = 0;
+    if (parent) {
+        childIndex = parent->indexOfChild(item);
+    } else {
+        childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item);
+    }
+
+
+    QString fileName =
+        tr("%1%2-%3_%4.png")
+        .arg(m_trace->fileName())
+        .arg(imageIndex)
+        .arg(parentIndex)
+        .arg(childIndex);
+    //qDebug()<<"save "<<fileName;
+    img.save(fileName, "PNG");
+    statusBar()->showMessage( tr("Saved '%1'").arg(fileName), 5000);
+}
+
 #include "mainwindow.moc"
index 97d6619bb5508e3785d63c3544741862ecebc155..5cb2e767eacaa0342a1d21d3307e96d6ac7cdf4c 100644 (file)
@@ -52,6 +52,7 @@ private slots:
     void openHelp(const QUrl &url);
     void showSurfacesMenu(const QPoint &pos);
     void showSelectedSurface();
+    void saveSelectedSurface();
     void slotGoTo();
     void slotJumpTo(int callNum);
     void createdTrace(const QString &path);