feat: add hidpi rounding policy option to setting dialog
This commit is contained in:
parent
d4ded92734
commit
0e1635e0e7
|
@ -5,6 +5,7 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include "playlistmanager.h"
|
#include "playlistmanager.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
|
@ -19,6 +20,8 @@
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Settings::instance()->hiDpiScaleFactorBehavior());
|
||||||
|
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||||
a.setAttribute(Qt::ApplicationAttribute::AA_UseHighDpiPixmaps);
|
a.setAttribute(Qt::ApplicationAttribute::AA_UseHighDpiPixmaps);
|
||||||
|
|
|
@ -68,6 +68,13 @@ Settings::WindowSizeBehavior Settings::initWindowSizeBehavior() const
|
||||||
return QEnumHelper::fromString<WindowSizeBehavior>(result, WindowSizeBehavior::Auto);
|
return QEnumHelper::fromString<WindowSizeBehavior>(result, WindowSizeBehavior::Auto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::HighDpiScaleFactorRoundingPolicy Settings::hiDpiScaleFactorBehavior() const
|
||||||
|
{
|
||||||
|
QString result = m_qsettings->value("hidpi_scale_factor_behavior", "PassThrough").toString();
|
||||||
|
|
||||||
|
return QEnumHelper::fromString<Qt::HighDpiScaleFactorRoundingPolicy>(result, Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||||
|
}
|
||||||
|
|
||||||
void Settings::setStayOnTop(bool on)
|
void Settings::setStayOnTop(bool on)
|
||||||
{
|
{
|
||||||
m_qsettings->setValue("stay_on_top", on);
|
m_qsettings->setValue("stay_on_top", on);
|
||||||
|
@ -92,6 +99,12 @@ void Settings::setInitWindowSizeBehavior(WindowSizeBehavior wsb)
|
||||||
m_qsettings->sync();
|
m_qsettings->sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Settings::setHiDpiScaleFactorBehavior(Qt::HighDpiScaleFactorRoundingPolicy hidpi)
|
||||||
|
{
|
||||||
|
m_qsettings->setValue("hidpi_scale_factor_behavior", QEnumHelper::toString(hidpi));
|
||||||
|
m_qsettings->sync();
|
||||||
|
}
|
||||||
|
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
: QObject(qApp)
|
: QObject(qApp)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,19 +16,19 @@ public:
|
||||||
Close,
|
Close,
|
||||||
Maximize,
|
Maximize,
|
||||||
};
|
};
|
||||||
Q_ENUM(DoubleClickBehavior);
|
Q_ENUM(DoubleClickBehavior)
|
||||||
|
|
||||||
enum MouseWheelBehavior {
|
enum MouseWheelBehavior {
|
||||||
Zoom,
|
Zoom,
|
||||||
Switch,
|
Switch,
|
||||||
};
|
};
|
||||||
Q_ENUM(MouseWheelBehavior);
|
Q_ENUM(MouseWheelBehavior)
|
||||||
|
|
||||||
enum WindowSizeBehavior {
|
enum WindowSizeBehavior {
|
||||||
Auto,
|
Auto,
|
||||||
Maximized,
|
Maximized,
|
||||||
};
|
};
|
||||||
Q_ENUM(WindowSizeBehavior);
|
Q_ENUM(WindowSizeBehavior)
|
||||||
|
|
||||||
static Settings *instance();
|
static Settings *instance();
|
||||||
|
|
||||||
|
@ -36,11 +36,13 @@ public:
|
||||||
DoubleClickBehavior doubleClickBehavior() const;
|
DoubleClickBehavior doubleClickBehavior() const;
|
||||||
MouseWheelBehavior mouseWheelBehavior() const;
|
MouseWheelBehavior mouseWheelBehavior() const;
|
||||||
WindowSizeBehavior initWindowSizeBehavior() const;
|
WindowSizeBehavior initWindowSizeBehavior() const;
|
||||||
|
Qt::HighDpiScaleFactorRoundingPolicy hiDpiScaleFactorBehavior() const;
|
||||||
|
|
||||||
void setStayOnTop(bool on);
|
void setStayOnTop(bool on);
|
||||||
void setDoubleClickBehavior(DoubleClickBehavior dcb);
|
void setDoubleClickBehavior(DoubleClickBehavior dcb);
|
||||||
void setMouseWheelBehavior(MouseWheelBehavior mwb);
|
void setMouseWheelBehavior(MouseWheelBehavior mwb);
|
||||||
void setInitWindowSizeBehavior(WindowSizeBehavior wsb);
|
void setInitWindowSizeBehavior(WindowSizeBehavior wsb);
|
||||||
|
void setHiDpiScaleFactorBehavior(Qt::HighDpiScaleFactorRoundingPolicy hidpi);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Settings();
|
Settings();
|
||||||
|
|
|
@ -17,6 +17,7 @@ SettingsDialog::SettingsDialog(QWidget *parent)
|
||||||
, m_doubleClickBehavior(new QComboBox)
|
, m_doubleClickBehavior(new QComboBox)
|
||||||
, m_mouseWheelBehavior(new QComboBox)
|
, m_mouseWheelBehavior(new QComboBox)
|
||||||
, m_initWindowSizeBehavior(new QComboBox)
|
, m_initWindowSizeBehavior(new QComboBox)
|
||||||
|
, m_hiDpiRoundingPolicyBehavior(new QComboBox)
|
||||||
{
|
{
|
||||||
this->setWindowTitle(tr("Settings"));
|
this->setWindowTitle(tr("Settings"));
|
||||||
|
|
||||||
|
@ -38,6 +39,13 @@ SettingsDialog::SettingsDialog(QWidget *parent)
|
||||||
{ Settings::WindowSizeBehavior::Maximized, tr("Maximized") }
|
{ Settings::WindowSizeBehavior::Maximized, tr("Maximized") }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static QList< QPair<Qt::HighDpiScaleFactorRoundingPolicy, QString> > _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;
|
QStringList dcbDropDown;
|
||||||
for (const QPair<Settings::DoubleClickBehavior, QString> & dcOption : _dc_options) {
|
for (const QPair<Settings::DoubleClickBehavior, QString> & dcOption : _dc_options) {
|
||||||
dcbDropDown.append(dcOption.second);
|
dcbDropDown.append(dcOption.second);
|
||||||
|
@ -53,10 +61,16 @@ SettingsDialog::SettingsDialog(QWidget *parent)
|
||||||
iwsbDropDown.append(iwsOption.second);
|
iwsbDropDown.append(iwsOption.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList hidpiDropDown;
|
||||||
|
for (const QPair<Qt::HighDpiScaleFactorRoundingPolicy, QString> & hidpiOption : _hidpi_options) {
|
||||||
|
hidpiDropDown.append(hidpiOption.second);
|
||||||
|
}
|
||||||
|
|
||||||
settingsForm->addRow(tr("Stay on top when start-up"), m_stayOnTop);
|
settingsForm->addRow(tr("Stay on top when start-up"), m_stayOnTop);
|
||||||
settingsForm->addRow(tr("Double-click behavior"), m_doubleClickBehavior);
|
settingsForm->addRow(tr("Double-click behavior"), m_doubleClickBehavior);
|
||||||
settingsForm->addRow(tr("Mouse wheel behavior"), m_mouseWheelBehavior);
|
settingsForm->addRow(tr("Mouse wheel behavior"), m_mouseWheelBehavior);
|
||||||
settingsForm->addRow(tr("Default window size"), m_initWindowSizeBehavior);
|
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_stayOnTop->setChecked(Settings::instance()->stayOnTop());
|
||||||
m_doubleClickBehavior->setModel(new QStringListModel(dcbDropDown));
|
m_doubleClickBehavior->setModel(new QStringListModel(dcbDropDown));
|
||||||
|
@ -68,6 +82,14 @@ SettingsDialog::SettingsDialog(QWidget *parent)
|
||||||
m_initWindowSizeBehavior->setModel(new QStringListModel(iwsbDropDown));
|
m_initWindowSizeBehavior->setModel(new QStringListModel(iwsbDropDown));
|
||||||
Settings::WindowSizeBehavior iwsb = Settings::instance()->initWindowSizeBehavior();
|
Settings::WindowSizeBehavior iwsb = Settings::instance()->initWindowSizeBehavior();
|
||||||
m_initWindowSizeBehavior->setCurrentIndex(static_cast<int>(iwsb));
|
m_initWindowSizeBehavior->setCurrentIndex(static_cast<int>(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){
|
connect(m_stayOnTop, &QCheckBox::stateChanged, this, [ = ](int state){
|
||||||
Settings::instance()->setStayOnTop(state == Qt::Checked);
|
Settings::instance()->setStayOnTop(state == Qt::Checked);
|
||||||
|
@ -85,6 +107,10 @@ SettingsDialog::SettingsDialog(QWidget *parent)
|
||||||
Settings::instance()->setInitWindowSizeBehavior(_iws_options.at(index).first);
|
Settings::instance()->setInitWindowSizeBehavior(_iws_options.at(index).first);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(m_hiDpiRoundingPolicyBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
|
||||||
|
Settings::instance()->setHiDpiScaleFactorBehavior(_hidpi_options.at(index).first);
|
||||||
|
});
|
||||||
|
|
||||||
adjustSize();
|
adjustSize();
|
||||||
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
|
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ private:
|
||||||
QComboBox * m_doubleClickBehavior = nullptr;
|
QComboBox * m_doubleClickBehavior = nullptr;
|
||||||
QComboBox * m_mouseWheelBehavior = nullptr;
|
QComboBox * m_mouseWheelBehavior = nullptr;
|
||||||
QComboBox * m_initWindowSizeBehavior = nullptr;
|
QComboBox * m_initWindowSizeBehavior = nullptr;
|
||||||
|
QComboBox * m_hiDpiRoundingPolicyBehavior = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SETTINGSDIALOG_H
|
#endif // SETTINGSDIALOG_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user