mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 06:45:37 +08:00
refactor: Remove manual high-dpi support
This removes the --scale command line option. Qt6 seems to have this already integrated to scale according to the nativ display settings: https://doc.qt.io/qt-6.8/highdpi.html Adjusting the scale on a per-application basis is not intended (anymore) according to the documentation. Tested on a (near) high-dpi screen.
This commit is contained in:
@@ -28,7 +28,6 @@ using namespace swift::core::afv::model;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QGuiApplication qa(argc, argv);
|
||||
|
||||
swift::core::registerMetadata();
|
||||
|
||||
@@ -16,7 +16,6 @@ using namespace swift::gui;
|
||||
//! main
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
CGuiApplication::highDpiScreenSupport();
|
||||
QApplication qa(argc, argv);
|
||||
CGuiApplication a("samplehotkey", swift::misc::CApplicationInfo::Sample, QPixmap());
|
||||
swift::gui::components::CSettingsHotkeyComponent w;
|
||||
|
||||
@@ -378,9 +378,6 @@ add_library(gui SHARED
|
||||
components/remoteaircraftselector.cpp
|
||||
components/remoteaircraftselector.h
|
||||
components/remoteaircraftselector.ui
|
||||
components/scalescreenfactor.cpp
|
||||
components/scalescreenfactor.h
|
||||
components/scalescreenfactor.ui
|
||||
components/selcalcodeselector.cpp
|
||||
components/selcalcodeselector.h
|
||||
components/selcalcodeselector.ui
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||
|
||||
#include "scalescreenfactor.h"
|
||||
|
||||
#include <QIntValidator>
|
||||
#include <QScreen>
|
||||
|
||||
#include "ui_scalescreenfactor.h"
|
||||
|
||||
#include "gui/guiutility.h"
|
||||
|
||||
namespace swift::gui::components
|
||||
{
|
||||
CScaleScreenFactor::CScaleScreenFactor(QWidget *parent) : QFrame(parent), ui(new Ui::CScaleScreenFactor)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setMinMax(50, 150);
|
||||
|
||||
connect(ui->hs_Factor, &QSlider::valueChanged, this, &CScaleScreenFactor::onSliderChanged);
|
||||
connect(ui->le_Factor, &QLineEdit::editingFinished, this, &CScaleScreenFactor::onEditFinished);
|
||||
|
||||
const QString tt = QStringLiteral("Scaling only works on High DPI screens");
|
||||
this->setToolTip(tt);
|
||||
}
|
||||
|
||||
CScaleScreenFactor::~CScaleScreenFactor() {}
|
||||
|
||||
void CScaleScreenFactor::setMinMax(int min, int max)
|
||||
{
|
||||
ui->hs_Factor->setMinimum(min);
|
||||
ui->hs_Factor->setMaximum(max);
|
||||
ui->le_Factor->setValidator(new QIntValidator(min, max, ui->le_Factor));
|
||||
|
||||
const QString tt = QStringLiteral("%1-%2").arg(min).arg(max);
|
||||
ui->le_Factor->setToolTip(tt);
|
||||
ui->le_Factor->setPlaceholderText(tt);
|
||||
ui->hs_Factor->setToolTip(tt);
|
||||
|
||||
const int v = (min + max) / 2;
|
||||
ui->hs_Factor->setValue(v);
|
||||
ui->le_Factor->setText(QString::number(v));
|
||||
}
|
||||
|
||||
qreal CScaleScreenFactor::getScaleFactor() const { return 0.01 * ui->hs_Factor->value(); }
|
||||
|
||||
QString CScaleScreenFactor::getScaleFactorAsString() const
|
||||
{
|
||||
const QString sf = QString::number(this->getScaleFactor(), 'f', 2);
|
||||
return sf;
|
||||
}
|
||||
|
||||
void CScaleScreenFactor::onSliderChanged(int value)
|
||||
{
|
||||
const QString v = QString::number(value);
|
||||
if (ui->le_Factor->text() == v) { return; } // avoid signal roundtrips
|
||||
ui->le_Factor->setText(v);
|
||||
}
|
||||
|
||||
void CScaleScreenFactor::onEditFinished()
|
||||
{
|
||||
const QString v = ui->le_Factor->text();
|
||||
if (v.isEmpty()) { return; }
|
||||
bool ok;
|
||||
const int value = v.toInt(&ok);
|
||||
if (!ok) { return; }
|
||||
if (ui->hs_Factor->value() == value) { return; } // avoid signal roundtrips
|
||||
ui->hs_Factor->setValue(value);
|
||||
}
|
||||
} // namespace swift::gui::components
|
||||
@@ -1,54 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef SWIFT_GUI_COMPONENTS_SCALESCREENFACTOR_H
|
||||
#define SWIFT_GUI_COMPONENTS_SCALESCREENFACTOR_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QScopedPointer>
|
||||
|
||||
#include "gui/swiftguiexport.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class CScaleScreenFactor;
|
||||
}
|
||||
namespace swift::gui::components
|
||||
{
|
||||
/*!
|
||||
* UI to scale screen factor
|
||||
*/
|
||||
class SWIFT_GUI_EXPORT CScaleScreenFactor : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CScaleScreenFactor(QWidget *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CScaleScreenFactor() override;
|
||||
|
||||
//! Minimum/maximum values
|
||||
void setMinMax(int min, int max);
|
||||
|
||||
//! Scale factor
|
||||
qreal getScaleFactor() const;
|
||||
|
||||
//! Scale factor as string
|
||||
QString getScaleFactorAsString() const;
|
||||
|
||||
private:
|
||||
//! Slider value changed
|
||||
void onSliderChanged(int value);
|
||||
|
||||
//! Line edit change
|
||||
void onEditFinished();
|
||||
|
||||
QScopedPointer<Ui::CScaleScreenFactor> ui;
|
||||
};
|
||||
} // namespace swift::gui::components
|
||||
|
||||
#endif // SWIFT_GUI_COMPONENTS_SCALESCREENFACTOR_H
|
||||
@@ -1,69 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CScaleScreenFactor</class>
|
||||
<widget class="QFrame" name="CScaleScreenFactor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>165</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Scale screen factor</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Scaling works only on High DPI screens</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="hl_ScaleScreenFactor" stretch="0,1,5">
|
||||
<property name="leftMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="lbl_Scale">
|
||||
<property name="text">
|
||||
<string>Scale:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="le_Factor">
|
||||
<property name="maxLength">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="hs_Factor">
|
||||
<property name="minimum">
|
||||
<number>50</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>150</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -105,7 +105,6 @@ namespace swift::gui
|
||||
{
|
||||
this->addWindowModeOption();
|
||||
this->addWindowResetSizeOption();
|
||||
this->addWindowScaleSizeOption();
|
||||
|
||||
// notify when app goes down
|
||||
connect(qGuiApp, &QGuiApplication::lastWindowClosed, this, &CGuiApplication::gracefulShutdown);
|
||||
@@ -150,15 +149,6 @@ namespace swift::gui
|
||||
this->addParserOption(m_cmdWindowSizeReset);
|
||||
}
|
||||
|
||||
void CGuiApplication::addWindowScaleSizeOption()
|
||||
{
|
||||
// just added here to display it in help
|
||||
// parseScaleFactor() is used since it is needed upfront (before application is created)
|
||||
m_cmdWindowScaleSize =
|
||||
QCommandLineOption("scale", QCoreApplication::translate("main", "Scale: number."), "scalevalue");
|
||||
this->addParserOption(m_cmdWindowScaleSize);
|
||||
}
|
||||
|
||||
void CGuiApplication::addWindowStateOption()
|
||||
{
|
||||
m_cmdWindowStateMinimized = QCommandLineOption(
|
||||
@@ -287,28 +277,6 @@ namespace swift::gui
|
||||
|
||||
void CGuiApplication::exit(int retcode) { CApplication::exit(retcode); }
|
||||
|
||||
void CGuiApplication::highDpiScreenSupport(const QString &scaleFactor)
|
||||
{
|
||||
// https://lists.qt-project.org/pipermail/development/2019-September/037434.html
|
||||
// QSize s = CGuiUtility::physicalScreenSizeOs();
|
||||
QString sf = scaleFactor.trimmed().isEmpty() ? defaultScaleFactorString() : scaleFactor;
|
||||
if (sf.contains('/'))
|
||||
{
|
||||
const double sfd = parseFraction(scaleFactor, -1);
|
||||
sf = sfd < 0 ? "1.0" : QString::number(sfd, 'f', 8);
|
||||
}
|
||||
|
||||
sf = cleanNumber(sf);
|
||||
|
||||
// qputenv("QT_ENABLE_HIGHDPI_SCALING", "1");
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor);
|
||||
|
||||
const QByteArray sfa = sf.toLatin1();
|
||||
qputenv("QT_SCALE_FACTOR", sfa);
|
||||
}
|
||||
|
||||
bool CGuiApplication::isUsingHighDpiScreenSupport() { return CGuiUtility::isUsingHighDpiScreenSupport(); }
|
||||
|
||||
QScreen *CGuiApplication::currentScreen()
|
||||
{
|
||||
const QWidget *w = CGuiApplication::mainApplicationWidget();
|
||||
@@ -455,53 +423,6 @@ namespace swift::gui
|
||||
}
|
||||
}
|
||||
|
||||
double CGuiApplication::parseScaleFactor(int argc, char *argv[])
|
||||
{
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
if (qstrcmp(argv[i], "--scale") == 0 || qstrcmp(argv[i], "-scale") == 0)
|
||||
{
|
||||
if (i + 1 >= argc) { return -1.0; } // no value
|
||||
const QString factor(argv[i + 1]);
|
||||
bool ok;
|
||||
const double f = factor.toDouble(&ok);
|
||||
return ok ? f : -1.0;
|
||||
}
|
||||
}
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
QString CGuiApplication::scaleFactor(int argc, char *argv[])
|
||||
{
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
if (qstrcmp(argv[i], "--scale") == 0 || qstrcmp(argv[i], "-scale") == 0)
|
||||
{
|
||||
if (i + 1 >= argc) { return QString(); } // no value
|
||||
const QString factor(argv[i + 1]);
|
||||
return factor.trimmed();
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString CGuiApplication::defaultScaleFactorString()
|
||||
{
|
||||
if (!CBuildConfig::isRunningOnWindowsNtPlatform()) { return "1.0"; }
|
||||
|
||||
// On windows
|
||||
// Qt 5.14.1 default is device ratio 3
|
||||
// Qt 5.14.0 default device ratio was 2
|
||||
|
||||
// 2/3 (0.66667) => device ratio 3
|
||||
// 0.75 => device ratio 2.25
|
||||
// 0.8 => device ratio 2.4
|
||||
// 1.00 => device ratio 3
|
||||
|
||||
// currently NOT used
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
void CGuiApplication::cmdLineErrorMessage(const QString &text, const QString &informativeText) const
|
||||
{
|
||||
QMessageBox errorBox(QMessageBox::Critical, QGuiApplication::applicationDisplayName(), "<b>" + text + "</b>");
|
||||
|
||||
@@ -90,9 +90,6 @@ namespace swift::gui
|
||||
//! CMD line arguments (reset size store)
|
||||
void addWindowResetSizeOption();
|
||||
|
||||
//! CMD line arguments (scale size on DPI screens)
|
||||
void addWindowScaleSizeOption();
|
||||
|
||||
//! Window state
|
||||
Qt::WindowState getWindowState() const;
|
||||
|
||||
@@ -255,13 +252,6 @@ namespace swift::gui
|
||||
//! Exit application, perform graceful shutdown and exit
|
||||
static void exit(int retcode = 0);
|
||||
|
||||
//! Support for high DPI screens
|
||||
//! \note Needs to be at the beginning of main
|
||||
static void highDpiScreenSupport(const QString &scaleFactor = {});
|
||||
|
||||
//! Uses the high DPI support?
|
||||
static bool isUsingHighDpiScreenSupport();
|
||||
|
||||
//! Current screen
|
||||
static QScreen *currentScreen();
|
||||
|
||||
@@ -272,16 +262,6 @@ namespace swift::gui
|
||||
//! Bring any modal dialog to front
|
||||
static void modalWindowToFront();
|
||||
|
||||
//! Parse scale factor if any
|
||||
//! \deprecated using scaleFactor now
|
||||
static double parseScaleFactor(int argc, char *argv[]);
|
||||
|
||||
//! Get the scale factor
|
||||
static QString scaleFactor(int argc, char *argv[]);
|
||||
|
||||
//! Get a default scale factor
|
||||
static QString defaultScaleFactorString();
|
||||
|
||||
signals:
|
||||
//! Style sheet changed
|
||||
void styleSheetsChanged();
|
||||
@@ -323,7 +303,6 @@ namespace swift::gui
|
||||
QCommandLineOption m_cmdWindowStateMinimized { "emptyMinimized" }; //!< window state (minimized)
|
||||
QCommandLineOption m_cmdWindowMode { "emptyWindowMode" }; //!< window mode (flags: frameless ...)
|
||||
QCommandLineOption m_cmdWindowSizeReset { "emptySizeReset" }; //!< window size reset
|
||||
QCommandLineOption m_cmdWindowScaleSize { "emptyScale" }; //!< window scale size
|
||||
CStyleSheetUtility m_styleSheetUtility { this }; //!< style sheet utility
|
||||
bool m_uiSetupCompleted = false; //!< ui setup completed
|
||||
bool m_saveMainWidgetState = true; //!< save/restore main widget's state
|
||||
|
||||
@@ -797,7 +797,7 @@ namespace swift::gui
|
||||
|
||||
QString CGuiUtility::metricsInfo()
|
||||
{
|
||||
static const QString s("%1 %2 %3 | 80 chars: w%4 h%5 | 43 chars: w%6 h%7");
|
||||
static const QString s("%1 %2 | 80 chars: w%3 h%4 | 43 chars: w%5 h%6");
|
||||
const QSizeF s80 = CGuiUtility::fontMetrics80Chars();
|
||||
const QSizeF s43 = CGuiUtility::fontMetricsLazyDog43Chars();
|
||||
|
||||
@@ -811,21 +811,7 @@ namespace swift::gui
|
||||
desktop = QStringLiteral("Desktop w%1 w%2").arg(sd.width()).arg(sd.height());
|
||||
ratio = QStringLiteral("ratio: %1").arg(mainWidget->devicePixelRatioF());
|
||||
}
|
||||
return s.arg(desktop)
|
||||
.arg(CGuiUtility::isUsingHighDpiScreenSupport() ? "hi DPI" : "-")
|
||||
.arg(ratio)
|
||||
.arg(s80.width())
|
||||
.arg(s80.height())
|
||||
.arg(s43.width())
|
||||
.arg(s43.height());
|
||||
}
|
||||
|
||||
bool CGuiUtility::isUsingHighDpiScreenSupport()
|
||||
{
|
||||
const QByteArray v = qgetenv("QT_AUTO_SCREEN_SCALE_FACTOR");
|
||||
const QString vs(v);
|
||||
const bool highDpi = stringToBool(vs);
|
||||
return highDpi;
|
||||
return s.arg(desktop).arg(ratio).arg(s80.width()).arg(s80.height()).arg(s43.width()).arg(s43.height());
|
||||
}
|
||||
|
||||
void CGuiUtility::forceStyleSheetUpdate(QWidget *widget)
|
||||
|
||||
@@ -254,9 +254,6 @@ namespace swift::gui
|
||||
//! Some info about font metrics
|
||||
static QString metricsInfo();
|
||||
|
||||
//! Using high DPI screen support
|
||||
static bool isUsingHighDpiScreenSupport();
|
||||
|
||||
//! Forces a stylesheet update
|
||||
static void forceStyleSheetUpdate(QWidget *widget);
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ using namespace swift::gui;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
CGuiApplication::highDpiScreenSupport(CGuiApplication::scaleFactor(argc, argv));
|
||||
QApplication qa(argc, argv);
|
||||
Q_UNUSED(qa) // init of qa is required, but qa not used
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ using namespace swift::gui;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
CGuiApplication::highDpiScreenSupport(CGuiApplication::scaleFactor(argc, argv));
|
||||
QApplication qa(argc, argv);
|
||||
Q_UNUSED(qa)
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ using namespace swift::core;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
CGuiApplication::highDpiScreenSupport(CGuiApplication::scaleFactor(argc, argv));
|
||||
QApplication qa(argc, argv);
|
||||
Q_UNUSED(qa) // application init needed
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ void initDbCacheFromResourceFileIfRequired(CGuiApplication &a)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
CGuiApplication::highDpiScreenSupport(CGuiApplication::scaleFactor(argc, argv));
|
||||
QApplication qa(argc, argv); // needed
|
||||
Q_UNUSED(qa)
|
||||
CGuiApplication a(CApplicationInfo::swiftLauncher(), CApplicationInfo::Launcher, CIcons::swiftLauncher1024());
|
||||
|
||||
@@ -425,8 +425,6 @@ QString CSwiftLauncher::toCmdLine(const QString &exe, const QStringList &exeArgs
|
||||
void CSwiftLauncher::startButtonPressed()
|
||||
{
|
||||
const QObject *sender = QObject::sender();
|
||||
const qreal scaleFactor = ui->comp_Scale->getScaleFactor();
|
||||
CGuiApplication::highDpiScreenSupport(QString::number(scaleFactor, 'f', 4));
|
||||
|
||||
const Qt::KeyboardModifiers km = QGuiApplication::queryKeyboardModifiers();
|
||||
const bool shift = km.testFlag(Qt::ShiftModifier);
|
||||
|
||||
@@ -735,16 +735,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="swift::gui::components::CScaleScreenFactor" name="comp_Scale">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3" colspan="2">
|
||||
<widget class="QCheckBox" name="cb_ResetWindow">
|
||||
<property name="text">
|
||||
@@ -846,12 +836,6 @@
|
||||
<header>gui/components/abouthtmlcomponent.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>swift::gui::components::CScaleScreenFactor</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>gui/components/scalescreenfactor.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>rb_SwiftStandalone</tabstop>
|
||||
|
||||
Reference in New Issue
Block a user