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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1509 - (hide annotations) (download)
Thu Nov 22 11:10:44 2007 UTC (16 years, 5 months ago) by capela
File size: 11090 byte(s)
* Audio routing table is initially hidden in the dialog, when
  creating a new sampler channel.

* README requirements and configuration notes update.

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

  ViewVC Help
Powered by ViewVC