diff options
author | Tom Rondeau <trondeau@vt.edu> | 2012-11-07 00:12:45 -0500 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2012-11-07 00:12:45 -0500 |
commit | 2f0985b105885c9eed1e213dd6da5a2389288e53 (patch) | |
tree | f20ebbf5481bd8339db4c27d19d8d0ff58371d14 /gr-qtgui | |
parent | 0617e68d5f6406e9f18580823e3530b2b21d017a (diff) |
qtgui: adding ability to save a qtgui sink.
Right-click menu has a "save" option to take a snapshot of the figure.
Diffstat (limited to 'gr-qtgui')
-rw-r--r-- | gr-qtgui/lib/displayform.cc | 45 | ||||
-rw-r--r-- | gr-qtgui/lib/displayform.h | 4 |
2 files changed, 49 insertions, 0 deletions
diff --git a/gr-qtgui/lib/displayform.cc b/gr-qtgui/lib/displayform.cc index 92f7ca59b6..4daf5c76ef 100644 --- a/gr-qtgui/lib/displayform.cc +++ b/gr-qtgui/lib/displayform.cc @@ -22,6 +22,8 @@ #include <displayform.h> #include <iostream> +#include <QPixmap> +#include <QFileDialog> DisplayForm::DisplayForm(int nplots, QWidget* parent) : QWidget(parent), _nplots(nplots), _systemSpecifiedFlag(false) @@ -95,6 +97,12 @@ DisplayForm::DisplayForm(int nplots, QWidget* parent) _menu->addMenu(_lines_menu[i]); } + + _save_act = new QAction("Save", this); + _save_act->setStatusTip(tr("Save Figure")); + connect(_save_act, SIGNAL(triggered()), this, SLOT(saveFigure())); + _menu->addAction(_save_act); + Reset(); // Create a timer to update plots at the specified rate @@ -278,3 +286,40 @@ DisplayForm::setGrid() else setGrid(false); } + +void +DisplayForm::saveFigure() +{ + QPixmap qpix = QPixmap::grabWidget(this); + + QString types = QString(tr("JPEG file (*.jpg);;Portable Network Graphics file (*.png);;Bitmap file (*.bmp);;TIFF file (*.tiff)")); + + QString filename, filetype; + QFileDialog *filebox = new QFileDialog(0, "Save Image", "./", types); + filebox->setViewMode(QFileDialog::Detail); + if(filebox->exec()) { + filename = filebox->selectedFiles()[0]; + filetype = filebox->selectedNameFilter(); + } + else { + return; + } + + if(filetype.contains(".jpg")) { + qpix.save(filename, "JPEG"); + } + else if(filetype.contains(".png")) { + qpix.save(filename, "PNG"); + } + else if(filetype.contains(".bmp")) { + qpix.save(filename, "BMP"); + } + else if(filetype.contains(".tiff")) { + qpix.save(filename, "TIFF"); + } + else { + qpix.save(filename, "JPEG"); + } + + delete filebox; +} diff --git a/gr-qtgui/lib/displayform.h b/gr-qtgui/lib/displayform.h index f436b526ac..99b0e714f4 100644 --- a/gr-qtgui/lib/displayform.h +++ b/gr-qtgui/lib/displayform.h @@ -67,6 +67,8 @@ public slots: void setGrid(bool on); void setGrid(); + void saveFigure(); + private slots: virtual void newData(const QEvent*) = 0; void updateGuiTimer(); @@ -100,6 +102,8 @@ protected: QList<LineMarkerMenu*> _line_marker_menu; QList<MarkerAlphaMenu*> _marker_alpha_menu; + QAction *_save_act; + QTimer *d_displayTimer; double d_update_time; }; |