mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 10:01:38 +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 up source files
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
${CMAKE_CURRENT_LIST_DIR}/jkqtpexampleapplication.cpp
|
${CMAKE_CURRENT_LIST_DIR}/jkqtpexampleapplication.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/jkqtpappsettingcontroller.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
${CMAKE_CURRENT_LIST_DIR}/jkqtpexampleapplication.h
|
${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),
|
saveSmallScreenshot(false),
|
||||||
saveScreenshotPlot(false),
|
saveScreenshotPlot(false),
|
||||||
saveSmallScreenshotPlot(false),
|
saveSmallScreenshotPlot(false),
|
||||||
|
scaleDownFromHighDPI(false),
|
||||||
screenshotBasename("screenshot")
|
screenshotBasename("screenshot")
|
||||||
{
|
{
|
||||||
screenshotDir=QDir::current();
|
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()
|
JKQTPExampleApplication::~JKQTPExampleApplication()
|
||||||
@ -41,15 +52,20 @@ void JKQTPExampleApplication::readCmdLine() {
|
|||||||
parser.addOption(screenshotPlotOption);
|
parser.addOption(screenshotPlotOption);
|
||||||
QCommandLineOption smallscreenshotPlotOption(QStringList()<<"smallscreenshotplot", "save screenshot(s) of the plot(s).");
|
QCommandLineOption smallscreenshotPlotOption(QStringList()<<"smallscreenshotplot", "save screenshot(s) of the plot(s).");
|
||||||
parser.addOption(smallscreenshotPlotOption);
|
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);
|
parser.process(*this);
|
||||||
|
|
||||||
screenshotDir=QDir(parser.value(outputDirectoryOption));
|
screenshotDir=QDir(parser.value(outputDirectoryOption));
|
||||||
screenshotBasename=parser.value(basenameOption);
|
screenshotBasename=parser.value(basenameOption).split(',');
|
||||||
saveScreenshot = parser.isSet(screenshotOption);
|
saveScreenshot = parser.isSet(screenshotOption);
|
||||||
saveSmallScreenshot = parser.isSet(smallscreenshotOption);
|
saveSmallScreenshot = parser.isSet(smallscreenshotOption);
|
||||||
saveScreenshotPlot = parser.isSet(screenshotPlotOption);
|
saveScreenshotPlot = parser.isSet(screenshotPlotOption);
|
||||||
saveSmallScreenshotPlot = parser.isSet(smallscreenshotPlotOption);
|
saveSmallScreenshotPlot = parser.isSet(smallscreenshotPlotOption);
|
||||||
|
scaleDownFromHighDPI = parser.isSet(scaleDownFromHighDPIOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect JKQTPExampleApplication::getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor)
|
QRect JKQTPExampleApplication::getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor)
|
||||||
@ -92,8 +108,8 @@ int JKQTPExampleApplication::exec()
|
|||||||
QWidget* w=widgets[i];
|
QWidget* w=widgets[i];
|
||||||
if (w->isVisible()) {
|
if (w->isVisible()) {
|
||||||
JKQTPlotter* plot=dynamic_cast<JKQTPlotter*>(w);
|
JKQTPlotter* plot=dynamic_cast<JKQTPlotter*>(w);
|
||||||
QString bn=screenshotBasename;
|
QString bn=screenshotBasename.value(iVisible, screenshotBasename.value(0));
|
||||||
if (iVisible>0) {
|
if (iVisible>0 && screenshotBasename.value(iVisible, "")=="") {
|
||||||
bn+=QString("_win%1").arg(iVisible, 2, 10, QLatin1Char('0'));
|
bn+=QString("_win%1").arg(iVisible, 2, 10, QLatin1Char('0'));
|
||||||
}
|
}
|
||||||
if (w) {
|
if (w) {
|
||||||
@ -105,8 +121,12 @@ int JKQTPExampleApplication::exec()
|
|||||||
pix=pix_win;
|
pix=pix_win;
|
||||||
}*/
|
}*/
|
||||||
if (saveScreenshot) {
|
if (saveScreenshot) {
|
||||||
|
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"));
|
pix_win.save(screenshotDir.absoluteFilePath(bn+".png"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (saveSmallScreenshot) {
|
if (saveSmallScreenshot) {
|
||||||
QPixmap img=pix_win.scaledToWidth(150, Qt::SmoothTransformation);
|
QPixmap img=pix_win.scaledToWidth(150, Qt::SmoothTransformation);
|
||||||
img.save(screenshotDir.absoluteFilePath(bn+"_small.png"));
|
img.save(screenshotDir.absoluteFilePath(bn+"_small.png"));
|
||||||
@ -119,8 +139,12 @@ int JKQTPExampleApplication::exec()
|
|||||||
if (saveScreenshotPlot) {
|
if (saveScreenshotPlot) {
|
||||||
QString fn=bn+"_small.png";
|
QString fn=bn+"_small.png";
|
||||||
if (saveScreenshot) fn=bnp+"_small.png";
|
if (saveScreenshot) fn=bnp+"_small.png";
|
||||||
|
if (scaleDownFromHighDPI && gr.devicePixelRatio()>1.0) {
|
||||||
|
gr.scaled((QSizeF(gr.size())/gr.devicePixelRatio()).toSize()).save(screenshotDir.absoluteFilePath(fn));
|
||||||
|
} else {
|
||||||
gr.save(screenshotDir.absoluteFilePath(fn));
|
gr.save(screenshotDir.absoluteFilePath(fn));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (saveSmallScreenshotPlot) {
|
if (saveSmallScreenshotPlot) {
|
||||||
QString fn=bn+"_small.png";
|
QString fn=bn+"_small.png";
|
||||||
if (saveSmallScreenshot) fn=bnp+"_small.png";
|
if (saveSmallScreenshot) fn=bnp+"_small.png";
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include "jkqtplotter/jkqtplotter.h"
|
#include "jkqtplotter/jkqtplotter.h"
|
||||||
|
#include "jkqtpappsettingcontroller.h"
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
|
|
||||||
@ -20,7 +21,8 @@ protected:
|
|||||||
bool saveSmallScreenshot;
|
bool saveSmallScreenshot;
|
||||||
bool saveScreenshotPlot;
|
bool saveScreenshotPlot;
|
||||||
bool saveSmallScreenshotPlot;
|
bool saveSmallScreenshotPlot;
|
||||||
QString screenshotBasename;
|
bool scaleDownFromHighDPI;
|
||||||
|
QStringList screenshotBasename;
|
||||||
void readCmdLine();
|
void readCmdLine();
|
||||||
QRect getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor = Qt::white);
|
QRect getBoundsWithoutColor(QImage qImage, const QColor &exclusionColor = Qt::white);
|
||||||
};
|
};
|
||||||
|
@ -5,10 +5,12 @@ isEmpty(JKQTP_LIBEXAMPLETOOLS_PRI_INCLUDED) {
|
|||||||
INCLUDEPATH += $PWD
|
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