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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1505 - (show annotations) (download)
Wed Nov 21 18:37:40 2007 UTC (16 years, 4 months ago) by capela
File size: 11504 byte(s)
- Qt4 migration: small step to squash bug leftovers,
  plenty still in the horizon.

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

  ViewVC Help
Powered by ViewVC