lbajardsilogic@0: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ lbajardsilogic@0: lbajardsilogic@0: /* lbajardsilogic@0: Sonic Visualiser lbajardsilogic@0: An audio file viewer and annotation editor. lbajardsilogic@0: Centre for Digital Music, Queen Mary, University of London. lbajardsilogic@0: This file copyright 2006 Chris Cannam. lbajardsilogic@0: lbajardsilogic@0: This program is free software; you can redistribute it and/or lbajardsilogic@0: modify it under the terms of the GNU General Public License as lbajardsilogic@0: published by the Free Software Foundation; either version 2 of the lbajardsilogic@0: License, or (at your option) any later version. See the file lbajardsilogic@0: COPYING included with this distribution for more information. lbajardsilogic@0: */ lbajardsilogic@0: lbajardsilogic@0: #include "PreferencesDialog.h" lbajardsilogic@0: lbajardsilogic@0: #include lbajardsilogic@0: #include lbajardsilogic@0: #include lbajardsilogic@0: #include lbajardsilogic@0: #include lbajardsilogic@0: #include lbajardsilogic@0: #include lbajardsilogic@0: #include lbajardsilogic@0: #include lbajardsilogic@0: lbajardsilogic@0: #include "widgets/WindowTypeSelector.h" lbajardsilogic@0: #include "base/Preferences.h" lbajardsilogic@0: lbajardsilogic@0: PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) : lbajardsilogic@0: QDialog(parent, flags) lbajardsilogic@0: { lbajardsilogic@0: setWindowTitle(tr("Application Preferences")); lbajardsilogic@0: lbajardsilogic@0: Preferences *prefs = Preferences::getInstance(); lbajardsilogic@0: lbajardsilogic@0: QGridLayout *grid = new QGridLayout; lbajardsilogic@0: setLayout(grid); lbajardsilogic@0: lbajardsilogic@0: QGroupBox *groupBox = new QGroupBox; lbajardsilogic@42: groupBox->setTitle(tr("Sound Access Application Preferences")); lbajardsilogic@0: grid->addWidget(groupBox, 0, 0); lbajardsilogic@0: lbajardsilogic@0: QGridLayout *subgrid = new QGridLayout; lbajardsilogic@0: groupBox->setLayout(subgrid); lbajardsilogic@0: lbajardsilogic@0: // Create this first, as slots that get called from the ctor will lbajardsilogic@0: // refer to it lbajardsilogic@0: m_applyButton = new QPushButton(tr("Apply")); lbajardsilogic@0: lbajardsilogic@0: int min, max, deflt, i; lbajardsilogic@0: lbajardsilogic@0: m_windowType = WindowType(prefs->getPropertyRangeAndValue lbajardsilogic@0: ("Window Type", &min, &max, &deflt)); lbajardsilogic@0: m_windowTypeSelector = new WindowTypeSelector(m_windowType); lbajardsilogic@0: lbajardsilogic@0: connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)), lbajardsilogic@0: this, SLOT(windowTypeChanged(WindowType))); lbajardsilogic@0: lbajardsilogic@0: QComboBox *smoothing = new QComboBox; lbajardsilogic@0: lbajardsilogic@0: int sm = prefs->getPropertyRangeAndValue("Spectrogram Smoothing", &min, &max, lbajardsilogic@0: &deflt); lbajardsilogic@0: m_spectrogramSmoothing = sm; lbajardsilogic@0: lbajardsilogic@0: for (i = min; i <= max; ++i) { lbajardsilogic@0: smoothing->addItem(prefs->getPropertyValueLabel("Spectrogram Smoothing", i)); lbajardsilogic@0: } lbajardsilogic@0: lbajardsilogic@0: smoothing->setCurrentIndex(sm); lbajardsilogic@0: lbajardsilogic@0: connect(smoothing, SIGNAL(currentIndexChanged(int)), lbajardsilogic@0: this, SLOT(spectrogramSmoothingChanged(int))); lbajardsilogic@0: lbajardsilogic@0: m_tuningFrequency = prefs->getTuningFrequency(); lbajardsilogic@0: lbajardsilogic@0: QDoubleSpinBox *frequency = new QDoubleSpinBox; lbajardsilogic@0: frequency->setMinimum(100.0); lbajardsilogic@0: frequency->setMaximum(5000.0); lbajardsilogic@0: frequency->setSuffix(" Hz"); lbajardsilogic@0: frequency->setSingleStep(1); lbajardsilogic@0: frequency->setValue(m_tuningFrequency); lbajardsilogic@0: frequency->setDecimals(2); lbajardsilogic@0: lbajardsilogic@0: connect(frequency, SIGNAL(valueChanged(double)), lbajardsilogic@0: this, SLOT(tuningFrequencyChanged(double))); lbajardsilogic@0: lbajardsilogic@0: QComboBox *resampleQuality = new QComboBox; lbajardsilogic@0: lbajardsilogic@0: int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max, lbajardsilogic@0: &deflt); lbajardsilogic@0: m_resampleQuality = rsq; lbajardsilogic@0: lbajardsilogic@0: for (i = min; i <= max; ++i) { lbajardsilogic@0: resampleQuality->addItem(prefs->getPropertyValueLabel("Resample Quality", i)); lbajardsilogic@0: } lbajardsilogic@0: lbajardsilogic@0: resampleQuality->setCurrentIndex(rsq); lbajardsilogic@0: lbajardsilogic@0: connect(resampleQuality, SIGNAL(currentIndexChanged(int)), lbajardsilogic@0: this, SLOT(resampleQualityChanged(int))); lbajardsilogic@0: lbajardsilogic@0: int row = 0; lbajardsilogic@0: lbajardsilogic@0: subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel lbajardsilogic@0: ("Tuning Frequency"))), lbajardsilogic@0: row, 0); lbajardsilogic@0: subgrid->addWidget(frequency, row++, 1, 1, 2); lbajardsilogic@0: lbajardsilogic@0: subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel lbajardsilogic@0: ("Resample Quality"))), lbajardsilogic@0: row, 0); lbajardsilogic@0: subgrid->addWidget(resampleQuality, row++, 1, 1, 2); lbajardsilogic@0: lbajardsilogic@0: subgrid->addWidget(new QLabel(prefs->getPropertyLabel lbajardsilogic@0: ("Spectrogram Smoothing")), lbajardsilogic@0: row, 0); lbajardsilogic@0: subgrid->addWidget(smoothing, row++, 1, 1, 2); lbajardsilogic@0: lbajardsilogic@0: subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel lbajardsilogic@0: ("Window Type"))), lbajardsilogic@0: row, 0); lbajardsilogic@0: subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2); lbajardsilogic@0: subgrid->setRowStretch(row, 10); lbajardsilogic@0: row++; lbajardsilogic@0: lbajardsilogic@0: QHBoxLayout *hbox = new QHBoxLayout; lbajardsilogic@0: grid->addLayout(hbox, 1, 0); lbajardsilogic@0: lbajardsilogic@0: QPushButton *ok = new QPushButton(tr("OK")); lbajardsilogic@0: QPushButton *cancel = new QPushButton(tr("Cancel")); lbajardsilogic@0: hbox->addStretch(10); lbajardsilogic@0: hbox->addWidget(ok); lbajardsilogic@0: hbox->addWidget(m_applyButton); lbajardsilogic@0: hbox->addWidget(cancel); lbajardsilogic@0: connect(ok, SIGNAL(clicked()), this, SLOT(okClicked())); lbajardsilogic@0: connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked())); lbajardsilogic@0: connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); lbajardsilogic@0: lbajardsilogic@0: m_applyButton->setEnabled(false); lbajardsilogic@0: } lbajardsilogic@0: lbajardsilogic@0: PreferencesDialog::~PreferencesDialog() lbajardsilogic@0: { lbajardsilogic@0: std::cerr << "PreferencesDialog::~PreferencesDialog()" << std::endl; lbajardsilogic@0: } lbajardsilogic@0: lbajardsilogic@0: void lbajardsilogic@0: PreferencesDialog::windowTypeChanged(WindowType type) lbajardsilogic@0: { lbajardsilogic@0: m_windowType = type; lbajardsilogic@0: m_applyButton->setEnabled(true); lbajardsilogic@0: } lbajardsilogic@0: lbajardsilogic@0: void lbajardsilogic@0: PreferencesDialog::spectrogramSmoothingChanged(int smoothing) lbajardsilogic@0: { lbajardsilogic@0: m_spectrogramSmoothing = smoothing; lbajardsilogic@0: m_applyButton->setEnabled(true); lbajardsilogic@0: } lbajardsilogic@0: lbajardsilogic@0: void lbajardsilogic@0: PreferencesDialog::tuningFrequencyChanged(double freq) lbajardsilogic@0: { lbajardsilogic@0: m_tuningFrequency = freq; lbajardsilogic@0: m_applyButton->setEnabled(true); lbajardsilogic@0: } lbajardsilogic@0: lbajardsilogic@0: void lbajardsilogic@0: PreferencesDialog::resampleQualityChanged(int q) lbajardsilogic@0: { lbajardsilogic@0: m_resampleQuality = q; lbajardsilogic@0: m_applyButton->setEnabled(true); lbajardsilogic@0: } lbajardsilogic@0: lbajardsilogic@0: void lbajardsilogic@0: PreferencesDialog::okClicked() lbajardsilogic@0: { lbajardsilogic@0: applyClicked(); lbajardsilogic@0: accept(); lbajardsilogic@0: } lbajardsilogic@0: lbajardsilogic@0: void lbajardsilogic@0: PreferencesDialog::applyClicked() lbajardsilogic@0: { lbajardsilogic@0: Preferences *prefs = Preferences::getInstance(); lbajardsilogic@0: prefs->setWindowType(WindowType(m_windowType)); lbajardsilogic@0: prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing lbajardsilogic@0: (m_spectrogramSmoothing)); lbajardsilogic@0: prefs->setTuningFrequency(m_tuningFrequency); lbajardsilogic@0: prefs->setResampleQuality(m_resampleQuality); lbajardsilogic@0: m_applyButton->setEnabled(false); lbajardsilogic@0: } lbajardsilogic@0: lbajardsilogic@0: void lbajardsilogic@0: PreferencesDialog::cancelClicked() lbajardsilogic@0: { lbajardsilogic@0: reject(); lbajardsilogic@0: } lbajardsilogic@0: