annotate main/PreferencesDialog.cpp @ 1097:df73c834764c 3.0-integration

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