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@180
|
29 #include <QTabWidget>
|
Chris@180
|
30 #include <QLineEdit>
|
Chris@180
|
31 #include <QFileDialog>
|
Chris@180
|
32 #include <QMessageBox>
|
Chris@225
|
33 #include <QSpinBox>
|
Chris@436
|
34 #include <QListWidget>
|
Chris@263
|
35 #include <QSettings>
|
Chris@0
|
36
|
Chris@436
|
37 #include <set>
|
Chris@436
|
38
|
Chris@9
|
39 #include "widgets/WindowTypeSelector.h"
|
Chris@180
|
40 #include "widgets/IconLoader.h"
|
Chris@0
|
41 #include "base/Preferences.h"
|
Chris@263
|
42 #include "audioio/AudioTargetFactory.h"
|
Chris@436
|
43 #include "base/ResourceFinder.h"
|
Chris@0
|
44
|
Chris@528
|
45 PreferencesDialog::PreferencesDialog(QWidget *parent) :
|
Chris@528
|
46 QDialog(parent),
|
Chris@263
|
47 m_audioDevice(0),
|
Chris@180
|
48 m_changesOnRestart(false)
|
Chris@0
|
49 {
|
Chris@163
|
50 setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
|
Chris@0
|
51
|
Chris@0
|
52 Preferences *prefs = Preferences::getInstance();
|
Chris@0
|
53
|
Chris@0
|
54 QGridLayout *grid = new QGridLayout;
|
Chris@0
|
55 setLayout(grid);
|
Chris@180
|
56
|
Chris@436
|
57 m_tabs = new QTabWidget;
|
Chris@436
|
58 grid->addWidget(m_tabs, 0, 0);
|
Chris@0
|
59
|
Chris@436
|
60 m_tabs->setTabPosition(QTabWidget::North);
|
Chris@0
|
61
|
Chris@0
|
62 // Create this first, as slots that get called from the ctor will
|
Chris@0
|
63 // refer to it
|
Chris@0
|
64 m_applyButton = new QPushButton(tr("Apply"));
|
Chris@0
|
65
|
Chris@180
|
66 // Create all the preference widgets first, then create the
|
Chris@180
|
67 // individual tab widgets and place the preferences in their
|
Chris@180
|
68 // appropriate places in one go afterwards
|
Chris@180
|
69
|
Chris@114
|
70 int min, max, deflt, i;
|
Chris@0
|
71
|
Chris@9
|
72 m_windowType = WindowType(prefs->getPropertyRangeAndValue
|
Chris@114
|
73 ("Window Type", &min, &max, &deflt));
|
Chris@9
|
74 m_windowTypeSelector = new WindowTypeSelector(m_windowType);
|
Chris@0
|
75
|
Chris@9
|
76 connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)),
|
Chris@9
|
77 this, SLOT(windowTypeChanged(WindowType)));
|
Chris@0
|
78
|
Chris@115
|
79 QComboBox *smoothing = new QComboBox;
|
Chris@115
|
80
|
Chris@299
|
81 int sm = prefs->getPropertyRangeAndValue("Spectrogram Y Smoothing", &min, &max,
|
Chris@115
|
82 &deflt);
|
Chris@115
|
83 m_spectrogramSmoothing = sm;
|
Chris@0
|
84
|
Chris@115
|
85 for (i = min; i <= max; ++i) {
|
Chris@299
|
86 smoothing->addItem(prefs->getPropertyValueLabel("Spectrogram Y Smoothing", i));
|
Chris@115
|
87 }
|
Chris@115
|
88
|
Chris@115
|
89 smoothing->setCurrentIndex(sm);
|
Chris@115
|
90
|
Chris@115
|
91 connect(smoothing, SIGNAL(currentIndexChanged(int)),
|
Chris@115
|
92 this, SLOT(spectrogramSmoothingChanged(int)));
|
Chris@0
|
93
|
Chris@299
|
94 QComboBox *xsmoothing = new QComboBox;
|
Chris@299
|
95
|
Chris@299
|
96 int xsm = prefs->getPropertyRangeAndValue("Spectrogram X Smoothing", &min, &max,
|
Chris@299
|
97 &deflt);
|
Chris@299
|
98 m_spectrogramXSmoothing = xsm;
|
Chris@299
|
99
|
Chris@299
|
100 for (i = min; i <= max; ++i) {
|
Chris@299
|
101 xsmoothing->addItem(prefs->getPropertyValueLabel("Spectrogram X Smoothing", i));
|
Chris@299
|
102 }
|
Chris@299
|
103
|
Chris@299
|
104 xsmoothing->setCurrentIndex(xsm);
|
Chris@299
|
105
|
Chris@299
|
106 connect(xsmoothing, SIGNAL(currentIndexChanged(int)),
|
Chris@299
|
107 this, SLOT(spectrogramXSmoothingChanged(int)));
|
Chris@299
|
108
|
Chris@0
|
109 QComboBox *propertyLayout = new QComboBox;
|
Chris@114
|
110 int pl = prefs->getPropertyRangeAndValue("Property Box Layout", &min, &max,
|
Chris@115
|
111 &deflt);
|
Chris@0
|
112 m_propertyLayout = pl;
|
Chris@0
|
113
|
Chris@0
|
114 for (i = min; i <= max; ++i) {
|
Chris@0
|
115 propertyLayout->addItem(prefs->getPropertyValueLabel("Property Box Layout", i));
|
Chris@0
|
116 }
|
Chris@0
|
117
|
Chris@0
|
118 propertyLayout->setCurrentIndex(pl);
|
Chris@0
|
119
|
Chris@0
|
120 connect(propertyLayout, SIGNAL(currentIndexChanged(int)),
|
Chris@0
|
121 this, SLOT(propertyLayoutChanged(int)));
|
Chris@0
|
122
|
Chris@0
|
123 m_tuningFrequency = prefs->getTuningFrequency();
|
Chris@0
|
124
|
Chris@0
|
125 QDoubleSpinBox *frequency = new QDoubleSpinBox;
|
Chris@0
|
126 frequency->setMinimum(100.0);
|
Chris@0
|
127 frequency->setMaximum(5000.0);
|
Chris@0
|
128 frequency->setSuffix(" Hz");
|
Chris@0
|
129 frequency->setSingleStep(1);
|
Chris@0
|
130 frequency->setValue(m_tuningFrequency);
|
Chris@0
|
131 frequency->setDecimals(2);
|
Chris@0
|
132
|
Chris@0
|
133 connect(frequency, SIGNAL(valueChanged(double)),
|
Chris@0
|
134 this, SLOT(tuningFrequencyChanged(double)));
|
Chris@0
|
135
|
Chris@263
|
136 QComboBox *audioDevice = new QComboBox;
|
Chris@263
|
137 std::vector<QString> devices =
|
Chris@263
|
138 AudioTargetFactory::getInstance()->getCallbackTargetNames();
|
Chris@263
|
139
|
Chris@263
|
140 QSettings settings;
|
Chris@263
|
141 settings.beginGroup("Preferences");
|
Chris@263
|
142 QString targetName = settings.value("audio-target", "").toString();
|
Chris@263
|
143 settings.endGroup();
|
Chris@263
|
144
|
Chris@658
|
145 for (int i = 0; i < (int)devices.size(); ++i) {
|
Chris@263
|
146 audioDevice->addItem(AudioTargetFactory::getInstance()
|
Chris@263
|
147 ->getCallbackTargetDescription(devices[i]));
|
Chris@263
|
148 if (targetName == devices[i]) audioDevice->setCurrentIndex(i);
|
Chris@263
|
149 }
|
Chris@263
|
150
|
Chris@263
|
151 connect(audioDevice, SIGNAL(currentIndexChanged(int)),
|
Chris@263
|
152 this, SLOT(audioDeviceChanged(int)));
|
Chris@263
|
153
|
Chris@32
|
154 QComboBox *resampleQuality = new QComboBox;
|
Chris@32
|
155
|
Chris@114
|
156 int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max,
|
Chris@114
|
157 &deflt);
|
Chris@32
|
158 m_resampleQuality = rsq;
|
Chris@32
|
159
|
Chris@32
|
160 for (i = min; i <= max; ++i) {
|
Chris@32
|
161 resampleQuality->addItem(prefs->getPropertyValueLabel("Resample Quality", i));
|
Chris@32
|
162 }
|
Chris@32
|
163
|
Chris@32
|
164 resampleQuality->setCurrentIndex(rsq);
|
Chris@32
|
165
|
Chris@32
|
166 connect(resampleQuality, SIGNAL(currentIndexChanged(int)),
|
Chris@32
|
167 this, SLOT(resampleQualityChanged(int)));
|
Chris@32
|
168
|
Chris@180
|
169 QCheckBox *resampleOnLoad = new QCheckBox;
|
Chris@180
|
170 m_resampleOnLoad = prefs->getResampleOnLoad();
|
Chris@180
|
171 resampleOnLoad->setCheckState(m_resampleOnLoad ? Qt::Checked :
|
Chris@180
|
172 Qt::Unchecked);
|
Chris@180
|
173 connect(resampleOnLoad, SIGNAL(stateChanged(int)),
|
Chris@180
|
174 this, SLOT(resampleOnLoadChanged(int)));
|
Chris@180
|
175
|
Chris@180
|
176 m_tempDirRootEdit = new QLineEdit;
|
Chris@180
|
177 QString dir = prefs->getTemporaryDirectoryRoot();
|
Chris@180
|
178 m_tempDirRoot = dir;
|
Chris@180
|
179 dir.replace("$HOME", tr("<home directory>"));
|
Chris@180
|
180 m_tempDirRootEdit->setText(dir);
|
Chris@180
|
181 m_tempDirRootEdit->setReadOnly(true);
|
Chris@180
|
182 QPushButton *tempDirButton = new QPushButton;
|
Chris@180
|
183 tempDirButton->setIcon(IconLoader().load("fileopen"));
|
Chris@180
|
184 connect(tempDirButton, SIGNAL(clicked()),
|
Chris@180
|
185 this, SLOT(tempDirButtonClicked()));
|
Chris@180
|
186 tempDirButton->setFixedSize(QSize(24, 24));
|
Chris@180
|
187
|
Chris@237
|
188 QCheckBox *showSplash = new QCheckBox;
|
Chris@237
|
189 m_showSplash = prefs->getShowSplash();
|
Chris@237
|
190 showSplash->setCheckState(m_showSplash ? Qt::Checked : Qt::Unchecked);
|
Chris@237
|
191 connect(showSplash, SIGNAL(stateChanged(int)),
|
Chris@237
|
192 this, SLOT(showSplashChanged(int)));
|
Chris@237
|
193
|
Chris@661
|
194 #ifndef Q_OS_MAC
|
Chris@180
|
195 QComboBox *bgMode = new QComboBox;
|
Chris@180
|
196 int bg = prefs->getPropertyRangeAndValue("Background Mode", &min, &max,
|
Chris@180
|
197 &deflt);
|
Chris@180
|
198 m_backgroundMode = bg;
|
Chris@180
|
199 for (i = min; i <= max; ++i) {
|
Chris@180
|
200 bgMode->addItem(prefs->getPropertyValueLabel("Background Mode", i));
|
Chris@180
|
201 }
|
Chris@180
|
202 bgMode->setCurrentIndex(bg);
|
Chris@180
|
203
|
Chris@180
|
204 connect(bgMode, SIGNAL(currentIndexChanged(int)),
|
Chris@180
|
205 this, SLOT(backgroundModeChanged(int)));
|
Chris@237
|
206 #endif
|
Chris@180
|
207
|
Chris@658
|
208 settings.beginGroup("Preferences");
|
Chris@658
|
209 QString userLocale = settings.value("locale", "").toString();
|
Chris@658
|
210 m_currentLocale = userLocale;
|
Chris@658
|
211 settings.endGroup();
|
Chris@658
|
212
|
Chris@658
|
213 QComboBox *locale = new QComboBox;
|
Chris@658
|
214 QStringList localeFiles = QDir(":i18n").entryList(QStringList() << "*.qm");
|
Chris@658
|
215 locale->addItem(tr("Follow system locale"));
|
Chris@658
|
216 m_locales.push_back("");
|
Chris@658
|
217 if (userLocale == "") {
|
Chris@658
|
218 locale->setCurrentIndex(0);
|
Chris@658
|
219 }
|
Chris@658
|
220 foreach (QString f, localeFiles) {
|
Chris@658
|
221 QString f0 = f;
|
Chris@658
|
222 f.replace("sonic-visualiser_", "").replace(".qm", "");
|
Chris@658
|
223 if (f == f0) { // our expectations about filename format were not met
|
Chris@658
|
224 std::cerr << "INFO: Unexpected filename " << f << " in i18n resource directory" << std::endl;
|
Chris@658
|
225 } else {
|
Chris@658
|
226 m_locales.push_back(f);
|
Chris@658
|
227 QString displayText;
|
Chris@658
|
228 // Add new translations here
|
Chris@658
|
229 if (f == "ru") displayText = tr("Russian");
|
Chris@658
|
230 else if (f == "en_GB") displayText = tr("British English");
|
Chris@658
|
231 else if (f == "en_US") displayText = tr("American English");
|
Chris@658
|
232 else if (f == "cs_CZ") displayText = tr("Czech");
|
Chris@658
|
233 else displayText = f;
|
Chris@658
|
234 locale->addItem(QString("%1 [%2]").arg(displayText).arg(f));
|
Chris@658
|
235 if (userLocale == f) {
|
Chris@658
|
236 locale->setCurrentIndex(locale->count() - 1);
|
Chris@658
|
237 }
|
Chris@658
|
238 }
|
Chris@658
|
239 }
|
Chris@658
|
240 connect(locale, SIGNAL(currentIndexChanged(int)),
|
Chris@658
|
241 this, SLOT(localeChanged(int)));
|
Chris@658
|
242
|
Chris@225
|
243 QSpinBox *fontSize = new QSpinBox;
|
Chris@225
|
244 int fs = prefs->getPropertyRangeAndValue("View Font Size", &min, &max,
|
Chris@225
|
245 &deflt);
|
Chris@234
|
246 m_viewFontSize = fs;
|
Chris@225
|
247 fontSize->setMinimum(min);
|
Chris@225
|
248 fontSize->setMaximum(max);
|
Chris@225
|
249 fontSize->setSuffix(" pt");
|
Chris@225
|
250 fontSize->setSingleStep(1);
|
Chris@225
|
251 fontSize->setValue(fs);
|
Chris@225
|
252
|
Chris@225
|
253 connect(fontSize, SIGNAL(valueChanged(int)),
|
Chris@225
|
254 this, SLOT(viewFontSizeChanged(int)));
|
Chris@225
|
255
|
Chris@337
|
256 QComboBox *ttMode = new QComboBox;
|
Chris@337
|
257 int tt = prefs->getPropertyRangeAndValue("Time To Text Mode", &min, &max,
|
Chris@337
|
258 &deflt);
|
Chris@337
|
259 m_timeToTextMode = tt;
|
Chris@337
|
260 for (i = min; i <= max; ++i) {
|
Chris@337
|
261 ttMode->addItem(prefs->getPropertyValueLabel("Time To Text Mode", i));
|
Chris@337
|
262 }
|
Chris@337
|
263 ttMode->setCurrentIndex(tt);
|
Chris@337
|
264
|
Chris@337
|
265 connect(ttMode, SIGNAL(currentIndexChanged(int)),
|
Chris@337
|
266 this, SLOT(timeToTextModeChanged(int)));
|
Chris@337
|
267
|
Chris@180
|
268 // General tab
|
Chris@180
|
269
|
Chris@180
|
270 QFrame *frame = new QFrame;
|
Chris@180
|
271
|
Chris@180
|
272 QGridLayout *subgrid = new QGridLayout;
|
Chris@180
|
273 frame->setLayout(subgrid);
|
Chris@180
|
274
|
Chris@0
|
275 int row = 0;
|
Chris@0
|
276
|
Chris@658
|
277 subgrid->addWidget(new QLabel(tr("%1:").arg(tr("User interface language"))),
|
Chris@658
|
278 row, 0);
|
Chris@658
|
279 subgrid->addWidget(locale, row++, 1, 1, 1);
|
Chris@658
|
280
|
Chris@0
|
281 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@263
|
282 ("Temporary Directory Root"))),
|
Chris@263
|
283 row, 0);
|
Chris@263
|
284 subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
|
Chris@263
|
285 subgrid->addWidget(tempDirButton, row, 2, 1, 1);
|
Chris@263
|
286 row++;
|
Chris@263
|
287
|
Chris@263
|
288 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@263
|
289 ("Resample On Load"))),
|
Chris@263
|
290 row, 0);
|
Chris@263
|
291 subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1);
|
Chris@263
|
292
|
Chris@263
|
293 subgrid->addWidget(new QLabel(tr("Playback audio device:")), row, 0);
|
Chris@263
|
294 subgrid->addWidget(audioDevice, row++, 1, 1, 2);
|
Chris@263
|
295
|
Chris@263
|
296 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@263
|
297 ("Resample Quality"))),
|
Chris@263
|
298 row, 0);
|
Chris@263
|
299 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
|
Chris@263
|
300
|
Chris@263
|
301 subgrid->setRowStretch(row, 10);
|
Chris@263
|
302
|
Chris@436
|
303 m_tabOrdering[GeneralTab] = m_tabs->count();
|
Chris@436
|
304 m_tabs->addTab(frame, tr("&General"));
|
Chris@263
|
305
|
Chris@263
|
306 // Appearance tab
|
Chris@263
|
307
|
Chris@263
|
308 frame = new QFrame;
|
Chris@263
|
309 subgrid = new QGridLayout;
|
Chris@263
|
310 frame->setLayout(subgrid);
|
Chris@263
|
311 row = 0;
|
Chris@263
|
312
|
Chris@263
|
313 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@0
|
314 ("Property Box Layout"))),
|
Chris@0
|
315 row, 0);
|
Chris@0
|
316 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
|
Chris@0
|
317
|
Chris@661
|
318 #ifndef Q_OS_MAC
|
Chris@0
|
319 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@180
|
320 ("Background Mode"))),
|
Chris@0
|
321 row, 0);
|
Chris@180
|
322 subgrid->addWidget(bgMode, row++, 1, 1, 2);
|
Chris@242
|
323 #endif
|
Chris@180
|
324
|
Chris@180
|
325 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@225
|
326 ("View Font Size"))),
|
Chris@225
|
327 row, 0);
|
Chris@225
|
328 subgrid->addWidget(fontSize, row++, 1, 1, 2);
|
Chris@225
|
329
|
Chris@225
|
330 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@337
|
331 ("Time To Text Mode"))),
|
Chris@337
|
332 row, 0);
|
Chris@337
|
333 subgrid->addWidget(ttMode, row++, 1, 1, 2);
|
Chris@337
|
334
|
Chris@337
|
335 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@237
|
336 ("Show Splash Screen"))),
|
Chris@237
|
337 row, 0);
|
Chris@237
|
338 subgrid->addWidget(showSplash, row++, 1, 1, 1);
|
Chris@237
|
339
|
Chris@180
|
340 subgrid->setRowStretch(row, 10);
|
Chris@180
|
341
|
Chris@436
|
342 m_tabOrdering[AppearanceTab] = m_tabs->count();
|
Chris@436
|
343 m_tabs->addTab(frame, tr("&Appearance"));
|
Chris@180
|
344
|
Chris@180
|
345 // Analysis tab
|
Chris@180
|
346
|
Chris@180
|
347 frame = new QFrame;
|
Chris@180
|
348 subgrid = new QGridLayout;
|
Chris@180
|
349 frame->setLayout(subgrid);
|
Chris@180
|
350 row = 0;
|
Chris@180
|
351
|
Chris@180
|
352 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@180
|
353 ("Tuning Frequency"))),
|
Chris@180
|
354 row, 0);
|
Chris@180
|
355 subgrid->addWidget(frequency, row++, 1, 1, 2);
|
Chris@180
|
356
|
Chris@0
|
357 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
|
Chris@299
|
358 ("Spectrogram Y Smoothing")),
|
Chris@115
|
359 row, 0);
|
Chris@115
|
360 subgrid->addWidget(smoothing, row++, 1, 1, 2);
|
Chris@0
|
361
|
Chris@299
|
362 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
|
Chris@299
|
363 ("Spectrogram X Smoothing")),
|
Chris@299
|
364 row, 0);
|
Chris@299
|
365 subgrid->addWidget(xsmoothing, row++, 1, 1, 2);
|
Chris@299
|
366
|
Chris@0
|
367 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
|
Chris@0
|
368 ("Window Type"))),
|
Chris@0
|
369 row, 0);
|
Chris@9
|
370 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
|
Chris@9
|
371 subgrid->setRowStretch(row, 10);
|
Chris@9
|
372 row++;
|
Chris@0
|
373
|
Chris@180
|
374 subgrid->setRowStretch(row, 10);
|
Chris@180
|
375
|
Chris@436
|
376 m_tabOrdering[AnalysisTab] = m_tabs->count();
|
Chris@436
|
377 m_tabs->addTab(frame, tr("Anal&ysis"));
|
Chris@436
|
378
|
Chris@436
|
379 // Template tab
|
Chris@436
|
380
|
Chris@436
|
381 frame = new QFrame;
|
Chris@436
|
382 subgrid = new QGridLayout;
|
Chris@436
|
383 frame->setLayout(subgrid);
|
Chris@436
|
384 row = 0;
|
Chris@436
|
385
|
Chris@436
|
386 subgrid->addWidget(new QLabel(tr("Default session template for audio files:")), row++, 0);
|
Chris@436
|
387
|
Chris@436
|
388 QListWidget *lw = new QListWidget();
|
Chris@436
|
389 subgrid->addWidget(lw, row, 0);
|
Chris@436
|
390 subgrid->setRowStretch(row, 10);
|
Chris@436
|
391 row++;
|
Chris@436
|
392
|
Chris@436
|
393 settings.beginGroup("MainWindow");
|
Chris@436
|
394 m_currentTemplate = settings.value("sessiontemplate", "").toString();
|
Chris@436
|
395 settings.endGroup();
|
Chris@436
|
396
|
Chris@455
|
397 lw->addItem(tr("Standard Waveform"));
|
Chris@436
|
398 if (m_currentTemplate == "" || m_currentTemplate == "default") {
|
Chris@436
|
399 lw->setCurrentRow(lw->count()-1);
|
Chris@436
|
400 }
|
Chris@436
|
401 m_templates.push_back("");
|
Chris@436
|
402
|
Chris@436
|
403 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
|
Chris@436
|
404
|
Chris@436
|
405 std::set<QString> byName;
|
Chris@436
|
406 foreach (QString t, templates) {
|
Chris@436
|
407 byName.insert(QFileInfo(t).baseName());
|
Chris@436
|
408 }
|
Chris@436
|
409
|
Chris@436
|
410 foreach (QString t, byName) {
|
Chris@436
|
411 if (t.toLower() == "default") continue;
|
Chris@436
|
412 m_templates.push_back(t);
|
Chris@436
|
413 lw->addItem(t);
|
Chris@436
|
414 if (m_currentTemplate == t) {
|
Chris@436
|
415 lw->setCurrentRow(lw->count()-1);
|
Chris@436
|
416 }
|
Chris@436
|
417 }
|
Chris@436
|
418
|
Chris@436
|
419 connect(lw, SIGNAL(currentRowChanged(int)), this, SLOT(defaultTemplateChanged(int)));
|
Chris@436
|
420
|
Chris@436
|
421 m_tabOrdering[TemplateTab] = m_tabs->count();
|
Chris@436
|
422 m_tabs->addTab(frame, tr("Session &Template"));
|
Chris@180
|
423
|
Chris@163
|
424 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
|
Chris@163
|
425 grid->addWidget(bb, 1, 0);
|
Chris@0
|
426
|
Chris@0
|
427 QPushButton *ok = new QPushButton(tr("OK"));
|
Chris@0
|
428 QPushButton *cancel = new QPushButton(tr("Cancel"));
|
Chris@163
|
429 bb->addButton(ok, QDialogButtonBox::AcceptRole);
|
Chris@163
|
430 bb->addButton(m_applyButton, QDialogButtonBox::ApplyRole);
|
Chris@163
|
431 bb->addButton(cancel, QDialogButtonBox::RejectRole);
|
Chris@0
|
432 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
|
Chris@0
|
433 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
|
Chris@0
|
434 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
|
Chris@0
|
435
|
Chris@0
|
436 m_applyButton->setEnabled(false);
|
Chris@0
|
437 }
|
Chris@0
|
438
|
Chris@0
|
439 PreferencesDialog::~PreferencesDialog()
|
Chris@0
|
440 {
|
Chris@438
|
441 SVDEBUG << "PreferencesDialog::~PreferencesDialog()" << endl;
|
Chris@0
|
442 }
|
Chris@0
|
443
|
Chris@0
|
444 void
|
Chris@436
|
445 PreferencesDialog::switchToTab(Tab t)
|
Chris@436
|
446 {
|
Chris@436
|
447 if (m_tabOrdering.contains(t)) {
|
Chris@436
|
448 m_tabs->setCurrentIndex(m_tabOrdering[t]);
|
Chris@436
|
449 }
|
Chris@436
|
450 }
|
Chris@436
|
451
|
Chris@436
|
452 void
|
Chris@9
|
453 PreferencesDialog::windowTypeChanged(WindowType type)
|
Chris@0
|
454 {
|
Chris@0
|
455 m_windowType = type;
|
Chris@0
|
456 m_applyButton->setEnabled(true);
|
Chris@0
|
457 }
|
Chris@0
|
458
|
Chris@0
|
459 void
|
Chris@115
|
460 PreferencesDialog::spectrogramSmoothingChanged(int smoothing)
|
Chris@0
|
461 {
|
Chris@115
|
462 m_spectrogramSmoothing = smoothing;
|
Chris@0
|
463 m_applyButton->setEnabled(true);
|
Chris@0
|
464 }
|
Chris@0
|
465
|
Chris@0
|
466 void
|
Chris@299
|
467 PreferencesDialog::spectrogramXSmoothingChanged(int smoothing)
|
Chris@299
|
468 {
|
Chris@299
|
469 m_spectrogramXSmoothing = smoothing;
|
Chris@299
|
470 m_applyButton->setEnabled(true);
|
Chris@299
|
471 }
|
Chris@299
|
472
|
Chris@299
|
473 void
|
Chris@0
|
474 PreferencesDialog::propertyLayoutChanged(int layout)
|
Chris@0
|
475 {
|
Chris@0
|
476 m_propertyLayout = layout;
|
Chris@0
|
477 m_applyButton->setEnabled(true);
|
Chris@0
|
478 }
|
Chris@0
|
479
|
Chris@0
|
480 void
|
Chris@0
|
481 PreferencesDialog::tuningFrequencyChanged(double freq)
|
Chris@0
|
482 {
|
Chris@0
|
483 m_tuningFrequency = freq;
|
Chris@0
|
484 m_applyButton->setEnabled(true);
|
Chris@0
|
485 }
|
Chris@0
|
486
|
Chris@0
|
487 void
|
Chris@263
|
488 PreferencesDialog::audioDeviceChanged(int s)
|
Chris@263
|
489 {
|
Chris@263
|
490 m_audioDevice = s;
|
Chris@263
|
491 m_applyButton->setEnabled(true);
|
Chris@263
|
492 m_changesOnRestart = true;
|
Chris@263
|
493 }
|
Chris@263
|
494
|
Chris@263
|
495 void
|
Chris@32
|
496 PreferencesDialog::resampleQualityChanged(int q)
|
Chris@32
|
497 {
|
Chris@32
|
498 m_resampleQuality = q;
|
Chris@32
|
499 m_applyButton->setEnabled(true);
|
Chris@32
|
500 }
|
Chris@32
|
501
|
Chris@32
|
502 void
|
Chris@180
|
503 PreferencesDialog::resampleOnLoadChanged(int state)
|
Chris@180
|
504 {
|
Chris@180
|
505 m_resampleOnLoad = (state == Qt::Checked);
|
Chris@180
|
506 m_applyButton->setEnabled(true);
|
Chris@180
|
507 m_changesOnRestart = true;
|
Chris@180
|
508 }
|
Chris@180
|
509
|
Chris@180
|
510 void
|
Chris@237
|
511 PreferencesDialog::showSplashChanged(int state)
|
Chris@237
|
512 {
|
Chris@237
|
513 m_showSplash = (state == Qt::Checked);
|
Chris@237
|
514 m_applyButton->setEnabled(true);
|
Chris@237
|
515 m_changesOnRestart = true;
|
Chris@237
|
516 }
|
Chris@237
|
517
|
Chris@237
|
518 void
|
Chris@436
|
519 PreferencesDialog::defaultTemplateChanged(int i)
|
Chris@436
|
520 {
|
Chris@436
|
521 m_currentTemplate = m_templates[i];
|
Chris@436
|
522 m_applyButton->setEnabled(true);
|
Chris@436
|
523 }
|
Chris@436
|
524
|
Chris@436
|
525 void
|
Chris@658
|
526 PreferencesDialog::localeChanged(int i)
|
Chris@658
|
527 {
|
Chris@658
|
528 m_currentLocale = m_locales[i];
|
Chris@658
|
529 m_applyButton->setEnabled(true);
|
Chris@658
|
530 m_changesOnRestart = true;
|
Chris@658
|
531 }
|
Chris@658
|
532
|
Chris@658
|
533 void
|
Chris@180
|
534 PreferencesDialog::tempDirRootChanged(QString r)
|
Chris@180
|
535 {
|
Chris@180
|
536 m_tempDirRoot = r;
|
Chris@180
|
537 m_applyButton->setEnabled(true);
|
Chris@180
|
538 }
|
Chris@180
|
539
|
Chris@180
|
540 void
|
Chris@180
|
541 PreferencesDialog::tempDirButtonClicked()
|
Chris@180
|
542 {
|
Chris@180
|
543 QString dir = QFileDialog::getExistingDirectory
|
Chris@180
|
544 (this, tr("Select a directory to create cache subdirectory in"),
|
Chris@180
|
545 m_tempDirRoot);
|
Chris@180
|
546 if (dir == "") return;
|
Chris@180
|
547 m_tempDirRootEdit->setText(dir);
|
Chris@180
|
548 tempDirRootChanged(dir);
|
Chris@180
|
549 m_changesOnRestart = true;
|
Chris@180
|
550 }
|
Chris@180
|
551
|
Chris@180
|
552 void
|
Chris@180
|
553 PreferencesDialog::backgroundModeChanged(int mode)
|
Chris@180
|
554 {
|
Chris@180
|
555 m_backgroundMode = mode;
|
Chris@180
|
556 m_applyButton->setEnabled(true);
|
Chris@180
|
557 m_changesOnRestart = true;
|
Chris@180
|
558 }
|
Chris@180
|
559
|
Chris@180
|
560 void
|
Chris@337
|
561 PreferencesDialog::timeToTextModeChanged(int mode)
|
Chris@337
|
562 {
|
Chris@337
|
563 m_timeToTextMode = mode;
|
Chris@337
|
564 m_applyButton->setEnabled(true);
|
Chris@337
|
565 }
|
Chris@337
|
566
|
Chris@337
|
567 void
|
Chris@225
|
568 PreferencesDialog::viewFontSizeChanged(int sz)
|
Chris@225
|
569 {
|
Chris@225
|
570 m_viewFontSize = sz;
|
Chris@225
|
571 m_applyButton->setEnabled(true);
|
Chris@225
|
572 }
|
Chris@225
|
573
|
Chris@225
|
574 void
|
Chris@0
|
575 PreferencesDialog::okClicked()
|
Chris@0
|
576 {
|
Chris@0
|
577 applyClicked();
|
Chris@0
|
578 accept();
|
Chris@0
|
579 }
|
Chris@0
|
580
|
Chris@0
|
581 void
|
Chris@0
|
582 PreferencesDialog::applyClicked()
|
Chris@0
|
583 {
|
Chris@0
|
584 Preferences *prefs = Preferences::getInstance();
|
Chris@0
|
585 prefs->setWindowType(WindowType(m_windowType));
|
Chris@115
|
586 prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing
|
Chris@115
|
587 (m_spectrogramSmoothing));
|
Chris@299
|
588 prefs->setSpectrogramXSmoothing(Preferences::SpectrogramXSmoothing
|
Chris@299
|
589 (m_spectrogramXSmoothing));
|
Chris@0
|
590 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
|
Chris@0
|
591 (m_propertyLayout));
|
Chris@0
|
592 prefs->setTuningFrequency(m_tuningFrequency);
|
Chris@32
|
593 prefs->setResampleQuality(m_resampleQuality);
|
Chris@180
|
594 prefs->setResampleOnLoad(m_resampleOnLoad);
|
Chris@237
|
595 prefs->setShowSplash(m_showSplash);
|
Chris@180
|
596 prefs->setTemporaryDirectoryRoot(m_tempDirRoot);
|
Chris@180
|
597 prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode));
|
Chris@337
|
598 prefs->setTimeToTextMode(Preferences::TimeToTextMode(m_timeToTextMode));
|
Chris@225
|
599 prefs->setViewFontSize(m_viewFontSize);
|
Chris@263
|
600
|
Chris@263
|
601 std::vector<QString> devices =
|
Chris@263
|
602 AudioTargetFactory::getInstance()->getCallbackTargetNames();
|
Chris@263
|
603
|
Chris@263
|
604 QSettings settings;
|
Chris@436
|
605
|
Chris@263
|
606 settings.beginGroup("Preferences");
|
Chris@263
|
607 settings.setValue("audio-target", devices[m_audioDevice]);
|
Chris@263
|
608 settings.endGroup();
|
Chris@180
|
609
|
Chris@436
|
610 settings.beginGroup("MainWindow");
|
Chris@436
|
611 settings.setValue("sessiontemplate", m_currentTemplate);
|
Chris@436
|
612 settings.endGroup();
|
Chris@436
|
613
|
Chris@658
|
614 settings.beginGroup("Preferences");
|
Chris@658
|
615 settings.setValue("locale", m_currentLocale);
|
Chris@658
|
616 settings.endGroup();
|
Chris@658
|
617
|
Chris@0
|
618 m_applyButton->setEnabled(false);
|
Chris@180
|
619
|
Chris@180
|
620 if (m_changesOnRestart) {
|
Chris@180
|
621 QMessageBox::information(this, tr("Preferences"),
|
Chris@255
|
622 tr("<b>Restart required</b><p>One or more of the application preferences you have changed may not take full effect until Sonic Visualiser is restarted.</p><p>Please exit and restart the application now if you want these changes to take effect immediately.</p>"));
|
Chris@180
|
623 m_changesOnRestart = false;
|
Chris@180
|
624 }
|
Chris@0
|
625 }
|
Chris@0
|
626
|
Chris@0
|
627 void
|
Chris@0
|
628 PreferencesDialog::cancelClicked()
|
Chris@0
|
629 {
|
Chris@0
|
630 reject();
|
Chris@0
|
631 }
|
Chris@0
|
632
|
Chris@163
|
633 void
|
Chris@163
|
634 PreferencesDialog::applicationClosing(bool quickly)
|
Chris@163
|
635 {
|
Chris@163
|
636 if (quickly) {
|
Chris@163
|
637 reject();
|
Chris@163
|
638 return;
|
Chris@163
|
639 }
|
Chris@163
|
640
|
Chris@163
|
641 if (m_applyButton->isEnabled()) {
|
Chris@163
|
642 int rv = QMessageBox::warning
|
Chris@163
|
643 (this, tr("Preferences Changed"),
|
Chris@163
|
644 tr("Some preferences have been changed but not applied.\n"
|
Chris@163
|
645 "Apply them before closing?"),
|
Chris@163
|
646 QMessageBox::Apply | QMessageBox::Discard,
|
Chris@163
|
647 QMessageBox::Discard);
|
Chris@163
|
648 if (rv == QMessageBox::Apply) {
|
Chris@163
|
649 applyClicked();
|
Chris@163
|
650 accept();
|
Chris@163
|
651 } else {
|
Chris@163
|
652 reject();
|
Chris@163
|
653 }
|
Chris@163
|
654 } else {
|
Chris@163
|
655 accept();
|
Chris@163
|
656 }
|
Chris@163
|
657 }
|
Chris@163
|
658
|