mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-02-07 04:43:38 +01:00
SettingsPage: Pass on scroll event to page
If the settings widget does not have focus, pass the event to the page for scrolling down instead of changing the setting. Fixes #1380
This commit is contained in:
parent
593a04d047
commit
306b3f72d8
@ -23,6 +23,7 @@
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QSpinBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QRadioButton>
|
||||
#include <QSlider>
|
||||
#include <QLineEdit>
|
||||
@ -63,15 +64,26 @@ void SettingsPage::Init(QWidget *ui_widget) {
|
||||
radiobuttons_ << qMakePair(radiobutton, radiobutton->isChecked());
|
||||
}
|
||||
else if (QComboBox *combobox = qobject_cast<QComboBox*>(w)) {
|
||||
combobox->setFocusPolicy(Qt::StrongFocus);
|
||||
combobox->installEventFilter(this);
|
||||
comboboxes_ << qMakePair(combobox, combobox->currentText());
|
||||
}
|
||||
else if (QSpinBox *spinbox = qobject_cast<QSpinBox*>(w)) {
|
||||
spinbox->setFocusPolicy(Qt::StrongFocus);
|
||||
spinbox->installEventFilter(this);
|
||||
spinboxes_ << qMakePair(spinbox, spinbox->value());
|
||||
}
|
||||
else if (QDoubleSpinBox *double_spinbox = qobject_cast<QDoubleSpinBox*>(w)) {
|
||||
double_spinbox->setFocusPolicy(Qt::StrongFocus);
|
||||
double_spinbox->installEventFilter(this);
|
||||
double_spinboxes_ << qMakePair(double_spinbox, double_spinbox->value());
|
||||
}
|
||||
else if (QLineEdit *lineedit = qobject_cast<QLineEdit*>(w)) {
|
||||
lineedits_ << qMakePair(lineedit, lineedit->text());
|
||||
}
|
||||
else if (QSlider *slider = qobject_cast<QSlider*>(w)) {
|
||||
slider->setFocusPolicy(Qt::StrongFocus);
|
||||
slider->installEventFilter(this);
|
||||
sliders_ << qMakePair(slider, slider->value());
|
||||
}
|
||||
}
|
||||
@ -114,6 +126,11 @@ void SettingsPage::Apply() {
|
||||
changed_ = true;
|
||||
qLog(Info) << spinbox.first->objectName() << "is changed for" << windowTitle() << "settings.";
|
||||
}
|
||||
for (QPair<QDoubleSpinBox*, int> &double_spinbox : double_spinboxes_) {
|
||||
if (double_spinbox.first->value() == double_spinbox.second) continue;
|
||||
changed_ = true;
|
||||
qLog(Info) << double_spinbox.first->objectName() << "is changed for" << windowTitle() << "settings.";
|
||||
}
|
||||
for (QPair<QLineEdit*, QString> &lineedit : lineedits_) {
|
||||
if (lineedit.first->text() == lineedit.second) continue;
|
||||
changed_ = true;
|
||||
@ -161,3 +178,32 @@ void SettingsPage::ComboBoxLoadFromSettingsByIndex(const QSettings &s, QComboBox
|
||||
|
||||
}
|
||||
|
||||
bool SettingsPage::eventFilter(QObject *obj, QEvent *e) {
|
||||
|
||||
if (e->type() == QEvent::Wheel) {
|
||||
if (QComboBox *combobox = qobject_cast<QComboBox*>(obj)) {
|
||||
if (!combobox->hasFocus()) {
|
||||
return event(e);
|
||||
}
|
||||
}
|
||||
else if (QSpinBox *spinbox = qobject_cast<QSpinBox*>(obj)) {
|
||||
if (!spinbox->hasFocus()) {
|
||||
return event(e);
|
||||
}
|
||||
}
|
||||
else if (QDoubleSpinBox *double_spinbox = qobject_cast<QDoubleSpinBox*>(obj)) {
|
||||
if (!double_spinbox->hasFocus()) {
|
||||
return event(e);
|
||||
}
|
||||
}
|
||||
else if (QSlider *slider = qobject_cast<QSlider*>(obj)) {
|
||||
if (!slider->hasFocus()) {
|
||||
return event(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ class QCheckBox;
|
||||
class QComboBox;
|
||||
class QRadioButton;
|
||||
class QSpinBox;
|
||||
class QDoubleSpinBox;
|
||||
class QSlider;
|
||||
class QLineEdit;
|
||||
class QShowEvent;
|
||||
@ -75,6 +76,9 @@ class SettingsPage : public QWidget {
|
||||
virtual void Save() = 0;
|
||||
virtual void Cancel() {}
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *e) override;
|
||||
|
||||
signals:
|
||||
void NotificationPreview(const OSDBase::Behaviour, const QString&, const QString&);
|
||||
|
||||
@ -86,6 +90,7 @@ class SettingsPage : public QWidget {
|
||||
QList<QPair<QRadioButton*, bool>> radiobuttons_;
|
||||
QList<QPair<QComboBox*, QString>> comboboxes_;
|
||||
QList<QPair<QSpinBox*, int>> spinboxes_;
|
||||
QList<QPair<QDoubleSpinBox*, int>> double_spinboxes_;
|
||||
QList<QPair<QSlider*, int>> sliders_;
|
||||
QList<QPair<QLineEdit*, QString>> lineedits_;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user