-
Notifications
You must be signed in to change notification settings - Fork 1
/
settingsdialog.cpp
67 lines (60 loc) · 1.91 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
#include "settingsdialog.h"
#include "decoder_openmpt.h"
#include <QSettings>
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
const QMap<QString, int> interpolators(OpenMPTHelper::interpolators());
for(auto itr = interpolators.begin(); itr != interpolators.end(); ++itr)
{
m_ui.interpolate_combo->addItem(itr.key(), itr.value());
}
restoreDefaults();
}
void SettingsDialog::accept()
{
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
QSettings settings;
#else
QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
#endif
settings.beginGroup("OpenMPT");
settings.setValue("interpolator", m_ui.interpolate_combo->itemData(m_ui.interpolate_combo->currentIndex()).toInt());
settings.setValue("stereo_separation", m_ui.stereo_separation->value());
settings.setValue("use_file_name", m_ui.use_filename->isChecked());
settings.endGroup();
if(DecoderOpenMPT::instance())
{
DecoderOpenMPT::instance()->readSettings();
}
QDialog::accept();
}
void SettingsDialog::restoreDefaults()
{
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
QSettings settings;
#else
QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
#endif
settings.beginGroup("OpenMPT");
setInterpolator(settings.value("interpolator", INTERP_WINDOWED).toInt());
m_ui.stereo_separation->setSliderPosition(settings.value("stereo_separation", 100).toInt());
m_ui.use_filename->setChecked(settings.value("use_file_name", 0).toBool());
settings.endGroup();
}
void SettingsDialog::setInterpolator(int interpolator)
{
const int i = m_ui.interpolate_combo->findData(interpolator);
if(i != -1)
{
m_ui.interpolate_combo->setCurrentIndex(i);
}
}