lightpreview: prompt for screenshot path

This commit is contained in:
Eric Wasylishen 2023-05-24 00:55:31 -06:00
parent 0d0d11314c
commit 901e87bce8
4 changed files with 16 additions and 10 deletions

View File

@ -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());
}

View File

@ -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<entdict_t> &entities, const settings::common_settings &settings);
void renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries_t &bspx,
const std::vector<entdict_t> &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;

View File

@ -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;

View File

@ -41,6 +41,7 @@ public:
private:
void setupMenu();
void fileOpen();
void takeScreenshot();
protected:
void dragEnterEvent(QDragEnterEvent *event) override;