annotate main/PreferencesDialog.cpp @ 1390:4c5533df5d72 levelpanwidget

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