annotate main/PreferencesDialog.cpp @ 36:da7a3828727f

* Pull alphabetical categorisation code out into a SubdividingMenu class
author Chris Cannam
date Mon, 25 Sep 2006 11:21:12 +0000
parents e3b32dc5180b
children f3516e520652
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@0 27
Chris@0 28 #include <fftw3.h>
Chris@0 29
Chris@9 30 #include "widgets/WindowTypeSelector.h"
Chris@0 31 #include "base/Preferences.h"
Chris@0 32
Chris@0 33 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) :
Chris@0 34 QDialog(parent, flags)
Chris@0 35 {
Chris@0 36 setWindowTitle(tr("Application Preferences"));
Chris@0 37
Chris@0 38 Preferences *prefs = Preferences::getInstance();
Chris@0 39
Chris@0 40 QGridLayout *grid = new QGridLayout;
Chris@0 41 setLayout(grid);
Chris@0 42
Chris@0 43 QGroupBox *groupBox = new QGroupBox;
Chris@0 44 groupBox->setTitle(tr("Sonic Visualiser Application Preferences"));
Chris@0 45 grid->addWidget(groupBox, 0, 0);
Chris@0 46
Chris@0 47 QGridLayout *subgrid = new QGridLayout;
Chris@0 48 groupBox->setLayout(subgrid);
Chris@0 49
Chris@0 50 // Create this first, as slots that get called from the ctor will
Chris@0 51 // refer to it
Chris@0 52 m_applyButton = new QPushButton(tr("Apply"));
Chris@0 53
Chris@9 54 int min, max, i;
Chris@0 55
Chris@9 56 m_windowType = WindowType(prefs->getPropertyRangeAndValue
Chris@9 57 ("Window Type", &min, &max));
Chris@9 58 m_windowTypeSelector = new WindowTypeSelector(m_windowType);
Chris@0 59
Chris@9 60 connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)),
Chris@9 61 this, SLOT(windowTypeChanged(WindowType)));
Chris@0 62
Chris@0 63 QCheckBox *smoothing = new QCheckBox;
Chris@0 64 m_smoothSpectrogram = prefs->getSmoothSpectrogram();
Chris@0 65 smoothing->setCheckState(m_smoothSpectrogram ?
Chris@0 66 Qt::Checked : Qt::Unchecked);
Chris@0 67
Chris@0 68 connect(smoothing, SIGNAL(stateChanged(int)),
Chris@0 69 this, SLOT(smoothSpectrogramChanged(int)));
Chris@0 70
Chris@0 71 QComboBox *propertyLayout = new QComboBox;
Chris@0 72 int pl = prefs->getPropertyRangeAndValue("Property Box Layout", &min, &max);
Chris@0 73 m_propertyLayout = pl;
Chris@0 74
Chris@0 75 for (i = min; i <= max; ++i) {
Chris@0 76 propertyLayout->addItem(prefs->getPropertyValueLabel("Property Box Layout", i));
Chris@0 77 }
Chris@0 78
Chris@0 79 propertyLayout->setCurrentIndex(pl);
Chris@0 80
Chris@0 81 connect(propertyLayout, SIGNAL(currentIndexChanged(int)),
Chris@0 82 this, SLOT(propertyLayoutChanged(int)));
Chris@0 83
Chris@0 84 m_tuningFrequency = prefs->getTuningFrequency();
Chris@0 85
Chris@0 86 QDoubleSpinBox *frequency = new QDoubleSpinBox;
Chris@0 87 frequency->setMinimum(100.0);
Chris@0 88 frequency->setMaximum(5000.0);
Chris@0 89 frequency->setSuffix(" Hz");
Chris@0 90 frequency->setSingleStep(1);
Chris@0 91 frequency->setValue(m_tuningFrequency);
Chris@0 92 frequency->setDecimals(2);
Chris@0 93
Chris@0 94 connect(frequency, SIGNAL(valueChanged(double)),
Chris@0 95 this, SLOT(tuningFrequencyChanged(double)));
Chris@0 96
Chris@32 97 QComboBox *resampleQuality = new QComboBox;
Chris@32 98
Chris@32 99 int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max);
Chris@32 100 m_resampleQuality = rsq;
Chris@32 101
Chris@32 102 for (i = min; i <= max; ++i) {
Chris@32 103 resampleQuality->addItem(prefs->getPropertyValueLabel("Resample Quality", i));
Chris@32 104 }
Chris@32 105
Chris@32 106 resampleQuality->setCurrentIndex(rsq);
Chris@32 107
Chris@32 108 connect(resampleQuality, SIGNAL(currentIndexChanged(int)),
Chris@32 109 this, SLOT(resampleQualityChanged(int)));
Chris@32 110
Chris@0 111 int row = 0;
Chris@0 112
Chris@0 113 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 114 ("Property Box Layout"))),
Chris@0 115 row, 0);
Chris@0 116 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
Chris@0 117
Chris@0 118 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 119 ("Tuning Frequency"))),
Chris@0 120 row, 0);
Chris@0 121 subgrid->addWidget(frequency, row++, 1, 1, 2);
Chris@0 122
Chris@32 123 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@32 124 ("Resample Quality"))),
Chris@32 125 row, 0);
Chris@32 126 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
Chris@32 127
Chris@0 128 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@0 129 ("Smooth Spectrogram")),
Chris@0 130 row, 0, 1, 2);
Chris@0 131 subgrid->addWidget(smoothing, row++, 2);
Chris@0 132
Chris@0 133 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 134 ("Window Type"))),
Chris@0 135 row, 0);
Chris@9 136 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
Chris@9 137 subgrid->setRowStretch(row, 10);
Chris@9 138 row++;
Chris@0 139
Chris@0 140 QHBoxLayout *hbox = new QHBoxLayout;
Chris@0 141 grid->addLayout(hbox, 1, 0);
Chris@0 142
Chris@0 143 QPushButton *ok = new QPushButton(tr("OK"));
Chris@0 144 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@0 145 hbox->addStretch(10);
Chris@0 146 hbox->addWidget(ok);
Chris@0 147 hbox->addWidget(m_applyButton);
Chris@0 148 hbox->addWidget(cancel);
Chris@0 149 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
Chris@0 150 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
Chris@0 151 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
Chris@0 152
Chris@0 153 m_applyButton->setEnabled(false);
Chris@0 154 }
Chris@0 155
Chris@0 156 PreferencesDialog::~PreferencesDialog()
Chris@0 157 {
Chris@0 158 std::cerr << "PreferencesDialog::~PreferencesDialog()" << std::endl;
Chris@0 159 }
Chris@0 160
Chris@0 161 void
Chris@9 162 PreferencesDialog::windowTypeChanged(WindowType type)
Chris@0 163 {
Chris@0 164 m_windowType = type;
Chris@0 165 m_applyButton->setEnabled(true);
Chris@0 166 }
Chris@0 167
Chris@0 168 void
Chris@0 169 PreferencesDialog::smoothSpectrogramChanged(int state)
Chris@0 170 {
Chris@0 171 m_smoothSpectrogram = (state == Qt::Checked);
Chris@0 172 m_applyButton->setEnabled(true);
Chris@0 173 }
Chris@0 174
Chris@0 175 void
Chris@0 176 PreferencesDialog::propertyLayoutChanged(int layout)
Chris@0 177 {
Chris@0 178 m_propertyLayout = layout;
Chris@0 179 m_applyButton->setEnabled(true);
Chris@0 180 }
Chris@0 181
Chris@0 182 void
Chris@0 183 PreferencesDialog::tuningFrequencyChanged(double freq)
Chris@0 184 {
Chris@0 185 m_tuningFrequency = freq;
Chris@0 186 m_applyButton->setEnabled(true);
Chris@0 187 }
Chris@0 188
Chris@0 189 void
Chris@32 190 PreferencesDialog::resampleQualityChanged(int q)
Chris@32 191 {
Chris@32 192 m_resampleQuality = q;
Chris@32 193 m_applyButton->setEnabled(true);
Chris@32 194 }
Chris@32 195
Chris@32 196 void
Chris@0 197 PreferencesDialog::okClicked()
Chris@0 198 {
Chris@0 199 applyClicked();
Chris@0 200 accept();
Chris@0 201 }
Chris@0 202
Chris@0 203 void
Chris@0 204 PreferencesDialog::applyClicked()
Chris@0 205 {
Chris@0 206 Preferences *prefs = Preferences::getInstance();
Chris@0 207 prefs->setWindowType(WindowType(m_windowType));
Chris@0 208 prefs->setSmoothSpectrogram(m_smoothSpectrogram);
Chris@0 209 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
Chris@0 210 (m_propertyLayout));
Chris@0 211 prefs->setTuningFrequency(m_tuningFrequency);
Chris@32 212 prefs->setResampleQuality(m_resampleQuality);
Chris@0 213 m_applyButton->setEnabled(false);
Chris@0 214 }
Chris@0 215
Chris@0 216 void
Chris@0 217 PreferencesDialog::cancelClicked()
Chris@0 218 {
Chris@0 219 reject();
Chris@0 220 }
Chris@0 221