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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1788 - (hide annotations) (download)
Sun Oct 26 15:44:42 2008 UTC (15 years, 5 months ago) by capela
File size: 13235 byte(s)
- Grayed/disabled palette color group fix for dark color themes.

1 capela 1464 // qsamplerOptionsForm.cpp
2     //
3     /****************************************************************************
4 capela 1738 Copyright (C) 2004-2008, rncbc aka Rui Nuno Capela. All rights reserved.
5 capela 1464 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 capela 1738 #include <QFileDialog>
31 schoenebeck 1461
32 capela 1499
33 schoenebeck 1461 namespace QSampler {
34    
35 capela 1558 //-------------------------------------------------------------------------
36     // QSampler::OptionsForm -- Options form implementation.
37     //
38    
39 capela 1509 OptionsForm::OptionsForm ( QWidget* pParent )
40     : QDialog(pParent)
41 capela 1473 {
42 capela 1509 m_ui.setupUi(this);
43 schoenebeck 1461
44 capela 1473 // No settings descriptor initially (the caller will set it).
45     m_pOptions = NULL;
46 schoenebeck 1461
47 capela 1473 // Initialize dirty control state.
48     m_iDirtySetup = 0;
49     m_iDirtyCount = 0;
50 schoenebeck 1461
51 capela 1473 // Set dialog validators...
52 capela 1509 m_ui.ServerPortComboBox->setValidator(
53     new QIntValidator(m_ui.ServerPortComboBox));
54 schoenebeck 1461
55 capela 1473 // Try to restore old window positioning.
56     adjustSize();
57 capela 1466
58 capela 1509 QObject::connect(m_ui.ServerHostComboBox,
59 capela 1504 SIGNAL(editTextChanged(const QString&)),
60 capela 1466 SLOT(optionsChanged()));
61 capela 1509 QObject::connect(m_ui.ServerPortComboBox,
62 capela 1504 SIGNAL(editTextChanged(const QString&)),
63 capela 1466 SLOT(optionsChanged()));
64 capela 1509 QObject::connect(m_ui.ServerTimeoutSpinBox,
65 capela 1466 SIGNAL(valueChanged(int)),
66     SLOT(optionsChanged()));
67 capela 1509 QObject::connect(m_ui.ServerStartCheckBox,
68 capela 1466 SIGNAL(stateChanged(int)),
69     SLOT(optionsChanged()));
70 capela 1509 QObject::connect(m_ui.ServerCmdLineComboBox,
71 capela 1504 SIGNAL(editTextChanged(const QString&)),
72 capela 1466 SLOT(optionsChanged()));
73 capela 1509 QObject::connect(m_ui.StartDelaySpinBox,
74 capela 1466 SIGNAL(valueChanged(int)),
75     SLOT(optionsChanged()));
76 capela 1738 QObject::connect(m_ui.MessagesLogCheckBox,
77     SIGNAL(stateChanged(int)),
78     SLOT(optionsChanged()));
79     QObject::connect(m_ui.MessagesLogPathComboBox,
80     SIGNAL(editTextChanged(const QString&)),
81     SLOT(optionsChanged()));
82     QObject::connect(m_ui.MessagesLogPathToolButton,
83     SIGNAL(clicked()),
84     SLOT(browseMessagesLogPath()));
85 capela 1509 QObject::connect(m_ui.DisplayFontPushButton,
86 capela 1466 SIGNAL(clicked()),
87     SLOT(chooseDisplayFont()));
88 capela 1509 QObject::connect(m_ui.DisplayEffectCheckBox,
89 capela 1466 SIGNAL(toggled(bool)),
90     SLOT(toggleDisplayEffect(bool)));
91 capela 1509 QObject::connect(m_ui.AutoRefreshCheckBox,
92 capela 1466 SIGNAL(stateChanged(int)),
93     SLOT(optionsChanged()));
94 capela 1509 QObject::connect(m_ui.AutoRefreshTimeSpinBox,
95 capela 1466 SIGNAL(valueChanged(int)),
96     SLOT(optionsChanged()));
97 capela 1509 QObject::connect(m_ui.MaxVolumeSpinBox,
98 capela 1466 SIGNAL(valueChanged(int)),
99     SLOT(optionsChanged()));
100 capela 1509 QObject::connect(m_ui.MessagesFontPushButton,
101 capela 1466 SIGNAL(clicked()),
102     SLOT(chooseMessagesFont()));
103 capela 1509 QObject::connect(m_ui.MessagesLimitCheckBox,
104 capela 1466 SIGNAL(stateChanged(int)),
105     SLOT(optionsChanged()));
106 capela 1509 QObject::connect(m_ui.MessagesLimitLinesSpinBox,
107 capela 1466 SIGNAL(valueChanged(int)),
108     SLOT(optionsChanged()));
109 capela 1509 QObject::connect(m_ui.ConfirmRemoveCheckBox,
110 capela 1466 SIGNAL(stateChanged(int)),
111     SLOT(optionsChanged()));
112 capela 1509 QObject::connect(m_ui.KeepOnTopCheckBox,
113 capela 1466 SIGNAL(stateChanged(int)),
114     SLOT(optionsChanged()));
115 capela 1509 QObject::connect(m_ui.StdoutCaptureCheckBox,
116 capela 1466 SIGNAL(stateChanged(int)),
117     SLOT(optionsChanged()));
118 capela 1509 QObject::connect(m_ui.MaxRecentFilesSpinBox,
119 capela 1466 SIGNAL(valueChanged(int)),
120     SLOT(optionsChanged()));
121 capela 1509 QObject::connect(m_ui.CompletePathCheckBox,
122 capela 1466 SIGNAL(stateChanged(int)),
123     SLOT(optionsChanged()));
124 capela 1509 QObject::connect(m_ui.InstrumentNamesCheckBox,
125 capela 1466 SIGNAL(stateChanged(int)),
126     SLOT(optionsChanged()));
127 capela 1749 QObject::connect(m_ui.BaseFontSizeComboBox,
128     SIGNAL(editTextChanged(const QString&)),
129     SLOT(optionsChanged()));
130 capela 1509 QObject::connect(m_ui.OkPushButton,
131 capela 1466 SIGNAL(clicked()),
132     SLOT(accept()));
133 capela 1509 QObject::connect(m_ui.CancelPushButton,
134 capela 1466 SIGNAL(clicked()),
135     SLOT(reject()));
136 schoenebeck 1461 }
137    
138 capela 1473 OptionsForm::~OptionsForm()
139     {
140 schoenebeck 1461 }
141    
142     // Populate (setup) dialog controls from settings descriptors.
143 capela 1558 void OptionsForm::setup ( Options *pOptions )
144 schoenebeck 1461 {
145 capela 1509 // Set reference descriptor.
146     m_pOptions = pOptions;
147 schoenebeck 1461
148 capela 1509 // Start clean.
149     m_iDirtyCount = 0;
150     // Avoid nested changes.
151     m_iDirtySetup++;
152 schoenebeck 1461
153 capela 1509 // Load combo box history...
154     m_pOptions->loadComboBoxHistory(m_ui.ServerHostComboBox);
155     m_pOptions->loadComboBoxHistory(m_ui.ServerPortComboBox);
156     m_pOptions->loadComboBoxHistory(m_ui.ServerCmdLineComboBox);
157 capela 1738 m_pOptions->loadComboBoxHistory(m_ui.MessagesLogPathComboBox);
158 schoenebeck 1461
159 capela 1509 // Load Server settings...
160     m_ui.ServerHostComboBox->setEditText(m_pOptions->sServerHost);
161     m_ui.ServerPortComboBox->setEditText(QString::number(m_pOptions->iServerPort));
162     m_ui.ServerTimeoutSpinBox->setValue(m_pOptions->iServerTimeout);
163     m_ui.ServerStartCheckBox->setChecked(m_pOptions->bServerStart);
164     m_ui.ServerCmdLineComboBox->setEditText(m_pOptions->sServerCmdLine);
165     m_ui.StartDelaySpinBox->setValue(m_pOptions->iStartDelay);
166 schoenebeck 1461
167 capela 1738 // Logging options...
168     m_ui.MessagesLogCheckBox->setChecked(m_pOptions->bMessagesLog);
169     m_ui.MessagesLogPathComboBox->setEditText(m_pOptions->sMessagesLogPath);
170    
171 capela 1509 // Load Display options...
172     QFont font;
173 capela 1504 QPalette pal;
174 schoenebeck 1461
175 capela 1509 // Display font.
176     if (m_pOptions->sDisplayFont.isEmpty()
177     || !font.fromString(m_pOptions->sDisplayFont))
178     font = QFont("Sans Serif", 8);
179     m_ui.DisplayFontTextLabel->setFont(font);
180     m_ui.DisplayFontTextLabel->setText(font.family()
181     + ' ' + QString::number(font.pointSize()));
182 schoenebeck 1461
183 capela 1509 // Display effect.
184     m_ui.DisplayEffectCheckBox->setChecked(m_pOptions->bDisplayEffect);
185     toggleDisplayEffect(m_pOptions->bDisplayEffect);
186 schoenebeck 1461
187 capela 1509 // Auto-refresh and maximum volume options.
188     m_ui.AutoRefreshCheckBox->setChecked(m_pOptions->bAutoRefresh);
189     m_ui.AutoRefreshTimeSpinBox->setValue(m_pOptions->iAutoRefreshTime);
190     m_ui.MaxVolumeSpinBox->setValue(m_pOptions->iMaxVolume);
191 schoenebeck 1461
192 capela 1509 // Messages font.
193     if (m_pOptions->sMessagesFont.isEmpty()
194     || !font.fromString(m_pOptions->sMessagesFont))
195 capela 1788 font = QFont("Monospace", 8);
196 capela 1509 pal = m_ui.MessagesFontTextLabel->palette();
197 capela 1788 pal.setColor(QPalette::Background, pal.base().color());
198 capela 1509 m_ui.MessagesFontTextLabel->setPalette(pal);
199     m_ui.MessagesFontTextLabel->setFont(font);
200     m_ui.MessagesFontTextLabel->setText(font.family()
201     + ' ' + QString::number(font.pointSize()));
202 schoenebeck 1461
203 capela 1509 // Messages limit option.
204     m_ui.MessagesLimitCheckBox->setChecked(m_pOptions->bMessagesLimit);
205     m_ui.MessagesLimitLinesSpinBox->setValue(m_pOptions->iMessagesLimitLines);
206 schoenebeck 1461
207 capela 1509 // Other options finally.
208     m_ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove);
209     m_ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop);
210     m_ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture);
211     m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath);
212     m_ui.InstrumentNamesCheckBox->setChecked(m_pOptions->bInstrumentNames);
213     m_ui.MaxRecentFilesSpinBox->setValue(m_pOptions->iMaxRecentFiles);
214 capela 1749 if (m_pOptions->iBaseFontSize > 0)
215     m_ui.BaseFontSizeComboBox->setEditText(QString::number(m_pOptions->iBaseFontSize));
216     else
217     m_ui.BaseFontSizeComboBox->setCurrentIndex(0);
218 schoenebeck 1461
219     #ifndef CONFIG_LIBGIG
220 capela 1509 m_ui.InstrumentNamesCheckBox->setEnabled(false);
221 schoenebeck 1461 #endif
222    
223 capela 1509 // Done.
224     m_iDirtySetup--;
225     stabilizeForm();
226 schoenebeck 1461 }
227    
228    
229     // Accept settings (OK button slot).
230     void OptionsForm::accept (void)
231     {
232 capela 1509 // Save options...
233     if (m_iDirtyCount > 0) {
234     // Server settings....
235     m_pOptions->sServerHost = m_ui.ServerHostComboBox->currentText().trimmed();
236     m_pOptions->iServerPort = m_ui.ServerPortComboBox->currentText().toInt();
237     m_pOptions->iServerTimeout = m_ui.ServerTimeoutSpinBox->value();
238     m_pOptions->bServerStart = m_ui.ServerStartCheckBox->isChecked();
239     m_pOptions->sServerCmdLine = m_ui.ServerCmdLineComboBox->currentText().trimmed();
240 capela 1738 m_pOptions->iStartDelay = m_ui.StartDelaySpinBox->value();
241     // Logging options...
242     m_pOptions->bMessagesLog = m_ui.MessagesLogCheckBox->isChecked();
243     m_pOptions->sMessagesLogPath = m_ui.MessagesLogPathComboBox->currentText();
244 capela 1509 // Channels options...
245     m_pOptions->sDisplayFont = m_ui.DisplayFontTextLabel->font().toString();
246     m_pOptions->bDisplayEffect = m_ui.DisplayEffectCheckBox->isChecked();
247     m_pOptions->bAutoRefresh = m_ui.AutoRefreshCheckBox->isChecked();
248     m_pOptions->iAutoRefreshTime = m_ui.AutoRefreshTimeSpinBox->value();
249     m_pOptions->iMaxVolume = m_ui.MaxVolumeSpinBox->value();
250     // Messages options...
251     m_pOptions->sMessagesFont = m_ui.MessagesFontTextLabel->font().toString();
252     m_pOptions->bMessagesLimit = m_ui.MessagesLimitCheckBox->isChecked();
253     m_pOptions->iMessagesLimitLines = m_ui.MessagesLimitLinesSpinBox->value();
254     // Other options...
255     m_pOptions->bConfirmRemove = m_ui.ConfirmRemoveCheckBox->isChecked();
256     m_pOptions->bKeepOnTop = m_ui.KeepOnTopCheckBox->isChecked();
257     m_pOptions->bStdoutCapture = m_ui.StdoutCaptureCheckBox->isChecked();
258     m_pOptions->bCompletePath = m_ui.CompletePathCheckBox->isChecked();
259     m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked();
260     m_pOptions->iMaxRecentFiles = m_ui.MaxRecentFilesSpinBox->value();
261 capela 1749 m_pOptions->iBaseFontSize = m_ui.BaseFontSizeComboBox->currentText().toInt();
262 capela 1509 // Reset dirty flag.
263     m_iDirtyCount = 0;
264     }
265 schoenebeck 1461
266 capela 1509 // Save combobox history...
267     m_pOptions->saveComboBoxHistory(m_ui.ServerHostComboBox);
268     m_pOptions->saveComboBoxHistory(m_ui.ServerPortComboBox);
269     m_pOptions->saveComboBoxHistory(m_ui.ServerCmdLineComboBox);
270 capela 1738 m_pOptions->saveComboBoxHistory(m_ui.MessagesLogPathComboBox);
271 schoenebeck 1461
272 capela 1509 // Just go with dialog acceptance.
273     QDialog::accept();
274 schoenebeck 1461 }
275    
276    
277     // Reject settings (Cancel button slot).
278     void OptionsForm::reject (void)
279     {
280 capela 1509 bool bReject = true;
281 schoenebeck 1461
282 capela 1509 // Check if there's any pending changes...
283     if (m_iDirtyCount > 0) {
284     switch (QMessageBox::warning(this,
285 schoenebeck 1461 QSAMPLER_TITLE ": " + tr("Warning"),
286 capela 1509 tr("Some settings have been changed.\n\n"
287     "Do you want to apply the changes?"),
288     tr("Apply"), tr("Discard"), tr("Cancel"))) {
289     case 0: // Apply...
290     accept();
291     return;
292     case 1: // Discard
293     break;
294     default: // Cancel.
295     bReject = false;
296     }
297     }
298 schoenebeck 1461
299 capela 1509 if (bReject)
300     QDialog::reject();
301 schoenebeck 1461 }
302    
303    
304     // Dirty up settings.
305     void OptionsForm::optionsChanged (void)
306     {
307 capela 1509 if (m_iDirtySetup > 0)
308     return;
309 schoenebeck 1461
310 capela 1509 m_iDirtyCount++;
311     stabilizeForm();
312 schoenebeck 1461 }
313    
314    
315     // Stabilize current form state.
316     void OptionsForm::stabilizeForm (void)
317     {
318 capela 1738 bool bValid = (m_iDirtyCount > 0);
319    
320 capela 1509 bool bEnabled = m_ui.ServerStartCheckBox->isChecked();
321     m_ui.ServerCmdLineTextLabel->setEnabled(bEnabled);
322     m_ui.ServerCmdLineComboBox->setEnabled(bEnabled);
323     m_ui.StartDelayTextLabel->setEnabled(bEnabled);
324     m_ui.StartDelaySpinBox->setEnabled(bEnabled);
325 schoenebeck 1461
326 capela 1738 bEnabled = m_ui.MessagesLogCheckBox->isChecked();
327     m_ui.MessagesLogPathComboBox->setEnabled(bEnabled);
328     m_ui.MessagesLogPathToolButton->setEnabled(bEnabled);
329     if (bEnabled && bValid) {
330     const QString& sPath = m_ui.MessagesLogPathComboBox->currentText();
331     bValid = !sPath.isEmpty();
332     }
333    
334 capela 1509 m_ui.AutoRefreshTimeSpinBox->setEnabled(
335     m_ui.AutoRefreshCheckBox->isChecked());
336     m_ui.MessagesLimitLinesSpinBox->setEnabled(
337     m_ui.MessagesLimitCheckBox->isChecked());
338 schoenebeck 1461
339 capela 1738 m_ui.OkPushButton->setEnabled(bValid);
340 schoenebeck 1461 }
341    
342    
343 capela 1738 // Messages log path browse slot.
344     void OptionsForm::browseMessagesLogPath (void)
345     {
346     QString sFileName = QFileDialog::getSaveFileName(
347     this, // Parent.
348     tr("Messages Log"), // Caption.
349     m_ui.MessagesLogPathComboBox->currentText(), // Start here.
350     tr("Log files") + " (*.log)" // Filter (log files)
351     );
352    
353     if (!sFileName.isEmpty()) {
354     m_ui.MessagesLogPathComboBox->setEditText(sFileName);
355     m_ui.MessagesLogPathComboBox->setFocus();
356     optionsChanged();
357     }
358     }
359    
360    
361 schoenebeck 1461 // The channel display font selection dialog.
362     void OptionsForm::chooseDisplayFont (void)
363     {
364 capela 1509 bool bOk = false;
365     QFont font = QFontDialog::getFont(&bOk,
366     m_ui.DisplayFontTextLabel->font(), this);
367     if (bOk) {
368     m_ui.DisplayFontTextLabel->setFont(font);
369     m_ui.DisplayFontTextLabel->setText(font.family()
370     + ' ' + QString::number(font.pointSize()));
371     optionsChanged();
372     }
373 schoenebeck 1461 }
374    
375    
376     // The messages font selection dialog.
377     void OptionsForm::chooseMessagesFont (void)
378     {
379 capela 1509 bool bOk = false;
380     QFont font = QFontDialog::getFont(&bOk,
381     m_ui.MessagesFontTextLabel->font(), this);
382     if (bOk) {
383     m_ui.MessagesFontTextLabel->setFont(font);
384     m_ui.MessagesFontTextLabel->setText(font.family()
385     + ' ' + QString::number(font.pointSize()));
386     optionsChanged();
387     }
388 schoenebeck 1461 }
389    
390    
391     // The channel display effect demo changer.
392     void OptionsForm::toggleDisplayEffect ( bool bOn )
393     {
394 capela 1499 QPalette pal;
395     pal.setColor(QPalette::Foreground, Qt::green);
396     if (bOn) {
397 capela 1504 QPixmap pm(":/icons/displaybg1.png");
398 capela 1499 pal.setBrush(QPalette::Background, QBrush(pm));
399     } else {
400     pal.setColor(QPalette::Background, Qt::black);
401     }
402 capela 1509 m_ui.DisplayFontTextLabel->setPalette(pal);
403 schoenebeck 1461
404 capela 1499 optionsChanged();
405 schoenebeck 1461 }
406    
407     } // namespace QSampler
408 capela 1464
409    
410 capela 1466 // end of qsamplerOptionsForm.cpp

  ViewVC Help
Powered by ViewVC