annotate main/PreferencesDialog.cpp @ 1034:7b2f70bcebe1 3.0-integration

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