annotate main/PreferencesDialog.cpp @ 1000:c05e5aa3d0f8 simple-fft-model

Smooth signal flow through from file to fft model
author Chris Cannam
date Mon, 15 Jun 2015 16:02:58 +0100
parents 6de549288477
children c9d87032f3da 28ccb621d1af
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 Sonic Visualiser
Chris@0 5 An audio file viewer and annotation editor.
Chris@0 6 Centre for Digital Music, Queen Mary, University of London.
Chris@0 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@0 9 This program is free software; you can redistribute it and/or
Chris@0 10 modify it under the terms of the GNU General Public License as
Chris@0 11 published by the Free Software Foundation; either version 2 of the
Chris@0 12 License, or (at your option) any later version. See the file
Chris@0 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "PreferencesDialog.h"
Chris@0 17
Chris@0 18 #include <QGridLayout>
Chris@0 19 #include <QComboBox>
Chris@0 20 #include <QCheckBox>
Chris@0 21 #include <QGroupBox>
Chris@0 22 #include <QDoubleSpinBox>
Chris@0 23 #include <QLabel>
Chris@0 24 #include <QPushButton>
Chris@0 25 #include <QHBoxLayout>
Chris@0 26 #include <QString>
Chris@163 27 #include <QDialogButtonBox>
Chris@163 28 #include <QMessageBox>
Chris@180 29 #include <QTabWidget>
Chris@180 30 #include <QLineEdit>
Chris@180 31 #include <QFileDialog>
Chris@180 32 #include <QMessageBox>
Chris@225 33 #include <QSpinBox>
Chris@436 34 #include <QListWidget>
Chris@263 35 #include <QSettings>
Chris@0 36
Chris@436 37 #include <set>
Chris@436 38
Chris@9 39 #include "widgets/WindowTypeSelector.h"
Chris@180 40 #include "widgets/IconLoader.h"
Chris@0 41 #include "base/Preferences.h"
Chris@263 42 #include "audioio/AudioTargetFactory.h"
Chris@436 43 #include "base/ResourceFinder.h"
Chris@0 44
Chris@686 45 #include "version.h"
Chris@686 46
Chris@528 47 PreferencesDialog::PreferencesDialog(QWidget *parent) :
Chris@528 48 QDialog(parent),
Chris@263 49 m_audioDevice(0),
Chris@180 50 m_changesOnRestart(false)
Chris@0 51 {
Chris@163 52 setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
Chris@0 53
Chris@0 54 Preferences *prefs = Preferences::getInstance();
Chris@0 55
Chris@0 56 QGridLayout *grid = new QGridLayout;
Chris@0 57 setLayout(grid);
Chris@180 58
Chris@436 59 m_tabs = new QTabWidget;
Chris@436 60 grid->addWidget(m_tabs, 0, 0);
Chris@0 61
Chris@436 62 m_tabs->setTabPosition(QTabWidget::North);
Chris@0 63
Chris@0 64 // Create this first, as slots that get called from the ctor will
Chris@0 65 // refer to it
Chris@0 66 m_applyButton = new QPushButton(tr("Apply"));
Chris@0 67
Chris@180 68 // Create all the preference widgets first, then create the
Chris@180 69 // individual tab widgets and place the preferences in their
Chris@180 70 // appropriate places in one go afterwards
Chris@180 71
Chris@114 72 int min, max, deflt, i;
Chris@0 73
Chris@9 74 m_windowType = WindowType(prefs->getPropertyRangeAndValue
Chris@114 75 ("Window Type", &min, &max, &deflt));
Chris@9 76 m_windowTypeSelector = new WindowTypeSelector(m_windowType);
Chris@0 77
Chris@9 78 connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)),
Chris@9 79 this, SLOT(windowTypeChanged(WindowType)));
Chris@0 80
Chris@115 81 QComboBox *smoothing = new QComboBox;
Chris@115 82
Chris@299 83 int sm = prefs->getPropertyRangeAndValue("Spectrogram Y Smoothing", &min, &max,
Chris@115 84 &deflt);
Chris@115 85 m_spectrogramSmoothing = sm;
Chris@0 86
Chris@115 87 for (i = min; i <= max; ++i) {
Chris@299 88 smoothing->addItem(prefs->getPropertyValueLabel("Spectrogram Y Smoothing", i));
Chris@115 89 }
Chris@115 90
Chris@115 91 smoothing->setCurrentIndex(sm);
Chris@115 92
Chris@115 93 connect(smoothing, SIGNAL(currentIndexChanged(int)),
Chris@115 94 this, SLOT(spectrogramSmoothingChanged(int)));
Chris@0 95
Chris@299 96 QComboBox *xsmoothing = new QComboBox;
Chris@299 97
Chris@299 98 int xsm = prefs->getPropertyRangeAndValue("Spectrogram X Smoothing", &min, &max,
Chris@299 99 &deflt);
Chris@299 100 m_spectrogramXSmoothing = xsm;
Chris@299 101
Chris@299 102 for (i = min; i <= max; ++i) {
Chris@299 103 xsmoothing->addItem(prefs->getPropertyValueLabel("Spectrogram X Smoothing", i));
Chris@299 104 }
Chris@299 105
Chris@299 106 xsmoothing->setCurrentIndex(xsm);
Chris@299 107
Chris@299 108 connect(xsmoothing, SIGNAL(currentIndexChanged(int)),
Chris@299 109 this, SLOT(spectrogramXSmoothingChanged(int)));
Chris@299 110
Chris@0 111 QComboBox *propertyLayout = new QComboBox;
Chris@114 112 int pl = prefs->getPropertyRangeAndValue("Property Box Layout", &min, &max,
Chris@115 113 &deflt);
Chris@0 114 m_propertyLayout = pl;
Chris@0 115
Chris@0 116 for (i = min; i <= max; ++i) {
Chris@0 117 propertyLayout->addItem(prefs->getPropertyValueLabel("Property Box Layout", i));
Chris@0 118 }
Chris@0 119
Chris@0 120 propertyLayout->setCurrentIndex(pl);
Chris@0 121
Chris@0 122 connect(propertyLayout, SIGNAL(currentIndexChanged(int)),
Chris@0 123 this, SLOT(propertyLayoutChanged(int)));
Chris@0 124
Chris@702 125
Chris@0 126 m_tuningFrequency = prefs->getTuningFrequency();
Chris@0 127
Chris@0 128 QDoubleSpinBox *frequency = new QDoubleSpinBox;
Chris@0 129 frequency->setMinimum(100.0);
Chris@0 130 frequency->setMaximum(5000.0);
Chris@0 131 frequency->setSuffix(" Hz");
Chris@0 132 frequency->setSingleStep(1);
Chris@0 133 frequency->setValue(m_tuningFrequency);
Chris@0 134 frequency->setDecimals(2);
Chris@0 135
Chris@0 136 connect(frequency, SIGNAL(valueChanged(double)),
Chris@0 137 this, SLOT(tuningFrequencyChanged(double)));
Chris@0 138
Chris@702 139 QComboBox *octaveSystem = new QComboBox;
Chris@702 140 int oct = prefs->getPropertyRangeAndValue
Chris@702 141 ("Octave Numbering System", &min, &max, &deflt);
Chris@702 142 m_octaveSystem = oct;
Chris@702 143 for (i = min; i <= max; ++i) {
Chris@702 144 octaveSystem->addItem(prefs->getPropertyValueLabel
Chris@702 145 ("Octave Numbering System", i));
Chris@702 146 }
Chris@702 147 octaveSystem->setCurrentIndex(oct);
Chris@702 148
Chris@702 149 connect(octaveSystem, SIGNAL(currentIndexChanged(int)),
Chris@702 150 this, SLOT(octaveSystemChanged(int)));
Chris@702 151
Chris@263 152 QComboBox *audioDevice = new QComboBox;
Chris@263 153 std::vector<QString> devices =
Chris@263 154 AudioTargetFactory::getInstance()->getCallbackTargetNames();
Chris@263 155
Chris@263 156 QSettings settings;
Chris@263 157 settings.beginGroup("Preferences");
Chris@263 158 QString targetName = settings.value("audio-target", "").toString();
Chris@263 159 settings.endGroup();
Chris@263 160
Chris@658 161 for (int i = 0; i < (int)devices.size(); ++i) {
Chris@263 162 audioDevice->addItem(AudioTargetFactory::getInstance()
Chris@263 163 ->getCallbackTargetDescription(devices[i]));
Chris@263 164 if (targetName == devices[i]) audioDevice->setCurrentIndex(i);
Chris@263 165 }
Chris@263 166
Chris@263 167 connect(audioDevice, SIGNAL(currentIndexChanged(int)),
Chris@263 168 this, SLOT(audioDeviceChanged(int)));
Chris@263 169
Chris@32 170 QComboBox *resampleQuality = new QComboBox;
Chris@32 171
Chris@114 172 int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max,
Chris@114 173 &deflt);
Chris@32 174 m_resampleQuality = rsq;
Chris@32 175
Chris@32 176 for (i = min; i <= max; ++i) {
Chris@32 177 resampleQuality->addItem(prefs->getPropertyValueLabel("Resample Quality", i));
Chris@32 178 }
Chris@32 179
Chris@32 180 resampleQuality->setCurrentIndex(rsq);
Chris@32 181
Chris@32 182 connect(resampleQuality, SIGNAL(currentIndexChanged(int)),
Chris@32 183 this, SLOT(resampleQualityChanged(int)));
Chris@32 184
Chris@180 185 QCheckBox *resampleOnLoad = new QCheckBox;
Chris@180 186 m_resampleOnLoad = prefs->getResampleOnLoad();
Chris@180 187 resampleOnLoad->setCheckState(m_resampleOnLoad ? Qt::Checked :
Chris@180 188 Qt::Unchecked);
Chris@180 189 connect(resampleOnLoad, SIGNAL(stateChanged(int)),
Chris@180 190 this, SLOT(resampleOnLoadChanged(int)));
Chris@180 191
Chris@180 192 m_tempDirRootEdit = new QLineEdit;
Chris@180 193 QString dir = prefs->getTemporaryDirectoryRoot();
Chris@180 194 m_tempDirRoot = dir;
Chris@180 195 dir.replace("$HOME", tr("<home directory>"));
Chris@180 196 m_tempDirRootEdit->setText(dir);
Chris@180 197 m_tempDirRootEdit->setReadOnly(true);
Chris@180 198 QPushButton *tempDirButton = new QPushButton;
Chris@180 199 tempDirButton->setIcon(IconLoader().load("fileopen"));
Chris@180 200 connect(tempDirButton, SIGNAL(clicked()),
Chris@180 201 this, SLOT(tempDirButtonClicked()));
Chris@180 202 tempDirButton->setFixedSize(QSize(24, 24));
Chris@180 203
Chris@237 204 QCheckBox *showSplash = new QCheckBox;
Chris@237 205 m_showSplash = prefs->getShowSplash();
Chris@237 206 showSplash->setCheckState(m_showSplash ? Qt::Checked : Qt::Unchecked);
Chris@237 207 connect(showSplash, SIGNAL(stateChanged(int)),
Chris@237 208 this, SLOT(showSplashChanged(int)));
Chris@237 209
Chris@661 210 #ifndef Q_OS_MAC
Chris@180 211 QComboBox *bgMode = new QComboBox;
Chris@180 212 int bg = prefs->getPropertyRangeAndValue("Background Mode", &min, &max,
Chris@180 213 &deflt);
Chris@180 214 m_backgroundMode = bg;
Chris@180 215 for (i = min; i <= max; ++i) {
Chris@180 216 bgMode->addItem(prefs->getPropertyValueLabel("Background Mode", i));
Chris@180 217 }
Chris@180 218 bgMode->setCurrentIndex(bg);
Chris@180 219
Chris@180 220 connect(bgMode, SIGNAL(currentIndexChanged(int)),
Chris@180 221 this, SLOT(backgroundModeChanged(int)));
Chris@237 222 #endif
Chris@180 223
Chris@658 224 settings.beginGroup("Preferences");
Chris@686 225
Chris@658 226 QString userLocale = settings.value("locale", "").toString();
Chris@658 227 m_currentLocale = userLocale;
Chris@686 228
Chris@686 229 QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
Chris@686 230 m_networkPermission = settings.value(permishTag, false).toBool();
Chris@686 231
Chris@658 232 settings.endGroup();
Chris@658 233
Chris@658 234 QComboBox *locale = new QComboBox;
Chris@658 235 QStringList localeFiles = QDir(":i18n").entryList(QStringList() << "*.qm");
Chris@658 236 locale->addItem(tr("Follow system locale"));
Chris@658 237 m_locales.push_back("");
Chris@658 238 if (userLocale == "") {
Chris@658 239 locale->setCurrentIndex(0);
Chris@658 240 }
Chris@658 241 foreach (QString f, localeFiles) {
Chris@658 242 QString f0 = f;
Chris@658 243 f.replace("sonic-visualiser_", "").replace(".qm", "");
Chris@658 244 if (f == f0) { // our expectations about filename format were not met
Chris@665 245 cerr << "INFO: Unexpected filename " << f << " in i18n resource directory" << endl;
Chris@658 246 } else {
Chris@658 247 m_locales.push_back(f);
Chris@658 248 QString displayText;
Chris@658 249 // Add new translations here
Chris@658 250 if (f == "ru") displayText = tr("Russian");
Chris@658 251 else if (f == "en_GB") displayText = tr("British English");
Chris@658 252 else if (f == "en_US") displayText = tr("American English");
Chris@658 253 else if (f == "cs_CZ") displayText = tr("Czech");
Chris@658 254 else displayText = f;
Chris@658 255 locale->addItem(QString("%1 [%2]").arg(displayText).arg(f));
Chris@658 256 if (userLocale == f) {
Chris@658 257 locale->setCurrentIndex(locale->count() - 1);
Chris@658 258 }
Chris@658 259 }
Chris@658 260 }
Chris@658 261 connect(locale, SIGNAL(currentIndexChanged(int)),
Chris@658 262 this, SLOT(localeChanged(int)));
Chris@658 263
Chris@686 264 QCheckBox *networkPermish = new QCheckBox;
Chris@686 265 networkPermish->setCheckState(m_networkPermission ? Qt::Checked : Qt::Unchecked);
Chris@686 266 connect(networkPermish, SIGNAL(stateChanged(int)),
Chris@686 267 this, SLOT(networkPermissionChanged(int)));
Chris@686 268
Chris@225 269 QSpinBox *fontSize = new QSpinBox;
Chris@225 270 int fs = prefs->getPropertyRangeAndValue("View Font Size", &min, &max,
Chris@225 271 &deflt);
Chris@234 272 m_viewFontSize = fs;
Chris@225 273 fontSize->setMinimum(min);
Chris@225 274 fontSize->setMaximum(max);
Chris@225 275 fontSize->setSuffix(" pt");
Chris@225 276 fontSize->setSingleStep(1);
Chris@225 277 fontSize->setValue(fs);
Chris@225 278
Chris@225 279 connect(fontSize, SIGNAL(valueChanged(int)),
Chris@225 280 this, SLOT(viewFontSizeChanged(int)));
Chris@225 281
Chris@337 282 QComboBox *ttMode = new QComboBox;
Chris@337 283 int tt = prefs->getPropertyRangeAndValue("Time To Text Mode", &min, &max,
Chris@337 284 &deflt);
Chris@337 285 m_timeToTextMode = tt;
Chris@337 286 for (i = min; i <= max; ++i) {
Chris@337 287 ttMode->addItem(prefs->getPropertyValueLabel("Time To Text Mode", i));
Chris@337 288 }
Chris@337 289 ttMode->setCurrentIndex(tt);
Chris@337 290
Chris@337 291 connect(ttMode, SIGNAL(currentIndexChanged(int)),
Chris@337 292 this, SLOT(timeToTextModeChanged(int)));
Chris@337 293
Chris@906 294 QCheckBox *hms = new QCheckBox;
Chris@906 295 int showHMS = prefs->getPropertyRangeAndValue
Chris@906 296 ("Show Hours And Minutes", &min, &max, &deflt);
Chris@906 297 m_showHMS = (showHMS != 0);
Chris@906 298 hms->setCheckState(m_showHMS ? Qt::Checked : Qt::Unchecked);
Chris@906 299 connect(hms, SIGNAL(stateChanged(int)),
Chris@906 300 this, SLOT(showHMSChanged(int)));
Chris@906 301
Chris@180 302 // General tab
Chris@180 303
Chris@180 304 QFrame *frame = new QFrame;
Chris@180 305
Chris@180 306 QGridLayout *subgrid = new QGridLayout;
Chris@180 307 frame->setLayout(subgrid);
Chris@180 308
Chris@0 309 int row = 0;
Chris@0 310
Chris@658 311 subgrid->addWidget(new QLabel(tr("%1:").arg(tr("User interface language"))),
Chris@658 312 row, 0);
Chris@658 313 subgrid->addWidget(locale, row++, 1, 1, 1);
Chris@658 314
Chris@686 315 subgrid->addWidget(new QLabel(tr("%1:").arg(tr("Allow network usage"))),
Chris@686 316 row, 0);
Chris@686 317 subgrid->addWidget(networkPermish, row++, 1, 1, 1);
Chris@686 318
Chris@0 319 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 320 ("Temporary Directory Root"))),
Chris@263 321 row, 0);
Chris@263 322 subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
Chris@263 323 subgrid->addWidget(tempDirButton, row, 2, 1, 1);
Chris@263 324 row++;
Chris@263 325
Chris@263 326 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 327 ("Resample On Load"))),
Chris@263 328 row, 0);
Chris@263 329 subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1);
Chris@263 330
Chris@263 331 subgrid->addWidget(new QLabel(tr("Playback audio device:")), row, 0);
Chris@263 332 subgrid->addWidget(audioDevice, row++, 1, 1, 2);
Chris@263 333
Chris@263 334 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 335 ("Resample Quality"))),
Chris@263 336 row, 0);
Chris@263 337 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
Chris@263 338
Chris@263 339 subgrid->setRowStretch(row, 10);
Chris@263 340
Chris@436 341 m_tabOrdering[GeneralTab] = m_tabs->count();
Chris@436 342 m_tabs->addTab(frame, tr("&General"));
Chris@263 343
Chris@263 344 // Appearance tab
Chris@263 345
Chris@263 346 frame = new QFrame;
Chris@263 347 subgrid = new QGridLayout;
Chris@263 348 frame->setLayout(subgrid);
Chris@263 349 row = 0;
Chris@263 350
Chris@263 351 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@906 352 ("Show Splash Screen"))),
Chris@906 353 row, 0);
Chris@906 354 subgrid->addWidget(showSplash, row++, 1, 1, 1);
Chris@906 355
Chris@906 356 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 357 ("Property Box Layout"))),
Chris@0 358 row, 0);
Chris@0 359 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
Chris@0 360
Chris@661 361 #ifndef Q_OS_MAC
Chris@0 362 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 363 ("Background Mode"))),
Chris@0 364 row, 0);
Chris@180 365 subgrid->addWidget(bgMode, row++, 1, 1, 2);
Chris@242 366 #endif
Chris@180 367
Chris@180 368 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@225 369 ("View Font Size"))),
Chris@225 370 row, 0);
Chris@225 371 subgrid->addWidget(fontSize, row++, 1, 1, 2);
Chris@225 372
Chris@225 373 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@337 374 ("Time To Text Mode"))),
Chris@337 375 row, 0);
Chris@337 376 subgrid->addWidget(ttMode, row++, 1, 1, 2);
Chris@337 377
Chris@337 378 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@906 379 ("Show Hours And Minutes"))),
Chris@237 380 row, 0);
Chris@906 381 subgrid->addWidget(hms, row++, 1, 1, 1);
Chris@237 382
Chris@180 383 subgrid->setRowStretch(row, 10);
Chris@180 384
Chris@436 385 m_tabOrdering[AppearanceTab] = m_tabs->count();
Chris@436 386 m_tabs->addTab(frame, tr("&Appearance"));
Chris@180 387
Chris@180 388 // Analysis tab
Chris@180 389
Chris@180 390 frame = new QFrame;
Chris@180 391 subgrid = new QGridLayout;
Chris@180 392 frame->setLayout(subgrid);
Chris@180 393 row = 0;
Chris@180 394
Chris@180 395 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 396 ("Tuning Frequency"))),
Chris@180 397 row, 0);
Chris@180 398 subgrid->addWidget(frequency, row++, 1, 1, 2);
Chris@180 399
Chris@702 400 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@702 401 ("Octave Numbering System"))),
Chris@702 402 row, 0);
Chris@702 403 subgrid->addWidget(octaveSystem, row++, 1, 1, 2);
Chris@702 404
Chris@0 405 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 406 ("Spectrogram Y Smoothing")),
Chris@115 407 row, 0);
Chris@115 408 subgrid->addWidget(smoothing, row++, 1, 1, 2);
Chris@0 409
Chris@299 410 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 411 ("Spectrogram X Smoothing")),
Chris@299 412 row, 0);
Chris@299 413 subgrid->addWidget(xsmoothing, row++, 1, 1, 2);
Chris@299 414
Chris@0 415 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 416 ("Window Type"))),
Chris@0 417 row, 0);
Chris@9 418 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
Chris@9 419 subgrid->setRowStretch(row, 10);
Chris@9 420 row++;
Chris@0 421
Chris@180 422 subgrid->setRowStretch(row, 10);
Chris@180 423
Chris@436 424 m_tabOrdering[AnalysisTab] = m_tabs->count();
Chris@436 425 m_tabs->addTab(frame, tr("Anal&ysis"));
Chris@436 426
Chris@436 427 // Template tab
Chris@436 428
Chris@436 429 frame = new QFrame;
Chris@436 430 subgrid = new QGridLayout;
Chris@436 431 frame->setLayout(subgrid);
Chris@436 432 row = 0;
Chris@436 433
Chris@436 434 subgrid->addWidget(new QLabel(tr("Default session template for audio files:")), row++, 0);
Chris@436 435
Chris@436 436 QListWidget *lw = new QListWidget();
Chris@436 437 subgrid->addWidget(lw, row, 0);
Chris@436 438 subgrid->setRowStretch(row, 10);
Chris@436 439 row++;
Chris@436 440
Chris@436 441 settings.beginGroup("MainWindow");
Chris@436 442 m_currentTemplate = settings.value("sessiontemplate", "").toString();
Chris@436 443 settings.endGroup();
Chris@436 444
Chris@455 445 lw->addItem(tr("Standard Waveform"));
Chris@436 446 if (m_currentTemplate == "" || m_currentTemplate == "default") {
Chris@436 447 lw->setCurrentRow(lw->count()-1);
Chris@436 448 }
Chris@436 449 m_templates.push_back("");
Chris@436 450
Chris@436 451 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
Chris@436 452
Chris@436 453 std::set<QString> byName;
Chris@436 454 foreach (QString t, templates) {
Chris@436 455 byName.insert(QFileInfo(t).baseName());
Chris@436 456 }
Chris@436 457
Chris@436 458 foreach (QString t, byName) {
Chris@436 459 if (t.toLower() == "default") continue;
Chris@436 460 m_templates.push_back(t);
Chris@436 461 lw->addItem(t);
Chris@436 462 if (m_currentTemplate == t) {
Chris@436 463 lw->setCurrentRow(lw->count()-1);
Chris@436 464 }
Chris@436 465 }
Chris@436 466
Chris@436 467 connect(lw, SIGNAL(currentRowChanged(int)), this, SLOT(defaultTemplateChanged(int)));
Chris@436 468
Chris@436 469 m_tabOrdering[TemplateTab] = m_tabs->count();
Chris@436 470 m_tabs->addTab(frame, tr("Session &Template"));
Chris@180 471
Chris@163 472 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
Chris@163 473 grid->addWidget(bb, 1, 0);
Chris@0 474
Chris@0 475 QPushButton *ok = new QPushButton(tr("OK"));
Chris@0 476 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@163 477 bb->addButton(ok, QDialogButtonBox::AcceptRole);
Chris@163 478 bb->addButton(m_applyButton, QDialogButtonBox::ApplyRole);
Chris@163 479 bb->addButton(cancel, QDialogButtonBox::RejectRole);
Chris@0 480 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
Chris@0 481 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
Chris@0 482 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
Chris@0 483
Chris@0 484 m_applyButton->setEnabled(false);
Chris@0 485 }
Chris@0 486
Chris@0 487 PreferencesDialog::~PreferencesDialog()
Chris@0 488 {
Chris@438 489 SVDEBUG << "PreferencesDialog::~PreferencesDialog()" << endl;
Chris@0 490 }
Chris@0 491
Chris@0 492 void
Chris@436 493 PreferencesDialog::switchToTab(Tab t)
Chris@436 494 {
Chris@436 495 if (m_tabOrdering.contains(t)) {
Chris@436 496 m_tabs->setCurrentIndex(m_tabOrdering[t]);
Chris@436 497 }
Chris@436 498 }
Chris@436 499
Chris@436 500 void
Chris@9 501 PreferencesDialog::windowTypeChanged(WindowType type)
Chris@0 502 {
Chris@0 503 m_windowType = type;
Chris@0 504 m_applyButton->setEnabled(true);
Chris@0 505 }
Chris@0 506
Chris@0 507 void
Chris@115 508 PreferencesDialog::spectrogramSmoothingChanged(int smoothing)
Chris@0 509 {
Chris@115 510 m_spectrogramSmoothing = smoothing;
Chris@0 511 m_applyButton->setEnabled(true);
Chris@0 512 }
Chris@0 513
Chris@0 514 void
Chris@299 515 PreferencesDialog::spectrogramXSmoothingChanged(int smoothing)
Chris@299 516 {
Chris@299 517 m_spectrogramXSmoothing = smoothing;
Chris@299 518 m_applyButton->setEnabled(true);
Chris@299 519 }
Chris@299 520
Chris@299 521 void
Chris@0 522 PreferencesDialog::propertyLayoutChanged(int layout)
Chris@0 523 {
Chris@0 524 m_propertyLayout = layout;
Chris@0 525 m_applyButton->setEnabled(true);
Chris@0 526 }
Chris@0 527
Chris@0 528 void
Chris@0 529 PreferencesDialog::tuningFrequencyChanged(double freq)
Chris@0 530 {
Chris@0 531 m_tuningFrequency = freq;
Chris@0 532 m_applyButton->setEnabled(true);
Chris@0 533 }
Chris@0 534
Chris@0 535 void
Chris@263 536 PreferencesDialog::audioDeviceChanged(int s)
Chris@263 537 {
Chris@263 538 m_audioDevice = s;
Chris@263 539 m_applyButton->setEnabled(true);
Chris@263 540 m_changesOnRestart = true;
Chris@263 541 }
Chris@263 542
Chris@263 543 void
Chris@32 544 PreferencesDialog::resampleQualityChanged(int q)
Chris@32 545 {
Chris@32 546 m_resampleQuality = q;
Chris@32 547 m_applyButton->setEnabled(true);
Chris@32 548 }
Chris@32 549
Chris@32 550 void
Chris@180 551 PreferencesDialog::resampleOnLoadChanged(int state)
Chris@180 552 {
Chris@180 553 m_resampleOnLoad = (state == Qt::Checked);
Chris@180 554 m_applyButton->setEnabled(true);
Chris@180 555 m_changesOnRestart = true;
Chris@180 556 }
Chris@180 557
Chris@180 558 void
Chris@686 559 PreferencesDialog::networkPermissionChanged(int state)
Chris@686 560 {
Chris@686 561 m_networkPermission = (state == Qt::Checked);
Chris@686 562 m_applyButton->setEnabled(true);
Chris@686 563 m_changesOnRestart = true;
Chris@686 564 }
Chris@686 565
Chris@686 566 void
Chris@237 567 PreferencesDialog::showSplashChanged(int state)
Chris@237 568 {
Chris@237 569 m_showSplash = (state == Qt::Checked);
Chris@237 570 m_applyButton->setEnabled(true);
Chris@237 571 m_changesOnRestart = true;
Chris@237 572 }
Chris@237 573
Chris@237 574 void
Chris@436 575 PreferencesDialog::defaultTemplateChanged(int i)
Chris@436 576 {
Chris@436 577 m_currentTemplate = m_templates[i];
Chris@436 578 m_applyButton->setEnabled(true);
Chris@436 579 }
Chris@436 580
Chris@436 581 void
Chris@658 582 PreferencesDialog::localeChanged(int i)
Chris@658 583 {
Chris@658 584 m_currentLocale = m_locales[i];
Chris@658 585 m_applyButton->setEnabled(true);
Chris@658 586 m_changesOnRestart = true;
Chris@658 587 }
Chris@658 588
Chris@658 589 void
Chris@180 590 PreferencesDialog::tempDirRootChanged(QString r)
Chris@180 591 {
Chris@180 592 m_tempDirRoot = r;
Chris@180 593 m_applyButton->setEnabled(true);
Chris@180 594 }
Chris@180 595
Chris@180 596 void
Chris@180 597 PreferencesDialog::tempDirButtonClicked()
Chris@180 598 {
Chris@180 599 QString dir = QFileDialog::getExistingDirectory
Chris@180 600 (this, tr("Select a directory to create cache subdirectory in"),
Chris@180 601 m_tempDirRoot);
Chris@180 602 if (dir == "") return;
Chris@180 603 m_tempDirRootEdit->setText(dir);
Chris@180 604 tempDirRootChanged(dir);
Chris@180 605 m_changesOnRestart = true;
Chris@180 606 }
Chris@180 607
Chris@180 608 void
Chris@180 609 PreferencesDialog::backgroundModeChanged(int mode)
Chris@180 610 {
Chris@180 611 m_backgroundMode = mode;
Chris@180 612 m_applyButton->setEnabled(true);
Chris@180 613 m_changesOnRestart = true;
Chris@180 614 }
Chris@180 615
Chris@180 616 void
Chris@337 617 PreferencesDialog::timeToTextModeChanged(int mode)
Chris@337 618 {
Chris@337 619 m_timeToTextMode = mode;
Chris@337 620 m_applyButton->setEnabled(true);
Chris@337 621 }
Chris@337 622
Chris@337 623 void
Chris@906 624 PreferencesDialog::showHMSChanged(int state)
Chris@906 625 {
Chris@906 626 m_showHMS = (state == Qt::Checked);
Chris@906 627 m_applyButton->setEnabled(true);
Chris@906 628 }
Chris@906 629
Chris@906 630 void
Chris@702 631 PreferencesDialog::octaveSystemChanged(int system)
Chris@702 632 {
Chris@702 633 m_octaveSystem = system;
Chris@702 634 m_applyButton->setEnabled(true);
Chris@702 635 }
Chris@702 636
Chris@702 637 void
Chris@225 638 PreferencesDialog::viewFontSizeChanged(int sz)
Chris@225 639 {
Chris@225 640 m_viewFontSize = sz;
Chris@225 641 m_applyButton->setEnabled(true);
Chris@225 642 }
Chris@225 643
Chris@225 644 void
Chris@0 645 PreferencesDialog::okClicked()
Chris@0 646 {
Chris@0 647 applyClicked();
Chris@0 648 accept();
Chris@0 649 }
Chris@0 650
Chris@0 651 void
Chris@0 652 PreferencesDialog::applyClicked()
Chris@0 653 {
Chris@0 654 Preferences *prefs = Preferences::getInstance();
Chris@0 655 prefs->setWindowType(WindowType(m_windowType));
Chris@115 656 prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing
Chris@115 657 (m_spectrogramSmoothing));
Chris@299 658 prefs->setSpectrogramXSmoothing(Preferences::SpectrogramXSmoothing
Chris@299 659 (m_spectrogramXSmoothing));
Chris@0 660 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
Chris@0 661 (m_propertyLayout));
Chris@0 662 prefs->setTuningFrequency(m_tuningFrequency);
Chris@32 663 prefs->setResampleQuality(m_resampleQuality);
Chris@180 664 prefs->setResampleOnLoad(m_resampleOnLoad);
Chris@237 665 prefs->setShowSplash(m_showSplash);
Chris@180 666 prefs->setTemporaryDirectoryRoot(m_tempDirRoot);
Chris@180 667 prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode));
Chris@337 668 prefs->setTimeToTextMode(Preferences::TimeToTextMode(m_timeToTextMode));
Chris@906 669 prefs->setShowHMS(m_showHMS);
Chris@225 670 prefs->setViewFontSize(m_viewFontSize);
Chris@263 671
Chris@702 672 prefs->setProperty("Octave Numbering System", m_octaveSystem);
Chris@702 673
Chris@263 674 std::vector<QString> devices =
Chris@263 675 AudioTargetFactory::getInstance()->getCallbackTargetNames();
Chris@263 676
Chris@263 677 QSettings settings;
Chris@263 678 settings.beginGroup("Preferences");
Chris@686 679 QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
Chris@686 680 settings.setValue(permishTag, m_networkPermission);
Chris@263 681 settings.setValue("audio-target", devices[m_audioDevice]);
Chris@686 682 settings.setValue("locale", m_currentLocale);
Chris@263 683 settings.endGroup();
Chris@180 684
Chris@436 685 settings.beginGroup("MainWindow");
Chris@436 686 settings.setValue("sessiontemplate", m_currentTemplate);
Chris@436 687 settings.endGroup();
Chris@436 688
Chris@0 689 m_applyButton->setEnabled(false);
Chris@180 690
Chris@180 691 if (m_changesOnRestart) {
Chris@180 692 QMessageBox::information(this, tr("Preferences"),
Chris@255 693 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 694 m_changesOnRestart = false;
Chris@180 695 }
Chris@0 696 }
Chris@0 697
Chris@0 698 void
Chris@0 699 PreferencesDialog::cancelClicked()
Chris@0 700 {
Chris@0 701 reject();
Chris@0 702 }
Chris@0 703
Chris@163 704 void
Chris@163 705 PreferencesDialog::applicationClosing(bool quickly)
Chris@163 706 {
Chris@163 707 if (quickly) {
Chris@163 708 reject();
Chris@163 709 return;
Chris@163 710 }
Chris@163 711
Chris@163 712 if (m_applyButton->isEnabled()) {
Chris@163 713 int rv = QMessageBox::warning
Chris@163 714 (this, tr("Preferences Changed"),
Chris@163 715 tr("Some preferences have been changed but not applied.\n"
Chris@163 716 "Apply them before closing?"),
Chris@163 717 QMessageBox::Apply | QMessageBox::Discard,
Chris@163 718 QMessageBox::Discard);
Chris@163 719 if (rv == QMessageBox::Apply) {
Chris@163 720 applyClicked();
Chris@163 721 accept();
Chris@163 722 } else {
Chris@163 723 reject();
Chris@163 724 }
Chris@163 725 } else {
Chris@163 726 accept();
Chris@163 727 }
Chris@163 728 }
Chris@163 729