comparison main/PreferencesDialog.cpp @ 263:9d47adc3e32d

* Add audio device selection to preferences * Add (not yet functional) insert, delete, edit buttons to data edit window * Add proper set methods for time fields in data edit window (using general sparse model base class)
author Chris Cannam
date Fri, 13 Jun 2008 21:09:43 +0000
parents 92cad26f44a1
children 15ce557e1bf8
comparison
equal deleted inserted replaced
262:f3df0494ae33 263:9d47adc3e32d
29 #include <QTabWidget> 29 #include <QTabWidget>
30 #include <QLineEdit> 30 #include <QLineEdit>
31 #include <QFileDialog> 31 #include <QFileDialog>
32 #include <QMessageBox> 32 #include <QMessageBox>
33 #include <QSpinBox> 33 #include <QSpinBox>
34 #include <QSettings>
34 35
35 #include "widgets/WindowTypeSelector.h" 36 #include "widgets/WindowTypeSelector.h"
36 #include "widgets/IconLoader.h" 37 #include "widgets/IconLoader.h"
37 #include "base/Preferences.h" 38 #include "base/Preferences.h"
39 #include "audioio/AudioTargetFactory.h"
38 40
39 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) : 41 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) :
40 QDialog(parent, flags), 42 QDialog(parent, flags),
43 m_audioDevice(0),
41 m_changesOnRestart(false) 44 m_changesOnRestart(false)
42 { 45 {
43 setWindowTitle(tr("Sonic Visualiser: Application Preferences")); 46 setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
44 47
45 Preferences *prefs = Preferences::getInstance(); 48 Preferences *prefs = Preferences::getInstance();
108 frequency->setValue(m_tuningFrequency); 111 frequency->setValue(m_tuningFrequency);
109 frequency->setDecimals(2); 112 frequency->setDecimals(2);
110 113
111 connect(frequency, SIGNAL(valueChanged(double)), 114 connect(frequency, SIGNAL(valueChanged(double)),
112 this, SLOT(tuningFrequencyChanged(double))); 115 this, SLOT(tuningFrequencyChanged(double)));
116
117 QComboBox *audioDevice = new QComboBox;
118 std::vector<QString> devices =
119 AudioTargetFactory::getInstance()->getCallbackTargetNames();
120
121 QSettings settings;
122 settings.beginGroup("Preferences");
123 QString targetName = settings.value("audio-target", "").toString();
124 settings.endGroup();
125
126 for (int i = 0; i < devices.size(); ++i) {
127 audioDevice->addItem(AudioTargetFactory::getInstance()
128 ->getCallbackTargetDescription(devices[i]));
129 if (targetName == devices[i]) audioDevice->setCurrentIndex(i);
130 }
131
132 connect(audioDevice, SIGNAL(currentIndexChanged(int)),
133 this, SLOT(audioDeviceChanged(int)));
113 134
114 QComboBox *resampleQuality = new QComboBox; 135 QComboBox *resampleQuality = new QComboBox;
115 136
116 int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max, 137 int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max,
117 &deflt); 138 &deflt);
186 frame->setLayout(subgrid); 207 frame->setLayout(subgrid);
187 208
188 int row = 0; 209 int row = 0;
189 210
190 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel 211 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
191 ("Property Box Layout"))),
192 row, 0);
193 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
194
195 #ifndef Q_WS_MAC
196 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
197 ("Background Mode"))),
198 row, 0);
199 subgrid->addWidget(bgMode, row++, 1, 1, 2);
200 #endif
201
202 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
203 ("View Font Size"))),
204 row, 0);
205 subgrid->addWidget(fontSize, row++, 1, 1, 2);
206
207 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
208 ("Show Splash Screen"))),
209 row, 0);
210 subgrid->addWidget(showSplash, row++, 1, 1, 1);
211
212 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
213 ("Temporary Directory Root"))), 212 ("Temporary Directory Root"))),
214 row, 0); 213 row, 0);
215 subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1); 214 subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
216 subgrid->addWidget(tempDirButton, row, 2, 1, 1); 215 subgrid->addWidget(tempDirButton, row, 2, 1, 1);
217 row++; 216 row++;
219 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel 218 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
220 ("Resample On Load"))), 219 ("Resample On Load"))),
221 row, 0); 220 row, 0);
222 subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1); 221 subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1);
223 222
223 subgrid->addWidget(new QLabel(tr("Playback audio device:")), row, 0);
224 subgrid->addWidget(audioDevice, row++, 1, 1, 2);
225
224 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel 226 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
225 ("Resample Quality"))), 227 ("Resample Quality"))),
226 row, 0); 228 row, 0);
227 subgrid->addWidget(resampleQuality, row++, 1, 1, 2); 229 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
228 230
229 subgrid->setRowStretch(row, 10); 231 subgrid->setRowStretch(row, 10);
230 232
231 tab->addTab(frame, tr("&General")); 233 tab->addTab(frame, tr("&General"));
232 234
233 // Analysis tab 235 // Appearance tab
234 236
235 frame = new QFrame; 237 frame = new QFrame;
236 subgrid = new QGridLayout; 238 subgrid = new QGridLayout;
237 frame->setLayout(subgrid); 239 frame->setLayout(subgrid);
238 row = 0; 240 row = 0;
239 241
240 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel 242 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
243 ("Property Box Layout"))),
244 row, 0);
245 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
246
247 #ifndef Q_WS_MAC
248 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
249 ("Background Mode"))),
250 row, 0);
251 subgrid->addWidget(bgMode, row++, 1, 1, 2);
252 #endif
253
254 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
255 ("View Font Size"))),
256 row, 0);
257 subgrid->addWidget(fontSize, row++, 1, 1, 2);
258
259 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
260 ("Show Splash Screen"))),
261 row, 0);
262 subgrid->addWidget(showSplash, row++, 1, 1, 1);
263
264 subgrid->setRowStretch(row, 10);
265
266 tab->addTab(frame, tr("&Appearance"));
267
268 // Analysis tab
269
270 frame = new QFrame;
271 subgrid = new QGridLayout;
272 frame->setLayout(subgrid);
273 row = 0;
274
275 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
241 ("Tuning Frequency"))), 276 ("Tuning Frequency"))),
242 row, 0); 277 row, 0);
243 subgrid->addWidget(frequency, row++, 1, 1, 2); 278 subgrid->addWidget(frequency, row++, 1, 1, 2);
244 279
245 subgrid->addWidget(new QLabel(prefs->getPropertyLabel 280 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
254 subgrid->setRowStretch(row, 10); 289 subgrid->setRowStretch(row, 10);
255 row++; 290 row++;
256 291
257 subgrid->setRowStretch(row, 10); 292 subgrid->setRowStretch(row, 10);
258 293
259 tab->addTab(frame, tr("&Analysis")); 294 tab->addTab(frame, tr("Anal&ysis"));
260 295
261 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal); 296 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
262 grid->addWidget(bb, 1, 0); 297 grid->addWidget(bb, 1, 0);
263 298
264 QPushButton *ok = new QPushButton(tr("OK")); 299 QPushButton *ok = new QPushButton(tr("OK"));
302 void 337 void
303 PreferencesDialog::tuningFrequencyChanged(double freq) 338 PreferencesDialog::tuningFrequencyChanged(double freq)
304 { 339 {
305 m_tuningFrequency = freq; 340 m_tuningFrequency = freq;
306 m_applyButton->setEnabled(true); 341 m_applyButton->setEnabled(true);
342 }
343
344 void
345 PreferencesDialog::audioDeviceChanged(int s)
346 {
347 m_audioDevice = s;
348 m_applyButton->setEnabled(true);
349 m_changesOnRestart = true;
307 } 350 }
308 351
309 void 352 void
310 PreferencesDialog::resampleQualityChanged(int q) 353 PreferencesDialog::resampleQualityChanged(int q)
311 { 354 {
384 prefs->setResampleOnLoad(m_resampleOnLoad); 427 prefs->setResampleOnLoad(m_resampleOnLoad);
385 prefs->setShowSplash(m_showSplash); 428 prefs->setShowSplash(m_showSplash);
386 prefs->setTemporaryDirectoryRoot(m_tempDirRoot); 429 prefs->setTemporaryDirectoryRoot(m_tempDirRoot);
387 prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode)); 430 prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode));
388 prefs->setViewFontSize(m_viewFontSize); 431 prefs->setViewFontSize(m_viewFontSize);
432
433 std::vector<QString> devices =
434 AudioTargetFactory::getInstance()->getCallbackTargetNames();
435
436 QSettings settings;
437 settings.beginGroup("Preferences");
438 settings.setValue("audio-target", devices[m_audioDevice]);
439 settings.endGroup();
389 440
390 m_applyButton->setEnabled(false); 441 m_applyButton->setEnabled(false);
391 442
392 if (m_changesOnRestart) { 443 if (m_changesOnRestart) {
393 QMessageBox::information(this, tr("Preferences"), 444 QMessageBox::information(this, tr("Preferences"),