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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1466 - (show annotations) (download)
Thu Nov 1 19:25:10 2007 UTC (16 years, 5 months ago) by capela
File size: 11298 byte(s)
* Qt4 migration: added missing signal/slot connections for most forms.

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

  ViewVC Help
Powered by ViewVC