comparison main/PreferencesDialog.cpp @ 180:98ba77e0d897

* Merge from sv-match-alignment branch (excluding alignment-specific document). - add aggregate wave model (not yet complete enough to be added as a true model in a layer, but there's potential) - add play solo mode - add alignment model -- unused in plain SV - fix two plugin leaks - add m3u playlist support (opens all files at once, potentially hazardous) - fix retrieval of pre-encoded URLs - add ability to resample audio files on import, so as to match rates with other files previously loaded; add preference for same - add preliminary support in transform code for range and rate of transform input - reorganise preferences dialog, move dark-background option to preferences, add option for temporary directory location
author Chris Cannam
date Fri, 28 Sep 2007 13:56:38 +0000
parents 652b22dcd4ed
children d7ded015af32 fc542303eda2
comparison
equal deleted inserted replaced
179:dab257bd9d2d 180:98ba77e0d897
24 #include <QPushButton> 24 #include <QPushButton>
25 #include <QHBoxLayout> 25 #include <QHBoxLayout>
26 #include <QString> 26 #include <QString>
27 #include <QDialogButtonBox> 27 #include <QDialogButtonBox>
28 #include <QMessageBox> 28 #include <QMessageBox>
29 #include <QTabWidget>
30 #include <QLineEdit>
31 #include <QFileDialog>
32 #include <QMessageBox>
29 33
30 #include "widgets/WindowTypeSelector.h" 34 #include "widgets/WindowTypeSelector.h"
35 #include "widgets/IconLoader.h"
31 #include "base/Preferences.h" 36 #include "base/Preferences.h"
32 37
33 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) : 38 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) :
34 QDialog(parent, flags) 39 QDialog(parent, flags),
40 m_changesOnRestart(false)
35 { 41 {
36 setWindowTitle(tr("Sonic Visualiser: Application Preferences")); 42 setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
37 43
38 Preferences *prefs = Preferences::getInstance(); 44 Preferences *prefs = Preferences::getInstance();
39 45
40 QGridLayout *grid = new QGridLayout; 46 QGridLayout *grid = new QGridLayout;
41 setLayout(grid); 47 setLayout(grid);
42 48
43 QGroupBox *groupBox = new QGroupBox; 49 QTabWidget *tab = new QTabWidget;
44 groupBox->setTitle(tr("Application Preferences")); 50 grid->addWidget(tab, 0, 0);
45 grid->addWidget(groupBox, 0, 0); 51
46 52 tab->setTabPosition(QTabWidget::North);
47 QGridLayout *subgrid = new QGridLayout;
48 groupBox->setLayout(subgrid);
49 53
50 // Create this first, as slots that get called from the ctor will 54 // Create this first, as slots that get called from the ctor will
51 // refer to it 55 // refer to it
52 m_applyButton = new QPushButton(tr("Apply")); 56 m_applyButton = new QPushButton(tr("Apply"));
57
58 // Create all the preference widgets first, then create the
59 // individual tab widgets and place the preferences in their
60 // appropriate places in one go afterwards
53 61
54 int min, max, deflt, i; 62 int min, max, deflt, i;
55 63
56 m_windowType = WindowType(prefs->getPropertyRangeAndValue 64 m_windowType = WindowType(prefs->getPropertyRangeAndValue
57 ("Window Type", &min, &max, &deflt)); 65 ("Window Type", &min, &max, &deflt));
115 resampleQuality->setCurrentIndex(rsq); 123 resampleQuality->setCurrentIndex(rsq);
116 124
117 connect(resampleQuality, SIGNAL(currentIndexChanged(int)), 125 connect(resampleQuality, SIGNAL(currentIndexChanged(int)),
118 this, SLOT(resampleQualityChanged(int))); 126 this, SLOT(resampleQualityChanged(int)));
119 127
128 QCheckBox *resampleOnLoad = new QCheckBox;
129 m_resampleOnLoad = prefs->getResampleOnLoad();
130 resampleOnLoad->setCheckState(m_resampleOnLoad ? Qt::Checked :
131 Qt::Unchecked);
132 connect(resampleOnLoad, SIGNAL(stateChanged(int)),
133 this, SLOT(resampleOnLoadChanged(int)));
134
135 m_tempDirRootEdit = new QLineEdit;
136 QString dir = prefs->getTemporaryDirectoryRoot();
137 m_tempDirRoot = dir;
138 dir.replace("$HOME", tr("<home directory>"));
139 m_tempDirRootEdit->setText(dir);
140 m_tempDirRootEdit->setReadOnly(true);
141 QPushButton *tempDirButton = new QPushButton;
142 tempDirButton->setIcon(IconLoader().load("fileopen"));
143 connect(tempDirButton, SIGNAL(clicked()),
144 this, SLOT(tempDirButtonClicked()));
145 tempDirButton->setFixedSize(QSize(24, 24));
146
147 QComboBox *bgMode = new QComboBox;
148 int bg = prefs->getPropertyRangeAndValue("Background Mode", &min, &max,
149 &deflt);
150 m_backgroundMode = bg;
151 for (i = min; i <= max; ++i) {
152 bgMode->addItem(prefs->getPropertyValueLabel("Background Mode", i));
153 }
154 bgMode->setCurrentIndex(bg);
155
156 connect(bgMode, SIGNAL(currentIndexChanged(int)),
157 this, SLOT(backgroundModeChanged(int)));
158
159 // General tab
160
161 QFrame *frame = new QFrame;
162
163 QGridLayout *subgrid = new QGridLayout;
164 frame->setLayout(subgrid);
165
120 int row = 0; 166 int row = 0;
121 167
122 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel 168 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
123 ("Property Box Layout"))), 169 ("Property Box Layout"))),
124 row, 0); 170 row, 0);
125 subgrid->addWidget(propertyLayout, row++, 1, 1, 2); 171 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
126 172
127 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel 173 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
174 ("Background Mode"))),
175 row, 0);
176 subgrid->addWidget(bgMode, row++, 1, 1, 2);
177
178 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
179 ("Resample On Load"))),
180 row, 0);
181 subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1);
182
183 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
184 ("Resample Quality"))),
185 row, 0);
186 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
187
188 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
189 ("Temporary Directory Root"))),
190 row, 0);
191 subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
192 subgrid->addWidget(tempDirButton, row, 2, 1, 1);
193 row++;
194
195 subgrid->setRowStretch(row, 10);
196
197 tab->addTab(frame, tr("&General"));
198
199 // Analysis tab
200
201 frame = new QFrame;
202 subgrid = new QGridLayout;
203 frame->setLayout(subgrid);
204 row = 0;
205
206 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
128 ("Tuning Frequency"))), 207 ("Tuning Frequency"))),
129 row, 0); 208 row, 0);
130 subgrid->addWidget(frequency, row++, 1, 1, 2); 209 subgrid->addWidget(frequency, row++, 1, 1, 2);
131
132 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
133 ("Resample Quality"))),
134 row, 0);
135 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
136 210
137 subgrid->addWidget(new QLabel(prefs->getPropertyLabel 211 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
138 ("Spectrogram Smoothing")), 212 ("Spectrogram Smoothing")),
139 row, 0); 213 row, 0);
140 subgrid->addWidget(smoothing, row++, 1, 1, 2); 214 subgrid->addWidget(smoothing, row++, 1, 1, 2);
144 row, 0); 218 row, 0);
145 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2); 219 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
146 subgrid->setRowStretch(row, 10); 220 subgrid->setRowStretch(row, 10);
147 row++; 221 row++;
148 222
223 subgrid->setRowStretch(row, 10);
224
225 tab->addTab(frame, tr("&Analysis"));
226
149 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal); 227 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
150 grid->addWidget(bb, 1, 0); 228 grid->addWidget(bb, 1, 0);
151 229
152 QPushButton *ok = new QPushButton(tr("OK")); 230 QPushButton *ok = new QPushButton(tr("OK"));
153 QPushButton *cancel = new QPushButton(tr("Cancel")); 231 QPushButton *cancel = new QPushButton(tr("Cancel"));
200 m_resampleQuality = q; 278 m_resampleQuality = q;
201 m_applyButton->setEnabled(true); 279 m_applyButton->setEnabled(true);
202 } 280 }
203 281
204 void 282 void
283 PreferencesDialog::resampleOnLoadChanged(int state)
284 {
285 m_resampleOnLoad = (state == Qt::Checked);
286 m_applyButton->setEnabled(true);
287 m_changesOnRestart = true;
288 }
289
290 void
291 PreferencesDialog::tempDirRootChanged(QString r)
292 {
293 m_tempDirRoot = r;
294 m_applyButton->setEnabled(true);
295 }
296
297 void
298 PreferencesDialog::tempDirButtonClicked()
299 {
300 QString dir = QFileDialog::getExistingDirectory
301 (this, tr("Select a directory to create cache subdirectory in"),
302 m_tempDirRoot);
303 if (dir == "") return;
304 m_tempDirRootEdit->setText(dir);
305 tempDirRootChanged(dir);
306 m_changesOnRestart = true;
307 }
308
309 void
310 PreferencesDialog::backgroundModeChanged(int mode)
311 {
312 m_backgroundMode = mode;
313 m_applyButton->setEnabled(true);
314 m_changesOnRestart = true;
315 }
316
317 void
205 PreferencesDialog::okClicked() 318 PreferencesDialog::okClicked()
206 { 319 {
207 applyClicked(); 320 applyClicked();
208 accept(); 321 accept();
209 } 322 }
217 (m_spectrogramSmoothing)); 330 (m_spectrogramSmoothing));
218 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout 331 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
219 (m_propertyLayout)); 332 (m_propertyLayout));
220 prefs->setTuningFrequency(m_tuningFrequency); 333 prefs->setTuningFrequency(m_tuningFrequency);
221 prefs->setResampleQuality(m_resampleQuality); 334 prefs->setResampleQuality(m_resampleQuality);
335 prefs->setResampleOnLoad(m_resampleOnLoad);
336 prefs->setTemporaryDirectoryRoot(m_tempDirRoot);
337 prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode));
338
222 m_applyButton->setEnabled(false); 339 m_applyButton->setEnabled(false);
340
341 if (m_changesOnRestart) {
342 QMessageBox::information(this, tr("Preferences"),
343 tr("One or more of the application preferences you have changed may not take full effect until Sonic Visualiser is restarted.\nPlease exit and restart the application now if you want these changes to take effect immediately."));
344 m_changesOnRestart = false;
345 }
223 } 346 }
224 347
225 void 348 void
226 PreferencesDialog::cancelClicked() 349 PreferencesDialog::cancelClicked()
227 { 350 {