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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1558 - (hide 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 capela 1464 // 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 schoenebeck 1461 #include "qsamplerOptionsForm.h"
24    
25     #include "qsamplerAbout.h"
26     #include "qsamplerOptions.h"
27    
28     #include <QMessageBox>
29     #include <QFontDialog>
30    
31 capela 1499
32 schoenebeck 1461 namespace QSampler {
33    
34 capela 1558 //-------------------------------------------------------------------------
35     // QSampler::OptionsForm -- Options form implementation.
36     //
37    
38 capela 1509 OptionsForm::OptionsForm ( QWidget* pParent )
39     : QDialog(pParent)
40 capela 1473 {
41 capela 1509 m_ui.setupUi(this);
42 schoenebeck 1461
43 capela 1473 // No settings descriptor initially (the caller will set it).
44     m_pOptions = NULL;
45 schoenebeck 1461
46 capela 1473 // Initialize dirty control state.
47     m_iDirtySetup = 0;
48     m_iDirtyCount = 0;
49 schoenebeck 1461
50 capela 1473 // Set dialog validators...
51 capela 1509 m_ui.ServerPortComboBox->setValidator(
52     new QIntValidator(m_ui.ServerPortComboBox));
53 schoenebeck 1461
54 capela 1473 // Try to restore old window positioning.
55     adjustSize();
56 capela 1466
57 capela 1509 QObject::connect(m_ui.ServerHostComboBox,
58 capela 1504 SIGNAL(editTextChanged(const QString&)),
59 capela 1466 SLOT(optionsChanged()));
60 capela 1509 QObject::connect(m_ui.ServerPortComboBox,
61 capela 1504 SIGNAL(editTextChanged(const QString&)),
62 capela 1466 SLOT(optionsChanged()));
63 capela 1509 QObject::connect(m_ui.ServerTimeoutSpinBox,
64 capela 1466 SIGNAL(valueChanged(int)),
65     SLOT(optionsChanged()));
66 capela 1509 QObject::connect(m_ui.ServerStartCheckBox,
67 capela 1466 SIGNAL(stateChanged(int)),
68     SLOT(optionsChanged()));
69 capela 1509 QObject::connect(m_ui.ServerCmdLineComboBox,
70 capela 1504 SIGNAL(editTextChanged(const QString&)),
71 capela 1466 SLOT(optionsChanged()));
72 capela 1509 QObject::connect(m_ui.StartDelaySpinBox,
73 capela 1466 SIGNAL(valueChanged(int)),
74     SLOT(optionsChanged()));
75 capela 1509 QObject::connect(m_ui.DisplayFontPushButton,
76 capela 1466 SIGNAL(clicked()),
77     SLOT(chooseDisplayFont()));
78 capela 1509 QObject::connect(m_ui.DisplayEffectCheckBox,
79 capela 1466 SIGNAL(toggled(bool)),
80     SLOT(toggleDisplayEffect(bool)));
81 capela 1509 QObject::connect(m_ui.AutoRefreshCheckBox,
82 capela 1466 SIGNAL(stateChanged(int)),
83     SLOT(optionsChanged()));
84 capela 1509 QObject::connect(m_ui.AutoRefreshTimeSpinBox,
85 capela 1466 SIGNAL(valueChanged(int)),
86     SLOT(optionsChanged()));
87 capela 1509 QObject::connect(m_ui.MaxVolumeSpinBox,
88 capela 1466 SIGNAL(valueChanged(int)),
89     SLOT(optionsChanged()));
90 capela 1509 QObject::connect(m_ui.MessagesFontPushButton,
91 capela 1466 SIGNAL(clicked()),
92     SLOT(chooseMessagesFont()));
93 capela 1509 QObject::connect(m_ui.MessagesLimitCheckBox,
94 capela 1466 SIGNAL(stateChanged(int)),
95     SLOT(optionsChanged()));
96 capela 1509 QObject::connect(m_ui.MessagesLimitLinesSpinBox,
97 capela 1466 SIGNAL(valueChanged(int)),
98     SLOT(optionsChanged()));
99 capela 1509 QObject::connect(m_ui.ConfirmRemoveCheckBox,
100 capela 1466 SIGNAL(stateChanged(int)),
101     SLOT(optionsChanged()));
102 capela 1509 QObject::connect(m_ui.KeepOnTopCheckBox,
103 capela 1466 SIGNAL(stateChanged(int)),
104     SLOT(optionsChanged()));
105 capela 1509 QObject::connect(m_ui.StdoutCaptureCheckBox,
106 capela 1466 SIGNAL(stateChanged(int)),
107     SLOT(optionsChanged()));
108 capela 1509 QObject::connect(m_ui.MaxRecentFilesSpinBox,
109 capela 1466 SIGNAL(valueChanged(int)),
110     SLOT(optionsChanged()));
111 capela 1509 QObject::connect(m_ui.CompletePathCheckBox,
112 capela 1466 SIGNAL(stateChanged(int)),
113     SLOT(optionsChanged()));
114 capela 1509 QObject::connect(m_ui.InstrumentNamesCheckBox,
115 capela 1466 SIGNAL(stateChanged(int)),
116     SLOT(optionsChanged()));
117 capela 1509 QObject::connect(m_ui.OkPushButton,
118 capela 1466 SIGNAL(clicked()),
119     SLOT(accept()));
120 capela 1509 QObject::connect(m_ui.CancelPushButton,
121 capela 1466 SIGNAL(clicked()),
122     SLOT(reject()));
123 schoenebeck 1461 }
124    
125 capela 1473 OptionsForm::~OptionsForm()
126     {
127 schoenebeck 1461 }
128    
129     // Populate (setup) dialog controls from settings descriptors.
130 capela 1558 void OptionsForm::setup ( Options *pOptions )
131 schoenebeck 1461 {
132 capela 1509 // Set reference descriptor.
133     m_pOptions = pOptions;
134 schoenebeck 1461
135 capela 1509 // Start clean.
136     m_iDirtyCount = 0;
137     // Avoid nested changes.
138     m_iDirtySetup++;
139 schoenebeck 1461
140 capela 1509 // 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 schoenebeck 1461
145 capela 1509 // 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 schoenebeck 1461
153 capela 1509 // Load Display options...
154     QFont font;
155 capela 1504 QPalette pal;
156 schoenebeck 1461
157 capela 1509 // 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 schoenebeck 1461
165 capela 1509 // Display effect.
166     m_ui.DisplayEffectCheckBox->setChecked(m_pOptions->bDisplayEffect);
167     toggleDisplayEffect(m_pOptions->bDisplayEffect);
168 schoenebeck 1461
169 capela 1509 // 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 schoenebeck 1461
174 capela 1509 // 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 capela 1504 pal.setColor(QPalette::Background, Qt::white);
180 capela 1509 m_ui.MessagesFontTextLabel->setPalette(pal);
181     m_ui.MessagesFontTextLabel->setFont(font);
182     m_ui.MessagesFontTextLabel->setText(font.family()
183     + ' ' + QString::number(font.pointSize()));
184 schoenebeck 1461
185 capela 1509 // Messages limit option.
186     m_ui.MessagesLimitCheckBox->setChecked(m_pOptions->bMessagesLimit);
187     m_ui.MessagesLimitLinesSpinBox->setValue(m_pOptions->iMessagesLimitLines);
188 schoenebeck 1461
189 capela 1509 // 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 schoenebeck 1461
197     #ifndef CONFIG_LIBGIG
198 capela 1509 m_ui.InstrumentNamesCheckBox->setEnabled(false);
199 schoenebeck 1461 #endif
200    
201 capela 1509 // Done.
202     m_iDirtySetup--;
203     stabilizeForm();
204 schoenebeck 1461 }
205    
206    
207     // Accept settings (OK button slot).
208     void OptionsForm::accept (void)
209     {
210 capela 1509 // 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 schoenebeck 1461
240 capela 1509 // 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 schoenebeck 1461
245 capela 1509 // Just go with dialog acceptance.
246     QDialog::accept();
247 schoenebeck 1461 }
248    
249    
250     // Reject settings (Cancel button slot).
251     void OptionsForm::reject (void)
252     {
253 capela 1509 bool bReject = true;
254 schoenebeck 1461
255 capela 1509 // Check if there's any pending changes...
256     if (m_iDirtyCount > 0) {
257     switch (QMessageBox::warning(this,
258 schoenebeck 1461 QSAMPLER_TITLE ": " + tr("Warning"),
259 capela 1509 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 schoenebeck 1461
272 capela 1509 if (bReject)
273     QDialog::reject();
274 schoenebeck 1461 }
275    
276    
277     // Dirty up settings.
278     void OptionsForm::optionsChanged (void)
279     {
280 capela 1509 if (m_iDirtySetup > 0)
281     return;
282 schoenebeck 1461
283 capela 1509 m_iDirtyCount++;
284     stabilizeForm();
285 schoenebeck 1461 }
286    
287    
288     // Stabilize current form state.
289     void OptionsForm::stabilizeForm (void)
290     {
291 capela 1509 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 schoenebeck 1461
297 capela 1509 m_ui.AutoRefreshTimeSpinBox->setEnabled(
298     m_ui.AutoRefreshCheckBox->isChecked());
299     m_ui.MessagesLimitLinesSpinBox->setEnabled(
300     m_ui.MessagesLimitCheckBox->isChecked());
301 schoenebeck 1461
302 capela 1509 m_ui.OkPushButton->setEnabled(m_iDirtyCount > 0);
303 schoenebeck 1461 }
304    
305    
306     // The channel display font selection dialog.
307     void OptionsForm::chooseDisplayFont (void)
308     {
309 capela 1509 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 schoenebeck 1461 }
319    
320    
321     // The messages font selection dialog.
322     void OptionsForm::chooseMessagesFont (void)
323     {
324 capela 1509 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 schoenebeck 1461 }
334    
335    
336     // The channel display effect demo changer.
337     void OptionsForm::toggleDisplayEffect ( bool bOn )
338     {
339 capela 1499 QPalette pal;
340     pal.setColor(QPalette::Foreground, Qt::green);
341     if (bOn) {
342 capela 1504 QPixmap pm(":/icons/displaybg1.png");
343 capela 1499 pal.setBrush(QPalette::Background, QBrush(pm));
344     } else {
345     pal.setColor(QPalette::Background, Qt::black);
346     }
347 capela 1509 m_ui.DisplayFontTextLabel->setPalette(pal);
348 schoenebeck 1461
349 capela 1499 optionsChanged();
350 schoenebeck 1461 }
351    
352     } // namespace QSampler
353 capela 1464
354    
355 capela 1466 // end of qsamplerOptionsForm.cpp

  ViewVC Help
Powered by ViewVC