mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-24 09:31:40 +08:00
added JKQTPAppSettingController to libexampletools
This commit is contained in:
parent
7839983310
commit
ec40e6c7d8
@ -10,10 +10,12 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
# Set up source files
|
||||
set(SOURCES
|
||||
${CMAKE_CURRENT_LIST_DIR}/jkqtpexampleapplication.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/jkqtpappsettingcontroller.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
${CMAKE_CURRENT_LIST_DIR}/jkqtpexampleapplication.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/jkqtpappsettingcontroller.h
|
||||
)
|
||||
|
||||
|
||||
|
37
examples/libexampletools/jkqtpappsettingcontroller.cpp
Normal file
37
examples/libexampletools/jkqtpappsettingcontroller.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include "jkqtpappsettingcontroller.h"
|
||||
#include <QApplication>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
JKQTPAppSettingController::JKQTPAppSettingController(int &argc, char **argv, bool enableHighDPIIfAVailable)
|
||||
{
|
||||
bool deactivated=false;
|
||||
for (int i=0; i<argc; i++) {
|
||||
if (QString(argv[i])=="--disablehighdpi") {
|
||||
//std::cout<<"disabling High-DPI\n";
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, false); // disable DPI support
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, false); // disable HiDPI pixmaps
|
||||
#endif
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
|
||||
QApplication::setAttribute(Qt::AA_Use96Dpi, true); // disable DPI support
|
||||
#endif
|
||||
deactivated=true;
|
||||
}
|
||||
}
|
||||
if (enableHighDPIIfAVailable && !deactivated) {
|
||||
//std::cout<<"enabling High-DPI\n";
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true); // enable DPI support
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); // enable HiDPI pixmaps
|
||||
#endif
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
|
||||
QApplication::setAttribute(Qt::AA_Use96Dpi, false); // disable revert to 96DPI support
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
JKQTPAppSettingController::~JKQTPAppSettingController()
|
||||
{
|
||||
|
||||
}
|
9
examples/libexampletools/jkqtpappsettingcontroller.h
Normal file
9
examples/libexampletools/jkqtpappsettingcontroller.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
class JKQTPAppSettingController {
|
||||
public:
|
||||
JKQTPAppSettingController(int &argc, char **argv, bool enableHighDPIIfAVailable=true);
|
||||
|
||||
~JKQTPAppSettingController();
|
||||
|
||||
};
|
@ -13,10 +13,21 @@ JKQTPExampleApplication::JKQTPExampleApplication(int &argc, char **argv):
|
||||
saveSmallScreenshot(false),
|
||||
saveScreenshotPlot(false),
|
||||
saveSmallScreenshotPlot(false),
|
||||
scaleDownFromHighDPI(false),
|
||||
screenshotBasename("screenshot")
|
||||
{
|
||||
screenshotDir=QDir::current();
|
||||
|
||||
for (int i=0; i<argc; i++) {
|
||||
if (QString(argv[i])=="--disablehighdpi") {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,6,0) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, false); // DPI support
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, false); //HiDPI pixmaps
|
||||
#endif
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
|
||||
QApplication::setAttribute(Qt::AA_Use96Dpi); // disable DPI support
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JKQTPExampleApplication::~JKQTPExampleApplication()
|
||||
@ -41,15 +52,20 @@ void JKQTPExampleApplication::readCmdLine() {
|
||||
parser.addOption(screenshotPlotOption);
|
||||
QCommandLineOption smallscreenshotPlotOption(QStringList()<<"smallscreenshotplot", "save screenshot(s) of the plot(s).");
|
||||
parser.addOption(smallscreenshotPlotOption);
|
||||
QCommandLineOption scaleDownFromHighDPIOption(QStringList()<<"scalescreenshotdownfromhighdpi", "if on high-dpi device, rescale to standard size.");
|
||||
parser.addOption(scaleDownFromHighDPIOption);
|
||||
QCommandLineOption disablehighdpiOption(QStringList()<<"disablehighdpi", "idisable high-dpi support.");
|
||||
parser.addOption(disablehighdpiOption);
|
||||
|
||||
parser.process(*this);
|
||||
|
||||
screenshotDir=QDir(parser.value(outputDirectoryOption));
|
||||
screenshotBasename=parser.value(basenameOption);
|
||||
screenshotBasename=parser.value(basenameOption).split(',');
|
||||
saveScreenshot = parser.isSet(screenshotOption);
|
||||
saveSmallScreenshot = parser.isSet(smallscreenshotOption);
|
||||
saveScreenshotPlot = parser.isSet(screenshotPlotOption);
|
||||
saveSmallScreenshotPlot = parser.isSet(smallscreenshotPlotOption);
|
||||
scaleDownFromHighDPI = parser.isSet(scaleDownFromHighDPIOption);
|
||||
}
|
||||
|
||||
QRect JKQTPExampleApplication::getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor)
|
||||
@ -92,8 +108,8 @@ int JKQTPExampleApplication::exec()
|
||||
QWidget* w=widgets[i];
|
||||
if (w->isVisible()) {
|
||||
JKQTPlotter* plot=dynamic_cast<JKQTPlotter*>(w);
|
||||
QString bn=screenshotBasename;
|
||||
if (iVisible>0) {
|
||||
QString bn=screenshotBasename.value(iVisible, screenshotBasename.value(0));
|
||||
if (iVisible>0 && screenshotBasename.value(iVisible, "")=="") {
|
||||
bn+=QString("_win%1").arg(iVisible, 2, 10, QLatin1Char('0'));
|
||||
}
|
||||
if (w) {
|
||||
@ -105,7 +121,11 @@ int JKQTPExampleApplication::exec()
|
||||
pix=pix_win;
|
||||
}*/
|
||||
if (saveScreenshot) {
|
||||
pix_win.save(screenshotDir.absoluteFilePath(bn+".png"));
|
||||
if (scaleDownFromHighDPI && pix_win.devicePixelRatio()>1.0) {
|
||||
pix_win.scaled((QSizeF(pix_win.size())/pix_win.devicePixelRatio()).toSize()).save(screenshotDir.absoluteFilePath(bn+".png"));
|
||||
} else {
|
||||
pix_win.save(screenshotDir.absoluteFilePath(bn+".png"));
|
||||
}
|
||||
}
|
||||
if (saveSmallScreenshot) {
|
||||
QPixmap img=pix_win.scaledToWidth(150, Qt::SmoothTransformation);
|
||||
@ -119,7 +139,11 @@ int JKQTPExampleApplication::exec()
|
||||
if (saveScreenshotPlot) {
|
||||
QString fn=bn+"_small.png";
|
||||
if (saveScreenshot) fn=bnp+"_small.png";
|
||||
gr.save(screenshotDir.absoluteFilePath(fn));
|
||||
if (scaleDownFromHighDPI && gr.devicePixelRatio()>1.0) {
|
||||
gr.scaled((QSizeF(gr.size())/gr.devicePixelRatio()).toSize()).save(screenshotDir.absoluteFilePath(fn));
|
||||
} else {
|
||||
gr.save(screenshotDir.absoluteFilePath(fn));
|
||||
}
|
||||
}
|
||||
if (saveSmallScreenshotPlot) {
|
||||
QString fn=bn+"_small.png";
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <QApplication>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtpappsettingcontroller.h"
|
||||
#include <QDir>
|
||||
|
||||
|
||||
@ -20,7 +21,8 @@ protected:
|
||||
bool saveSmallScreenshot;
|
||||
bool saveScreenshotPlot;
|
||||
bool saveSmallScreenshotPlot;
|
||||
QString screenshotBasename;
|
||||
bool scaleDownFromHighDPI;
|
||||
QStringList screenshotBasename;
|
||||
void readCmdLine();
|
||||
QRect getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor = Qt::white);
|
||||
};
|
||||
|
@ -5,10 +5,12 @@ isEmpty(JKQTP_LIBEXAMPLETOOLS_PRI_INCLUDED) {
|
||||
INCLUDEPATH += $PWD
|
||||
|
||||
|
||||
HEADERS += $$PWD/jkqtpexampleapplication.h
|
||||
HEADERS += $$PWD/jkqtpexampleapplication.h \
|
||||
$$PWD/jkqtpappsettingcontroller.h
|
||||
|
||||
|
||||
SOURCES += $$PWD/jkqtpexampleapplication.cpp
|
||||
SOURCES += $$PWD/jkqtpexampleapplication.cpp \
|
||||
$$PWD/jkqtpappsettingcontroller.cpp
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user