annotate main/PreferencesDialog.cpp @ 1096:11ef2f95ea15 3.0-integration

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