From 901e87bce80710b99d1be96d70aa66d7d0848afa Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 24 May 2023 00:55:31 -0600 Subject: [PATCH] lightpreview: prompt for screenshot path --- lightpreview/glview.cpp | 8 ++------ lightpreview/glview.h | 5 +++-- lightpreview/mainwindow.cpp | 12 ++++++++++-- lightpreview/mainwindow.h | 1 + 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lightpreview/glview.cpp b/lightpreview/glview.cpp index f848f6e6..e7b5ad56 100644 --- a/lightpreview/glview.cpp +++ b/lightpreview/glview.cpp @@ -316,7 +316,7 @@ void GLView::setKeepOrigin(bool keeporigin) m_keepOrigin = keeporigin; } -void GLView::takeScreenshot(int w, int h) +void GLView::takeScreenshot(QString destPath, int w, int h) { // update aspect ratio float backupDisplayAspect = m_displayAspect; @@ -334,12 +334,8 @@ void GLView::takeScreenshot(int w, int h) glViewport(0, 0, w, h); paintGL(); - QString dest = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + - QLatin1String("/Screenshots/lightpreview_") + - QDateTime::currentDateTime().toString("yyyyMMdd_HHmmss") + QLatin1String(".png"); - QImage image = fbo.toImage(); - image.save(dest); + image.save(destPath); assert(fbo.release()); } diff --git a/lightpreview/glview.h b/lightpreview/glview.h index 1983c31e..68e68fee 100644 --- a/lightpreview/glview.h +++ b/lightpreview/glview.h @@ -115,7 +115,8 @@ public: GLView(QWidget *parent = nullptr); ~GLView(); - void renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries_t &bspx, const std::vector &entities, const settings::common_settings &settings); + void renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries_t &bspx, + const std::vector &entities, const settings::common_settings &settings); void setCamera(const qvec3d &origin, const qvec3d &fwd); void setLighmapOnly(bool lighmapOnly); void setFullbright(bool fullbright); @@ -125,7 +126,7 @@ public: void setKeepOrigin(bool keeporigin); const bool &getKeepOrigin() const { return m_keepOrigin; } - void takeScreenshot(int w, int h); + void takeScreenshot(QString destPath, int w, int h); protected: void initializeGL() override; diff --git a/lightpreview/mainwindow.cpp b/lightpreview/mainwindow.cpp index 7431a0d5..c1095be0 100644 --- a/lightpreview/mainwindow.cpp +++ b/lightpreview/mainwindow.cpp @@ -135,9 +135,9 @@ void MainWindow::setupMenu() auto *open = menu->addAction(tr("&Open"), this, &MainWindow::fileOpen); open->setShortcut(QKeySequence::Open); - auto *openRecent = menu->addAction(tr("Open &Recent")); + // auto *openRecent = menu->addAction(tr("Open &Recent")); - auto *takeScreenshot = menu->addAction(tr("Take Screenshot"), this, [=]() { glView->takeScreenshot(3840, 2160); }); + auto *takeScreenshot = menu->addAction(tr("Save Screenshot..."), this, &MainWindow::takeScreenshot); auto *exit = menu->addAction(tr("E&xit"), this, &QWidget::close); exit->setShortcut(QKeySequence::Quit); @@ -180,6 +180,14 @@ void MainWindow::fileOpen() loadFile(fileName); } +void MainWindow::takeScreenshot() +{ + QString fileName = QFileDialog::getSaveFileName(this, tr("Save Screenshot"), "", tr("PNG (*.png)")); + + if (!fileName.isEmpty()) + glView->takeScreenshot(fileName, 3840, 2160); +} + void MainWindow::loadFile(const QString &file) { qDebug() << "load " << file; diff --git a/lightpreview/mainwindow.h b/lightpreview/mainwindow.h index a6de726a..f262493b 100644 --- a/lightpreview/mainwindow.h +++ b/lightpreview/mainwindow.h @@ -41,6 +41,7 @@ public: private: void setupMenu(); void fileOpen(); + void takeScreenshot(); protected: void dragEnterEvent(QDragEnterEvent *event) override;