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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1504 - (hide annotations) (download)
Wed Nov 21 11:46:40 2007 UTC (16 years, 4 months ago) by capela
File size: 11639 byte(s)
* Qt4 migration: Qt3Support is now scrapped.

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 1499 ui.ServerHostComboBox->setItemText(
141     ui.ServerHostComboBox->currentIndex(),
142     m_pOptions->sServerHost);
143     ui.ServerPortComboBox->setItemText(
144     ui.ServerPortComboBox->currentIndex(),
145     QString::number(m_pOptions->iServerPort));
146 schoenebeck 1461 ui.ServerTimeoutSpinBox->setValue(m_pOptions->iServerTimeout);
147     ui.ServerStartCheckBox->setChecked(m_pOptions->bServerStart);
148 capela 1499 ui.ServerCmdLineComboBox->setItemText(
149     ui.ServerCmdLineComboBox->currentIndex(),
150     m_pOptions->sServerCmdLine);
151 schoenebeck 1461 ui.StartDelaySpinBox->setValue(m_pOptions->iStartDelay);
152    
153     // Load Display options...
154     QFont font;
155 capela 1504 QPalette pal;
156 schoenebeck 1461
157     // Display font.
158     if (m_pOptions->sDisplayFont.isEmpty() || !font.fromString(m_pOptions->sDisplayFont))
159     font = QFont("Sans Serif", 8);
160     ui.DisplayFontTextLabel->setFont(font);
161     ui.DisplayFontTextLabel->setText(font.family() + " " + QString::number(font.pointSize()));
162    
163     // Display effect.
164     ui.DisplayEffectCheckBox->setChecked(m_pOptions->bDisplayEffect);
165     toggleDisplayEffect(m_pOptions->bDisplayEffect);
166    
167     // Auto-refresh and maximum volume options.
168     ui.AutoRefreshCheckBox->setChecked(m_pOptions->bAutoRefresh);
169     ui.AutoRefreshTimeSpinBox->setValue(m_pOptions->iAutoRefreshTime);
170     ui.MaxVolumeSpinBox->setValue(m_pOptions->iMaxVolume);
171    
172     // Messages font.
173     if (m_pOptions->sMessagesFont.isEmpty() || !font.fromString(m_pOptions->sMessagesFont))
174     font = QFont("Fixed", 8);
175 capela 1504 pal = ui.MessagesFontTextLabel->palette();
176     pal.setColor(QPalette::Background, Qt::white);
177     ui.MessagesFontTextLabel->setPalette(pal);
178 schoenebeck 1461 ui.MessagesFontTextLabel->setFont(font);
179 capela 1504 ui.MessagesFontTextLabel->setText(font.family() + ' ' + QString::number(font.pointSize()));
180 schoenebeck 1461
181     // Messages limit option.
182     ui.MessagesLimitCheckBox->setChecked(m_pOptions->bMessagesLimit);
183     ui.MessagesLimitLinesSpinBox->setValue(m_pOptions->iMessagesLimitLines);
184    
185     // Other options finally.
186     ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove);
187     ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop);
188     ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture);
189     ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath);
190     ui.InstrumentNamesCheckBox->setChecked(m_pOptions->bInstrumentNames);
191     ui.MaxRecentFilesSpinBox->setValue(m_pOptions->iMaxRecentFiles);
192    
193     #ifndef CONFIG_LIBGIG
194     ui.InstrumentNamesCheckBox->setEnabled(false);
195     #endif
196    
197     // Done.
198     m_iDirtySetup--;
199     stabilizeForm();
200     }
201    
202    
203     // Accept settings (OK button slot).
204     void OptionsForm::accept (void)
205     {
206     // Save options...
207     if (m_iDirtyCount > 0) {
208     // Server settings....
209 capela 1499 m_pOptions->sServerHost = ui.ServerHostComboBox->currentText().trimmed();
210 schoenebeck 1461 m_pOptions->iServerPort = ui.ServerPortComboBox->currentText().toInt();
211     m_pOptions->iServerTimeout = ui.ServerTimeoutSpinBox->value();
212     m_pOptions->bServerStart = ui.ServerStartCheckBox->isChecked();
213 capela 1499 m_pOptions->sServerCmdLine = ui.ServerCmdLineComboBox->currentText().trimmed();
214 schoenebeck 1461 m_pOptions->iStartDelay = ui.StartDelaySpinBox->value();
215     // Channels options...
216     m_pOptions->sDisplayFont = ui.DisplayFontTextLabel->font().toString();
217     m_pOptions->bDisplayEffect = ui.DisplayEffectCheckBox->isChecked();
218     m_pOptions->bAutoRefresh = ui.AutoRefreshCheckBox->isChecked();
219     m_pOptions->iAutoRefreshTime = ui.AutoRefreshTimeSpinBox->value();
220     m_pOptions->iMaxVolume = ui.MaxVolumeSpinBox->value();
221     // Messages options...
222     m_pOptions->sMessagesFont = ui.MessagesFontTextLabel->font().toString();
223     m_pOptions->bMessagesLimit = ui.MessagesLimitCheckBox->isChecked();
224     m_pOptions->iMessagesLimitLines = ui.MessagesLimitLinesSpinBox->value();
225     // Other options...
226     m_pOptions->bConfirmRemove = ui.ConfirmRemoveCheckBox->isChecked();
227     m_pOptions->bKeepOnTop = ui.KeepOnTopCheckBox->isChecked();
228     m_pOptions->bStdoutCapture = ui.StdoutCaptureCheckBox->isChecked();
229     m_pOptions->bCompletePath = ui.CompletePathCheckBox->isChecked();
230     m_pOptions->bInstrumentNames = ui.InstrumentNamesCheckBox->isChecked();
231     m_pOptions->iMaxRecentFiles = ui.MaxRecentFilesSpinBox->value();
232     // Reset dirty flag.
233     m_iDirtyCount = 0;
234     }
235    
236     // Save combobox history...
237     m_pOptions->saveComboBoxHistory(ui.ServerHostComboBox);
238     m_pOptions->saveComboBoxHistory(ui.ServerPortComboBox);
239     m_pOptions->saveComboBoxHistory(ui.ServerCmdLineComboBox);
240    
241     // Just go with dialog acceptance.
242     QDialog::accept();
243     }
244    
245    
246     // Reject settings (Cancel button slot).
247     void OptionsForm::reject (void)
248     {
249     bool bReject = true;
250    
251     // Check if there's any pending changes...
252     if (m_iDirtyCount > 0) {
253     switch (QMessageBox::warning(this,
254     QSAMPLER_TITLE ": " + tr("Warning"),
255     tr("Some settings have been changed.\n\n"
256     "Do you want to apply the changes?"),
257     tr("Apply"), tr("Discard"), tr("Cancel"))) {
258     case 0: // Apply...
259     accept();
260     return;
261     case 1: // Discard
262     break;
263     default: // Cancel.
264     bReject = false;
265     }
266     }
267    
268     if (bReject)
269     QDialog::reject();
270     }
271    
272    
273     // Dirty up settings.
274     void OptionsForm::optionsChanged (void)
275     {
276     if (m_iDirtySetup > 0)
277     return;
278    
279     m_iDirtyCount++;
280     stabilizeForm();
281     }
282    
283    
284     // Stabilize current form state.
285     void OptionsForm::stabilizeForm (void)
286     {
287     bool bEnabled = ui.ServerStartCheckBox->isChecked();
288     ui.ServerCmdLineTextLabel->setEnabled(bEnabled);
289     ui.ServerCmdLineComboBox->setEnabled(bEnabled);
290     ui.StartDelayTextLabel->setEnabled(bEnabled);
291     ui.StartDelaySpinBox->setEnabled(bEnabled);
292    
293     ui.AutoRefreshTimeSpinBox->setEnabled(ui.AutoRefreshCheckBox->isChecked());
294     ui.MessagesLimitLinesSpinBox->setEnabled(ui.MessagesLimitCheckBox->isChecked());
295    
296     ui.OkPushButton->setEnabled(m_iDirtyCount > 0);
297     }
298    
299    
300     // The channel display font selection dialog.
301     void OptionsForm::chooseDisplayFont (void)
302     {
303     bool bOk = false;
304     QFont font = QFontDialog::getFont(&bOk, ui.DisplayFontTextLabel->font(), this);
305     if (bOk) {
306     ui.DisplayFontTextLabel->setFont(font);
307     ui.DisplayFontTextLabel->setText(font.family() + " " + QString::number(font.pointSize()));
308     optionsChanged();
309     }
310     }
311    
312    
313     // The messages font selection dialog.
314     void OptionsForm::chooseMessagesFont (void)
315     {
316     bool bOk = false;
317     QFont font = QFontDialog::getFont(&bOk, ui.MessagesFontTextLabel->font(), this);
318     if (bOk) {
319     ui.MessagesFontTextLabel->setFont(font);
320     ui.MessagesFontTextLabel->setText(font.family() + " " + QString::number(font.pointSize()));
321     optionsChanged();
322     }
323     }
324    
325    
326     // The channel display effect demo changer.
327     void OptionsForm::toggleDisplayEffect ( bool bOn )
328     {
329 capela 1499 QPalette pal;
330     pal.setColor(QPalette::Foreground, Qt::green);
331     if (bOn) {
332 capela 1504 QPixmap pm(":/icons/displaybg1.png");
333 capela 1499 pal.setBrush(QPalette::Background, QBrush(pm));
334     } else {
335     pal.setColor(QPalette::Background, Qt::black);
336     }
337     ui.DisplayFontTextLabel->setPalette(pal);
338 schoenebeck 1461
339 capela 1499 optionsChanged();
340 schoenebeck 1461 }
341    
342     } // namespace QSampler
343 capela 1464
344    
345 capela 1466 // end of qsamplerOptionsForm.cpp

  ViewVC Help
Powered by ViewVC