2020-07-29 00:57:43 +08:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
|
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QStringListModel>
|
|
|
|
|
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent)
|
|
|
|
: QDialog(parent)
|
|
|
|
, m_stayOnTop(new QCheckBox)
|
|
|
|
, 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)
|
2020-07-29 00:57:43 +08:00
|
|
|
{
|
2020-10-05 20:43:30 +08:00
|
|
|
this->setWindowTitle(tr("Settings"));
|
|
|
|
|
2020-07-29 00:57:43 +08:00
|
|
|
QFormLayout * settingsForm = new QFormLayout(this);
|
|
|
|
|
2021-01-24 00:07:58 +08:00
|
|
|
static QMap<DoubleClickBehavior, QString> _dc_map {
|
2020-07-29 00:57:43 +08:00
|
|
|
{ ActionDoNothing, tr("Do nothing") },
|
|
|
|
{ ActionCloseWindow, tr("Close the window") },
|
|
|
|
{ ActionMaximizeWindow, tr("Toggle maximize") }
|
|
|
|
};
|
|
|
|
|
2021-01-24 00:07:58 +08:00
|
|
|
static QMap<MouseWheelBehavior, QString> _mw_map {
|
|
|
|
{ ActionZoomImage, tr("Zoom in and out") },
|
|
|
|
{ ActionPrevNextImage, tr("View next or previous item") }
|
|
|
|
};
|
|
|
|
|
2022-03-11 16:21:56 +08:00
|
|
|
static QMap<WindowSizeBehavior, QString> _iws_map {
|
|
|
|
{ ActionAutoSize, "Auto size" },
|
|
|
|
{ ActionMaximize, "Maximize" }
|
|
|
|
};
|
|
|
|
|
2021-01-24 00:07:58 +08:00
|
|
|
QStringList dcbDropDown;
|
|
|
|
for (int dcb = DCActionStart; dcb <= DCActionEnd; dcb++) {
|
|
|
|
dcbDropDown.append(_dc_map.value(static_cast<DoubleClickBehavior>(dcb)));
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList mwbDropDown;
|
|
|
|
for (int mwb = MWActionStart; mwb <= MWActionEnd; mwb++) {
|
|
|
|
mwbDropDown.append(_mw_map.value(static_cast<MouseWheelBehavior>(mwb)));
|
2020-07-29 00:57:43 +08:00
|
|
|
}
|
|
|
|
|
2022-03-11 16:21:56 +08:00
|
|
|
QStringList iwsbDropDown;
|
|
|
|
for (int iwsb = IWSActionStart; iwsb <= IWSActionEnd; iwsb++) {
|
|
|
|
iwsbDropDown.append(_iws_map.value(static_cast<WindowSizeBehavior>(iwsb)));
|
|
|
|
}
|
|
|
|
|
2020-07-29 00:57:43 +08:00
|
|
|
settingsForm->addRow(tr("Stay on top when start-up"), m_stayOnTop);
|
|
|
|
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-03-11 16:21:56 +08:00
|
|
|
settingsForm->addRow("Init window size behavior", m_initWindowSizeBehavior);
|
2020-07-29 00:57:43 +08:00
|
|
|
|
|
|
|
m_stayOnTop->setChecked(Settings::instance()->stayOnTop());
|
2021-01-24 00:07:58 +08:00
|
|
|
m_doubleClickBehavior->setModel(new QStringListModel(dcbDropDown));
|
2020-07-29 00:57:43 +08:00
|
|
|
DoubleClickBehavior dcb = Settings::instance()->doubleClickBehavior();
|
|
|
|
m_doubleClickBehavior->setCurrentIndex(static_cast<int>(dcb));
|
2021-01-24 00:07:58 +08:00
|
|
|
m_mouseWheelBehavior->setModel(new QStringListModel(mwbDropDown));
|
|
|
|
MouseWheelBehavior mwb = Settings::instance()->mouseWheelBehavior();
|
|
|
|
m_mouseWheelBehavior->setCurrentIndex(static_cast<int>(mwb));
|
2022-03-11 16:21:56 +08:00
|
|
|
m_initWindowSizeBehavior->setModel(new QStringListModel(iwsbDropDown));
|
|
|
|
WindowSizeBehavior iwsb = Settings::instance()->initWindowSizeBehavior();
|
|
|
|
m_initWindowSizeBehavior->setCurrentIndex(static_cast<int>(iwsb));
|
2020-07-29 00:57:43 +08:00
|
|
|
|
|
|
|
connect(m_stayOnTop, &QCheckBox::stateChanged, this, [ = ](int state){
|
|
|
|
Settings::instance()->setStayOnTop(state == Qt::Checked);
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(m_doubleClickBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
|
|
|
|
Settings::instance()->setDoubleClickBehavior(static_cast<DoubleClickBehavior>(index));
|
|
|
|
});
|
|
|
|
|
2021-01-24 00:07:58 +08:00
|
|
|
connect(m_mouseWheelBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
|
|
|
|
Settings::instance()->setMouseWheelBehavior(static_cast<MouseWheelBehavior>(index));
|
|
|
|
});
|
|
|
|
|
2022-03-11 16:21:56 +08:00
|
|
|
connect(m_initWindowSizeBehavior, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [ = ](int index){
|
|
|
|
Settings::instance()->setInitWindowSizeBehavior(static_cast<WindowSizeBehavior>(index));
|
|
|
|
});
|
|
|
|
|
|
|
|
this->setMinimumSize(300, 90); // not sure why it complain "Unable to set geometry"
|
2020-08-10 23:42:43 +08:00
|
|
|
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
|
2020-07-29 00:57:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|