mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-05 06:25:16 +00:00
Add image saving to SVG format
This allows to create images independent from screen resolution Replaced copy-pasted screenshot code with the single implementation
This commit is contained in:
parent
bbd1bce0b8
commit
56dbec82d4
14 changed files with 96 additions and 62 deletions
|
|
@ -164,6 +164,7 @@ HEADERS += \
|
|||
preferences.h \
|
||||
savable.h \
|
||||
scpi.h \
|
||||
screenshot.h \
|
||||
streamingserver.h \
|
||||
tcpserver.h \
|
||||
touchstone.h \
|
||||
|
|
@ -320,6 +321,7 @@ SOURCES += \
|
|||
preferences.cpp \
|
||||
savable.cpp \
|
||||
scpi.cpp \
|
||||
screenshot.cpp \
|
||||
streamingserver.cpp \
|
||||
tcpserver.cpp \
|
||||
touchstone.cpp \
|
||||
|
|
@ -338,7 +340,7 @@ mac{
|
|||
PKGCONFIG += libusb-1.0
|
||||
}
|
||||
|
||||
QT += widgets network
|
||||
QT += widgets network svg
|
||||
|
||||
FORMS += \
|
||||
Calibration/CalStandardLineEditDialog.ui \
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "fftcomplex.h"
|
||||
#include "preferences.h"
|
||||
#include "appwindow.h"
|
||||
#include "screenshot.h"
|
||||
|
||||
#include <random>
|
||||
#include <thread>
|
||||
|
|
@ -403,17 +404,7 @@ void EyeDiagramPlot::updateContextMenu()
|
|||
auto image = new QAction("Save image...", contextmenu);
|
||||
contextmenu->addAction(image);
|
||||
connect(image, &QAction::triggered, this, [=]() {
|
||||
auto filename = QFileDialog::getSaveFileName(nullptr, "Save plot image", Preferences::getInstance().UISettings.Paths.image, "PNG image files (*.png)", nullptr, Preferences::QFileDialogOptions());
|
||||
if(filename.isEmpty()) {
|
||||
// aborted selection
|
||||
return;
|
||||
}
|
||||
Preferences::getInstance().UISettings.Paths.image = QFileInfo(filename).path();
|
||||
if(filename.endsWith(".png")) {
|
||||
filename.chop(4);
|
||||
}
|
||||
filename += ".png";
|
||||
grab().save(filename);
|
||||
SaveScreenshot(this);
|
||||
});
|
||||
|
||||
contextmenu->addSection("Traces");
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "Marker/marker.h"
|
||||
#include "Util/util.h"
|
||||
#include "preferences.h"
|
||||
#include "screenshot.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
|
|
@ -253,17 +254,7 @@ void TracePolar::updateContextMenu()
|
|||
auto image = new QAction("Save image...", contextmenu);
|
||||
contextmenu->addAction(image);
|
||||
connect(image, &QAction::triggered, [=]() {
|
||||
auto filename = QFileDialog::getSaveFileName(nullptr, "Save plot image", Preferences::getInstance().UISettings.Paths.image, "PNG image files (*.png)", nullptr, Preferences::QFileDialogOptions());
|
||||
if(filename.isEmpty()) {
|
||||
// aborted selection
|
||||
return;
|
||||
}
|
||||
Preferences::getInstance().UISettings.Paths.image = QFileInfo(filename).path();
|
||||
if(filename.endsWith(".png")) {
|
||||
filename.chop(4);
|
||||
}
|
||||
filename += ".png";
|
||||
grab().save(filename);
|
||||
SaveScreenshot(this);
|
||||
});
|
||||
|
||||
auto createMarker = contextmenu->addAction("Add marker here");
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "waterfallaxisdialog.h"
|
||||
#include "appwindow.h"
|
||||
#include "tracexyplot.h"
|
||||
#include "screenshot.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QPainter>
|
||||
|
|
@ -213,17 +214,7 @@ void TraceWaterfall::updateContextMenu()
|
|||
auto image = new QAction("Save image...", contextmenu);
|
||||
contextmenu->addAction(image);
|
||||
connect(image, &QAction::triggered, [=]() {
|
||||
auto filename = QFileDialog::getSaveFileName(nullptr, "Save plot image", Preferences::getInstance().UISettings.Paths.image, "PNG image files (*.png)", nullptr, Preferences::QFileDialogOptions());
|
||||
if(filename.isEmpty()) {
|
||||
// aborted selection
|
||||
return;
|
||||
}
|
||||
Preferences::getInstance().UISettings.Paths.image = QFileInfo(filename).path();
|
||||
if(filename.endsWith(".png")) {
|
||||
filename.chop(4);
|
||||
}
|
||||
filename += ".png";
|
||||
grab().save(filename);
|
||||
SaveScreenshot(this);
|
||||
});
|
||||
|
||||
contextmenu->addSection("Traces");
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "preferences.h"
|
||||
#include "appwindow.h"
|
||||
#include "ui_XYPlotConstantLineEditDialog.h"
|
||||
#include "screenshot.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <cmath>
|
||||
|
|
@ -349,17 +350,7 @@ void TraceXYPlot::updateContextMenu()
|
|||
auto image = new QAction("Save image...", contextmenu);
|
||||
contextmenu->addAction(image);
|
||||
connect(image, &QAction::triggered, [=]() {
|
||||
auto filename = QFileDialog::getSaveFileName(nullptr, "Save plot image", Preferences::getInstance().UISettings.Paths.image, "PNG image files (*.png)", nullptr, Preferences::QFileDialogOptions());
|
||||
if(filename.isEmpty()) {
|
||||
// aborted selection
|
||||
return;
|
||||
}
|
||||
Preferences::getInstance().UISettings.Paths.image = QFileInfo(filename).path();
|
||||
if(filename.endsWith(".png")) {
|
||||
filename.chop(4);
|
||||
}
|
||||
filename += ".png";
|
||||
grab().save(filename);
|
||||
SaveScreenshot(this);
|
||||
});
|
||||
|
||||
auto createMarker = contextmenu->addAction("Add marker here");
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "CustomWidgets/informationbox.h"
|
||||
|
||||
#include "ui_main.h"
|
||||
#include "screenshot.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
|
|
@ -141,17 +142,7 @@ Mode::Type Mode::TypeFromName(QString s)
|
|||
|
||||
void Mode::saveSreenshot()
|
||||
{
|
||||
auto filename = QFileDialog::getSaveFileName(nullptr, "Save plot image", Preferences::getInstance().UISettings.Paths.image, "PNG image files (*.png)", nullptr, Preferences::QFileDialogOptions());
|
||||
if(filename.isEmpty()) {
|
||||
// aborted selection
|
||||
return;
|
||||
}
|
||||
Preferences::getInstance().UISettings.Paths.image = QFileInfo(filename).path();
|
||||
if(filename.endsWith(".png")) {
|
||||
filename.chop(4);
|
||||
}
|
||||
filename += ".png";
|
||||
central->grab().save(filename);
|
||||
SaveScreenshot(central);
|
||||
}
|
||||
|
||||
void Mode::finalize(QWidget *centralWidget)
|
||||
|
|
|
|||
|
|
@ -229,6 +229,7 @@ public:
|
|||
QString pref;
|
||||
QString firmware;
|
||||
} Paths;
|
||||
qsizetype saveImageFilterIndex;
|
||||
} UISettings;
|
||||
|
||||
bool TCPoverride; // in case of manual port specification via command line
|
||||
|
|
@ -413,6 +414,7 @@ private:
|
|||
{&UISettings.Paths.limitLines, "UISettings.Paths.limitLines", ""},
|
||||
{&UISettings.Paths.pref, "UISettings.Paths.pref", ""},
|
||||
{&UISettings.Paths.firmware, "UISettings.Paths.firmware", ""},
|
||||
{&UISettings.saveImageFilterIndex, "UISettings.saveImageFilterIndex", 0},
|
||||
}};
|
||||
};
|
||||
|
||||
|
|
|
|||
65
Software/PC_Application/LibreVNA-GUI/screenshot.cpp
Normal file
65
Software/PC_Application/LibreVNA-GUI/screenshot.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#include "screenshot.h"
|
||||
|
||||
#include "preferences.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QPainter>
|
||||
#include <QSvgGenerator>
|
||||
|
||||
void SaveScreenshot(QWidget *widget)
|
||||
{
|
||||
Q_ASSERT(widget != nullptr);
|
||||
|
||||
const QStringList extensions = QStringList() << "png" << "svg";
|
||||
QStringList filters;
|
||||
|
||||
for (const QString& ext: extensions) {
|
||||
filters << QString("%1 image files (*.%2)").arg(ext.toUpper(), ext);
|
||||
}
|
||||
|
||||
auto& settings = Preferences::getInstance().UISettings;
|
||||
const QString filterString = filters.join(";;");
|
||||
qsizetype filterIndex = qBound(0, settings.saveImageFilterIndex, filters.size() - 1);
|
||||
QString selectedFilter = filters[filterIndex];
|
||||
|
||||
auto filename = QFileDialog::getSaveFileName(nullptr, "Save plot image", settings.Paths.image, filterString, &selectedFilter, Preferences::QFileDialogOptions());
|
||||
if(filename.isEmpty()) {
|
||||
// aborted selection
|
||||
return;
|
||||
}
|
||||
|
||||
filterIndex = filters.indexOf(selectedFilter);
|
||||
const QString& extension = extensions[filterIndex];
|
||||
if(!filename.endsWith(extension)) {
|
||||
filename += '.' + extension;
|
||||
}
|
||||
|
||||
settings.Paths.image = QFileInfo(filename).path();
|
||||
settings.saveImageFilterIndex = filterIndex;
|
||||
|
||||
switch (filterIndex)
|
||||
{
|
||||
case 0: // PNG
|
||||
widget->grab().save(filename);
|
||||
break;
|
||||
|
||||
case 1: // SVG
|
||||
{
|
||||
QSvgGenerator generator;
|
||||
generator.setFileName(filename);
|
||||
generator.setViewBox(QRect(QPoint(), widget->size()));
|
||||
generator.setTitle(QCoreApplication::applicationName());
|
||||
generator.setDescription(QString("Created by %1 %2").arg(QCoreApplication::applicationName(), QCoreApplication::applicationVersion()));
|
||||
|
||||
QPainter painter;
|
||||
painter.begin(&generator);
|
||||
widget->render(&painter);
|
||||
painter.end();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
8
Software/PC_Application/LibreVNA-GUI/screenshot.h
Normal file
8
Software/PC_Application/LibreVNA-GUI/screenshot.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef SCREENSHOT_H
|
||||
#define SCREENSHOT_H
|
||||
|
||||
class QWidget;
|
||||
|
||||
void SaveScreenshot(QWidget *widget);
|
||||
|
||||
#endif // SCREENSHOT_H
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
QT += testlib widgets network
|
||||
QT += testlib widgets network svg
|
||||
|
||||
CONFIG += qt console warn_on depend_includepath testcase
|
||||
CONFIG -= app_bundle
|
||||
|
|
@ -155,6 +155,7 @@ SOURCES += \
|
|||
../LibreVNA-GUI/preferences.cpp \
|
||||
../LibreVNA-GUI/savable.cpp \
|
||||
../LibreVNA-GUI/scpi.cpp \
|
||||
../LibreVNA-GUI/screenshot.cpp \
|
||||
../LibreVNA-GUI/tcpserver.cpp \
|
||||
../LibreVNA-GUI/streamingserver.cpp \
|
||||
../LibreVNA-GUI/touchstone.cpp \
|
||||
|
|
@ -359,6 +360,7 @@ HEADERS += \
|
|||
../LibreVNA-GUI/preferences.h \
|
||||
../LibreVNA-GUI/savable.h \
|
||||
../LibreVNA-GUI/scpi.h \
|
||||
../LibreVNA-GUI/screenshot.h \
|
||||
../LibreVNA-GUI/tcpserver.h \
|
||||
../LibreVNA-GUI/streamingserver.h \
|
||||
../LibreVNA-GUI/touchstone.h \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue