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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1499 - (hide annotations) (download)
Tue Nov 20 16:48:04 2007 UTC (16 years, 5 months ago) by capela
File size: 11487 byte(s)
* Qt4 migration: one first step forward to kiss Qt3Support goodbye.

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

  ViewVC Help
Powered by ViewVC