annotate main/PreferencesDialog.cpp @ 116:99d65ba33c88

* More useful status bar text -- show the current play time and the extents of the visible area * Add update-i18n.sh to update the i18n/ts and qm files -- I can't get qmake to do the right thing now that the project file has been split up into several project files * Fix missing Q_OBJECTs, etc, reported by lupdate * Update Russian translation from AlexandrE
author Chris Cannam
date Wed, 07 Mar 2007 17:07:02 +0000
parents c9930ec7a3f9
children 652b22dcd4ed
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@9 28 #include "widgets/WindowTypeSelector.h"
Chris@0 29 #include "base/Preferences.h"
Chris@0 30
Chris@0 31 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) :
Chris@0 32 QDialog(parent, flags)
Chris@0 33 {
Chris@0 34 setWindowTitle(tr("Application Preferences"));
Chris@0 35
Chris@0 36 Preferences *prefs = Preferences::getInstance();
Chris@0 37
Chris@0 38 QGridLayout *grid = new QGridLayout;
Chris@0 39 setLayout(grid);
Chris@0 40
Chris@0 41 QGroupBox *groupBox = new QGroupBox;
Chris@0 42 groupBox->setTitle(tr("Sonic Visualiser Application Preferences"));
Chris@0 43 grid->addWidget(groupBox, 0, 0);
Chris@0 44
Chris@0 45 QGridLayout *subgrid = new QGridLayout;
Chris@0 46 groupBox->setLayout(subgrid);
Chris@0 47
Chris@0 48 // Create this first, as slots that get called from the ctor will
Chris@0 49 // refer to it
Chris@0 50 m_applyButton = new QPushButton(tr("Apply"));
Chris@0 51
Chris@114 52 int min, max, deflt, i;
Chris@0 53
Chris@9 54 m_windowType = WindowType(prefs->getPropertyRangeAndValue
Chris@114 55 ("Window Type", &min, &max, &deflt));
Chris@9 56 m_windowTypeSelector = new WindowTypeSelector(m_windowType);
Chris@0 57
Chris@9 58 connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)),
Chris@9 59 this, SLOT(windowTypeChanged(WindowType)));
Chris@0 60
Chris@115 61 QComboBox *smoothing = new QComboBox;
Chris@115 62
Chris@115 63 int sm = prefs->getPropertyRangeAndValue("Spectrogram Smoothing", &min, &max,
Chris@115 64 &deflt);
Chris@115 65 m_spectrogramSmoothing = sm;
Chris@0 66
Chris@115 67 for (i = min; i <= max; ++i) {
Chris@115 68 smoothing->addItem(prefs->getPropertyValueLabel("Spectrogram Smoothing", i));
Chris@115 69 }
Chris@115 70
Chris@115 71 smoothing->setCurrentIndex(sm);
Chris@115 72
Chris@115 73 connect(smoothing, SIGNAL(currentIndexChanged(int)),
Chris@115 74 this, SLOT(spectrogramSmoothingChanged(int)));
Chris@0 75
Chris@0 76 QComboBox *propertyLayout = new QComboBox;
Chris@114 77 int pl = prefs->getPropertyRangeAndValue("Property Box Layout", &min, &max,
Chris@115 78 &deflt);
Chris@0 79 m_propertyLayout = pl;
Chris@0 80
Chris@0 81 for (i = min; i <= max; ++i) {
Chris@0 82 propertyLayout->addItem(prefs->getPropertyValueLabel("Property Box Layout", i));
Chris@0 83 }
Chris@0 84
Chris@0 85 propertyLayout->setCurrentIndex(pl);
Chris@0 86
Chris@0 87 connect(propertyLayout, SIGNAL(currentIndexChanged(int)),
Chris@0 88 this, SLOT(propertyLayoutChanged(int)));
Chris@0 89
Chris@0 90 m_tuningFrequency = prefs->getTuningFrequency();
Chris@0 91
Chris@0 92 QDoubleSpinBox *frequency = new QDoubleSpinBox;
Chris@0 93 frequency->setMinimum(100.0);
Chris@0 94 frequency->setMaximum(5000.0);
Chris@0 95 frequency->setSuffix(" Hz");
Chris@0 96 frequency->setSingleStep(1);
Chris@0 97 frequency->setValue(m_tuningFrequency);
Chris@0 98 frequency->setDecimals(2);
Chris@0 99
Chris@0 100 connect(frequency, SIGNAL(valueChanged(double)),
Chris@0 101 this, SLOT(tuningFrequencyChanged(double)));
Chris@0 102
Chris@32 103 QComboBox *resampleQuality = new QComboBox;
Chris@32 104
Chris@114 105 int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max,
Chris@114 106 &deflt);
Chris@32 107 m_resampleQuality = rsq;
Chris@32 108
Chris@32 109 for (i = min; i <= max; ++i) {
Chris@32 110 resampleQuality->addItem(prefs->getPropertyValueLabel("Resample Quality", i));
Chris@32 111 }
Chris@32 112
Chris@32 113 resampleQuality->setCurrentIndex(rsq);
Chris@32 114
Chris@32 115 connect(resampleQuality, SIGNAL(currentIndexChanged(int)),
Chris@32 116 this, SLOT(resampleQualityChanged(int)));
Chris@32 117
Chris@0 118 int row = 0;
Chris@0 119
Chris@0 120 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 121 ("Property Box Layout"))),
Chris@0 122 row, 0);
Chris@0 123 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
Chris@0 124
Chris@0 125 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 126 ("Tuning Frequency"))),
Chris@0 127 row, 0);
Chris@0 128 subgrid->addWidget(frequency, row++, 1, 1, 2);
Chris@0 129
Chris@32 130 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@32 131 ("Resample Quality"))),
Chris@32 132 row, 0);
Chris@32 133 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
Chris@32 134
Chris@0 135 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@115 136 ("Spectrogram Smoothing")),
Chris@115 137 row, 0);
Chris@115 138 subgrid->addWidget(smoothing, row++, 1, 1, 2);
Chris@0 139
Chris@0 140 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 141 ("Window Type"))),
Chris@0 142 row, 0);
Chris@9 143 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
Chris@9 144 subgrid->setRowStretch(row, 10);
Chris@9 145 row++;
Chris@0 146
Chris@0 147 QHBoxLayout *hbox = new QHBoxLayout;
Chris@0 148 grid->addLayout(hbox, 1, 0);
Chris@0 149
Chris@0 150 QPushButton *ok = new QPushButton(tr("OK"));
Chris@0 151 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@0 152 hbox->addStretch(10);
Chris@0 153 hbox->addWidget(ok);
Chris@0 154 hbox->addWidget(m_applyButton);
Chris@0 155 hbox->addWidget(cancel);
Chris@0 156 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
Chris@0 157 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
Chris@0 158 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
Chris@0 159
Chris@0 160 m_applyButton->setEnabled(false);
Chris@0 161 }
Chris@0 162
Chris@0 163 PreferencesDialog::~PreferencesDialog()
Chris@0 164 {
Chris@0 165 std::cerr << "PreferencesDialog::~PreferencesDialog()" << std::endl;
Chris@0 166 }
Chris@0 167
Chris@0 168 void
Chris@9 169 PreferencesDialog::windowTypeChanged(WindowType type)
Chris@0 170 {
Chris@0 171 m_windowType = type;
Chris@0 172 m_applyButton->setEnabled(true);
Chris@0 173 }
Chris@0 174
Chris@0 175 void
Chris@115 176 PreferencesDialog::spectrogramSmoothingChanged(int smoothing)
Chris@0 177 {
Chris@115 178 m_spectrogramSmoothing = smoothing;
Chris@0 179 m_applyButton->setEnabled(true);
Chris@0 180 }
Chris@0 181
Chris@0 182 void
Chris@0 183 PreferencesDialog::propertyLayoutChanged(int layout)
Chris@0 184 {
Chris@0 185 m_propertyLayout = layout;
Chris@0 186 m_applyButton->setEnabled(true);
Chris@0 187 }
Chris@0 188
Chris@0 189 void
Chris@0 190 PreferencesDialog::tuningFrequencyChanged(double freq)
Chris@0 191 {
Chris@0 192 m_tuningFrequency = freq;
Chris@0 193 m_applyButton->setEnabled(true);
Chris@0 194 }
Chris@0 195
Chris@0 196 void
Chris@32 197 PreferencesDialog::resampleQualityChanged(int q)
Chris@32 198 {
Chris@32 199 m_resampleQuality = q;
Chris@32 200 m_applyButton->setEnabled(true);
Chris@32 201 }
Chris@32 202
Chris@32 203 void
Chris@0 204 PreferencesDialog::okClicked()
Chris@0 205 {
Chris@0 206 applyClicked();
Chris@0 207 accept();
Chris@0 208 }
Chris@0 209
Chris@0 210 void
Chris@0 211 PreferencesDialog::applyClicked()
Chris@0 212 {
Chris@0 213 Preferences *prefs = Preferences::getInstance();
Chris@0 214 prefs->setWindowType(WindowType(m_windowType));
Chris@115 215 prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing
Chris@115 216 (m_spectrogramSmoothing));
Chris@0 217 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
Chris@0 218 (m_propertyLayout));
Chris@0 219 prefs->setTuningFrequency(m_tuningFrequency);
Chris@32 220 prefs->setResampleQuality(m_resampleQuality);
Chris@0 221 m_applyButton->setEnabled(false);
Chris@0 222 }
Chris@0 223
Chris@0 224 void
Chris@0 225 PreferencesDialog::cancelClicked()
Chris@0 226 {
Chris@0 227 reject();
Chris@0 228 }
Chris@0 229