annotate main/PreferencesDialog.cpp @ 903:6d3220e7ecef cxx11

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