/[svn]/qsampler/trunk/src/qsamplerOptionsForm.cpp
ViewVC logotype

Contents of /qsampler/trunk/src/qsamplerOptionsForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1509 - (show annotations) (download)
Thu Nov 22 11:10:44 2007 UTC (16 years, 4 months ago) by capela
File size: 11090 byte(s)
* Audio routing table is initially hidden in the dialog, when
  creating a new sampler channel.

* README requirements and configuration notes update.

1 // qsamplerOptionsForm.cpp
2 //
3 /****************************************************************************
4 Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5 Copyright (C) 2007, Christian Schoenebeck
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 *****************************************************************************/
22
23 #include "qsamplerOptionsForm.h"
24
25 #include "qsamplerAbout.h"
26 #include "qsamplerOptions.h"
27
28 #include <QMessageBox>
29 #include <QFontDialog>
30
31
32 namespace QSampler {
33
34 OptionsForm::OptionsForm ( QWidget* pParent )
35 : QDialog(pParent)
36 {
37 m_ui.setupUi(this);
38
39 // No settings descriptor initially (the caller will set it).
40 m_pOptions = NULL;
41
42 // Initialize dirty control state.
43 m_iDirtySetup = 0;
44 m_iDirtyCount = 0;
45
46 // Set dialog validators...
47 m_ui.ServerPortComboBox->setValidator(
48 new QIntValidator(m_ui.ServerPortComboBox));
49
50 // Try to restore old window positioning.
51 adjustSize();
52
53 QObject::connect(m_ui.ServerHostComboBox,
54 SIGNAL(editTextChanged(const QString&)),
55 SLOT(optionsChanged()));
56 QObject::connect(m_ui.ServerPortComboBox,
57 SIGNAL(editTextChanged(const QString&)),
58 SLOT(optionsChanged()));
59 QObject::connect(m_ui.ServerTimeoutSpinBox,
60 SIGNAL(valueChanged(int)),
61 SLOT(optionsChanged()));
62 QObject::connect(m_ui.ServerStartCheckBox,
63 SIGNAL(stateChanged(int)),
64 SLOT(optionsChanged()));
65 QObject::connect(m_ui.ServerCmdLineComboBox,
66 SIGNAL(editTextChanged(const QString&)),
67 SLOT(optionsChanged()));
68 QObject::connect(m_ui.StartDelaySpinBox,
69 SIGNAL(valueChanged(int)),
70 SLOT(optionsChanged()));
71 QObject::connect(m_ui.DisplayFontPushButton,
72 SIGNAL(clicked()),
73 SLOT(chooseDisplayFont()));
74 QObject::connect(m_ui.DisplayEffectCheckBox,
75 SIGNAL(toggled(bool)),
76 SLOT(toggleDisplayEffect(bool)));
77 QObject::connect(m_ui.AutoRefreshCheckBox,
78 SIGNAL(stateChanged(int)),
79 SLOT(optionsChanged()));
80 QObject::connect(m_ui.AutoRefreshTimeSpinBox,
81 SIGNAL(valueChanged(int)),
82 SLOT(optionsChanged()));
83 QObject::connect(m_ui.MaxVolumeSpinBox,
84 SIGNAL(valueChanged(int)),
85 SLOT(optionsChanged()));
86 QObject::connect(m_ui.MessagesFontPushButton,
87 SIGNAL(clicked()),
88 SLOT(chooseMessagesFont()));
89 QObject::connect(m_ui.MessagesLimitCheckBox,
90 SIGNAL(stateChanged(int)),
91 SLOT(optionsChanged()));
92 QObject::connect(m_ui.MessagesLimitLinesSpinBox,
93 SIGNAL(valueChanged(int)),
94 SLOT(optionsChanged()));
95 QObject::connect(m_ui.ConfirmRemoveCheckBox,
96 SIGNAL(stateChanged(int)),
97 SLOT(optionsChanged()));
98 QObject::connect(m_ui.KeepOnTopCheckBox,
99 SIGNAL(stateChanged(int)),
100 SLOT(optionsChanged()));
101 QObject::connect(m_ui.StdoutCaptureCheckBox,
102 SIGNAL(stateChanged(int)),
103 SLOT(optionsChanged()));
104 QObject::connect(m_ui.MaxRecentFilesSpinBox,
105 SIGNAL(valueChanged(int)),
106 SLOT(optionsChanged()));
107 QObject::connect(m_ui.CompletePathCheckBox,
108 SIGNAL(stateChanged(int)),
109 SLOT(optionsChanged()));
110 QObject::connect(m_ui.InstrumentNamesCheckBox,
111 SIGNAL(stateChanged(int)),
112 SLOT(optionsChanged()));
113 QObject::connect(m_ui.OkPushButton,
114 SIGNAL(clicked()),
115 SLOT(accept()));
116 QObject::connect(m_ui.CancelPushButton,
117 SIGNAL(clicked()),
118 SLOT(reject()));
119 }
120
121 OptionsForm::~OptionsForm()
122 {
123 }
124
125 // Populate (setup) dialog controls from settings descriptors.
126 void OptionsForm::setup ( qsamplerOptions *pOptions )
127 {
128 // Set reference descriptor.
129 m_pOptions = pOptions;
130
131 // Start clean.
132 m_iDirtyCount = 0;
133 // Avoid nested changes.
134 m_iDirtySetup++;
135
136 // Load combo box history...
137 m_pOptions->loadComboBoxHistory(m_ui.ServerHostComboBox);
138 m_pOptions->loadComboBoxHistory(m_ui.ServerPortComboBox);
139 m_pOptions->loadComboBoxHistory(m_ui.ServerCmdLineComboBox);
140
141 // Load Server settings...
142 m_ui.ServerHostComboBox->setEditText(m_pOptions->sServerHost);
143 m_ui.ServerPortComboBox->setEditText(QString::number(m_pOptions->iServerPort));
144 m_ui.ServerTimeoutSpinBox->setValue(m_pOptions->iServerTimeout);
145 m_ui.ServerStartCheckBox->setChecked(m_pOptions->bServerStart);
146 m_ui.ServerCmdLineComboBox->setEditText(m_pOptions->sServerCmdLine);
147 m_ui.StartDelaySpinBox->setValue(m_pOptions->iStartDelay);
148
149 // Load Display options...
150 QFont font;
151 QPalette pal;
152
153 // Display font.
154 if (m_pOptions->sDisplayFont.isEmpty()
155 || !font.fromString(m_pOptions->sDisplayFont))
156 font = QFont("Sans Serif", 8);
157 m_ui.DisplayFontTextLabel->setFont(font);
158 m_ui.DisplayFontTextLabel->setText(font.family()
159 + ' ' + QString::number(font.pointSize()));
160
161 // Display effect.
162 m_ui.DisplayEffectCheckBox->setChecked(m_pOptions->bDisplayEffect);
163 toggleDisplayEffect(m_pOptions->bDisplayEffect);
164
165 // Auto-refresh and maximum volume options.
166 m_ui.AutoRefreshCheckBox->setChecked(m_pOptions->bAutoRefresh);
167 m_ui.AutoRefreshTimeSpinBox->setValue(m_pOptions->iAutoRefreshTime);
168 m_ui.MaxVolumeSpinBox->setValue(m_pOptions->iMaxVolume);
169
170 // Messages font.
171 if (m_pOptions->sMessagesFont.isEmpty()
172 || !font.fromString(m_pOptions->sMessagesFont))
173 font = QFont("Fixed", 8);
174 pal = m_ui.MessagesFontTextLabel->palette();
175 pal.setColor(QPalette::Background, Qt::white);
176 m_ui.MessagesFontTextLabel->setPalette(pal);
177 m_ui.MessagesFontTextLabel->setFont(font);
178 m_ui.MessagesFontTextLabel->setText(font.family()
179 + ' ' + QString::number(font.pointSize()));
180
181 // Messages limit option.
182 m_ui.MessagesLimitCheckBox->setChecked(m_pOptions->bMessagesLimit);
183 m_ui.MessagesLimitLinesSpinBox->setValue(m_pOptions->iMessagesLimitLines);
184
185 // Other options finally.
186 m_ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove);
187 m_ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop);
188 m_ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture);
189 m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath);
190 m_ui.InstrumentNamesCheckBox->setChecked(m_pOptions->bInstrumentNames);
191 m_ui.MaxRecentFilesSpinBox->setValue(m_pOptions->iMaxRecentFiles);
192
193 #ifndef CONFIG_LIBGIG
194 m_ui.InstrumentNamesCheckBox->setEnabled(false);
195 #endif
196
197 // Done.
198 m_iDirtySetup--;
199 stabilizeForm();
200 }
201
202
203 // Accept settings (OK button slot).
204 void OptionsForm::accept (void)
205 {
206 // Save options...
207 if (m_iDirtyCount > 0) {
208 // Server settings....
209 m_pOptions->sServerHost = m_ui.ServerHostComboBox->currentText().trimmed();
210 m_pOptions->iServerPort = m_ui.ServerPortComboBox->currentText().toInt();
211 m_pOptions->iServerTimeout = m_ui.ServerTimeoutSpinBox->value();
212 m_pOptions->bServerStart = m_ui.ServerStartCheckBox->isChecked();
213 m_pOptions->sServerCmdLine = m_ui.ServerCmdLineComboBox->currentText().trimmed();
214 m_pOptions->iStartDelay = m_ui.StartDelaySpinBox->value();
215 // Channels options...
216 m_pOptions->sDisplayFont = m_ui.DisplayFontTextLabel->font().toString();
217 m_pOptions->bDisplayEffect = m_ui.DisplayEffectCheckBox->isChecked();
218 m_pOptions->bAutoRefresh = m_ui.AutoRefreshCheckBox->isChecked();
219 m_pOptions->iAutoRefreshTime = m_ui.AutoRefreshTimeSpinBox->value();
220 m_pOptions->iMaxVolume = m_ui.MaxVolumeSpinBox->value();
221 // Messages options...
222 m_pOptions->sMessagesFont = m_ui.MessagesFontTextLabel->font().toString();
223 m_pOptions->bMessagesLimit = m_ui.MessagesLimitCheckBox->isChecked();
224 m_pOptions->iMessagesLimitLines = m_ui.MessagesLimitLinesSpinBox->value();
225 // Other options...
226 m_pOptions->bConfirmRemove = m_ui.ConfirmRemoveCheckBox->isChecked();
227 m_pOptions->bKeepOnTop = m_ui.KeepOnTopCheckBox->isChecked();
228 m_pOptions->bStdoutCapture = m_ui.StdoutCaptureCheckBox->isChecked();
229 m_pOptions->bCompletePath = m_ui.CompletePathCheckBox->isChecked();
230 m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked();
231 m_pOptions->iMaxRecentFiles = m_ui.MaxRecentFilesSpinBox->value();
232 // Reset dirty flag.
233 m_iDirtyCount = 0;
234 }
235
236 // Save combobox history...
237 m_pOptions->saveComboBoxHistory(m_ui.ServerHostComboBox);
238 m_pOptions->saveComboBoxHistory(m_ui.ServerPortComboBox);
239 m_pOptions->saveComboBoxHistory(m_ui.ServerCmdLineComboBox);
240
241 // Just go with dialog acceptance.
242 QDialog::accept();
243 }
244
245
246 // Reject settings (Cancel button slot).
247 void OptionsForm::reject (void)
248 {
249 bool bReject = true;
250
251 // Check if there's any pending changes...
252 if (m_iDirtyCount > 0) {
253 switch (QMessageBox::warning(this,
254 QSAMPLER_TITLE ": " + tr("Warning"),
255 tr("Some settings have been changed.\n\n"
256 "Do you want to apply the changes?"),
257 tr("Apply"), tr("Discard"), tr("Cancel"))) {
258 case 0: // Apply...
259 accept();
260 return;
261 case 1: // Discard
262 break;
263 default: // Cancel.
264 bReject = false;
265 }
266 }
267
268 if (bReject)
269 QDialog::reject();
270 }
271
272
273 // Dirty up settings.
274 void OptionsForm::optionsChanged (void)
275 {
276 if (m_iDirtySetup > 0)
277 return;
278
279 m_iDirtyCount++;
280 stabilizeForm();
281 }
282
283
284 // Stabilize current form state.
285 void OptionsForm::stabilizeForm (void)
286 {
287 bool bEnabled = m_ui.ServerStartCheckBox->isChecked();
288 m_ui.ServerCmdLineTextLabel->setEnabled(bEnabled);
289 m_ui.ServerCmdLineComboBox->setEnabled(bEnabled);
290 m_ui.StartDelayTextLabel->setEnabled(bEnabled);
291 m_ui.StartDelaySpinBox->setEnabled(bEnabled);
292
293 m_ui.AutoRefreshTimeSpinBox->setEnabled(
294 m_ui.AutoRefreshCheckBox->isChecked());
295 m_ui.MessagesLimitLinesSpinBox->setEnabled(
296 m_ui.MessagesLimitCheckBox->isChecked());
297
298 m_ui.OkPushButton->setEnabled(m_iDirtyCount > 0);
299 }
300
301
302 // The channel display font selection dialog.
303 void OptionsForm::chooseDisplayFont (void)
304 {
305 bool bOk = false;
306 QFont font = QFontDialog::getFont(&bOk,
307 m_ui.DisplayFontTextLabel->font(), this);
308 if (bOk) {
309 m_ui.DisplayFontTextLabel->setFont(font);
310 m_ui.DisplayFontTextLabel->setText(font.family()
311 + ' ' + QString::number(font.pointSize()));
312 optionsChanged();
313 }
314 }
315
316
317 // The messages font selection dialog.
318 void OptionsForm::chooseMessagesFont (void)
319 {
320 bool bOk = false;
321 QFont font = QFontDialog::getFont(&bOk,
322 m_ui.MessagesFontTextLabel->font(), this);
323 if (bOk) {
324 m_ui.MessagesFontTextLabel->setFont(font);
325 m_ui.MessagesFontTextLabel->setText(font.family()
326 + ' ' + QString::number(font.pointSize()));
327 optionsChanged();
328 }
329 }
330
331
332 // The channel display effect demo changer.
333 void OptionsForm::toggleDisplayEffect ( bool bOn )
334 {
335 QPalette pal;
336 pal.setColor(QPalette::Foreground, Qt::green);
337 if (bOn) {
338 QPixmap pm(":/icons/displaybg1.png");
339 pal.setBrush(QPalette::Background, QBrush(pm));
340 } else {
341 pal.setColor(QPalette::Background, Qt::black);
342 }
343 m_ui.DisplayFontTextLabel->setPalette(pal);
344
345 optionsChanged();
346 }
347
348 } // namespace QSampler
349
350
351 // end of qsamplerOptionsForm.cpp

  ViewVC Help
Powered by ViewVC