Chris@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 Sonic Visualiser
|
Chris@0
|
5 An audio file viewer and annotation editor.
|
Chris@0
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@0
|
7 This file copyright 2006 Chris Cannam.
|
Chris@0
|
8
|
Chris@0
|
9 This program is free software; you can redistribute it and/or
|
Chris@0
|
10 modify it under the terms of the GNU General Public License as
|
Chris@0
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@0
|
12 License, or (at your option) any later version. See the file
|
Chris@0
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #include "PreferencesDialog.h"
|
Chris@0
|
17
|
Chris@0
|
18 #include <QGridLayout>
|
Chris@0
|
19 #include <QComboBox>
|
Chris@0
|
20 #include <QCheckBox>
|
Chris@0
|
21 #include <QGroupBox>
|
Chris@0
|
22 #include <QDoubleSpinBox>
|
Chris@0
|
23 #include <QLabel>
|
Chris@0
|
24 #include <QPushButton>
|
Chris@0
|
25 #include <QHBoxLayout>
|
Chris@0
|
26 #include <QString>
|
Chris@0
|
27
|
Chris@9
|
28 #include "widgets/WindowTypeSelector.h"
|
Chris@0
|
29 #include "base/Preferences.h"
|
Chris@0
|
30
|
Chris@0
|
31 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) :
|
Chris@0
|
32 QDialog(parent, flags)
|
Chris@0
|
33 {
|
Chris@0
|
34 setWindowTitle(tr("Application Preferences"));
|
Chris@0
|
35
|
Chris@0
|
36 Preferences *prefs = Preferences::getInstance();
|
Chris@0
|
37
|
Chris@0
|
38 QGridLayout *grid = new QGridLayout;
|
Chris@0
|
39 setLayout(grid);
|
Chris@0
|
40
|
Chris@0
|
41 QGroupBox *groupBox = new QGroupBox;
|
Chris@0
|
42 groupBox->setTitle(tr("Sonic Visualiser Application Preferences"));
|
Chris@0
|
43 grid->addWidget(groupBox, 0, 0);
|
Chris@0
|
44
|
Chris@0
|
45 QGridLayout *subgrid = new QGridLayout;
|
Chris@0
|
46 groupBox->setLayout(subgrid);
|
Chris@0
|
47
|
Chris@0
|
48 // Create this first, as slots that get called from the ctor will
|
Chris@0
|
49 // refer to it
|
Chris@0
|
50 m_applyButton = new QPushButton(tr("Apply"));
|
Chris@0
|
51
|
Chris@9
|
52 int min, max, i;
|
Chris@0
|
53
|
Chris@9
|
54 m_windowType = WindowType(prefs->getPropertyRangeAndValue
|
Chris@9
|
55 ("Window Type", &min, &max));
|
Chris@9
|
56 m_windowTypeSelector = new WindowTypeSelector(m_windowType);
|
Chris@0
|
57
|
Chris@9
|
58 connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)),
|
Chris@9
|
59 this, SLOT(windowTypeChanged(WindowType)));
|
Chris@0
|
60
|
Chris@0
|
61 QCheckBox *smoothing = new QCheckBox;
|
Chris@0
|
62 m_smoothSpectrogram = prefs->getSmoothSpectrogram();
|
Chris@0
|
63 smoothing->setCheckState(m_smoothSpectrogram ?
|
Chris@0
|
64 Qt::Checked : Qt::Unchecked);
|
Chris@0
|
65
|
Chris@0
|
66 connect(smoothing, SIGNAL(stateChanged(int)),
|
Chris@0
|
67 this, SLOT(smoothSpectrogramChanged(int)));
|
Chris@0
|
68
|
Chris@0
|
69 QComboBox *propertyLayout = new QComboBox;
|
Chris@0
|
70 int pl = prefs->getPropertyRangeAndValue("Property Box Layout", &min, &max);
|
Chris@0
|
71 m_propertyLayout = pl;
|
Chris@0
|
72
|
Chris@0
|
73 for (i = min; i <= max; ++i) {
|
Chris@0
|
74 propertyLayout->addItem(prefs->getPropertyValueLabel("Property Box Layout", i));
|
Chris@0
|
75 }
|
Chris@0
|
76
|
Chris@0
|
77 propertyLayout->setCurrentIndex(pl);
|
Chris@0
|
78
|
Chris@0
|
79 connect(propertyLayout, SIGNAL(currentIndexChanged(int)),
|
Chris@0
|
80 this, SLOT(propertyLayoutChanged(int)));
|
Chris@0
|
81
|
Chris@0
|
82 m_tuningFrequency = prefs->getTuningFrequency();
|
Chris@0
|
83
|
Chris@0
|
84 QDoubleSpinBox *frequency = new QDoubleSpinBox;
|
Chris@0
|
85 frequency->setMinimum(100.0);
|
Chris@0
|
86 frequency->setMaximum(5000.0);
|
Chris@0
|
87 frequency->setSuffix(" Hz");
|
Chris@0
|
88 frequency->setSingleStep(1);
|
Chris@0
|
89 frequency->setValue(m_tuningFrequency);
|
Chris@0
|
90 frequency->setDecimals(2);
|
Chris@0
|
91
|
Chris@0
|
92 connect(frequency, SIGNAL(valueChanged(double)),
|
Chris@0
|
93 this, SLOT(tuningFrequencyChanged(double)));
|
Chris@0
|
94
|
Chris@32
|
95 QComboBox *resampleQuality = new QComboBox;
|
Chris@32
|
96
|
Chris@32
|
97 int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max);
|
Chris@32
|
98 m_resampleQuality = rsq;
|
Chris@32
|
99
|
Chris@32
|
100 for (i = min; i <= max; ++i) {
|
Chris@32
|
101 resampleQuality->addItem(prefs->getPropertyValueLabel("Resample Quality", i));
|
Chris@32
|
102 }
|
Chris@32
|
103
|
Chris@32
|
104 resampleQuality->setCurrentIndex(rsq);
|
Chris@32
|
105
|
Chris@32
|
106 connect(resampleQuality, SIGNAL(currentIndexChanged(int)),
|
Chris@32
|
107 this, SLOT(resampleQualityChanged(int)));
|
Chris@32
|
108
|
Chris@0
|
109 int row = 0;
|
Chris@0
|
110
|
Chris@0
|
111 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@0
|
112 ("Property Box Layout"))),
|
Chris@0
|
113 row, 0);
|
Chris@0
|
114 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
|
Chris@0
|
115
|
Chris@0
|
116 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@0
|
117 ("Tuning Frequency"))),
|
Chris@0
|
118 row, 0);
|
Chris@0
|
119 subgrid->addWidget(frequency, row++, 1, 1, 2);
|
Chris@0
|
120
|
Chris@32
|
121 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@32
|
122 ("Resample Quality"))),
|
Chris@32
|
123 row, 0);
|
Chris@32
|
124 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
|
Chris@32
|
125
|
Chris@0
|
126 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
|
Chris@0
|
127 ("Smooth Spectrogram")),
|
Chris@0
|
128 row, 0, 1, 2);
|
Chris@0
|
129 subgrid->addWidget(smoothing, row++, 2);
|
Chris@0
|
130
|
Chris@0
|
131 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@0
|
132 ("Window Type"))),
|
Chris@0
|
133 row, 0);
|
Chris@9
|
134 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
|
Chris@9
|
135 subgrid->setRowStretch(row, 10);
|
Chris@9
|
136 row++;
|
Chris@0
|
137
|
Chris@0
|
138 QHBoxLayout *hbox = new QHBoxLayout;
|
Chris@0
|
139 grid->addLayout(hbox, 1, 0);
|
Chris@0
|
140
|
Chris@0
|
141 QPushButton *ok = new QPushButton(tr("OK"));
|
Chris@0
|
142 QPushButton *cancel = new QPushButton(tr("Cancel"));
|
Chris@0
|
143 hbox->addStretch(10);
|
Chris@0
|
144 hbox->addWidget(ok);
|
Chris@0
|
145 hbox->addWidget(m_applyButton);
|
Chris@0
|
146 hbox->addWidget(cancel);
|
Chris@0
|
147 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
|
Chris@0
|
148 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
|
Chris@0
|
149 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
|
Chris@0
|
150
|
Chris@0
|
151 m_applyButton->setEnabled(false);
|
Chris@0
|
152 }
|
Chris@0
|
153
|
Chris@0
|
154 PreferencesDialog::~PreferencesDialog()
|
Chris@0
|
155 {
|
Chris@0
|
156 std::cerr << "PreferencesDialog::~PreferencesDialog()" << std::endl;
|
Chris@0
|
157 }
|
Chris@0
|
158
|
Chris@0
|
159 void
|
Chris@9
|
160 PreferencesDialog::windowTypeChanged(WindowType type)
|
Chris@0
|
161 {
|
Chris@0
|
162 m_windowType = type;
|
Chris@0
|
163 m_applyButton->setEnabled(true);
|
Chris@0
|
164 }
|
Chris@0
|
165
|
Chris@0
|
166 void
|
Chris@0
|
167 PreferencesDialog::smoothSpectrogramChanged(int state)
|
Chris@0
|
168 {
|
Chris@0
|
169 m_smoothSpectrogram = (state == Qt::Checked);
|
Chris@0
|
170 m_applyButton->setEnabled(true);
|
Chris@0
|
171 }
|
Chris@0
|
172
|
Chris@0
|
173 void
|
Chris@0
|
174 PreferencesDialog::propertyLayoutChanged(int layout)
|
Chris@0
|
175 {
|
Chris@0
|
176 m_propertyLayout = layout;
|
Chris@0
|
177 m_applyButton->setEnabled(true);
|
Chris@0
|
178 }
|
Chris@0
|
179
|
Chris@0
|
180 void
|
Chris@0
|
181 PreferencesDialog::tuningFrequencyChanged(double freq)
|
Chris@0
|
182 {
|
Chris@0
|
183 m_tuningFrequency = freq;
|
Chris@0
|
184 m_applyButton->setEnabled(true);
|
Chris@0
|
185 }
|
Chris@0
|
186
|
Chris@0
|
187 void
|
Chris@32
|
188 PreferencesDialog::resampleQualityChanged(int q)
|
Chris@32
|
189 {
|
Chris@32
|
190 m_resampleQuality = q;
|
Chris@32
|
191 m_applyButton->setEnabled(true);
|
Chris@32
|
192 }
|
Chris@32
|
193
|
Chris@32
|
194 void
|
Chris@0
|
195 PreferencesDialog::okClicked()
|
Chris@0
|
196 {
|
Chris@0
|
197 applyClicked();
|
Chris@0
|
198 accept();
|
Chris@0
|
199 }
|
Chris@0
|
200
|
Chris@0
|
201 void
|
Chris@0
|
202 PreferencesDialog::applyClicked()
|
Chris@0
|
203 {
|
Chris@0
|
204 Preferences *prefs = Preferences::getInstance();
|
Chris@0
|
205 prefs->setWindowType(WindowType(m_windowType));
|
Chris@0
|
206 prefs->setSmoothSpectrogram(m_smoothSpectrogram);
|
Chris@0
|
207 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
|
Chris@0
|
208 (m_propertyLayout));
|
Chris@0
|
209 prefs->setTuningFrequency(m_tuningFrequency);
|
Chris@32
|
210 prefs->setResampleQuality(m_resampleQuality);
|
Chris@0
|
211 m_applyButton->setEnabled(false);
|
Chris@0
|
212 }
|
Chris@0
|
213
|
Chris@0
|
214 void
|
Chris@0
|
215 PreferencesDialog::cancelClicked()
|
Chris@0
|
216 {
|
Chris@0
|
217 reject();
|
Chris@0
|
218 }
|
Chris@0
|
219
|