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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1505 - (hide 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 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 1473 OptionsForm::OptionsForm(QWidget* parent) : QDialog(parent)
35     {
36     ui.setupUi(this);
37 schoenebeck 1461
38 capela 1473 // No settings descriptor initially (the caller will set it).
39     m_pOptions = NULL;
40 schoenebeck 1461
41 capela 1473 // Initialize dirty control state.
42     m_iDirtySetup = 0;
43     m_iDirtyCount = 0;
44 schoenebeck 1461
45 capela 1473 // Set dialog validators...
46     ui.ServerPortComboBox->setValidator(new QIntValidator(ui.ServerPortComboBox));
47 schoenebeck 1461
48 capela 1473 // Try to restore old window positioning.
49     adjustSize();
50 capela 1466
51     QObject::connect(ui.ServerHostComboBox,
52 capela 1504 SIGNAL(editTextChanged(const QString&)),
53 capela 1466 SLOT(optionsChanged()));
54     QObject::connect(ui.ServerPortComboBox,
55 capela 1504 SIGNAL(editTextChanged(const QString&)),
56 capela 1466 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 capela 1504 SIGNAL(editTextChanged(const QString&)),
65 capela 1466 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 schoenebeck 1461 }
118    
119 capela 1473 OptionsForm::~OptionsForm()
120     {
121 schoenebeck 1461 }
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 capela 1505 ui.ServerHostComboBox->setEditText(m_pOptions->sServerHost);
141     ui.ServerPortComboBox->setEditText(QString::number(m_pOptions->iServerPort));
142 schoenebeck 1461 ui.ServerTimeoutSpinBox->setValue(m_pOptions->iServerTimeout);
143     ui.ServerStartCheckBox->setChecked(m_pOptions->bServerStart);
144 capela 1505 ui.ServerCmdLineComboBox->setEditText(m_pOptions->sServerCmdLine);
145 schoenebeck 1461 ui.StartDelaySpinBox->setValue(m_pOptions->iStartDelay);
146    
147     // Load Display options...
148     QFont font;
149 capela 1504 QPalette pal;
150 schoenebeck 1461
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 capela 1504 pal = ui.MessagesFontTextLabel->palette();
170     pal.setColor(QPalette::Background, Qt::white);
171     ui.MessagesFontTextLabel->setPalette(pal);
172 schoenebeck 1461 ui.MessagesFontTextLabel->setFont(font);
173 capela 1504 ui.MessagesFontTextLabel->setText(font.family() + ' ' + QString::number(font.pointSize()));
174 schoenebeck 1461
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 capela 1499 m_pOptions->sServerHost = ui.ServerHostComboBox->currentText().trimmed();
204 schoenebeck 1461 m_pOptions->iServerPort = ui.ServerPortComboBox->currentText().toInt();
205     m_pOptions->iServerTimeout = ui.ServerTimeoutSpinBox->value();
206     m_pOptions->bServerStart = ui.ServerStartCheckBox->isChecked();
207 capela 1499 m_pOptions->sServerCmdLine = ui.ServerCmdLineComboBox->currentText().trimmed();
208 schoenebeck 1461 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 capela 1499 QPalette pal;
324     pal.setColor(QPalette::Foreground, Qt::green);
325     if (bOn) {
326 capela 1504 QPixmap pm(":/icons/displaybg1.png");
327 capela 1499 pal.setBrush(QPalette::Background, QBrush(pm));
328     } else {
329     pal.setColor(QPalette::Background, Qt::black);
330     }
331     ui.DisplayFontTextLabel->setPalette(pal);
332 schoenebeck 1461
333 capela 1499 optionsChanged();
334 schoenebeck 1461 }
335    
336     } // namespace QSampler
337 capela 1464
338    
339 capela 1466 // end of qsamplerOptionsForm.cpp

  ViewVC Help
Powered by ViewVC