Skip to content

Remove high dpi scaling option with Qt6 #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ jobs:
swiftinstaller-linux-64-${{ needs.preBuild.outputs.version }}.run
swiftinstaller-windows-64-${{ needs.preBuild.outputs.version }}.exe
swiftinstaller-macos-64-${{ needs.preBuild.outputs.version }}.dmg
xswiftbus-fat-allos-${{ needs.preBuild.outputs.version }}.7z
xswiftbus-fat-allos-${{ needs.preBuild.outputs.version }}.zip
swiftsymbols-allos-${{ needs.preBuild.outputs.version }}:swiftsymbols
- name: Publish doxygen
uses: actions/deploy-pages@v4
Expand Down
1 change: 0 additions & 1 deletion samples/hotkey/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 0 additions & 70 deletions src/gui/components/scalescreenfactor.cpp

This file was deleted.

54 changes: 0 additions & 54 deletions src/gui/components/scalescreenfactor.h

This file was deleted.

69 changes: 0 additions & 69 deletions src/gui/components/scalescreenfactor.ui

This file was deleted.

79 changes: 0 additions & 79 deletions src/gui/guiapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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>");
Expand Down
21 changes: 0 additions & 21 deletions src/gui/guiapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down
Loading