-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettingsdialog.cpp
71 lines (63 loc) · 1.85 KB
/
settingsdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "settingsdialog.h"
#include "subwooferplugin.h"
#include <QSettings>
#include <QAbstractButton>
SettingsDialog::SettingsDialog(QWidget *parent)
: QDialog(parent)
{
m_ui.setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
#ifdef Q_OS_UNIX
for(QAbstractButton *button : m_ui.buttonBox->buttons())
{
button->setFocusPolicy(Qt::NoFocus);
}
#endif
m_ui.levelSlider->setRange(3, 30);
m_ui.cutOffSlider->setRange(50, 500);
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
QSettings settings;
#else
QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
#endif
m_level = settings.value("Subwoofer/level", 10).toUInt();
m_cutoff = settings.value("Subwoofer/cutoff", 250).toUInt();
m_ui.levelSlider->setValue(m_level);
m_ui.cutOffSlider->setValue(m_cutoff);
}
void SettingsDialog::accept()
{
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
QSettings settings;
#else
QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
#endif
settings.setValue("Subwoofer/level", m_ui.levelSlider->value());
settings.setValue("Subwoofer/cutoff", m_ui.cutOffSlider->value());
QDialog::accept();
}
void SettingsDialog::SettingsDialog::reject()
{
if(SubwooferPlugin::instance())
{
SubwooferPlugin::instance()->setLevel(m_level); // restore settings
SubwooferPlugin::instance()->setCutOff(m_cutoff); // restore settings
}
QDialog::reject();
}
void SettingsDialog::on_levelSlider_valueChanged(int value)
{
m_ui.levelLabel->setText(tr("%1").arg(value / 10.0f));
if(SubwooferPlugin::instance())
{
SubwooferPlugin::instance()->setLevel(value);
}
}
void SettingsDialog::on_cutOffSlider_valueChanged(int value)
{
m_ui.cutOffLabel->setText(tr("%1").arg(value));
if(SubwooferPlugin::instance())
{
SubwooferPlugin::instance()->setCutOff(value);
}
}