annotate main/PreferencesDialog.cpp @ 1150:5e6e1e074080 3.0-plus-imaf

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