annotate main/PreferencesDialog.cpp @ 597:110eecb5d9f6

Reset cyclical counters when document is replaced (#182)
author Chris Cannam
date Wed, 24 Jul 2013 12:02:01 +0100
parents e5e6625deb85
children ba338234c001 86d1f640ae1e
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@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@263 145 for (int i = 0; i < 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@237 194 #ifndef Q_WS_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@225 208 QSpinBox *fontSize = new QSpinBox;
Chris@225 209 int fs = prefs->getPropertyRangeAndValue("View Font Size", &min, &max,
Chris@225 210 &deflt);
Chris@234 211 m_viewFontSize = fs;
Chris@225 212 fontSize->setMinimum(min);
Chris@225 213 fontSize->setMaximum(max);
Chris@225 214 fontSize->setSuffix(" pt");
Chris@225 215 fontSize->setSingleStep(1);
Chris@225 216 fontSize->setValue(fs);
Chris@225 217
Chris@225 218 connect(fontSize, SIGNAL(valueChanged(int)),
Chris@225 219 this, SLOT(viewFontSizeChanged(int)));
Chris@225 220
Chris@337 221 QComboBox *ttMode = new QComboBox;
Chris@337 222 int tt = prefs->getPropertyRangeAndValue("Time To Text Mode", &min, &max,
Chris@337 223 &deflt);
Chris@337 224 m_timeToTextMode = tt;
Chris@337 225 for (i = min; i <= max; ++i) {
Chris@337 226 ttMode->addItem(prefs->getPropertyValueLabel("Time To Text Mode", i));
Chris@337 227 }
Chris@337 228 ttMode->setCurrentIndex(tt);
Chris@337 229
Chris@337 230 connect(ttMode, SIGNAL(currentIndexChanged(int)),
Chris@337 231 this, SLOT(timeToTextModeChanged(int)));
Chris@337 232
Chris@180 233 // General tab
Chris@180 234
Chris@180 235 QFrame *frame = new QFrame;
Chris@180 236
Chris@180 237 QGridLayout *subgrid = new QGridLayout;
Chris@180 238 frame->setLayout(subgrid);
Chris@180 239
Chris@0 240 int row = 0;
Chris@0 241
Chris@0 242 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 243 ("Temporary Directory Root"))),
Chris@263 244 row, 0);
Chris@263 245 subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
Chris@263 246 subgrid->addWidget(tempDirButton, row, 2, 1, 1);
Chris@263 247 row++;
Chris@263 248
Chris@263 249 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 250 ("Resample On Load"))),
Chris@263 251 row, 0);
Chris@263 252 subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1);
Chris@263 253
Chris@263 254 subgrid->addWidget(new QLabel(tr("Playback audio device:")), row, 0);
Chris@263 255 subgrid->addWidget(audioDevice, row++, 1, 1, 2);
Chris@263 256
Chris@263 257 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 258 ("Resample Quality"))),
Chris@263 259 row, 0);
Chris@263 260 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
Chris@263 261
Chris@263 262 subgrid->setRowStretch(row, 10);
Chris@263 263
Chris@436 264 m_tabOrdering[GeneralTab] = m_tabs->count();
Chris@436 265 m_tabs->addTab(frame, tr("&General"));
Chris@263 266
Chris@263 267 // Appearance tab
Chris@263 268
Chris@263 269 frame = new QFrame;
Chris@263 270 subgrid = new QGridLayout;
Chris@263 271 frame->setLayout(subgrid);
Chris@263 272 row = 0;
Chris@263 273
Chris@263 274 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 275 ("Property Box Layout"))),
Chris@0 276 row, 0);
Chris@0 277 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
Chris@0 278
Chris@242 279 #ifndef Q_WS_MAC
Chris@0 280 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 281 ("Background Mode"))),
Chris@0 282 row, 0);
Chris@180 283 subgrid->addWidget(bgMode, row++, 1, 1, 2);
Chris@242 284 #endif
Chris@180 285
Chris@180 286 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@225 287 ("View Font Size"))),
Chris@225 288 row, 0);
Chris@225 289 subgrid->addWidget(fontSize, row++, 1, 1, 2);
Chris@225 290
Chris@225 291 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@337 292 ("Time To Text Mode"))),
Chris@337 293 row, 0);
Chris@337 294 subgrid->addWidget(ttMode, row++, 1, 1, 2);
Chris@337 295
Chris@337 296 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@237 297 ("Show Splash Screen"))),
Chris@237 298 row, 0);
Chris@237 299 subgrid->addWidget(showSplash, row++, 1, 1, 1);
Chris@237 300
Chris@180 301 subgrid->setRowStretch(row, 10);
Chris@180 302
Chris@436 303 m_tabOrdering[AppearanceTab] = m_tabs->count();
Chris@436 304 m_tabs->addTab(frame, tr("&Appearance"));
Chris@180 305
Chris@180 306 // Analysis tab
Chris@180 307
Chris@180 308 frame = new QFrame;
Chris@180 309 subgrid = new QGridLayout;
Chris@180 310 frame->setLayout(subgrid);
Chris@180 311 row = 0;
Chris@180 312
Chris@180 313 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 314 ("Tuning Frequency"))),
Chris@180 315 row, 0);
Chris@180 316 subgrid->addWidget(frequency, row++, 1, 1, 2);
Chris@180 317
Chris@0 318 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 319 ("Spectrogram Y Smoothing")),
Chris@115 320 row, 0);
Chris@115 321 subgrid->addWidget(smoothing, row++, 1, 1, 2);
Chris@0 322
Chris@299 323 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 324 ("Spectrogram X Smoothing")),
Chris@299 325 row, 0);
Chris@299 326 subgrid->addWidget(xsmoothing, row++, 1, 1, 2);
Chris@299 327
Chris@0 328 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 329 ("Window Type"))),
Chris@0 330 row, 0);
Chris@9 331 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
Chris@9 332 subgrid->setRowStretch(row, 10);
Chris@9 333 row++;
Chris@0 334
Chris@180 335 subgrid->setRowStretch(row, 10);
Chris@180 336
Chris@436 337 m_tabOrdering[AnalysisTab] = m_tabs->count();
Chris@436 338 m_tabs->addTab(frame, tr("Anal&ysis"));
Chris@436 339
Chris@436 340 // Template tab
Chris@436 341
Chris@436 342 frame = new QFrame;
Chris@436 343 subgrid = new QGridLayout;
Chris@436 344 frame->setLayout(subgrid);
Chris@436 345 row = 0;
Chris@436 346
Chris@436 347 subgrid->addWidget(new QLabel(tr("Default session template for audio files:")), row++, 0);
Chris@436 348
Chris@436 349 QListWidget *lw = new QListWidget();
Chris@436 350 subgrid->addWidget(lw, row, 0);
Chris@436 351 subgrid->setRowStretch(row, 10);
Chris@436 352 row++;
Chris@436 353
Chris@436 354 settings.beginGroup("MainWindow");
Chris@436 355 m_currentTemplate = settings.value("sessiontemplate", "").toString();
Chris@436 356 settings.endGroup();
Chris@436 357
Chris@455 358 lw->addItem(tr("Standard Waveform"));
Chris@436 359 if (m_currentTemplate == "" || m_currentTemplate == "default") {
Chris@436 360 lw->setCurrentRow(lw->count()-1);
Chris@436 361 }
Chris@436 362 m_templates.push_back("");
Chris@436 363
Chris@436 364 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
Chris@436 365
Chris@436 366 std::set<QString> byName;
Chris@436 367 foreach (QString t, templates) {
Chris@436 368 byName.insert(QFileInfo(t).baseName());
Chris@436 369 }
Chris@436 370
Chris@436 371 foreach (QString t, byName) {
Chris@436 372 if (t.toLower() == "default") continue;
Chris@436 373 m_templates.push_back(t);
Chris@436 374 lw->addItem(t);
Chris@436 375 if (m_currentTemplate == t) {
Chris@436 376 lw->setCurrentRow(lw->count()-1);
Chris@436 377 }
Chris@436 378 }
Chris@436 379
Chris@436 380 connect(lw, SIGNAL(currentRowChanged(int)), this, SLOT(defaultTemplateChanged(int)));
Chris@436 381
Chris@436 382 m_tabOrdering[TemplateTab] = m_tabs->count();
Chris@436 383 m_tabs->addTab(frame, tr("Session &Template"));
Chris@180 384
Chris@163 385 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
Chris@163 386 grid->addWidget(bb, 1, 0);
Chris@0 387
Chris@0 388 QPushButton *ok = new QPushButton(tr("OK"));
Chris@0 389 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@163 390 bb->addButton(ok, QDialogButtonBox::AcceptRole);
Chris@163 391 bb->addButton(m_applyButton, QDialogButtonBox::ApplyRole);
Chris@163 392 bb->addButton(cancel, QDialogButtonBox::RejectRole);
Chris@0 393 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
Chris@0 394 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
Chris@0 395 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
Chris@0 396
Chris@0 397 m_applyButton->setEnabled(false);
Chris@0 398 }
Chris@0 399
Chris@0 400 PreferencesDialog::~PreferencesDialog()
Chris@0 401 {
Chris@438 402 SVDEBUG << "PreferencesDialog::~PreferencesDialog()" << endl;
Chris@0 403 }
Chris@0 404
Chris@0 405 void
Chris@436 406 PreferencesDialog::switchToTab(Tab t)
Chris@436 407 {
Chris@436 408 if (m_tabOrdering.contains(t)) {
Chris@436 409 m_tabs->setCurrentIndex(m_tabOrdering[t]);
Chris@436 410 }
Chris@436 411 }
Chris@436 412
Chris@436 413 void
Chris@9 414 PreferencesDialog::windowTypeChanged(WindowType type)
Chris@0 415 {
Chris@0 416 m_windowType = type;
Chris@0 417 m_applyButton->setEnabled(true);
Chris@0 418 }
Chris@0 419
Chris@0 420 void
Chris@115 421 PreferencesDialog::spectrogramSmoothingChanged(int smoothing)
Chris@0 422 {
Chris@115 423 m_spectrogramSmoothing = smoothing;
Chris@0 424 m_applyButton->setEnabled(true);
Chris@0 425 }
Chris@0 426
Chris@0 427 void
Chris@299 428 PreferencesDialog::spectrogramXSmoothingChanged(int smoothing)
Chris@299 429 {
Chris@299 430 m_spectrogramXSmoothing = smoothing;
Chris@299 431 m_applyButton->setEnabled(true);
Chris@299 432 }
Chris@299 433
Chris@299 434 void
Chris@0 435 PreferencesDialog::propertyLayoutChanged(int layout)
Chris@0 436 {
Chris@0 437 m_propertyLayout = layout;
Chris@0 438 m_applyButton->setEnabled(true);
Chris@0 439 }
Chris@0 440
Chris@0 441 void
Chris@0 442 PreferencesDialog::tuningFrequencyChanged(double freq)
Chris@0 443 {
Chris@0 444 m_tuningFrequency = freq;
Chris@0 445 m_applyButton->setEnabled(true);
Chris@0 446 }
Chris@0 447
Chris@0 448 void
Chris@263 449 PreferencesDialog::audioDeviceChanged(int s)
Chris@263 450 {
Chris@263 451 m_audioDevice = s;
Chris@263 452 m_applyButton->setEnabled(true);
Chris@263 453 m_changesOnRestart = true;
Chris@263 454 }
Chris@263 455
Chris@263 456 void
Chris@32 457 PreferencesDialog::resampleQualityChanged(int q)
Chris@32 458 {
Chris@32 459 m_resampleQuality = q;
Chris@32 460 m_applyButton->setEnabled(true);
Chris@32 461 }
Chris@32 462
Chris@32 463 void
Chris@180 464 PreferencesDialog::resampleOnLoadChanged(int state)
Chris@180 465 {
Chris@180 466 m_resampleOnLoad = (state == Qt::Checked);
Chris@180 467 m_applyButton->setEnabled(true);
Chris@180 468 m_changesOnRestart = true;
Chris@180 469 }
Chris@180 470
Chris@180 471 void
Chris@237 472 PreferencesDialog::showSplashChanged(int state)
Chris@237 473 {
Chris@237 474 m_showSplash = (state == Qt::Checked);
Chris@237 475 m_applyButton->setEnabled(true);
Chris@237 476 m_changesOnRestart = true;
Chris@237 477 }
Chris@237 478
Chris@237 479 void
Chris@436 480 PreferencesDialog::defaultTemplateChanged(int i)
Chris@436 481 {
Chris@436 482 m_currentTemplate = m_templates[i];
Chris@436 483 m_applyButton->setEnabled(true);
Chris@436 484 }
Chris@436 485
Chris@436 486 void
Chris@180 487 PreferencesDialog::tempDirRootChanged(QString r)
Chris@180 488 {
Chris@180 489 m_tempDirRoot = r;
Chris@180 490 m_applyButton->setEnabled(true);
Chris@180 491 }
Chris@180 492
Chris@180 493 void
Chris@180 494 PreferencesDialog::tempDirButtonClicked()
Chris@180 495 {
Chris@180 496 QString dir = QFileDialog::getExistingDirectory
Chris@180 497 (this, tr("Select a directory to create cache subdirectory in"),
Chris@180 498 m_tempDirRoot);
Chris@180 499 if (dir == "") return;
Chris@180 500 m_tempDirRootEdit->setText(dir);
Chris@180 501 tempDirRootChanged(dir);
Chris@180 502 m_changesOnRestart = true;
Chris@180 503 }
Chris@180 504
Chris@180 505 void
Chris@180 506 PreferencesDialog::backgroundModeChanged(int mode)
Chris@180 507 {
Chris@180 508 m_backgroundMode = mode;
Chris@180 509 m_applyButton->setEnabled(true);
Chris@180 510 m_changesOnRestart = true;
Chris@180 511 }
Chris@180 512
Chris@180 513 void
Chris@337 514 PreferencesDialog::timeToTextModeChanged(int mode)
Chris@337 515 {
Chris@337 516 m_timeToTextMode = mode;
Chris@337 517 m_applyButton->setEnabled(true);
Chris@337 518 }
Chris@337 519
Chris@337 520 void
Chris@225 521 PreferencesDialog::viewFontSizeChanged(int sz)
Chris@225 522 {
Chris@225 523 m_viewFontSize = sz;
Chris@225 524 m_applyButton->setEnabled(true);
Chris@225 525 }
Chris@225 526
Chris@225 527 void
Chris@0 528 PreferencesDialog::okClicked()
Chris@0 529 {
Chris@0 530 applyClicked();
Chris@0 531 accept();
Chris@0 532 }
Chris@0 533
Chris@0 534 void
Chris@0 535 PreferencesDialog::applyClicked()
Chris@0 536 {
Chris@0 537 Preferences *prefs = Preferences::getInstance();
Chris@0 538 prefs->setWindowType(WindowType(m_windowType));
Chris@115 539 prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing
Chris@115 540 (m_spectrogramSmoothing));
Chris@299 541 prefs->setSpectrogramXSmoothing(Preferences::SpectrogramXSmoothing
Chris@299 542 (m_spectrogramXSmoothing));
Chris@0 543 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
Chris@0 544 (m_propertyLayout));
Chris@0 545 prefs->setTuningFrequency(m_tuningFrequency);
Chris@32 546 prefs->setResampleQuality(m_resampleQuality);
Chris@180 547 prefs->setResampleOnLoad(m_resampleOnLoad);
Chris@237 548 prefs->setShowSplash(m_showSplash);
Chris@180 549 prefs->setTemporaryDirectoryRoot(m_tempDirRoot);
Chris@180 550 prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode));
Chris@337 551 prefs->setTimeToTextMode(Preferences::TimeToTextMode(m_timeToTextMode));
Chris@225 552 prefs->setViewFontSize(m_viewFontSize);
Chris@263 553
Chris@263 554 std::vector<QString> devices =
Chris@263 555 AudioTargetFactory::getInstance()->getCallbackTargetNames();
Chris@263 556
Chris@263 557 QSettings settings;
Chris@436 558
Chris@263 559 settings.beginGroup("Preferences");
Chris@263 560 settings.setValue("audio-target", devices[m_audioDevice]);
Chris@263 561 settings.endGroup();
Chris@180 562
Chris@436 563 settings.beginGroup("MainWindow");
Chris@436 564 settings.setValue("sessiontemplate", m_currentTemplate);
Chris@436 565 settings.endGroup();
Chris@436 566
Chris@0 567 m_applyButton->setEnabled(false);
Chris@180 568
Chris@180 569 if (m_changesOnRestart) {
Chris@180 570 QMessageBox::information(this, tr("Preferences"),
Chris@255 571 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 572 m_changesOnRestart = false;
Chris@180 573 }
Chris@0 574 }
Chris@0 575
Chris@0 576 void
Chris@0 577 PreferencesDialog::cancelClicked()
Chris@0 578 {
Chris@0 579 reject();
Chris@0 580 }
Chris@0 581
Chris@163 582 void
Chris@163 583 PreferencesDialog::applicationClosing(bool quickly)
Chris@163 584 {
Chris@163 585 if (quickly) {
Chris@163 586 reject();
Chris@163 587 return;
Chris@163 588 }
Chris@163 589
Chris@163 590 if (m_applyButton->isEnabled()) {
Chris@163 591 int rv = QMessageBox::warning
Chris@163 592 (this, tr("Preferences Changed"),
Chris@163 593 tr("Some preferences have been changed but not applied.\n"
Chris@163 594 "Apply them before closing?"),
Chris@163 595 QMessageBox::Apply | QMessageBox::Discard,
Chris@163 596 QMessageBox::Discard);
Chris@163 597 if (rv == QMessageBox::Apply) {
Chris@163 598 applyClicked();
Chris@163 599 accept();
Chris@163 600 } else {
Chris@163 601 reject();
Chris@163 602 }
Chris@163 603 } else {
Chris@163 604 accept();
Chris@163 605 }
Chris@163 606 }
Chris@163 607