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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1474 - (show annotations) (download)
Mon Nov 5 20:47:38 2007 UTC (16 years, 5 months ago) by schoenebeck
File size: 11256 byte(s)
* Qt4 migration: fixed another bunch of ghost connections, fixed engine
  combo box in channel form, fixed stdout ouptut in message window (a lot
  of white lines were shown), show channel strip on the work space (and not
  in the nirvana of the desktop universe)

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

  ViewVC Help
Powered by ViewVC