diff --git a/app/main.cpp b/app/main.cpp index 7847c4a..e1b38d0 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -5,6 +5,7 @@ #include "mainwindow.h" #include "playlistmanager.h" +#include "settings.h" #include #include @@ -19,6 +20,8 @@ int main(int argc, char *argv[]) { + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Settings::instance()->hiDpiScaleFactorBehavior()); + QApplication a(argc, argv); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) a.setAttribute(Qt::ApplicationAttribute::AA_UseHighDpiPixmaps); diff --git a/app/settings.cpp b/app/settings.cpp index 6efa3dd..c296c6b 100644 --- a/app/settings.cpp +++ b/app/settings.cpp @@ -68,6 +68,13 @@ Settings::WindowSizeBehavior Settings::initWindowSizeBehavior() const return QEnumHelper::fromString(result, WindowSizeBehavior::Auto); } +Qt::HighDpiScaleFactorRoundingPolicy Settings::hiDpiScaleFactorBehavior() const +{ + QString result = m_qsettings->value("hidpi_scale_factor_behavior", "PassThrough").toString(); + + return QEnumHelper::fromString(result, Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); +} + void Settings::setStayOnTop(bool on) { m_qsettings->setValue("stay_on_top", on); @@ -92,6 +99,12 @@ void Settings::setInitWindowSizeBehavior(WindowSizeBehavior wsb) m_qsettings->sync(); } +void Settings::setHiDpiScaleFactorBehavior(Qt::HighDpiScaleFactorRoundingPolicy hidpi) +{ + m_qsettings->setValue("hidpi_scale_factor_behavior", QEnumHelper::toString(hidpi)); + m_qsettings->sync(); +} + Settings::Settings() : QObject(qApp) { diff --git a/app/settings.h b/app/settings.h index 57f2c1d..9800fe1 100644 --- a/app/settings.h +++ b/app/settings.h @@ -16,19 +16,19 @@ public: Close, Maximize, }; - Q_ENUM(DoubleClickBehavior); + Q_ENUM(DoubleClickBehavior) enum MouseWheelBehavior { Zoom, Switch, }; - Q_ENUM(MouseWheelBehavior); + Q_ENUM(MouseWheelBehavior) enum WindowSizeBehavior { Auto, Maximized, }; - Q_ENUM(WindowSizeBehavior); + Q_ENUM(WindowSizeBehavior) static Settings *instance(); @@ -36,11 +36,13 @@ public: DoubleClickBehavior doubleClickBehavior() const; MouseWheelBehavior mouseWheelBehavior() const; WindowSizeBehavior initWindowSizeBehavior() const; + Qt::HighDpiScaleFactorRoundingPolicy hiDpiScaleFactorBehavior() const; void setStayOnTop(bool on); void setDoubleClickBehavior(DoubleClickBehavior dcb); void setMouseWheelBehavior(MouseWheelBehavior mwb); void setInitWindowSizeBehavior(WindowSizeBehavior wsb); + void setHiDpiScaleFactorBehavior(Qt::HighDpiScaleFactorRoundingPolicy hidpi); private: Settings(); diff --git a/app/settingsdialog.cpp b/app/settingsdialog.cpp index 4740735..e1d1e75 100644 --- a/app/settingsdialog.cpp +++ b/app/settingsdialog.cpp @@ -17,6 +17,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) , m_doubleClickBehavior(new QComboBox) , m_mouseWheelBehavior(new QComboBox) , m_initWindowSizeBehavior(new QComboBox) + , m_hiDpiRoundingPolicyBehavior(new QComboBox) { this->setWindowTitle(tr("Settings")); @@ -38,6 +39,13 @@ SettingsDialog::SettingsDialog(QWidget *parent) { Settings::WindowSizeBehavior::Maximized, tr("Maximized") } }; + static QList< QPair > _hidpi_options { + { Qt::HighDpiScaleFactorRoundingPolicy::Round, tr("Round (Integer scaling)", "This option means round up for .5 and above") }, + { Qt::HighDpiScaleFactorRoundingPolicy::Ceil, tr("Ceil (Integer scaling)", "This option means always round up") }, + { Qt::HighDpiScaleFactorRoundingPolicy::Floor, tr("Floor (Integer scaling)", "This option means always round down") }, + { Qt::HighDpiScaleFactorRoundingPolicy::PassThrough, tr("Follow system (Fractional scaling)", "This option means don't round") } + }; + QStringList dcbDropDown; for (const QPair & dcOption : _dc_options) { dcbDropDown.append(dcOption.second); @@ -53,10 +61,16 @@ SettingsDialog::SettingsDialog(QWidget *parent) iwsbDropDown.append(iwsOption.second); } + QStringList hidpiDropDown; + for (const QPair & hidpiOption : _hidpi_options) { + hidpiDropDown.append(hidpiOption.second); + } + settingsForm->addRow(tr("Stay on top when start-up"), m_stayOnTop); settingsForm->addRow(tr("Double-click behavior"), m_doubleClickBehavior); settingsForm->addRow(tr("Mouse wheel behavior"), m_mouseWheelBehavior); settingsForm->addRow(tr("Default window size"), m_initWindowSizeBehavior); + settingsForm->addRow(tr("HiDPI scale factor rounding policy"), m_hiDpiRoundingPolicyBehavior); m_stayOnTop->setChecked(Settings::instance()->stayOnTop()); m_doubleClickBehavior->setModel(new QStringListModel(dcbDropDown)); @@ -68,6 +82,14 @@ SettingsDialog::SettingsDialog(QWidget *parent) m_initWindowSizeBehavior->setModel(new QStringListModel(iwsbDropDown)); Settings::WindowSizeBehavior iwsb = Settings::instance()->initWindowSizeBehavior(); m_initWindowSizeBehavior->setCurrentIndex(static_cast(iwsb)); + m_hiDpiRoundingPolicyBehavior->setModel(new QStringListModel(hidpiDropDown)); + Qt::HighDpiScaleFactorRoundingPolicy hidpi = Settings::instance()->hiDpiScaleFactorBehavior(); + for (int i = 0; i < _hidpi_options.count(); i++) { + if (_hidpi_options.at(i).first == hidpi) { + m_hiDpiRoundingPolicyBehavior->setCurrentIndex(i); + break; + } + } connect(m_stayOnTop, &QCheckBox::stateChanged, this, [ = ](int state){ Settings::instance()->setStayOnTop(state == Qt::Checked); @@ -85,6 +107,10 @@ SettingsDialog::SettingsDialog(QWidget *parent) Settings::instance()->setInitWindowSizeBehavior(_iws_options.at(index).first); }); + connect(m_hiDpiRoundingPolicyBehavior, QOverload::of(&QComboBox::currentIndexChanged), this, [ = ](int index){ + Settings::instance()->setHiDpiScaleFactorBehavior(_hidpi_options.at(index).first); + }); + adjustSize(); setWindowFlag(Qt::WindowContextHelpButtonHint, false); } diff --git a/app/settingsdialog.h b/app/settingsdialog.h index 2be75ee..166cbe8 100644 --- a/app/settingsdialog.h +++ b/app/settingsdialog.h @@ -26,6 +26,7 @@ private: QComboBox * m_doubleClickBehavior = nullptr; QComboBox * m_mouseWheelBehavior = nullptr; QComboBox * m_initWindowSizeBehavior = nullptr; + QComboBox * m_hiDpiRoundingPolicyBehavior = nullptr; }; #endif // SETTINGSDIALOG_H