Mercurial > hg > easaier-soundaccess
comparison sv/main/PreferencesDialog.cpp @ 0:fc9323a41f5a
start base : Sonic Visualiser sv1-1.0rc1
author | lbajardsilogic |
---|---|
date | Fri, 11 May 2007 09:08:14 +0000 |
parents | |
children | 00b5875d8c30 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fc9323a41f5a |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "PreferencesDialog.h" | |
17 | |
18 #include <QGridLayout> | |
19 #include <QComboBox> | |
20 #include <QCheckBox> | |
21 #include <QGroupBox> | |
22 #include <QDoubleSpinBox> | |
23 #include <QLabel> | |
24 #include <QPushButton> | |
25 #include <QHBoxLayout> | |
26 #include <QString> | |
27 | |
28 #include "widgets/WindowTypeSelector.h" | |
29 #include "base/Preferences.h" | |
30 | |
31 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) : | |
32 QDialog(parent, flags) | |
33 { | |
34 setWindowTitle(tr("Application Preferences")); | |
35 | |
36 Preferences *prefs = Preferences::getInstance(); | |
37 | |
38 QGridLayout *grid = new QGridLayout; | |
39 setLayout(grid); | |
40 | |
41 QGroupBox *groupBox = new QGroupBox; | |
42 groupBox->setTitle(tr("Sonic Visualiser Application Preferences")); | |
43 grid->addWidget(groupBox, 0, 0); | |
44 | |
45 QGridLayout *subgrid = new QGridLayout; | |
46 groupBox->setLayout(subgrid); | |
47 | |
48 // Create this first, as slots that get called from the ctor will | |
49 // refer to it | |
50 m_applyButton = new QPushButton(tr("Apply")); | |
51 | |
52 int min, max, deflt, i; | |
53 | |
54 m_windowType = WindowType(prefs->getPropertyRangeAndValue | |
55 ("Window Type", &min, &max, &deflt)); | |
56 m_windowTypeSelector = new WindowTypeSelector(m_windowType); | |
57 | |
58 connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)), | |
59 this, SLOT(windowTypeChanged(WindowType))); | |
60 | |
61 QComboBox *smoothing = new QComboBox; | |
62 | |
63 int sm = prefs->getPropertyRangeAndValue("Spectrogram Smoothing", &min, &max, | |
64 &deflt); | |
65 m_spectrogramSmoothing = sm; | |
66 | |
67 for (i = min; i <= max; ++i) { | |
68 smoothing->addItem(prefs->getPropertyValueLabel("Spectrogram Smoothing", i)); | |
69 } | |
70 | |
71 smoothing->setCurrentIndex(sm); | |
72 | |
73 connect(smoothing, SIGNAL(currentIndexChanged(int)), | |
74 this, SLOT(spectrogramSmoothingChanged(int))); | |
75 | |
76 QComboBox *propertyLayout = new QComboBox; | |
77 int pl = prefs->getPropertyRangeAndValue("Property Box Layout", &min, &max, | |
78 &deflt); | |
79 m_propertyLayout = pl; | |
80 | |
81 for (i = min; i <= max; ++i) { | |
82 propertyLayout->addItem(prefs->getPropertyValueLabel("Property Box Layout", i)); | |
83 } | |
84 | |
85 propertyLayout->setCurrentIndex(pl); | |
86 | |
87 connect(propertyLayout, SIGNAL(currentIndexChanged(int)), | |
88 this, SLOT(propertyLayoutChanged(int))); | |
89 | |
90 m_tuningFrequency = prefs->getTuningFrequency(); | |
91 | |
92 QDoubleSpinBox *frequency = new QDoubleSpinBox; | |
93 frequency->setMinimum(100.0); | |
94 frequency->setMaximum(5000.0); | |
95 frequency->setSuffix(" Hz"); | |
96 frequency->setSingleStep(1); | |
97 frequency->setValue(m_tuningFrequency); | |
98 frequency->setDecimals(2); | |
99 | |
100 connect(frequency, SIGNAL(valueChanged(double)), | |
101 this, SLOT(tuningFrequencyChanged(double))); | |
102 | |
103 QComboBox *resampleQuality = new QComboBox; | |
104 | |
105 int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max, | |
106 &deflt); | |
107 m_resampleQuality = rsq; | |
108 | |
109 for (i = min; i <= max; ++i) { | |
110 resampleQuality->addItem(prefs->getPropertyValueLabel("Resample Quality", i)); | |
111 } | |
112 | |
113 resampleQuality->setCurrentIndex(rsq); | |
114 | |
115 connect(resampleQuality, SIGNAL(currentIndexChanged(int)), | |
116 this, SLOT(resampleQualityChanged(int))); | |
117 | |
118 int row = 0; | |
119 | |
120 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel | |
121 ("Property Box Layout"))), | |
122 row, 0); | |
123 subgrid->addWidget(propertyLayout, row++, 1, 1, 2); | |
124 | |
125 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel | |
126 ("Tuning Frequency"))), | |
127 row, 0); | |
128 subgrid->addWidget(frequency, row++, 1, 1, 2); | |
129 | |
130 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel | |
131 ("Resample Quality"))), | |
132 row, 0); | |
133 subgrid->addWidget(resampleQuality, row++, 1, 1, 2); | |
134 | |
135 subgrid->addWidget(new QLabel(prefs->getPropertyLabel | |
136 ("Spectrogram Smoothing")), | |
137 row, 0); | |
138 subgrid->addWidget(smoothing, row++, 1, 1, 2); | |
139 | |
140 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel | |
141 ("Window Type"))), | |
142 row, 0); | |
143 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2); | |
144 subgrid->setRowStretch(row, 10); | |
145 row++; | |
146 | |
147 QHBoxLayout *hbox = new QHBoxLayout; | |
148 grid->addLayout(hbox, 1, 0); | |
149 | |
150 QPushButton *ok = new QPushButton(tr("OK")); | |
151 QPushButton *cancel = new QPushButton(tr("Cancel")); | |
152 hbox->addStretch(10); | |
153 hbox->addWidget(ok); | |
154 hbox->addWidget(m_applyButton); | |
155 hbox->addWidget(cancel); | |
156 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked())); | |
157 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked())); | |
158 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); | |
159 | |
160 m_applyButton->setEnabled(false); | |
161 } | |
162 | |
163 PreferencesDialog::~PreferencesDialog() | |
164 { | |
165 std::cerr << "PreferencesDialog::~PreferencesDialog()" << std::endl; | |
166 } | |
167 | |
168 void | |
169 PreferencesDialog::windowTypeChanged(WindowType type) | |
170 { | |
171 m_windowType = type; | |
172 m_applyButton->setEnabled(true); | |
173 } | |
174 | |
175 void | |
176 PreferencesDialog::spectrogramSmoothingChanged(int smoothing) | |
177 { | |
178 m_spectrogramSmoothing = smoothing; | |
179 m_applyButton->setEnabled(true); | |
180 } | |
181 | |
182 void | |
183 PreferencesDialog::propertyLayoutChanged(int layout) | |
184 { | |
185 m_propertyLayout = layout; | |
186 m_applyButton->setEnabled(true); | |
187 } | |
188 | |
189 void | |
190 PreferencesDialog::tuningFrequencyChanged(double freq) | |
191 { | |
192 m_tuningFrequency = freq; | |
193 m_applyButton->setEnabled(true); | |
194 } | |
195 | |
196 void | |
197 PreferencesDialog::resampleQualityChanged(int q) | |
198 { | |
199 m_resampleQuality = q; | |
200 m_applyButton->setEnabled(true); | |
201 } | |
202 | |
203 void | |
204 PreferencesDialog::okClicked() | |
205 { | |
206 applyClicked(); | |
207 accept(); | |
208 } | |
209 | |
210 void | |
211 PreferencesDialog::applyClicked() | |
212 { | |
213 Preferences *prefs = Preferences::getInstance(); | |
214 prefs->setWindowType(WindowType(m_windowType)); | |
215 prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing | |
216 (m_spectrogramSmoothing)); | |
217 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout | |
218 (m_propertyLayout)); | |
219 prefs->setTuningFrequency(m_tuningFrequency); | |
220 prefs->setResampleQuality(m_resampleQuality); | |
221 m_applyButton->setEnabled(false); | |
222 } | |
223 | |
224 void | |
225 PreferencesDialog::cancelClicked() | |
226 { | |
227 reject(); | |
228 } | |
229 |