annotate main/PreferencesDialog.cpp @ 645:22974bf810ce toggle

Close obsolete branch toggle
author Chris Cannam
date Sat, 23 Jul 2011 14:23:46 +0100
parents f8f74f1b5b4f
children 33d0632255b5
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
mathieu@459 190 QCheckBox *startInMiniMode = new QCheckBox;
mathieu@459 191 m_startInMiniMode = prefs->getStartInMiniMode();
mathieu@459 192 startInMiniMode->setCheckState(m_startInMiniMode ? Qt::Checked : Qt::Unchecked);
mathieu@459 193 connect(startInMiniMode, SIGNAL(stateChanged(int)),
mathieu@459 194 this, SLOT(startInMiniModeChanged(int)));
mathieu@459 195
Chris@237 196 #ifndef Q_WS_MAC
Chris@180 197 QComboBox *bgMode = new QComboBox;
Chris@180 198 int bg = prefs->getPropertyRangeAndValue("Background Mode", &min, &max,
Chris@180 199 &deflt);
Chris@180 200 m_backgroundMode = bg;
Chris@180 201 for (i = min; i <= max; ++i) {
Chris@180 202 bgMode->addItem(prefs->getPropertyValueLabel("Background Mode", i));
Chris@180 203 }
Chris@180 204 bgMode->setCurrentIndex(bg);
Chris@180 205
Chris@180 206 connect(bgMode, SIGNAL(currentIndexChanged(int)),
Chris@180 207 this, SLOT(backgroundModeChanged(int)));
Chris@237 208 #endif
Chris@180 209
Chris@225 210 QSpinBox *fontSize = new QSpinBox;
Chris@225 211 int fs = prefs->getPropertyRangeAndValue("View Font Size", &min, &max,
Chris@225 212 &deflt);
Chris@234 213 m_viewFontSize = fs;
Chris@225 214 fontSize->setMinimum(min);
Chris@225 215 fontSize->setMaximum(max);
Chris@225 216 fontSize->setSuffix(" pt");
Chris@225 217 fontSize->setSingleStep(1);
Chris@225 218 fontSize->setValue(fs);
Chris@225 219
Chris@225 220 connect(fontSize, SIGNAL(valueChanged(int)),
Chris@225 221 this, SLOT(viewFontSizeChanged(int)));
Chris@225 222
Chris@337 223 QComboBox *ttMode = new QComboBox;
Chris@337 224 int tt = prefs->getPropertyRangeAndValue("Time To Text Mode", &min, &max,
Chris@337 225 &deflt);
Chris@337 226 m_timeToTextMode = tt;
Chris@337 227 for (i = min; i <= max; ++i) {
Chris@337 228 ttMode->addItem(prefs->getPropertyValueLabel("Time To Text Mode", i));
Chris@337 229 }
Chris@337 230 ttMode->setCurrentIndex(tt);
Chris@337 231
Chris@337 232 connect(ttMode, SIGNAL(currentIndexChanged(int)),
Chris@337 233 this, SLOT(timeToTextModeChanged(int)));
Chris@337 234
Chris@180 235 // General tab
Chris@180 236
Chris@180 237 QFrame *frame = new QFrame;
Chris@180 238
Chris@180 239 QGridLayout *subgrid = new QGridLayout;
Chris@180 240 frame->setLayout(subgrid);
Chris@180 241
Chris@0 242 int row = 0;
Chris@0 243
Chris@0 244 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 245 ("Temporary Directory Root"))),
Chris@263 246 row, 0);
Chris@263 247 subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
Chris@263 248 subgrid->addWidget(tempDirButton, row, 2, 1, 1);
Chris@263 249 row++;
Chris@263 250
Chris@263 251 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 252 ("Resample On Load"))),
Chris@263 253 row, 0);
Chris@263 254 subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1);
Chris@263 255
Chris@263 256 subgrid->addWidget(new QLabel(tr("Playback audio device:")), row, 0);
Chris@263 257 subgrid->addWidget(audioDevice, row++, 1, 1, 2);
Chris@263 258
Chris@263 259 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 260 ("Resample Quality"))),
Chris@263 261 row, 0);
Chris@263 262 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
Chris@263 263
Chris@263 264 subgrid->setRowStretch(row, 10);
Chris@263 265
Chris@263 266 tab->addTab(frame, tr("&General"));
Chris@263 267
Chris@263 268 // Appearance tab
Chris@263 269
Chris@263 270 frame = new QFrame;
Chris@263 271 subgrid = new QGridLayout;
Chris@263 272 frame->setLayout(subgrid);
Chris@263 273 row = 0;
Chris@263 274
Chris@263 275 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 276 ("Property Box Layout"))),
Chris@0 277 row, 0);
Chris@0 278 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
Chris@0 279
Chris@242 280 #ifndef Q_WS_MAC
Chris@0 281 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 282 ("Background Mode"))),
Chris@0 283 row, 0);
Chris@180 284 subgrid->addWidget(bgMode, row++, 1, 1, 2);
Chris@242 285 #endif
Chris@180 286
Chris@180 287 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@225 288 ("View Font Size"))),
Chris@225 289 row, 0);
Chris@225 290 subgrid->addWidget(fontSize, row++, 1, 1, 2);
Chris@225 291
Chris@225 292 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@337 293 ("Time To Text Mode"))),
Chris@337 294 row, 0);
Chris@337 295 subgrid->addWidget(ttMode, row++, 1, 1, 2);
Chris@337 296
Chris@337 297 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@237 298 ("Show Splash Screen"))),
Chris@237 299 row, 0);
Chris@237 300 subgrid->addWidget(showSplash, row++, 1, 1, 1);
Chris@237 301
Chris@180 302 subgrid->setRowStretch(row, 10);
mathieu@459 303
mathieu@459 304 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
mathieu@459 305 ("Start In Minimal Mode"))),
mathieu@459 306 row, 0);
mathieu@459 307 subgrid->addWidget(startInMiniMode, row++, 1, 1, 1);
mathieu@459 308
mathieu@459 309 subgrid->setRowStretch(row, 10);
Chris@180 310
Chris@263 311 tab->addTab(frame, tr("&Appearance"));
Chris@180 312
Chris@180 313 // Analysis tab
Chris@180 314
Chris@180 315 frame = new QFrame;
Chris@180 316 subgrid = new QGridLayout;
Chris@180 317 frame->setLayout(subgrid);
Chris@180 318 row = 0;
Chris@180 319
Chris@180 320 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 321 ("Tuning Frequency"))),
Chris@180 322 row, 0);
Chris@180 323 subgrid->addWidget(frequency, row++, 1, 1, 2);
Chris@180 324
Chris@0 325 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 326 ("Spectrogram Y Smoothing")),
Chris@115 327 row, 0);
Chris@115 328 subgrid->addWidget(smoothing, row++, 1, 1, 2);
Chris@0 329
Chris@299 330 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 331 ("Spectrogram X Smoothing")),
Chris@299 332 row, 0);
Chris@299 333 subgrid->addWidget(xsmoothing, row++, 1, 1, 2);
Chris@299 334
Chris@0 335 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 336 ("Window Type"))),
Chris@0 337 row, 0);
Chris@9 338 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
Chris@9 339 subgrid->setRowStretch(row, 10);
Chris@9 340 row++;
Chris@0 341
Chris@180 342 subgrid->setRowStretch(row, 10);
Chris@180 343
Chris@263 344 tab->addTab(frame, tr("Anal&ysis"));
Chris@180 345
Chris@163 346 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
Chris@163 347 grid->addWidget(bb, 1, 0);
Chris@0 348
Chris@0 349 QPushButton *ok = new QPushButton(tr("OK"));
Chris@0 350 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@163 351 bb->addButton(ok, QDialogButtonBox::AcceptRole);
Chris@163 352 bb->addButton(m_applyButton, QDialogButtonBox::ApplyRole);
Chris@163 353 bb->addButton(cancel, QDialogButtonBox::RejectRole);
Chris@0 354 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
Chris@0 355 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
Chris@0 356 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
Chris@0 357
Chris@0 358 m_applyButton->setEnabled(false);
Chris@0 359 }
Chris@0 360
Chris@0 361 PreferencesDialog::~PreferencesDialog()
Chris@0 362 {
Chris@438 363 SVDEBUG << "PreferencesDialog::~PreferencesDialog()" << endl;
Chris@0 364 }
Chris@0 365
Chris@0 366 void
Chris@9 367 PreferencesDialog::windowTypeChanged(WindowType type)
Chris@0 368 {
Chris@0 369 m_windowType = type;
Chris@0 370 m_applyButton->setEnabled(true);
Chris@0 371 }
Chris@0 372
Chris@0 373 void
Chris@115 374 PreferencesDialog::spectrogramSmoothingChanged(int smoothing)
Chris@0 375 {
Chris@115 376 m_spectrogramSmoothing = smoothing;
Chris@0 377 m_applyButton->setEnabled(true);
Chris@0 378 }
Chris@0 379
Chris@0 380 void
Chris@299 381 PreferencesDialog::spectrogramXSmoothingChanged(int smoothing)
Chris@299 382 {
Chris@299 383 m_spectrogramXSmoothing = smoothing;
Chris@299 384 m_applyButton->setEnabled(true);
Chris@299 385 }
Chris@299 386
Chris@299 387 void
Chris@0 388 PreferencesDialog::propertyLayoutChanged(int layout)
Chris@0 389 {
Chris@0 390 m_propertyLayout = layout;
Chris@0 391 m_applyButton->setEnabled(true);
Chris@0 392 }
Chris@0 393
Chris@0 394 void
Chris@0 395 PreferencesDialog::tuningFrequencyChanged(double freq)
Chris@0 396 {
Chris@0 397 m_tuningFrequency = freq;
Chris@0 398 m_applyButton->setEnabled(true);
Chris@0 399 }
Chris@0 400
Chris@0 401 void
Chris@263 402 PreferencesDialog::audioDeviceChanged(int s)
Chris@263 403 {
Chris@263 404 m_audioDevice = s;
Chris@263 405 m_applyButton->setEnabled(true);
Chris@263 406 m_changesOnRestart = true;
Chris@263 407 }
Chris@263 408
Chris@263 409 void
Chris@32 410 PreferencesDialog::resampleQualityChanged(int q)
Chris@32 411 {
Chris@32 412 m_resampleQuality = q;
Chris@32 413 m_applyButton->setEnabled(true);
Chris@32 414 }
Chris@32 415
Chris@32 416 void
Chris@180 417 PreferencesDialog::resampleOnLoadChanged(int state)
Chris@180 418 {
Chris@180 419 m_resampleOnLoad = (state == Qt::Checked);
Chris@180 420 m_applyButton->setEnabled(true);
Chris@180 421 m_changesOnRestart = true;
Chris@180 422 }
Chris@180 423
Chris@180 424 void
Chris@237 425 PreferencesDialog::showSplashChanged(int state)
Chris@237 426 {
Chris@237 427 m_showSplash = (state == Qt::Checked);
Chris@237 428 m_applyButton->setEnabled(true);
Chris@237 429 m_changesOnRestart = true;
Chris@237 430 }
Chris@237 431
Chris@237 432 void
mathieu@459 433 PreferencesDialog::startInMiniModeChanged(int state)
mathieu@459 434 {
mathieu@459 435 m_startInMiniMode = (state == Qt::Checked);
mathieu@459 436 m_applyButton->setEnabled(true);
mathieu@459 437 m_changesOnRestart = true;
mathieu@459 438 }
mathieu@459 439
mathieu@459 440 void
Chris@180 441 PreferencesDialog::tempDirRootChanged(QString r)
Chris@180 442 {
Chris@180 443 m_tempDirRoot = r;
Chris@180 444 m_applyButton->setEnabled(true);
Chris@180 445 }
Chris@180 446
Chris@180 447 void
Chris@180 448 PreferencesDialog::tempDirButtonClicked()
Chris@180 449 {
Chris@180 450 QString dir = QFileDialog::getExistingDirectory
Chris@180 451 (this, tr("Select a directory to create cache subdirectory in"),
Chris@180 452 m_tempDirRoot);
Chris@180 453 if (dir == "") return;
Chris@180 454 m_tempDirRootEdit->setText(dir);
Chris@180 455 tempDirRootChanged(dir);
Chris@180 456 m_changesOnRestart = true;
Chris@180 457 }
Chris@180 458
Chris@180 459 void
Chris@180 460 PreferencesDialog::backgroundModeChanged(int mode)
Chris@180 461 {
Chris@180 462 m_backgroundMode = mode;
Chris@180 463 m_applyButton->setEnabled(true);
Chris@180 464 m_changesOnRestart = true;
Chris@180 465 }
Chris@180 466
Chris@180 467 void
Chris@337 468 PreferencesDialog::timeToTextModeChanged(int mode)
Chris@337 469 {
Chris@337 470 m_timeToTextMode = mode;
Chris@337 471 m_applyButton->setEnabled(true);
Chris@337 472 }
Chris@337 473
Chris@337 474 void
Chris@225 475 PreferencesDialog::viewFontSizeChanged(int sz)
Chris@225 476 {
Chris@225 477 m_viewFontSize = sz;
Chris@225 478 m_applyButton->setEnabled(true);
Chris@225 479 }
Chris@225 480
Chris@225 481 void
Chris@0 482 PreferencesDialog::okClicked()
Chris@0 483 {
Chris@0 484 applyClicked();
Chris@0 485 accept();
Chris@0 486 }
Chris@0 487
Chris@0 488 void
Chris@0 489 PreferencesDialog::applyClicked()
Chris@0 490 {
Chris@0 491 Preferences *prefs = Preferences::getInstance();
Chris@0 492 prefs->setWindowType(WindowType(m_windowType));
Chris@115 493 prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing
Chris@115 494 (m_spectrogramSmoothing));
Chris@299 495 prefs->setSpectrogramXSmoothing(Preferences::SpectrogramXSmoothing
Chris@299 496 (m_spectrogramXSmoothing));
Chris@0 497 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
Chris@0 498 (m_propertyLayout));
Chris@0 499 prefs->setTuningFrequency(m_tuningFrequency);
Chris@32 500 prefs->setResampleQuality(m_resampleQuality);
Chris@180 501 prefs->setResampleOnLoad(m_resampleOnLoad);
Chris@237 502 prefs->setShowSplash(m_showSplash);
mathieu@459 503 prefs->setStartInMiniMode(m_startInMiniMode);
Chris@180 504 prefs->setTemporaryDirectoryRoot(m_tempDirRoot);
Chris@180 505 prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode));
Chris@337 506 prefs->setTimeToTextMode(Preferences::TimeToTextMode(m_timeToTextMode));
Chris@225 507 prefs->setViewFontSize(m_viewFontSize);
Chris@263 508
Chris@263 509 std::vector<QString> devices =
Chris@263 510 AudioTargetFactory::getInstance()->getCallbackTargetNames();
Chris@263 511
Chris@263 512 QSettings settings;
Chris@263 513 settings.beginGroup("Preferences");
Chris@263 514 settings.setValue("audio-target", devices[m_audioDevice]);
Chris@263 515 settings.endGroup();
Chris@180 516
Chris@0 517 m_applyButton->setEnabled(false);
Chris@180 518
Chris@180 519 if (m_changesOnRestart) {
Chris@180 520 QMessageBox::information(this, tr("Preferences"),
Chris@255 521 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 522 m_changesOnRestart = false;
Chris@180 523 }
Chris@0 524 }
Chris@0 525
Chris@0 526 void
Chris@0 527 PreferencesDialog::cancelClicked()
Chris@0 528 {
Chris@0 529 reject();
Chris@0 530 }
Chris@0 531
Chris@163 532 void
Chris@163 533 PreferencesDialog::applicationClosing(bool quickly)
Chris@163 534 {
Chris@163 535 if (quickly) {
Chris@163 536 reject();
Chris@163 537 return;
Chris@163 538 }
Chris@163 539
Chris@163 540 if (m_applyButton->isEnabled()) {
Chris@163 541 int rv = QMessageBox::warning
Chris@163 542 (this, tr("Preferences Changed"),
Chris@163 543 tr("Some preferences have been changed but not applied.\n"
Chris@163 544 "Apply them before closing?"),
Chris@163 545 QMessageBox::Apply | QMessageBox::Discard,
Chris@163 546 QMessageBox::Discard);
Chris@163 547 if (rv == QMessageBox::Apply) {
Chris@163 548 applyClicked();
Chris@163 549 accept();
Chris@163 550 } else {
Chris@163 551 reject();
Chris@163 552 }
Chris@163 553 } else {
Chris@163 554 accept();
Chris@163 555 }
Chris@163 556 }
Chris@163 557