MCPcopy Create free account
hub / github.com/IENT/YUView / saveScreenshot

Method saveScreenshot

YUViewLib/src/ui/Mainwindow.cpp:818–877  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

816}
817
818void MainWindow::saveScreenshot()
819{
820 // Ask the use if he wants to save the current view as it is or the complete frame of the item.
821 QMessageBox msgBox;
822 msgBox.setWindowTitle("Select screenshot mode");
823 msgBox.setText("<b>Current View: </b>Save a screenshot of the central view as you can see it "
824 "right now.<br><b>Item Frame: </b>Save the entire current frame of the selected "
825 "item in it's original resolution.");
826 msgBox.addButton(tr("Current View"), QMessageBox::AcceptRole);
827 QPushButton *itemFrame = msgBox.addButton(tr("Item Frame"), QMessageBox::AcceptRole);
828 QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort);
829 msgBox.exec();
830
831 bool fullItem = (msgBox.clickedButton() == itemFrame);
832 if (msgBox.clickedButton() == abortButton)
833 // The use pressed cancel
834 return;
835
836 // What image formats are supported?
837 QString allFormats;
838 QStringList fileExtensions;
839 QStringList fileFilterStrings;
840 for (QByteArray f : QImageWriter::supportedImageFormats())
841 {
842 QString filterString = QString("%1 (*.%1)").arg(QString(f));
843 fileExtensions.append(QString(f));
844 fileFilterStrings.append(filterString);
845
846 allFormats += filterString + ";;";
847 }
848
849 // Get the filename for the screenshot
850 QSettings settings;
851 QString selectedFilter = "png (*.png)";
852 QString filename = QFileDialog::getSaveFileName(this,
853 tr("Save Screenshot"),
854 settings.value("LastScreenshotPath").toString(),
855 allFormats,
856 &selectedFilter);
857
858 // Is a file extension set?
859 QString setSuffix = QFileInfo(filename).suffix();
860 if (!fileExtensions.contains(setSuffix))
861 {
862 // The file extension is not set or not used.
863 // Add the file extensinos of the selected filter.
864 int idx = fileFilterStrings.indexOf(selectedFilter);
865 filename += "." + fileExtensions[idx];
866 }
867
868 if (!filename.isEmpty())
869 {
870 ui.displaySplitView->getScreenshot(fullItem).save(filename);
871
872 // Save the path to the file so that we can open the next "save screenshot" file dialog in the
873 // same directory.
874 filename = filename.section('/', 0, -2);
875 settings.setValue("LastScreenshotPath", filename);

Callers

nothing calls this directly

Calls 7

setTextMethod · 0.80
appendMethod · 0.80
toStringMethod · 0.80
containsMethod · 0.80
indexOfMethod · 0.80
getScreenshotMethod · 0.80
isEmptyMethod · 0.45

Tested by

no test coverage detected