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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1738 - (hide annotations) (download)
Wed May 14 15:24:22 2008 UTC (15 years, 11 months ago) by capela
File size: 12849 byte(s)
* Messages file logging makes its first long overdue appearance,
  with user configurable settings in View/Options.../Server/Logging.

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 1509 QObject::connect(m_ui.OkPushButton,
128 capela 1466 SIGNAL(clicked()),
129     SLOT(accept()));
130 capela 1509 QObject::connect(m_ui.CancelPushButton,
131 capela 1466 SIGNAL(clicked()),
132     SLOT(reject()));
133 schoenebeck 1461 }
134    
135 capela 1473 OptionsForm::~OptionsForm()
136     {
137 schoenebeck 1461 }
138    
139     // Populate (setup) dialog controls from settings descriptors.
140 capela 1558 void OptionsForm::setup ( Options *pOptions )
141 schoenebeck 1461 {
142 capela 1509 // Set reference descriptor.
143     m_pOptions = pOptions;
144 schoenebeck 1461
145 capela 1509 // Start clean.
146     m_iDirtyCount = 0;
147     // Avoid nested changes.
148     m_iDirtySetup++;
149 schoenebeck 1461
150 capela 1509 // Load combo box history...
151     m_pOptions->loadComboBoxHistory(m_ui.ServerHostComboBox);
152     m_pOptions->loadComboBoxHistory(m_ui.ServerPortComboBox);
153     m_pOptions->loadComboBoxHistory(m_ui.ServerCmdLineComboBox);
154 capela 1738 m_pOptions->loadComboBoxHistory(m_ui.MessagesLogPathComboBox);
155 schoenebeck 1461
156 capela 1509 // Load Server settings...
157     m_ui.ServerHostComboBox->setEditText(m_pOptions->sServerHost);
158     m_ui.ServerPortComboBox->setEditText(QString::number(m_pOptions->iServerPort));
159     m_ui.ServerTimeoutSpinBox->setValue(m_pOptions->iServerTimeout);
160     m_ui.ServerStartCheckBox->setChecked(m_pOptions->bServerStart);
161     m_ui.ServerCmdLineComboBox->setEditText(m_pOptions->sServerCmdLine);
162     m_ui.StartDelaySpinBox->setValue(m_pOptions->iStartDelay);
163 schoenebeck 1461
164 capela 1738 // Logging options...
165     m_ui.MessagesLogCheckBox->setChecked(m_pOptions->bMessagesLog);
166     m_ui.MessagesLogPathComboBox->setEditText(m_pOptions->sMessagesLogPath);
167    
168 capela 1509 // Load Display options...
169     QFont font;
170 capela 1504 QPalette pal;
171 schoenebeck 1461
172 capela 1509 // Display font.
173     if (m_pOptions->sDisplayFont.isEmpty()
174     || !font.fromString(m_pOptions->sDisplayFont))
175     font = QFont("Sans Serif", 8);
176     m_ui.DisplayFontTextLabel->setFont(font);
177     m_ui.DisplayFontTextLabel->setText(font.family()
178     + ' ' + QString::number(font.pointSize()));
179 schoenebeck 1461
180 capela 1509 // Display effect.
181     m_ui.DisplayEffectCheckBox->setChecked(m_pOptions->bDisplayEffect);
182     toggleDisplayEffect(m_pOptions->bDisplayEffect);
183 schoenebeck 1461
184 capela 1509 // Auto-refresh and maximum volume options.
185     m_ui.AutoRefreshCheckBox->setChecked(m_pOptions->bAutoRefresh);
186     m_ui.AutoRefreshTimeSpinBox->setValue(m_pOptions->iAutoRefreshTime);
187     m_ui.MaxVolumeSpinBox->setValue(m_pOptions->iMaxVolume);
188 schoenebeck 1461
189 capela 1509 // Messages font.
190     if (m_pOptions->sMessagesFont.isEmpty()
191     || !font.fromString(m_pOptions->sMessagesFont))
192     font = QFont("Fixed", 8);
193     pal = m_ui.MessagesFontTextLabel->palette();
194 capela 1504 pal.setColor(QPalette::Background, Qt::white);
195 capela 1509 m_ui.MessagesFontTextLabel->setPalette(pal);
196     m_ui.MessagesFontTextLabel->setFont(font);
197     m_ui.MessagesFontTextLabel->setText(font.family()
198     + ' ' + QString::number(font.pointSize()));
199 schoenebeck 1461
200 capela 1509 // Messages limit option.
201     m_ui.MessagesLimitCheckBox->setChecked(m_pOptions->bMessagesLimit);
202     m_ui.MessagesLimitLinesSpinBox->setValue(m_pOptions->iMessagesLimitLines);
203 schoenebeck 1461
204 capela 1509 // Other options finally.
205     m_ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove);
206     m_ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop);
207     m_ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture);
208     m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath);
209     m_ui.InstrumentNamesCheckBox->setChecked(m_pOptions->bInstrumentNames);
210     m_ui.MaxRecentFilesSpinBox->setValue(m_pOptions->iMaxRecentFiles);
211 schoenebeck 1461
212     #ifndef CONFIG_LIBGIG
213 capela 1509 m_ui.InstrumentNamesCheckBox->setEnabled(false);
214 schoenebeck 1461 #endif
215    
216 capela 1509 // Done.
217     m_iDirtySetup--;
218     stabilizeForm();
219 schoenebeck 1461 }
220    
221    
222     // Accept settings (OK button slot).
223     void OptionsForm::accept (void)
224     {
225 capela 1509 // Save options...
226     if (m_iDirtyCount > 0) {
227     // Server settings....
228     m_pOptions->sServerHost = m_ui.ServerHostComboBox->currentText().trimmed();
229     m_pOptions->iServerPort = m_ui.ServerPortComboBox->currentText().toInt();
230     m_pOptions->iServerTimeout = m_ui.ServerTimeoutSpinBox->value();
231     m_pOptions->bServerStart = m_ui.ServerStartCheckBox->isChecked();
232     m_pOptions->sServerCmdLine = m_ui.ServerCmdLineComboBox->currentText().trimmed();
233 capela 1738 m_pOptions->iStartDelay = m_ui.StartDelaySpinBox->value();
234     // Logging options...
235     m_pOptions->bMessagesLog = m_ui.MessagesLogCheckBox->isChecked();
236     m_pOptions->sMessagesLogPath = m_ui.MessagesLogPathComboBox->currentText();
237 capela 1509 // Channels options...
238     m_pOptions->sDisplayFont = m_ui.DisplayFontTextLabel->font().toString();
239     m_pOptions->bDisplayEffect = m_ui.DisplayEffectCheckBox->isChecked();
240     m_pOptions->bAutoRefresh = m_ui.AutoRefreshCheckBox->isChecked();
241     m_pOptions->iAutoRefreshTime = m_ui.AutoRefreshTimeSpinBox->value();
242     m_pOptions->iMaxVolume = m_ui.MaxVolumeSpinBox->value();
243     // Messages options...
244     m_pOptions->sMessagesFont = m_ui.MessagesFontTextLabel->font().toString();
245     m_pOptions->bMessagesLimit = m_ui.MessagesLimitCheckBox->isChecked();
246     m_pOptions->iMessagesLimitLines = m_ui.MessagesLimitLinesSpinBox->value();
247     // Other options...
248     m_pOptions->bConfirmRemove = m_ui.ConfirmRemoveCheckBox->isChecked();
249     m_pOptions->bKeepOnTop = m_ui.KeepOnTopCheckBox->isChecked();
250     m_pOptions->bStdoutCapture = m_ui.StdoutCaptureCheckBox->isChecked();
251     m_pOptions->bCompletePath = m_ui.CompletePathCheckBox->isChecked();
252     m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked();
253     m_pOptions->iMaxRecentFiles = m_ui.MaxRecentFilesSpinBox->value();
254     // Reset dirty flag.
255     m_iDirtyCount = 0;
256     }
257 schoenebeck 1461
258 capela 1509 // Save combobox history...
259     m_pOptions->saveComboBoxHistory(m_ui.ServerHostComboBox);
260     m_pOptions->saveComboBoxHistory(m_ui.ServerPortComboBox);
261     m_pOptions->saveComboBoxHistory(m_ui.ServerCmdLineComboBox);
262 capela 1738 m_pOptions->saveComboBoxHistory(m_ui.MessagesLogPathComboBox);
263 schoenebeck 1461
264 capela 1509 // Just go with dialog acceptance.
265     QDialog::accept();
266 schoenebeck 1461 }
267    
268    
269     // Reject settings (Cancel button slot).
270     void OptionsForm::reject (void)
271     {
272 capela 1509 bool bReject = true;
273 schoenebeck 1461
274 capela 1509 // Check if there's any pending changes...
275     if (m_iDirtyCount > 0) {
276     switch (QMessageBox::warning(this,
277 schoenebeck 1461 QSAMPLER_TITLE ": " + tr("Warning"),
278 capela 1509 tr("Some settings have been changed.\n\n"
279     "Do you want to apply the changes?"),
280     tr("Apply"), tr("Discard"), tr("Cancel"))) {
281     case 0: // Apply...
282     accept();
283     return;
284     case 1: // Discard
285     break;
286     default: // Cancel.
287     bReject = false;
288     }
289     }
290 schoenebeck 1461
291 capela 1509 if (bReject)
292     QDialog::reject();
293 schoenebeck 1461 }
294    
295    
296     // Dirty up settings.
297     void OptionsForm::optionsChanged (void)
298     {
299 capela 1509 if (m_iDirtySetup > 0)
300     return;
301 schoenebeck 1461
302 capela 1509 m_iDirtyCount++;
303     stabilizeForm();
304 schoenebeck 1461 }
305    
306    
307     // Stabilize current form state.
308     void OptionsForm::stabilizeForm (void)
309     {
310 capela 1738 bool bValid = (m_iDirtyCount > 0);
311    
312 capela 1509 bool bEnabled = m_ui.ServerStartCheckBox->isChecked();
313     m_ui.ServerCmdLineTextLabel->setEnabled(bEnabled);
314     m_ui.ServerCmdLineComboBox->setEnabled(bEnabled);
315     m_ui.StartDelayTextLabel->setEnabled(bEnabled);
316     m_ui.StartDelaySpinBox->setEnabled(bEnabled);
317 schoenebeck 1461
318 capela 1738 bEnabled = m_ui.MessagesLogCheckBox->isChecked();
319     m_ui.MessagesLogPathComboBox->setEnabled(bEnabled);
320     m_ui.MessagesLogPathToolButton->setEnabled(bEnabled);
321     if (bEnabled && bValid) {
322     const QString& sPath = m_ui.MessagesLogPathComboBox->currentText();
323     bValid = !sPath.isEmpty();
324     }
325    
326 capela 1509 m_ui.AutoRefreshTimeSpinBox->setEnabled(
327     m_ui.AutoRefreshCheckBox->isChecked());
328     m_ui.MessagesLimitLinesSpinBox->setEnabled(
329     m_ui.MessagesLimitCheckBox->isChecked());
330 schoenebeck 1461
331 capela 1738 m_ui.OkPushButton->setEnabled(bValid);
332 schoenebeck 1461 }
333    
334    
335 capela 1738 // Messages log path browse slot.
336     void OptionsForm::browseMessagesLogPath (void)
337     {
338     QString sFileName = QFileDialog::getSaveFileName(
339     this, // Parent.
340     tr("Messages Log"), // Caption.
341     m_ui.MessagesLogPathComboBox->currentText(), // Start here.
342     tr("Log files") + " (*.log)" // Filter (log files)
343     );
344    
345     if (!sFileName.isEmpty()) {
346     m_ui.MessagesLogPathComboBox->setEditText(sFileName);
347     m_ui.MessagesLogPathComboBox->setFocus();
348     optionsChanged();
349     }
350     }
351    
352    
353 schoenebeck 1461 // The channel display font selection dialog.
354     void OptionsForm::chooseDisplayFont (void)
355     {
356 capela 1509 bool bOk = false;
357     QFont font = QFontDialog::getFont(&bOk,
358     m_ui.DisplayFontTextLabel->font(), this);
359     if (bOk) {
360     m_ui.DisplayFontTextLabel->setFont(font);
361     m_ui.DisplayFontTextLabel->setText(font.family()
362     + ' ' + QString::number(font.pointSize()));
363     optionsChanged();
364     }
365 schoenebeck 1461 }
366    
367    
368     // The messages font selection dialog.
369     void OptionsForm::chooseMessagesFont (void)
370     {
371 capela 1509 bool bOk = false;
372     QFont font = QFontDialog::getFont(&bOk,
373     m_ui.MessagesFontTextLabel->font(), this);
374     if (bOk) {
375     m_ui.MessagesFontTextLabel->setFont(font);
376     m_ui.MessagesFontTextLabel->setText(font.family()
377     + ' ' + QString::number(font.pointSize()));
378     optionsChanged();
379     }
380 schoenebeck 1461 }
381    
382    
383     // The channel display effect demo changer.
384     void OptionsForm::toggleDisplayEffect ( bool bOn )
385     {
386 capela 1499 QPalette pal;
387     pal.setColor(QPalette::Foreground, Qt::green);
388     if (bOn) {
389 capela 1504 QPixmap pm(":/icons/displaybg1.png");
390 capela 1499 pal.setBrush(QPalette::Background, QBrush(pm));
391     } else {
392     pal.setColor(QPalette::Background, Qt::black);
393     }
394 capela 1509 m_ui.DisplayFontTextLabel->setPalette(pal);
395 schoenebeck 1461
396 capela 1499 optionsChanged();
397 schoenebeck 1461 }
398    
399     } // namespace QSampler
400 capela 1464
401    
402 capela 1466 // end of qsamplerOptionsForm.cpp

  ViewVC Help
Powered by ViewVC