From 9c27e7bfeda6a38fa58f1e04aded0d92a8c08430 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 9 Feb 2017 15:43:17 +0200 Subject: [PATCH] Fixed issue #624. Icon resulotion issues with some display setups. --HG-- branch : develop --- dist/OBS_debian/debian.tape.1 | 2 ++ dist/OBS_debian/debian.valentina.1 | 2 ++ dist/debian/tape.1 | 2 ++ dist/debian/valentina.1 | 2 ++ src/app/tape/main.cpp | 6 ++-- src/app/tape/mapplication.cpp | 5 ++++ src/app/valentina/core/vcmdexport.cpp | 16 ++++++++++- src/app/valentina/core/vcmdexport.h | 11 ++++++-- src/app/valentina/main.cpp | 6 ++-- src/app/valentina/mainwindow.cpp | 35 +++++++++++++++++++++-- src/app/valentina/mainwindowsnogui.cpp | 21 ++++++++++---- src/app/valentina/mainwindowsnogui.h | 1 + src/libs/vmisc/commandoptions.cpp | 4 ++- src/libs/vmisc/def.cpp | 39 +++++++++++++++++++++++++- src/libs/vmisc/def.h | 4 +++ 15 files changed, 136 insertions(+), 20 deletions(-) diff --git a/dist/OBS_debian/debian.tape.1 b/dist/OBS_debian/debian.tape.1 index 0c2c5f40a..a3eccfd7b 100644 --- a/dist/OBS_debian/debian.tape.1 +++ b/dist/OBS_debian/debian.tape.1 @@ -28,6 +28,8 @@ Open with the base size. Valid values: 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 4 Set pattern file unit: cm, mm, inch. .IP "--test" Use for unit testing. Run the program and open a file without showing the main window. +.IP "--no-scaling" +Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). Alternatively you can use the QT_AUTO_SCREEN_SCALE_FACTOR=0 environment variable. .IP Arguments: .I filename \- the measurement file. diff --git a/dist/OBS_debian/debian.valentina.1 b/dist/OBS_debian/debian.valentina.1 index 6e3cc9df9..0057404f3 100644 --- a/dist/OBS_debian/debian.valentina.1 +++ b/dist/OBS_debian/debian.valentina.1 @@ -131,6 +131,8 @@ The path to output destination folder. By default the directory at which the app .RE .IP "-t, --test" Run the program in a test mode. The program in this mode loads a single pattern file and silently quit without showing the main window. The key have priority before key \*(lqbasename\*(rq. +.IP "--no-scaling" +.RB "Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). Alternatively you can use the QT_AUTO_SCREEN_SCALE_FACTOR=0 environment variable." .IP Arguments: .I filename \- a pattern file. diff --git a/dist/debian/tape.1 b/dist/debian/tape.1 index 0c2c5f40a..a3eccfd7b 100644 --- a/dist/debian/tape.1 +++ b/dist/debian/tape.1 @@ -28,6 +28,8 @@ Open with the base size. Valid values: 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 4 Set pattern file unit: cm, mm, inch. .IP "--test" Use for unit testing. Run the program and open a file without showing the main window. +.IP "--no-scaling" +Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). Alternatively you can use the QT_AUTO_SCREEN_SCALE_FACTOR=0 environment variable. .IP Arguments: .I filename \- the measurement file. diff --git a/dist/debian/valentina.1 b/dist/debian/valentina.1 index 6e3cc9df9..0057404f3 100644 --- a/dist/debian/valentina.1 +++ b/dist/debian/valentina.1 @@ -131,6 +131,8 @@ The path to output destination folder. By default the directory at which the app .RE .IP "-t, --test" Run the program in a test mode. The program in this mode loads a single pattern file and silently quit without showing the main window. The key have priority before key \*(lqbasename\*(rq. +.IP "--no-scaling" +.RB "Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). Alternatively you can use the QT_AUTO_SCREEN_SCALE_FACTOR=0 environment variable." .IP Arguments: .I filename \- a pattern file. diff --git a/src/app/tape/main.cpp b/src/app/tape/main.cpp index 1cccb6535..b80bc2c91 100644 --- a/src/app/tape/main.cpp +++ b/src/app/tape/main.cpp @@ -49,9 +49,9 @@ int main(int argc, char *argv[]) qt_qhash_seed.store(0); // Lock producing random attribute order in XML -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // DPI support -#endif +#ifndef Q_OS_MAC // supports natively + InitHighDpiScaling(argc, argv); +#endif //Q_OS_MAC MApplication app(argc, argv); app.InitOptions(); diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index 6c13938ae..5c22c5fa3 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -581,6 +581,11 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS tr("Use for unit testing. Run the program and open a file without showing the main window.")); parser.addOption(testOption); //----- + QCommandLineOption scalingOption(QStringList() << LONG_OPTION_NO_HDPI_SCALING, + tr("Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). " + "Alternatively you can use the QT_AUTO_SCREEN_SCALE_FACTOR=0 environment variable.")); + parser.addOption(scalingOption); + //----- parser.process(arguments); bool flagHeight = false; diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index f938970f3..cbd9c17c0 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -249,6 +249,14 @@ void VCommandLine::InitOptions(VCommandLineOptions &options, QMap "this mode loads a single pattern file and silently quit without " "showing the main window. The key have priority before key '%1'.") .arg(LONG_OPTION_BASENAME))); + + optionsIndex.insert(LONG_OPTION_NO_HDPI_SCALING, index++); + options.append(new QCommandLineOption(QStringList() << LONG_OPTION_NO_HDPI_SCALING, + translate("VCommandLine", "Disable high dpi scaling. Call this option if has " + "problem with scaling (by default scaling " + "enabled). Alternatively you can use the " + "QT_AUTO_SCREEN_SCALE_FACTOR=0 environment " + "variable."))); } //------------------------------------------------------------------------------------------------------ @@ -500,7 +508,13 @@ bool VCommandLine::IsTestModeEnabled() const return r; } -//------------------------------------------------------------------------------------------------------ +//--------------------------------------------------------------------------------------------------------------------- +bool VCommandLine::IsNoScalingEnabled() const +{ + return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_NO_HDPI_SCALING))); +} + +//--------------------------------------------------------------------------------------------------------------------- bool VCommandLine::IsExportEnabled() const { const bool r = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BASENAME))); diff --git a/src/app/valentina/core/vcmdexport.h b/src/app/valentina/core/vcmdexport.h index 56784c1f0..91f78645e 100644 --- a/src/app/valentina/core/vcmdexport.h +++ b/src/app/valentina/core/vcmdexport.h @@ -56,10 +56,14 @@ public: //@brief creates object and applies export related options to parser - //@brief tests if user enabled test mode from cmd, throws exception if not exactly 1 input VAL file supplied in case test mode enabled + //@brief tests if user enabled test mode from cmd, throws exception if not exactly 1 input VAL file supplied in + //case test mode enabled bool IsTestModeEnabled() const; - //@brief tests if user enabled export from cmd, throws exception if not exactly 1 input VAL file supplied in case export enabled + bool IsNoScalingEnabled() const; + + //@brief tests if user enabled export from cmd, throws exception if not exactly 1 input VAL file supplied in case + //export enabled bool IsExportEnabled() const; //@brief returns path to custom measure file or empty string @@ -68,7 +72,8 @@ public: //@brief returns the base name of layout files or empty string if not set QString OptBaseName() const; - //@brief returns the absolute path to output destination directory or path to application's current directory if not set + //@brief returns the absolute path to output destination directory or path to application's current directory if + //not set QString OptDestinationPath() const; //@brief returns export type set, defaults 0 - svg diff --git a/src/app/valentina/main.cpp b/src/app/valentina/main.cpp index 530f40ac8..8943ecb73 100644 --- a/src/app/valentina/main.cpp +++ b/src/app/valentina/main.cpp @@ -56,9 +56,9 @@ int main(int argc, char *argv[]) qRegisterMetaTypeStreamOperators("VPieceNode"); -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // DPI support -#endif +#ifndef Q_OS_MAC // supports natively + InitHighDpiScaling(argc, argv); +#endif //Q_OS_MAC VApplication app(argc, argv); diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 98edc1f3a..6c36508a7 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1506,6 +1506,12 @@ void MainWindow::ShowMeasurements() << "-u" << VDomDocument::UnitsToStr(qApp->patternUnit()); } + + if (isNoScaling) + { + arguments.append(QLatin1String("--") + LONG_OPTION_NO_HDPI_SCALING); + } + const QString tape = qApp->TapeFilePath(); const QString workingDirectory = QFileInfo(tape).absoluteDir().absolutePath(); QProcess::startDetached(tape, arguments, workingDirectory); @@ -3779,7 +3785,14 @@ void MainWindow::CreateActions() { const QString tape = qApp->TapeFilePath(); const QString workingDirectory = QFileInfo(tape).absoluteDir().absolutePath(); - QProcess::startDetached(tape, QStringList(), workingDirectory); + + QStringList arguments; + if (isNoScaling) + { + arguments.append(QLatin1String("--") + LONG_OPTION_NO_HDPI_SCALING); + } + + QProcess::startDetached(tape, arguments, workingDirectory); }); connect(ui->actionShowM, &QAction::triggered, this, &MainWindow::ShowMeasurements); @@ -3906,7 +3919,14 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu { const QString tape = qApp->TapeFilePath(); const QString workingDirectory = QFileInfo(tape).absoluteDir().absolutePath(); - QProcess::startDetached(tape, QStringList(fileName), workingDirectory); + + QStringList arguments = QStringList() << fileName; + if (isNoScaling) + { + arguments.append(QLatin1String("--") + LONG_OPTION_NO_HDPI_SCALING); + } + + QProcess::startDetached(tape, arguments, workingDirectory); qApp->exit(V_EX_OK); return false; // stop continue processing } @@ -4134,7 +4154,14 @@ void MainWindow::CreateMeasurements() { const QString tape = qApp->TapeFilePath(); const QString workingDirectory = QFileInfo(tape).absoluteDir().absolutePath(); - QProcess::startDetached(tape, QStringList(), workingDirectory); + + QStringList arguments; + if (isNoScaling) + { + arguments.append(QLatin1String("--") + LONG_OPTION_NO_HDPI_SCALING); + } + + QProcess::startDetached(tape, arguments, workingDirectory); } //--------------------------------------------------------------------------------------------------------------------- @@ -4547,6 +4574,8 @@ void MainWindow::ProcessCMD() const VCommandLinePtr cmd = qApp->CommandLine(); auto args = cmd->OptInputFileNames(); + isNoScaling = cmd->IsNoScalingEnabled(); + if (VApplication::IsGUIMode()) { ReopenFilesAfterCrash(args); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index fed83e0f9..ce764ac6f 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -61,11 +61,22 @@ //--------------------------------------------------------------------------------------------------------------------- MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) - : VAbstractMainWindow(parent), listDetails(QVector()), currentScene(nullptr), tempSceneLayout(nullptr), - pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP())), doc(nullptr), papers(QList()), - shadows(QList()), scenes(QList()), details(QList >()), - undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), actionDockWidgetGroups(nullptr), - curFile(QString()), + : VAbstractMainWindow(parent), + listDetails(), + currentScene(nullptr), + tempSceneLayout(nullptr), + pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP())), + doc(nullptr), + papers(), + shadows(), + scenes(), + details(), + undoAction(nullptr), + redoAction(nullptr), + actionDockWidgetToolOptions(nullptr), + actionDockWidgetGroups(nullptr), + curFile(), + isNoScaling(false), isLayoutStale(true), ignorePrinterFields(false), margins(), diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 17f715dfb..74c78b8f1 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -84,6 +84,7 @@ protected: /** @brief fileName name current pattern file. */ QString curFile; + bool isNoScaling; bool isLayoutStale; bool ignorePrinterFields; QMarginsF margins; diff --git a/src/libs/vmisc/commandoptions.cpp b/src/libs/vmisc/commandoptions.cpp index 945c944c9..3b5c1c674 100644 --- a/src/libs/vmisc/commandoptions.cpp +++ b/src/libs/vmisc/commandoptions.cpp @@ -27,6 +27,7 @@ *************************************************************************/ #include "commandoptions.h" +#include "def.h" #include #include @@ -132,7 +133,8 @@ QStringList AllKeys() << LONG_OPTION_LEFT_MARGIN << SINGLE_OPTION_LEFT_MARGIN << LONG_OPTION_RIGHT_MARGIN << SINGLE_OPTION_RIGHT_MARGIN << LONG_OPTION_TOP_MARGIN << SINGLE_OPTION_TOP_MARGIN - << LONG_OPTION_BOTTOM_MARGIN << SINGLE_OPTION_BOTTOM_MARGIN; + << LONG_OPTION_BOTTOM_MARGIN << SINGLE_OPTION_BOTTOM_MARGIN + << LONG_OPTION_NO_HDPI_SCALING; return list; } diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 8eba5da5e..2b41af8b6 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -1919,7 +1919,6 @@ QPixmap darkenPixmap(const QPixmap &pixmap) return QPixmap::fromImage(img); } - //--------------------------------------------------------------------------------------------------------------------- void ShowInGraphicalShell(const QString &filePath) { @@ -1968,3 +1967,41 @@ void ShowInGraphicalShell(const QString &filePath) #endif } + +const QString LONG_OPTION_NO_HDPI_SCALING = QStringLiteral("no-scaling"); + +//--------------------------------------------------------------------------------------------------------------------- +bool IsOptionSet(int argc, char *argv[], const char *option) +{ + for (int i = 1; i < argc; ++i) + { + if (!qstrcmp(argv[i], option)) + { + return true; + } + } + return false; +} + +//--------------------------------------------------------------------------------------------------------------------- +// See issue #624. https://bitbucket.org/dismine/valentina/issues/624 +void InitHighDpiScaling(int argc, char *argv[]) +{ + /* For more info see: http://doc.qt.io/qt-5/highdpi.html */ + if (IsOptionSet(argc, argv, qPrintable(QLatin1String("--") + LONG_OPTION_NO_HDPI_SCALING))) + { +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) + QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); +#else + qputenv("QT_DEVICE_PIXEL_RATIO", QByteArray("1")); +#endif + } + else + { +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // DPI support +#else + qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", QByteArray("1")); +#endif + } +} diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 15a5ef7aa..1e40736ca 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -255,6 +255,10 @@ enum class GSizes : unsigned char { ALL, #define V_FALLTHROUGH #endif +extern const QString LONG_OPTION_NO_HDPI_SCALING; +bool IsOptionSet(int argc, char *argv[], const char *option); +void InitHighDpiScaling(int argc, char *argv[]); + // measurements // A extern const QString height_M; // A01