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