Skip to content

Commit

Permalink
Change to Screen Capture saving - now allows all QT identified image …
Browse files Browse the repository at this point in the history
…formats

Also added an error message when the file save fails.
  • Loading branch information
alanspencer committed Nov 5, 2018
1 parent 6286e64 commit 145bb08
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions SPIERSview/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,18 +711,42 @@ void MainWindow::on_actionLarge_Move_Away_triggered()
void MainWindow::on_actionScreen_Capture_triggered()
{
UpdateGL();
QImage ScreenCapture = gl3widget->grabFramebuffer();
FilterKeys = false;

// 32-bit RGB image from GLWidget
QImage screenCapture = gl3widget->grabFramebuffer();

// Find all available image formats that the program can use for saving
QString availableFormats = "";
for (int i = 0; i < QImageWriter::supportedImageFormats().size(); ++i)
{
if (i > 0) availableFormats.append(";;");
availableFormats.append(QString(QImageWriter::supportedImageFormats().at(i).constData()).toUpper());
availableFormats.append(" image (*.");
availableFormats.append(QImageWriter::supportedImageFormats().at(i).constData());
availableFormats.append(")");
}

FilterKeys = false;
QString fileName = QFileDialog::getSaveFileName(
this,
tr("Save Current View"),
"",
tr("JPEG Image (*.jpg);;Windows Bitmap Image (*.bmp);;TIFF image (*.tif);;PNG Image (*.png)")
tr(availableFormats.toLocal8Bit())
);
FilterKeys = true;

ScreenCapture.save(fileName);
// Only save if there is a file name, otherwise assume it is canceled
if (!fileName.isNull())
{
bool didItSave = screenCapture.save(fileName);

if (!didItSave)
{
QMessageBox messageBox;
messageBox.warning(nullptr, "Saving Error", "The program could not save the image format to your selected location.");
messageBox.setFixedSize(500, 200);
}
}
}

/**
Expand Down

0 comments on commit 145bb08

Please sign in to comment.