summaryrefslogtreecommitdiff
path: root/src/qcam/main_window.cpp
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2020-02-05 16:02:05 +0000
committerKieran Bingham <kieran.bingham@ideasonboard.com>2020-02-14 12:34:36 +0000
commit0f292e7821b809df77de443dd30148a609cc4f49 (patch)
treec5459a79c7f327a3f9f06f513d6378e376ee9bd0 /src/qcam/main_window.cpp
parent2dc85eabe1d9e9946f39692ea9a3bf1bb635bbcc (diff)
qcam: Provide save image functionality
Implement a save image button on the toolbar which will take a current viewfinder image and present the user with a QFileDialog to allow them to choose where to save the image. Utilise the QImageWriter to perform the output task. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/qcam/main_window.cpp')
-rw-r--r--src/qcam/main_window.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index f76890e7..29eaba84 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -12,7 +12,10 @@
#include <QComboBox>
#include <QCoreApplication>
+#include <QFileDialog>
#include <QIcon>
+#include <QImage>
+#include <QImageWriter>
#include <QInputDialog>
#include <QTimer>
#include <QToolBar>
@@ -88,6 +91,9 @@ int MainWindow::createToolbars()
action = toolbar_->addAction(QIcon(":stop-circle.svg"), "stop");
connect(action, &QAction::triggered, this, &MainWindow::stopCapture);
+ action = toolbar_->addAction(QIcon(":save.svg"), "saveAs");
+ connect(action, &QAction::triggered, this, &MainWindow::saveImageAs);
+
return 0;
}
@@ -339,6 +345,22 @@ void MainWindow::stopCapture()
setWindowTitle(title_);
}
+void MainWindow::saveImageAs()
+{
+ QImage image = viewfinder_->getCurrentImage();
+
+ QString filename = QFileDialog::getSaveFileName(this, "Save Image", "",
+ "Image Files (*.png *.jpg *.jpeg)");
+
+ std::cout << "Save image to " << filename.toStdString() << std::endl;
+
+ if (filename.isEmpty())
+ return;
+
+ QImageWriter writer(filename);
+ writer.write(image);
+}
+
void MainWindow::requestComplete(Request *request)
{
if (request->status() == Request::RequestCancelled)