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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1558 - (show annotations) (download)
Thu Dec 6 09:35:33 2007 UTC (16 years, 4 months ago) by capela
File size: 11219 byte(s)
* Qt4 migration: complete QSampler namespace overhaul.

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

  ViewVC Help
Powered by ViewVC