annotate main/PreferencesDialog.cpp @ 430:45bfc5962c33 templating

Add some "proper" default templates; ensure default template is updated in menu if our template file disappears
author Chris Cannam
date Wed, 11 May 2011 13:52:00 +0100
parents a3b2cba73143
children ae68fc09bf16 6d827453657f
rev   line source
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@263 34 #include <QSettings>
Chris@0 35
Chris@9 36 #include "widgets/WindowTypeSelector.h"
Chris@180 37 #include "widgets/IconLoader.h"
Chris@0 38 #include "base/Preferences.h"
Chris@263 39 #include "audioio/AudioTargetFactory.h"
Chris@0 40
Chris@0 41 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) :
Chris@180 42 QDialog(parent, flags),
Chris@263 43 m_audioDevice(0),
Chris@180 44 m_changesOnRestart(false)
Chris@0 45 {
Chris@163 46 setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
Chris@0 47
Chris@0 48 Preferences *prefs = Preferences::getInstance();
Chris@0 49
Chris@0 50 QGridLayout *grid = new QGridLayout;
Chris@0 51 setLayout(grid);
Chris@180 52
Chris@180 53 QTabWidget *tab = new QTabWidget;
Chris@180 54 grid->addWidget(tab, 0, 0);
Chris@0 55
Chris@180 56 tab->setTabPosition(QTabWidget::North);
Chris@0 57
Chris@0 58 // Create this first, as slots that get called from the ctor will
Chris@0 59 // refer to it
Chris@0 60 m_applyButton = new QPushButton(tr("Apply"));
Chris@0 61
Chris@180 62 // Create all the preference widgets first, then create the
Chris@180 63 // individual tab widgets and place the preferences in their
Chris@180 64 // appropriate places in one go afterwards
Chris@180 65
Chris@114 66 int min, max, deflt, i;
Chris@0 67
Chris@9 68 m_windowType = WindowType(prefs->getPropertyRangeAndValue
Chris@114 69 ("Window Type", &min, &max, &deflt));
Chris@9 70 m_windowTypeSelector = new WindowTypeSelector(m_windowType);
Chris@0 71
Chris@9 72 connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)),
Chris@9 73 this, SLOT(windowTypeChanged(WindowType)));
Chris@0 74
Chris@115 75 QComboBox *smoothing = new QComboBox;
Chris@115 76
Chris@299 77 int sm = prefs->getPropertyRangeAndValue("Spectrogram Y Smoothing", &min, &max,
Chris@115 78 &deflt);
Chris@115 79 m_spectrogramSmoothing = sm;
Chris@0 80
Chris@115 81 for (i = min; i <= max; ++i) {
Chris@299 82 smoothing->addItem(prefs->getPropertyValueLabel("Spectrogram Y Smoothing", i));
Chris@115 83 }
Chris@115 84
Chris@115 85 smoothing->setCurrentIndex(sm);
Chris@115 86
Chris@115 87 connect(smoothing, SIGNAL(currentIndexChanged(int)),
Chris@115 88 this, SLOT(spectrogramSmoothingChanged(int)));
Chris@0 89
Chris@299 90 QComboBox *xsmoothing = new QComboBox;
Chris@299 91
Chris@299 92 int xsm = prefs->getPropertyRangeAndValue("Spectrogram X Smoothing", &min, &max,
Chris@299 93 &deflt);
Chris@299 94 m_spectrogramXSmoothing = xsm;
Chris@299 95
Chris@299 96 for (i = min; i <= max; ++i) {
Chris@299 97 xsmoothing->addItem(prefs->getPropertyValueLabel("Spectrogram X Smoothing", i));
Chris@299 98 }
Chris@299 99
Chris@299 100 xsmoothing->setCurrentIndex(xsm);
Chris@299 101
Chris@299 102 connect(xsmoothing, SIGNAL(currentIndexChanged(int)),
Chris@299 103 this, SLOT(spectrogramXSmoothingChanged(int)));
Chris@299 104
Chris@0 105 QComboBox *propertyLayout = new QComboBox;
Chris@114 106 int pl = prefs->getPropertyRangeAndValue("Property Box Layout", &min, &max,
Chris@115 107 &deflt);
Chris@0 108 m_propertyLayout = pl;
Chris@0 109
Chris@0 110 for (i = min; i <= max; ++i) {
Chris@0 111 propertyLayout->addItem(prefs->getPropertyValueLabel("Property Box Layout", i));
Chris@0 112 }
Chris@0 113
Chris@0 114 propertyLayout->setCurrentIndex(pl);
Chris@0 115
Chris@0 116 connect(propertyLayout, SIGNAL(currentIndexChanged(int)),
Chris@0 117 this, SLOT(propertyLayoutChanged(int)));
Chris@0 118
Chris@0 119 m_tuningFrequency = prefs->getTuningFrequency();
Chris@0 120
Chris@0 121 QDoubleSpinBox *frequency = new QDoubleSpinBox;
Chris@0 122 frequency->setMinimum(100.0);
Chris@0 123 frequency->setMaximum(5000.0);
Chris@0 124 frequency->setSuffix(" Hz");
Chris@0 125 frequency->setSingleStep(1);
Chris@0 126 frequency->setValue(m_tuningFrequency);
Chris@0 127 frequency->setDecimals(2);
Chris@0 128
Chris@0 129 connect(frequency, SIGNAL(valueChanged(double)),
Chris@0 130 this, SLOT(tuningFrequencyChanged(double)));
Chris@0 131
Chris@263 132 QComboBox *audioDevice = new QComboBox;
Chris@263 133 std::vector<QString> devices =
Chris@263 134 AudioTargetFactory::getInstance()->getCallbackTargetNames();
Chris@263 135
Chris@263 136 QSettings settings;
Chris@263 137 settings.beginGroup("Preferences");
Chris@263 138 QString targetName = settings.value("audio-target", "").toString();
Chris@263 139 settings.endGroup();
Chris@263 140
Chris@263 141 for (int i = 0; i < devices.size(); ++i) {
Chris@263 142 audioDevice->addItem(AudioTargetFactory::getInstance()
Chris@263 143 ->getCallbackTargetDescription(devices[i]));
Chris@263 144 if (targetName == devices[i]) audioDevice->setCurrentIndex(i);
Chris@263 145 }
Chris@263 146
Chris@263 147 connect(audioDevice, SIGNAL(currentIndexChanged(int)),
Chris@263 148 this, SLOT(audioDeviceChanged(int)));
Chris@263 149
Chris@32 150 QComboBox *resampleQuality = new QComboBox;
Chris@32 151
Chris@114 152 int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max,
Chris@114 153 &deflt);
Chris@32 154 m_resampleQuality = rsq;
Chris@32 155
Chris@32 156 for (i = min; i <= max; ++i) {
Chris@32 157 resampleQuality->addItem(prefs->getPropertyValueLabel("Resample Quality", i));
Chris@32 158 }
Chris@32 159
Chris@32 160 resampleQuality->setCurrentIndex(rsq);
Chris@32 161
Chris@32 162 connect(resampleQuality, SIGNAL(currentIndexChanged(int)),
Chris@32 163 this, SLOT(resampleQualityChanged(int)));
Chris@32 164
Chris@180 165 QCheckBox *resampleOnLoad = new QCheckBox;
Chris@180 166 m_resampleOnLoad = prefs->getResampleOnLoad();
Chris@180 167 resampleOnLoad->setCheckState(m_resampleOnLoad ? Qt::Checked :
Chris@180 168 Qt::Unchecked);
Chris@180 169 connect(resampleOnLoad, SIGNAL(stateChanged(int)),
Chris@180 170 this, SLOT(resampleOnLoadChanged(int)));
Chris@180 171
Chris@180 172 m_tempDirRootEdit = new QLineEdit;
Chris@180 173 QString dir = prefs->getTemporaryDirectoryRoot();
Chris@180 174 m_tempDirRoot = dir;
Chris@180 175 dir.replace("$HOME", tr("<home directory>"));
Chris@180 176 m_tempDirRootEdit->setText(dir);
Chris@180 177 m_tempDirRootEdit->setReadOnly(true);
Chris@180 178 QPushButton *tempDirButton = new QPushButton;
Chris@180 179 tempDirButton->setIcon(IconLoader().load("fileopen"));
Chris@180 180 connect(tempDirButton, SIGNAL(clicked()),
Chris@180 181 this, SLOT(tempDirButtonClicked()));
Chris@180 182 tempDirButton->setFixedSize(QSize(24, 24));
Chris@180 183
Chris@237 184 QCheckBox *showSplash = new QCheckBox;
Chris@237 185 m_showSplash = prefs->getShowSplash();
Chris@237 186 showSplash->setCheckState(m_showSplash ? Qt::Checked : Qt::Unchecked);
Chris@237 187 connect(showSplash, SIGNAL(stateChanged(int)),
Chris@237 188 this, SLOT(showSplashChanged(int)));
Chris@237 189
Chris@237 190 #ifndef Q_WS_MAC
Chris@180 191 QComboBox *bgMode = new QComboBox;
Chris@180 192 int bg = prefs->getPropertyRangeAndValue("Background Mode", &min, &max,
Chris@180 193 &deflt);
Chris@180 194 m_backgroundMode = bg;
Chris@180 195 for (i = min; i <= max; ++i) {
Chris@180 196 bgMode->addItem(prefs->getPropertyValueLabel("Background Mode", i));
Chris@180 197 }
Chris@180 198 bgMode->setCurrentIndex(bg);
Chris@180 199
Chris@180 200 connect(bgMode, SIGNAL(currentIndexChanged(int)),
Chris@180 201 this, SLOT(backgroundModeChanged(int)));
Chris@237 202 #endif
Chris@180 203
Chris@225 204 QSpinBox *fontSize = new QSpinBox;
Chris@225 205 int fs = prefs->getPropertyRangeAndValue("View Font Size", &min, &max,
Chris@225 206 &deflt);
Chris@234 207 m_viewFontSize = fs;
Chris@225 208 fontSize->setMinimum(min);
Chris@225 209 fontSize->setMaximum(max);
Chris@225 210 fontSize->setSuffix(" pt");
Chris@225 211 fontSize->setSingleStep(1);
Chris@225 212 fontSize->setValue(fs);
Chris@225 213
Chris@225 214 connect(fontSize, SIGNAL(valueChanged(int)),
Chris@225 215 this, SLOT(viewFontSizeChanged(int)));
Chris@225 216
Chris@337 217 QComboBox *ttMode = new QComboBox;
Chris@337 218 int tt = prefs->getPropertyRangeAndValue("Time To Text Mode", &min, &max,
Chris@337 219 &deflt);
Chris@337 220 m_timeToTextMode = tt;
Chris@337 221 for (i = min; i <= max; ++i) {
Chris@337 222 ttMode->addItem(prefs->getPropertyValueLabel("Time To Text Mode", i));
Chris@337 223 }
Chris@337 224 ttMode->setCurrentIndex(tt);
Chris@337 225
Chris@337 226 connect(ttMode, SIGNAL(currentIndexChanged(int)),
Chris@337 227 this, SLOT(timeToTextModeChanged(int)));
Chris@337 228
Chris@180 229 // General tab
Chris@180 230
Chris@180 231 QFrame *frame = new QFrame;
Chris@180 232
Chris@180 233 QGridLayout *subgrid = new QGridLayout;
Chris@180 234 frame->setLayout(subgrid);
Chris@180 235
Chris@0 236 int row = 0;
Chris@0 237
Chris@0 238 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 239 ("Temporary Directory Root"))),
Chris@263 240 row, 0);
Chris@263 241 subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
Chris@263 242 subgrid->addWidget(tempDirButton, row, 2, 1, 1);
Chris@263 243 row++;
Chris@263 244
Chris@263 245 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 246 ("Resample On Load"))),
Chris@263 247 row, 0);
Chris@263 248 subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1);
Chris@263 249
Chris@263 250 subgrid->addWidget(new QLabel(tr("Playback audio device:")), row, 0);
Chris@263 251 subgrid->addWidget(audioDevice, row++, 1, 1, 2);
Chris@263 252
Chris@263 253 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 254 ("Resample Quality"))),
Chris@263 255 row, 0);
Chris@263 256 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
Chris@263 257
Chris@263 258 subgrid->setRowStretch(row, 10);
Chris@263 259
Chris@263 260 tab->addTab(frame, tr("&General"));
Chris@263 261
Chris@263 262 // Appearance tab
Chris@263 263
Chris@263 264 frame = new QFrame;
Chris@263 265 subgrid = new QGridLayout;
Chris@263 266 frame->setLayout(subgrid);
Chris@263 267 row = 0;
Chris@263 268
Chris@263 269 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 270 ("Property Box Layout"))),
Chris@0 271 row, 0);
Chris@0 272 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
Chris@0 273
Chris@242 274 #ifndef Q_WS_MAC
Chris@0 275 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 276 ("Background Mode"))),
Chris@0 277 row, 0);
Chris@180 278 subgrid->addWidget(bgMode, row++, 1, 1, 2);
Chris@242 279 #endif
Chris@180 280
Chris@180 281 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@225 282 ("View Font Size"))),
Chris@225 283 row, 0);
Chris@225 284 subgrid->addWidget(fontSize, row++, 1, 1, 2);
Chris@225 285
Chris@225 286 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@337 287 ("Time To Text Mode"))),
Chris@337 288 row, 0);
Chris@337 289 subgrid->addWidget(ttMode, row++, 1, 1, 2);
Chris@337 290
Chris@337 291 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@237 292 ("Show Splash Screen"))),
Chris@237 293 row, 0);
Chris@237 294 subgrid->addWidget(showSplash, row++, 1, 1, 1);
Chris@237 295
Chris@180 296 subgrid->setRowStretch(row, 10);
Chris@180 297
Chris@263 298 tab->addTab(frame, tr("&Appearance"));
Chris@180 299
Chris@180 300 // Analysis tab
Chris@180 301
Chris@180 302 frame = new QFrame;
Chris@180 303 subgrid = new QGridLayout;
Chris@180 304 frame->setLayout(subgrid);
Chris@180 305 row = 0;
Chris@180 306
Chris@180 307 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 308 ("Tuning Frequency"))),
Chris@180 309 row, 0);
Chris@180 310 subgrid->addWidget(frequency, row++, 1, 1, 2);
Chris@180 311
Chris@0 312 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 313 ("Spectrogram Y Smoothing")),
Chris@115 314 row, 0);
Chris@115 315 subgrid->addWidget(smoothing, row++, 1, 1, 2);
Chris@0 316
Chris@299 317 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 318 ("Spectrogram X Smoothing")),
Chris@299 319 row, 0);
Chris@299 320 subgrid->addWidget(xsmoothing, row++, 1, 1, 2);
Chris@299 321
Chris@0 322 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 323 ("Window Type"))),
Chris@0 324 row, 0);
Chris@9 325 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
Chris@9 326 subgrid->setRowStretch(row, 10);
Chris@9 327 row++;
Chris@0 328
Chris@180 329 subgrid->setRowStretch(row, 10);
Chris@180 330
Chris@263 331 tab->addTab(frame, tr("Anal&ysis"));
Chris@180 332
Chris@163 333 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
Chris@163 334 grid->addWidget(bb, 1, 0);
Chris@0 335
Chris@0 336 QPushButton *ok = new QPushButton(tr("OK"));
Chris@0 337 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@163 338 bb->addButton(ok, QDialogButtonBox::AcceptRole);
Chris@163 339 bb->addButton(m_applyButton, QDialogButtonBox::ApplyRole);
Chris@163 340 bb->addButton(cancel, QDialogButtonBox::RejectRole);
Chris@0 341 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
Chris@0 342 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
Chris@0 343 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
Chris@0 344
Chris@0 345 m_applyButton->setEnabled(false);
Chris@0 346 }
Chris@0 347
Chris@0 348 PreferencesDialog::~PreferencesDialog()
Chris@0 349 {
Chris@0 350 std::cerr << "PreferencesDialog::~PreferencesDialog()" << std::endl;
Chris@0 351 }
Chris@0 352
Chris@0 353 void
Chris@9 354 PreferencesDialog::windowTypeChanged(WindowType type)
Chris@0 355 {
Chris@0 356 m_windowType = type;
Chris@0 357 m_applyButton->setEnabled(true);
Chris@0 358 }
Chris@0 359
Chris@0 360 void
Chris@115 361 PreferencesDialog::spectrogramSmoothingChanged(int smoothing)
Chris@0 362 {
Chris@115 363 m_spectrogramSmoothing = smoothing;
Chris@0 364 m_applyButton->setEnabled(true);
Chris@0 365 }
Chris@0 366
Chris@0 367 void
Chris@299 368 PreferencesDialog::spectrogramXSmoothingChanged(int smoothing)
Chris@299 369 {
Chris@299 370 m_spectrogramXSmoothing = smoothing;
Chris@299 371 m_applyButton->setEnabled(true);
Chris@299 372 }
Chris@299 373
Chris@299 374 void
Chris@0 375 PreferencesDialog::propertyLayoutChanged(int layout)
Chris@0 376 {
Chris@0 377 m_propertyLayout = layout;
Chris@0 378 m_applyButton->setEnabled(true);
Chris@0 379 }
Chris@0 380
Chris@0 381 void
Chris@0 382 PreferencesDialog::tuningFrequencyChanged(double freq)
Chris@0 383 {
Chris@0 384 m_tuningFrequency = freq;
Chris@0 385 m_applyButton->setEnabled(true);
Chris@0 386 }
Chris@0 387
Chris@0 388 void
Chris@263 389 PreferencesDialog::audioDeviceChanged(int s)
Chris@263 390 {
Chris@263 391 m_audioDevice = s;
Chris@263 392 m_applyButton->setEnabled(true);
Chris@263 393 m_changesOnRestart = true;
Chris@263 394 }
Chris@263 395
Chris@263 396 void
Chris@32 397 PreferencesDialog::resampleQualityChanged(int q)
Chris@32 398 {
Chris@32 399 m_resampleQuality = q;
Chris@32 400 m_applyButton->setEnabled(true);
Chris@32 401 }
Chris@32 402
Chris@32 403 void
Chris@180 404 PreferencesDialog::resampleOnLoadChanged(int state)
Chris@180 405 {
Chris@180 406 m_resampleOnLoad = (state == Qt::Checked);
Chris@180 407 m_applyButton->setEnabled(true);
Chris@180 408 m_changesOnRestart = true;
Chris@180 409 }
Chris@180 410
Chris@180 411 void
Chris@237 412 PreferencesDialog::showSplashChanged(int state)
Chris@237 413 {
Chris@237 414 m_showSplash = (state == Qt::Checked);
Chris@237 415 m_applyButton->setEnabled(true);
Chris@237 416 m_changesOnRestart = true;
Chris@237 417 }
Chris@237 418
Chris@237 419 void
Chris@180 420 PreferencesDialog::tempDirRootChanged(QString r)
Chris@180 421 {
Chris@180 422 m_tempDirRoot = r;
Chris@180 423 m_applyButton->setEnabled(true);
Chris@180 424 }
Chris@180 425
Chris@180 426 void
Chris@180 427 PreferencesDialog::tempDirButtonClicked()
Chris@180 428 {
Chris@180 429 QString dir = QFileDialog::getExistingDirectory
Chris@180 430 (this, tr("Select a directory to create cache subdirectory in"),
Chris@180 431 m_tempDirRoot);
Chris@180 432 if (dir == "") return;
Chris@180 433 m_tempDirRootEdit->setText(dir);
Chris@180 434 tempDirRootChanged(dir);
Chris@180 435 m_changesOnRestart = true;
Chris@180 436 }
Chris@180 437
Chris@180 438 void
Chris@180 439 PreferencesDialog::backgroundModeChanged(int mode)
Chris@180 440 {
Chris@180 441 m_backgroundMode = mode;
Chris@180 442 m_applyButton->setEnabled(true);
Chris@180 443 m_changesOnRestart = true;
Chris@180 444 }
Chris@180 445
Chris@180 446 void
Chris@337 447 PreferencesDialog::timeToTextModeChanged(int mode)
Chris@337 448 {
Chris@337 449 m_timeToTextMode = mode;
Chris@337 450 m_applyButton->setEnabled(true);
Chris@337 451 }
Chris@337 452
Chris@337 453 void
Chris@225 454 PreferencesDialog::viewFontSizeChanged(int sz)
Chris@225 455 {
Chris@225 456 m_viewFontSize = sz;
Chris@225 457 m_applyButton->setEnabled(true);
Chris@225 458 }
Chris@225 459
Chris@225 460 void
Chris@0 461 PreferencesDialog::okClicked()
Chris@0 462 {
Chris@0 463 applyClicked();
Chris@0 464 accept();
Chris@0 465 }
Chris@0 466
Chris@0 467 void
Chris@0 468 PreferencesDialog::applyClicked()
Chris@0 469 {
Chris@0 470 Preferences *prefs = Preferences::getInstance();
Chris@0 471 prefs->setWindowType(WindowType(m_windowType));
Chris@115 472 prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing
Chris@115 473 (m_spectrogramSmoothing));
Chris@299 474 prefs->setSpectrogramXSmoothing(Preferences::SpectrogramXSmoothing
Chris@299 475 (m_spectrogramXSmoothing));
Chris@0 476 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
Chris@0 477 (m_propertyLayout));
Chris@0 478 prefs->setTuningFrequency(m_tuningFrequency);
Chris@32 479 prefs->setResampleQuality(m_resampleQuality);
Chris@180 480 prefs->setResampleOnLoad(m_resampleOnLoad);
Chris@237 481 prefs->setShowSplash(m_showSplash);
Chris@180 482 prefs->setTemporaryDirectoryRoot(m_tempDirRoot);
Chris@180 483 prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode));
Chris@337 484 prefs->setTimeToTextMode(Preferences::TimeToTextMode(m_timeToTextMode));
Chris@225 485 prefs->setViewFontSize(m_viewFontSize);
Chris@263 486
Chris@263 487 std::vector<QString> devices =
Chris@263 488 AudioTargetFactory::getInstance()->getCallbackTargetNames();
Chris@263 489
Chris@263 490 QSettings settings;
Chris@263 491 settings.beginGroup("Preferences");
Chris@263 492 settings.setValue("audio-target", devices[m_audioDevice]);
Chris@263 493 settings.endGroup();
Chris@180 494
Chris@0 495 m_applyButton->setEnabled(false);
Chris@180 496
Chris@180 497 if (m_changesOnRestart) {
Chris@180 498 QMessageBox::information(this, tr("Preferences"),
Chris@255 499 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 500 m_changesOnRestart = false;
Chris@180 501 }
Chris@0 502 }
Chris@0 503
Chris@0 504 void
Chris@0 505 PreferencesDialog::cancelClicked()
Chris@0 506 {
Chris@0 507 reject();
Chris@0 508 }
Chris@0 509
Chris@163 510 void
Chris@163 511 PreferencesDialog::applicationClosing(bool quickly)
Chris@163 512 {
Chris@163 513 if (quickly) {
Chris@163 514 reject();
Chris@163 515 return;
Chris@163 516 }
Chris@163 517
Chris@163 518 if (m_applyButton->isEnabled()) {
Chris@163 519 int rv = QMessageBox::warning
Chris@163 520 (this, tr("Preferences Changed"),
Chris@163 521 tr("Some preferences have been changed but not applied.\n"
Chris@163 522 "Apply them before closing?"),
Chris@163 523 QMessageBox::Apply | QMessageBox::Discard,
Chris@163 524 QMessageBox::Discard);
Chris@163 525 if (rv == QMessageBox::Apply) {
Chris@163 526 applyClicked();
Chris@163 527 accept();
Chris@163 528 } else {
Chris@163 529 reject();
Chris@163 530 }
Chris@163 531 } else {
Chris@163 532 accept();
Chris@163 533 }
Chris@163 534 }
Chris@163 535