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@163
|
27 #include <QDialogButtonBox>
|
Chris@163
|
28 #include <QMessageBox>
|
Chris@0
|
29
|
Chris@9
|
30 #include "widgets/WindowTypeSelector.h"
|
Chris@0
|
31 #include "base/Preferences.h"
|
Chris@0
|
32
|
Chris@0
|
33 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) :
|
Chris@0
|
34 QDialog(parent, flags)
|
Chris@0
|
35 {
|
Chris@163
|
36 setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
|
Chris@0
|
37
|
Chris@0
|
38 Preferences *prefs = Preferences::getInstance();
|
Chris@0
|
39
|
Chris@0
|
40 QGridLayout *grid = new QGridLayout;
|
Chris@0
|
41 setLayout(grid);
|
Chris@0
|
42
|
Chris@0
|
43 QGroupBox *groupBox = new QGroupBox;
|
Chris@163
|
44 groupBox->setTitle(tr("Application Preferences"));
|
Chris@0
|
45 grid->addWidget(groupBox, 0, 0);
|
Chris@0
|
46
|
Chris@0
|
47 QGridLayout *subgrid = new QGridLayout;
|
Chris@0
|
48 groupBox->setLayout(subgrid);
|
Chris@0
|
49
|
Chris@0
|
50 // Create this first, as slots that get called from the ctor will
|
Chris@0
|
51 // refer to it
|
Chris@0
|
52 m_applyButton = new QPushButton(tr("Apply"));
|
Chris@0
|
53
|
Chris@114
|
54 int min, max, deflt, i;
|
Chris@0
|
55
|
Chris@9
|
56 m_windowType = WindowType(prefs->getPropertyRangeAndValue
|
Chris@114
|
57 ("Window Type", &min, &max, &deflt));
|
Chris@9
|
58 m_windowTypeSelector = new WindowTypeSelector(m_windowType);
|
Chris@0
|
59
|
Chris@9
|
60 connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)),
|
Chris@9
|
61 this, SLOT(windowTypeChanged(WindowType)));
|
Chris@0
|
62
|
Chris@115
|
63 QComboBox *smoothing = new QComboBox;
|
Chris@115
|
64
|
Chris@115
|
65 int sm = prefs->getPropertyRangeAndValue("Spectrogram Smoothing", &min, &max,
|
Chris@115
|
66 &deflt);
|
Chris@115
|
67 m_spectrogramSmoothing = sm;
|
Chris@0
|
68
|
Chris@115
|
69 for (i = min; i <= max; ++i) {
|
Chris@115
|
70 smoothing->addItem(prefs->getPropertyValueLabel("Spectrogram Smoothing", i));
|
Chris@115
|
71 }
|
Chris@115
|
72
|
Chris@115
|
73 smoothing->setCurrentIndex(sm);
|
Chris@115
|
74
|
Chris@115
|
75 connect(smoothing, SIGNAL(currentIndexChanged(int)),
|
Chris@115
|
76 this, SLOT(spectrogramSmoothingChanged(int)));
|
Chris@0
|
77
|
Chris@0
|
78 QComboBox *propertyLayout = new QComboBox;
|
Chris@114
|
79 int pl = prefs->getPropertyRangeAndValue("Property Box Layout", &min, &max,
|
Chris@115
|
80 &deflt);
|
Chris@0
|
81 m_propertyLayout = pl;
|
Chris@0
|
82
|
Chris@0
|
83 for (i = min; i <= max; ++i) {
|
Chris@0
|
84 propertyLayout->addItem(prefs->getPropertyValueLabel("Property Box Layout", i));
|
Chris@0
|
85 }
|
Chris@0
|
86
|
Chris@0
|
87 propertyLayout->setCurrentIndex(pl);
|
Chris@0
|
88
|
Chris@0
|
89 connect(propertyLayout, SIGNAL(currentIndexChanged(int)),
|
Chris@0
|
90 this, SLOT(propertyLayoutChanged(int)));
|
Chris@0
|
91
|
Chris@0
|
92 m_tuningFrequency = prefs->getTuningFrequency();
|
Chris@0
|
93
|
Chris@0
|
94 QDoubleSpinBox *frequency = new QDoubleSpinBox;
|
Chris@0
|
95 frequency->setMinimum(100.0);
|
Chris@0
|
96 frequency->setMaximum(5000.0);
|
Chris@0
|
97 frequency->setSuffix(" Hz");
|
Chris@0
|
98 frequency->setSingleStep(1);
|
Chris@0
|
99 frequency->setValue(m_tuningFrequency);
|
Chris@0
|
100 frequency->setDecimals(2);
|
Chris@0
|
101
|
Chris@0
|
102 connect(frequency, SIGNAL(valueChanged(double)),
|
Chris@0
|
103 this, SLOT(tuningFrequencyChanged(double)));
|
Chris@0
|
104
|
Chris@32
|
105 QComboBox *resampleQuality = new QComboBox;
|
Chris@32
|
106
|
Chris@114
|
107 int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max,
|
Chris@114
|
108 &deflt);
|
Chris@32
|
109 m_resampleQuality = rsq;
|
Chris@32
|
110
|
Chris@32
|
111 for (i = min; i <= max; ++i) {
|
Chris@32
|
112 resampleQuality->addItem(prefs->getPropertyValueLabel("Resample Quality", i));
|
Chris@32
|
113 }
|
Chris@32
|
114
|
Chris@32
|
115 resampleQuality->setCurrentIndex(rsq);
|
Chris@32
|
116
|
Chris@32
|
117 connect(resampleQuality, SIGNAL(currentIndexChanged(int)),
|
Chris@32
|
118 this, SLOT(resampleQualityChanged(int)));
|
Chris@32
|
119
|
Chris@0
|
120 int row = 0;
|
Chris@0
|
121
|
Chris@0
|
122 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@0
|
123 ("Property Box Layout"))),
|
Chris@0
|
124 row, 0);
|
Chris@0
|
125 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
|
Chris@0
|
126
|
Chris@0
|
127 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@0
|
128 ("Tuning Frequency"))),
|
Chris@0
|
129 row, 0);
|
Chris@0
|
130 subgrid->addWidget(frequency, row++, 1, 1, 2);
|
Chris@0
|
131
|
Chris@32
|
132 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@32
|
133 ("Resample Quality"))),
|
Chris@32
|
134 row, 0);
|
Chris@32
|
135 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
|
Chris@32
|
136
|
Chris@0
|
137 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
|
Chris@115
|
138 ("Spectrogram Smoothing")),
|
Chris@115
|
139 row, 0);
|
Chris@115
|
140 subgrid->addWidget(smoothing, row++, 1, 1, 2);
|
Chris@0
|
141
|
Chris@0
|
142 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@0
|
143 ("Window Type"))),
|
Chris@0
|
144 row, 0);
|
Chris@9
|
145 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
|
Chris@9
|
146 subgrid->setRowStretch(row, 10);
|
Chris@9
|
147 row++;
|
Chris@0
|
148
|
Chris@163
|
149 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
|
Chris@163
|
150 grid->addWidget(bb, 1, 0);
|
Chris@0
|
151
|
Chris@0
|
152 QPushButton *ok = new QPushButton(tr("OK"));
|
Chris@0
|
153 QPushButton *cancel = new QPushButton(tr("Cancel"));
|
Chris@163
|
154 bb->addButton(ok, QDialogButtonBox::AcceptRole);
|
Chris@163
|
155 bb->addButton(m_applyButton, QDialogButtonBox::ApplyRole);
|
Chris@163
|
156 bb->addButton(cancel, QDialogButtonBox::RejectRole);
|
Chris@0
|
157 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
|
Chris@0
|
158 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
|
Chris@0
|
159 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
|
Chris@0
|
160
|
Chris@0
|
161 m_applyButton->setEnabled(false);
|
Chris@0
|
162 }
|
Chris@0
|
163
|
Chris@0
|
164 PreferencesDialog::~PreferencesDialog()
|
Chris@0
|
165 {
|
Chris@0
|
166 std::cerr << "PreferencesDialog::~PreferencesDialog()" << std::endl;
|
Chris@0
|
167 }
|
Chris@0
|
168
|
Chris@0
|
169 void
|
Chris@9
|
170 PreferencesDialog::windowTypeChanged(WindowType type)
|
Chris@0
|
171 {
|
Chris@0
|
172 m_windowType = type;
|
Chris@0
|
173 m_applyButton->setEnabled(true);
|
Chris@0
|
174 }
|
Chris@0
|
175
|
Chris@0
|
176 void
|
Chris@115
|
177 PreferencesDialog::spectrogramSmoothingChanged(int smoothing)
|
Chris@0
|
178 {
|
Chris@115
|
179 m_spectrogramSmoothing = smoothing;
|
Chris@0
|
180 m_applyButton->setEnabled(true);
|
Chris@0
|
181 }
|
Chris@0
|
182
|
Chris@0
|
183 void
|
Chris@0
|
184 PreferencesDialog::propertyLayoutChanged(int layout)
|
Chris@0
|
185 {
|
Chris@0
|
186 m_propertyLayout = layout;
|
Chris@0
|
187 m_applyButton->setEnabled(true);
|
Chris@0
|
188 }
|
Chris@0
|
189
|
Chris@0
|
190 void
|
Chris@0
|
191 PreferencesDialog::tuningFrequencyChanged(double freq)
|
Chris@0
|
192 {
|
Chris@0
|
193 m_tuningFrequency = freq;
|
Chris@0
|
194 m_applyButton->setEnabled(true);
|
Chris@0
|
195 }
|
Chris@0
|
196
|
Chris@0
|
197 void
|
Chris@32
|
198 PreferencesDialog::resampleQualityChanged(int q)
|
Chris@32
|
199 {
|
Chris@32
|
200 m_resampleQuality = q;
|
Chris@32
|
201 m_applyButton->setEnabled(true);
|
Chris@32
|
202 }
|
Chris@32
|
203
|
Chris@32
|
204 void
|
Chris@0
|
205 PreferencesDialog::okClicked()
|
Chris@0
|
206 {
|
Chris@0
|
207 applyClicked();
|
Chris@0
|
208 accept();
|
Chris@0
|
209 }
|
Chris@0
|
210
|
Chris@0
|
211 void
|
Chris@0
|
212 PreferencesDialog::applyClicked()
|
Chris@0
|
213 {
|
Chris@0
|
214 Preferences *prefs = Preferences::getInstance();
|
Chris@0
|
215 prefs->setWindowType(WindowType(m_windowType));
|
Chris@115
|
216 prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing
|
Chris@115
|
217 (m_spectrogramSmoothing));
|
Chris@0
|
218 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
|
Chris@0
|
219 (m_propertyLayout));
|
Chris@0
|
220 prefs->setTuningFrequency(m_tuningFrequency);
|
Chris@32
|
221 prefs->setResampleQuality(m_resampleQuality);
|
Chris@0
|
222 m_applyButton->setEnabled(false);
|
Chris@0
|
223 }
|
Chris@0
|
224
|
Chris@0
|
225 void
|
Chris@0
|
226 PreferencesDialog::cancelClicked()
|
Chris@0
|
227 {
|
Chris@0
|
228 reject();
|
Chris@0
|
229 }
|
Chris@0
|
230
|
Chris@163
|
231 void
|
Chris@163
|
232 PreferencesDialog::applicationClosing(bool quickly)
|
Chris@163
|
233 {
|
Chris@163
|
234 if (quickly) {
|
Chris@163
|
235 reject();
|
Chris@163
|
236 return;
|
Chris@163
|
237 }
|
Chris@163
|
238
|
Chris@163
|
239 if (m_applyButton->isEnabled()) {
|
Chris@163
|
240 int rv = QMessageBox::warning
|
Chris@163
|
241 (this, tr("Preferences Changed"),
|
Chris@163
|
242 tr("Some preferences have been changed but not applied.\n"
|
Chris@163
|
243 "Apply them before closing?"),
|
Chris@163
|
244 QMessageBox::Apply | QMessageBox::Discard,
|
Chris@163
|
245 QMessageBox::Discard);
|
Chris@163
|
246 if (rv == QMessageBox::Apply) {
|
Chris@163
|
247 applyClicked();
|
Chris@163
|
248 accept();
|
Chris@163
|
249 } else {
|
Chris@163
|
250 reject();
|
Chris@163
|
251 }
|
Chris@163
|
252 } else {
|
Chris@163
|
253 accept();
|
Chris@163
|
254 }
|
Chris@163
|
255 }
|
Chris@163
|
256
|