2022-06-19 16:17:38 +08:00
|
|
|
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2020-07-29 00:57:43 +08:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
|
|
|
|
#include "settings.h"
|
2024-10-29 23:28:27 +08:00
|
|
|
#include "shortcutedit.h"
|
2020-07-29 00:57:43 +08:00
|
|
|
|
2024-10-30 00:15:47 +08:00
|
|
|
#include <QAction>
|
2020-07-29 00:57:43 +08:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QFormLayout>
|
2024-10-29 23:28:27 +08:00
|
|
|
#include <QKeySequenceEdit>
|
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QSplitter>
|
2020-07-29 00:57:43 +08:00
|
|
|
#include <QStringListModel>
|
|
|
|
|
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent)
|
|
|
|
: QDialog(parent)
|
|
|
|
, m_stayOnTop(new QCheckBox)
|
2024-10-10 22:58:11 +08:00
|
|
|
, m_useLightCheckerboard(new QCheckBox)
|
2020-07-29 00:57:43 +08:00
|
|
|
, m_doubleClickBehavior(new QComboBox)
|
2021-01-24 00:07:58 +08:00
|
|
|
, m_mouseWheelBehavior(new QComboBox)
|
2022-03-11 16:21:56 +08:00
|
|
|
, m_initWindowSizeBehavior(new QComboBox)
|
2023-07-10 01:07:01 +08:00
|
|
|
, m_hiDpiRoundingPolicyBehavior(new QComboBox)
|
2020-07-29 00:57:43 +08:00
|
|
|
{
|
2020-10-05 20:43:30 +08:00
|
|
|
this->setWindowTitle(tr("Settings"));
|
|
|
|
|
2024-10-29 23:28:27 +08:00
|
|
|
QHBoxLayout * mainLayout = new QHBoxLayout(this);
|
|
|
|
QTabWidget * settingsTabs = new QTabWidget(this);
|
|
|
|
mainLayout->addWidget(settingsTabs);
|
|
|
|
|
|
|
|
QWidget * settingsFormHolder = new QWidget;
|
|
|
|
QFormLayout * settingsForm = new QFormLayout(settingsFormHolder);
|
|
|
|
settingsTabs->addTab(settingsFormHolder, tr("Options"));
|
|
|
|
|
|
|
|
QSplitter * shortcutEditorSplitter = new QSplitter;
|
|
|
|
shortcutEditorSplitter->setOrientation(Qt::Vertical);
|
|
|
|
shortcutEditorSplitter->setChildrenCollapsible(false);
|
|
|
|
QScrollArea * shortcutScrollArea = new QScrollArea;
|
|
|
|
shortcutEditorSplitter->addWidget(shortcutScrollArea);
|
|
|
|
shortcutScrollArea->setWidgetResizable(true);
|
|
|
|
shortcutScrollArea->setMinimumHeight(200);
|
|
|
|
QWidget * shortcutsFormHolder = new QWidget;
|
|
|
|
QFormLayout * shortcutsForm = new QFormLayout(shortcutsFormHolder);
|
|
|
|
shortcutScrollArea->setWidget(shortcutsFormHolder);
|
|
|
|
settingsTabs->addTab(shortcutEditorSplitter, tr("Shortcuts"));
|
|
|
|
|
|
|
|
for (const QAction * action : parent->actions()) {
|
|
|
|
ShortcutEdit * shortcutEdit = new ShortcutEdit;
|
|
|
|
shortcutEdit->setObjectName(QLatin1String("shortcut_") + action->objectName());
|
|
|
|
shortcutEdit->setShortcuts(action->shortcuts());
|
|
|
|
shortcutsForm->addRow(action->text(), shortcutEdit);
|
|
|
|
connect(shortcutEdit, &ShortcutEdit::editButtonClicked, this, [=](){
|
|
|
|
if (shortcutEditorSplitter->count() == 1) shortcutEditorSplitter->addWidget(new QWidget);
|
|
|
|
ShortcutEditor * shortcutEditor = new ShortcutEditor(shortcutEdit);
|
|
|
|
shortcutEditor->setDescription(tr("Editing shortcuts for action \"%1\":").arg(action->text()));
|
|
|
|
QWidget * oldEditor = shortcutEditorSplitter->replaceWidget(1, shortcutEditor);
|
|
|
|
shortcutEditorSplitter->setSizes({shortcutEditorSplitter->height(), 1});
|
|
|
|
oldEditor->deleteLater();
|
|
|
|
});
|
|
|
|
connect(shortcutEdit, &ShortcutEdit::shortcutsChanged, this, [=](){
|
|
|
|
Settings::instance()->setShortcutsForAction(parent, shortcutEdit->objectName().mid(9),
|
|
|
|
shortcutEdit->shortcuts());
|
|
|
|
});
|
|
|
|
}
|
2020-07-29 00:57:43 +08:00
|
|
|
|
2022-03-12 10:35:23 +08:00
|
|
|
static QList< QPair<Settings::DoubleClickBehavior, QString> > _dc_options {
|
|
|
|
{ Settings::DoubleClickBehavior::Ignore, tr("Do nothing") },
|
|
|
|
{ Settings::DoubleClickBehavior::Close, tr("Close the window") },
|
|
|
|
{ Settings::DoubleClickBehavior::Maximize, tr("Toggle maximize") }
|
2020-07-29 00:57:43 +08:00
|
|
|
};
|
|
|
|
|
2022-03-12 10:35:23 +08:00
|
|
|
static QList< QPair<Settings::MouseWheelBehavior, QString> > _mw_options {
|
|
|
|
{ Settings::MouseWheelBehavior::Zoom, tr("Zoom in and out") },
|
|
|
|
{ Settings::MouseWheelBehavior::Switch, tr("View next or previous item") }
|
2021-01-24 00:07:58 +08:00
|
|
|
};
|
|
|
|
|
2022-03-12 10:35:23 +08:00
|
|
|
static QList< QPair<Settings::WindowSizeBehavior, QString> > _iws_options {
|
2022-04-13 00:03:37 +08:00
|
|
|
{ Settings::WindowSizeBehavior::Auto, tr("Auto size") },
|
|
|
|
{ Settings::WindowSizeBehavior::Maximized, tr("Maximized") }
|
2022-03-11 16:21:56 +08:00
|
|
|
};
|
|
|
|
|
2023-07-10 01:07:01 +08:00
|
|
|
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") }
|
|
|
|
};
|
|
|
|
|
2021-01-24 00:07:58 +08:00
|
|
|
QStringList dcbDropDown;
|
2022-03-12 10:35:23 +08:00
|
|
|
for (const QPair<Settings::DoubleClickBehavior, QString> & dcOption : _dc_options) {
|
|
|
|
dcbDropDown.append(dcOption.second);
|
2021-01-24 00:07:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList mwbDropDown;
|
2022-03-12 10:35:23 +08:00
|
|
|
for (const QPair<Settings::MouseWheelBehavior, QString> & mwOption : _mw_options) {
|
|
|
|
mwbDropDown.append(mwOption.second);
|
2020-07-29 00:57:43 +08:00
|
|
|
}
|
|
|
|
|
2022-03-11 16:21:56 +08:00
|
|
|
QStringList iwsbDropDown;
|
2022-03-12 10:35:23 +08:00
|
|
|
for (const QPair<Settings::WindowSizeBehavior, QString> & iwsOption : _iws_options) {
|
|
|
|
iwsbDropDown.append(iwsOption.second);
|
2022-03-11 16:21:56 +08:00
|
|
|
}
|
|
|
|
|
2023-07-10 01:07:01 +08:00
|
|
|
QStringList hidpiDropDown;
|
|
|
|
for (const QPair<Qt::HighDpiScaleFactorRoundingPolicy, QString> & hidpiOption : _hidpi_options) {
|
|
|
|
hidpiDropDown.append(hidpiOption.second);
|
|
|
|
}
|
|
|
|
|
2020-07-29 00:57:43 +08:00
|
|
|
settingsForm->addRow(tr("Stay on top when start-up"), m_stayOnTop);
|
2024-10-10 22:58:11 +08:00
|
|
|
settingsForm->addRow(tr("Use light-color checkerboard"), m_useLightCheckerboard);
|
2020-07-29 00:57:43 +08:00
|
|
|
settingsForm->addRow(tr("Double-click behavior"), m_doubleClickBehavior);
|
2021-01-24 00:07:58 +08:00
|
|
|
settingsForm->addRow(tr("Mouse wheel behavior"), m_mouseWheelBehavior);
|
2022-04-13 00:03:37 +08:00
|
|
|
settingsForm->addRow(tr("Default window size"), m_initWindowSizeBehavior);
|
2023-07-10 01:07:01 +08:00
|
|
|
settingsForm->addRow(tr("HiDPI scale factor rounding policy"), m_hiDpiRoundingPolicyBehavior);
|
2020-07-29 00:57:43 +08:00
|
|
|
|
|
|
|
m_stayOnTop->setChecked(Settings::instance()->stayOnTop());
|
2024-10-10 22:58:11 +08:00
|
|
|
m_useLightCheckerboard->setChecked(Settings::instance()->useLightCheckerboard());
|
2021-01-24 00:07:58 +08:00
|
|
|
m_doubleClickBehavior->setModel(new QStringListModel(dcbDropDown));
|
2022-03-12 10:35:23 +08:00
|
|
|
Settings::DoubleClickBehavior dcb = Settings::instance()->doubleClickBehavior();
|
2020-07-29 00:57:43 +08:00
|
|
|
m_doubleClickBehavior->setCurrentIndex(static_cast<int>(dcb));
|
2021-01-24 00:07:58 +08:00
|
|
|
m_mouseWheelBehavior->setModel(new QStringListModel(mwbDropDown));
|
2022-03-12 10:35:23 +08:00
|
|
|
Settings::MouseWheelBehavior mwb = Settings::instance()->mouseWheelBehavior();
|
2021-01-24 00:07:58 +08:00
|
|
|
m_mouseWheelBehavior->setCurrentIndex(static_cast<int>(mwb));
|
2022-03-11 16:21:56 +08:00
|
|
|
m_initWindowSizeBehavior->setModel(new QStringListModel(iwsbDropDown));
|
2022-03-12 10:35:23 +08:00
|
|
|
Settings::WindowSizeBehavior iwsb = Settings::instance()->initWindowSizeBehavior();
|
2022-03-11 16:21:56 +08:00
|
|
|
m_initWindowSizeBehavior->setCurrentIndex(static_cast<int>(iwsb));
|
2023-07-10 01:07:01 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2020-07-29 00:57:43 +08:00
|
|
|
|
|
|
|
connect(m_stayOnTop, &QCheckBox::stateChanged, this, [ = ](int state){
|
|
|
|
Settings::instance()->setStayOnTop(state == Qt::Checked);
|
|
|
|
});
|
|
|
|
|
2024-10-10 22:58:11 +08:00
|
|
|
connect(m_useLightCheckerboard, &QCheckBox::stateChanged, this, [ = ](int state){
|
|
|
|
Settings::instance()->setUseLightCheckerboard(state == Qt::Checked);
|
|
|
|
});
|
|
|
|
|
2020-07-29 00:57:43 +08:00
|
|
|
connect(m_doubleClickBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
|
2022-03-12 10:35:23 +08:00
|
|
|
Settings::instance()->setDoubleClickBehavior(_dc_options.at(index).first);
|
2020-07-29 00:57:43 +08:00
|
|
|
});
|
|
|
|
|
2021-01-24 00:07:58 +08:00
|
|
|
connect(m_mouseWheelBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
|
2022-03-12 10:35:23 +08:00
|
|
|
Settings::instance()->setMouseWheelBehavior(_mw_options.at(index).first);
|
2021-01-24 00:07:58 +08:00
|
|
|
});
|
|
|
|
|
2022-03-11 16:21:56 +08:00
|
|
|
connect(m_initWindowSizeBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
|
2022-03-12 10:35:23 +08:00
|
|
|
Settings::instance()->setInitWindowSizeBehavior(_iws_options.at(index).first);
|
2022-03-11 16:21:56 +08:00
|
|
|
});
|
|
|
|
|
2023-07-10 01:07:01 +08:00
|
|
|
connect(m_hiDpiRoundingPolicyBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
|
|
|
|
Settings::instance()->setHiDpiScaleFactorBehavior(_hidpi_options.at(index).first);
|
|
|
|
});
|
|
|
|
|
2023-06-18 22:54:41 +08:00
|
|
|
adjustSize();
|
2020-08-10 23:42:43 +08:00
|
|
|
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
|
2020-07-29 00:57:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|