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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1474 by schoenebeck, Mon Nov 5 20:47:38 2007 UTC revision 3794 by capela, Tue Jun 16 09:13:12 2020 UTC
# Line 1  Line 1 
1  // qsamplerOptionsForm.cpp  // qsamplerOptionsForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2020, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
# Line 25  Line 25 
25  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
26  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
27    
28    #include "qsamplerPaletteForm.h"
29    
30  #include <QMessageBox>  #include <QMessageBox>
31  #include <QFontDialog>  #include <QFontDialog>
32    #include <QFileDialog>
33    
34    #include <QStyleFactory>
35    
36    
37    // Default (empty/blank) name.
38    static const char *g_pszDefName = QT_TRANSLATE_NOOP("qsamplerOptionsForm", "(default)");
39    
40    
41  namespace QSampler {  namespace QSampler {
42    
43  OptionsForm::OptionsForm(QWidget* parent) : QDialog(parent)  //-------------------------------------------------------------------------
44    // QSampler::OptionsForm -- Options form implementation.
45    //
46    
47    OptionsForm::OptionsForm ( QWidget* pParent )
48            : QDialog(pParent)
49  {  {
50          ui.setupUi(this);          m_ui.setupUi(this);
51    
52          // No settings descriptor initially (the caller will set it).          // No settings descriptor initially (the caller will set it).
53          m_pOptions = NULL;          m_pOptions = nullptr;
54    
55          // Initialize dirty control state.          // Initialize dirty control state.
56          m_iDirtySetup = 0;          m_iDirtySetup = 0;
57          m_iDirtyCount = 0;          m_iDirtyCount = 0;
58    
59          // Set dialog validators...          // Set dialog validators...
60          ui.ServerPortComboBox->setValidator(new QIntValidator(ui.ServerPortComboBox));          m_ui.ServerPortComboBox->setValidator(
61                    new QIntValidator(m_ui.ServerPortComboBox));
62    
63          // Try to restore old window positioning.          // Try to restore old window positioning.
64          adjustSize();          adjustSize();
65    
66          QObject::connect(ui.ServerHostComboBox,          QObject::connect(m_ui.ServerHostComboBox,
67                  SIGNAL(textChanged(const QString&)),                  SIGNAL(editTextChanged(const QString&)),
68                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
69          QObject::connect(ui.ServerPortComboBox,          QObject::connect(m_ui.ServerPortComboBox,
70                  SIGNAL(textChanged(const QString&)),                  SIGNAL(editTextChanged(const QString&)),
71                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
72          QObject::connect(ui.ServerTimeoutSpinBox,          QObject::connect(m_ui.ServerTimeoutSpinBox,
73                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
74                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
75          QObject::connect(ui.ServerStartCheckBox,          QObject::connect(m_ui.ServerStartCheckBox,
76                  SIGNAL(stateChanged(int)),                  SIGNAL(stateChanged(int)),
77                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
78          QObject::connect(ui.ServerCmdLineComboBox,          QObject::connect(m_ui.ServerCmdLineComboBox,
79                  SIGNAL(textChanged(const QString&)),                  SIGNAL(editTextChanged(const QString&)),
80                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
81          QObject::connect(ui.StartDelaySpinBox,          QObject::connect(m_ui.StartDelaySpinBox,
82                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
83                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
84          QObject::connect(ui.DisplayFontPushButton,          QObject::connect(m_ui.MessagesLogCheckBox,
85                    SIGNAL(stateChanged(int)),
86                    SLOT(optionsChanged()));
87            QObject::connect(m_ui.MessagesLogPathComboBox,
88                    SIGNAL(editTextChanged(const QString&)),
89                    SLOT(optionsChanged()));
90            QObject::connect(m_ui.MessagesLogPathToolButton,
91                    SIGNAL(clicked()),
92                    SLOT(browseMessagesLogPath()));
93            QObject::connect(m_ui.DisplayFontPushButton,
94                  SIGNAL(clicked()),                  SIGNAL(clicked()),
95                  SLOT(chooseDisplayFont()));                  SLOT(chooseDisplayFont()));
96          QObject::connect(ui.DisplayEffectCheckBox,          QObject::connect(m_ui.DisplayEffectCheckBox,
97                  SIGNAL(toggled(bool)),                  SIGNAL(toggled(bool)),
98                  SLOT(toggleDisplayEffect(bool)));                  SLOT(toggleDisplayEffect(bool)));
99          QObject::connect(ui.AutoRefreshCheckBox,          QObject::connect(m_ui.AutoRefreshCheckBox,
100                  SIGNAL(stateChanged(int)),                  SIGNAL(stateChanged(int)),
101                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
102          QObject::connect(ui.AutoRefreshTimeSpinBox,          QObject::connect(m_ui.AutoRefreshTimeSpinBox,
103                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
104                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
105          QObject::connect(ui.MaxVolumeSpinBox,          QObject::connect(m_ui.MaxVolumeSpinBox,
106                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
107                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
108          QObject::connect(ui.MessagesFontPushButton,          QObject::connect(m_ui.MessagesFontPushButton,
109                  SIGNAL(clicked()),                  SIGNAL(clicked()),
110                  SLOT(chooseMessagesFont()));                  SLOT(chooseMessagesFont()));
111          QObject::connect(ui.MessagesLimitCheckBox,          QObject::connect(m_ui.MessagesLimitCheckBox,
112                  SIGNAL(stateChanged(int)),                  SIGNAL(stateChanged(int)),
113                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
114          QObject::connect(ui.MessagesLimitLinesSpinBox,          QObject::connect(m_ui.MessagesLimitLinesSpinBox,
115                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
116                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
117          QObject::connect(ui.ConfirmRemoveCheckBox,          QObject::connect(m_ui.ConfirmRemoveCheckBox,
118                    SIGNAL(stateChanged(int)),
119                    SLOT(optionsChanged()));
120            QObject::connect(m_ui.ConfirmResetCheckBox,
121                  SIGNAL(stateChanged(int)),                  SIGNAL(stateChanged(int)),
122                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
123          QObject::connect(ui.KeepOnTopCheckBox,          QObject::connect(m_ui.ConfirmRestartCheckBox,
124                  SIGNAL(stateChanged(int)),                  SIGNAL(stateChanged(int)),
125                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
126          QObject::connect(ui.StdoutCaptureCheckBox,          QObject::connect(m_ui.ConfirmErrorCheckBox,
127                  SIGNAL(stateChanged(int)),                  SIGNAL(stateChanged(int)),
128                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
129          QObject::connect(ui.MaxRecentFilesSpinBox,          QObject::connect(m_ui.KeepOnTopCheckBox,
130                    SIGNAL(stateChanged(int)),
131                    SLOT(optionsChanged()));
132            QObject::connect(m_ui.StdoutCaptureCheckBox,
133                    SIGNAL(stateChanged(int)),
134                    SLOT(optionsChanged()));
135            QObject::connect(m_ui.MaxRecentFilesSpinBox,
136                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
137                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
138          QObject::connect(ui.CompletePathCheckBox,          QObject::connect(m_ui.CompletePathCheckBox,
139                  SIGNAL(stateChanged(int)),                  SIGNAL(stateChanged(int)),
140                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
141          QObject::connect(ui.InstrumentNamesCheckBox,          QObject::connect(m_ui.InstrumentNamesCheckBox,
142                  SIGNAL(stateChanged(int)),                  SIGNAL(stateChanged(int)),
143                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
144          QObject::connect(ui.OkPushButton,          QObject::connect(m_ui.CustomColorThemeComboBox,
145                    SIGNAL(activated(int)),
146                    SLOT(optionsChanged()));
147            QObject::connect(m_ui.CustomColorThemeToolButton,
148                  SIGNAL(clicked()),                  SIGNAL(clicked()),
149                    SLOT(editCustomColorThemes()));
150            QObject::connect(m_ui.CustomStyleThemeComboBox,
151                    SIGNAL(activated(int)),
152                    SLOT(optionsChanged()));
153            QObject::connect(m_ui.BaseFontSizeComboBox,
154                    SIGNAL(editTextChanged(const QString&)),
155                    SLOT(optionsChanged()));
156            QObject::connect(m_ui.MaxVoicesSpinBox,
157                    SIGNAL(valueChanged(int)),
158                    SLOT(maxVoicesChanged(int)));
159            QObject::connect(m_ui.MaxStreamsSpinBox,
160                    SIGNAL(valueChanged(int)),
161                    SLOT(maxStreamsChanged(int)));
162            QObject::connect(m_ui.DialogButtonBox,
163                    SIGNAL(accepted()),
164                  SLOT(accept()));                  SLOT(accept()));
165          QObject::connect(ui.CancelPushButton,          QObject::connect(m_ui.DialogButtonBox,
166                  SIGNAL(clicked()),                  SIGNAL(rejected()),
167                  SLOT(reject()));                  SLOT(reject()));
168  }  }
169    
# Line 120  OptionsForm::~OptionsForm() Line 172  OptionsForm::~OptionsForm()
172  }  }
173    
174  // Populate (setup) dialog controls from settings descriptors.  // Populate (setup) dialog controls from settings descriptors.
175  void OptionsForm::setup ( qsamplerOptions *pOptions )  void OptionsForm::setup ( Options *pOptions )
176  {  {
177      // Set reference descriptor.          // Set reference descriptor.
178      m_pOptions = pOptions;          m_pOptions = pOptions;
179    
180      // Start clean.          // Start clean.
181      m_iDirtyCount = 0;          m_iDirtyCount = 0;
182      // Avoid nested changes.          // Avoid nested changes.
183      m_iDirtySetup++;          m_iDirtySetup++;
184    
185      // Load combo box history...          // Load combo box history...
186      m_pOptions->loadComboBoxHistory(ui.ServerHostComboBox);          m_pOptions->loadComboBoxHistory(m_ui.ServerHostComboBox);
187      m_pOptions->loadComboBoxHistory(ui.ServerPortComboBox);          m_pOptions->loadComboBoxHistory(m_ui.ServerPortComboBox);
188      m_pOptions->loadComboBoxHistory(ui.ServerCmdLineComboBox);          m_pOptions->loadComboBoxHistory(m_ui.ServerCmdLineComboBox);
189            m_pOptions->loadComboBoxHistory(m_ui.MessagesLogPathComboBox);
190      // Load Server settings...  
191      ui.ServerHostComboBox->setCurrentText(m_pOptions->sServerHost);          // Load Server settings...
192      ui.ServerPortComboBox->setCurrentText(QString::number(m_pOptions->iServerPort));          m_ui.ServerHostComboBox->setEditText(m_pOptions->sServerHost);
193      ui.ServerTimeoutSpinBox->setValue(m_pOptions->iServerTimeout);          m_ui.ServerPortComboBox->setEditText(QString::number(m_pOptions->iServerPort));
194      ui.ServerStartCheckBox->setChecked(m_pOptions->bServerStart);          m_ui.ServerTimeoutSpinBox->setValue(m_pOptions->iServerTimeout);
195      ui.ServerCmdLineComboBox->setCurrentText(m_pOptions->sServerCmdLine);          m_ui.ServerStartCheckBox->setChecked(m_pOptions->bServerStart);
196      ui.StartDelaySpinBox->setValue(m_pOptions->iStartDelay);          m_ui.ServerCmdLineComboBox->setEditText(m_pOptions->sServerCmdLine);
197            m_ui.StartDelaySpinBox->setValue(m_pOptions->iStartDelay);
198      // Load Display options...  
199      QFont font;          // Logging options...
200            m_ui.MessagesLogCheckBox->setChecked(m_pOptions->bMessagesLog);
201      // Display font.          m_ui.MessagesLogPathComboBox->setEditText(m_pOptions->sMessagesLogPath);
202      if (m_pOptions->sDisplayFont.isEmpty() || !font.fromString(m_pOptions->sDisplayFont))  
203          font = QFont("Sans Serif", 8);          // Load Display options...
204      ui.DisplayFontTextLabel->setFont(font);          QFont font;
205      ui.DisplayFontTextLabel->setText(font.family() + " " + QString::number(font.pointSize()));          QPalette pal;
206    
207      // Display effect.          // Display font.
208      ui.DisplayEffectCheckBox->setChecked(m_pOptions->bDisplayEffect);          if (m_pOptions->sDisplayFont.isEmpty()
209      toggleDisplayEffect(m_pOptions->bDisplayEffect);                  || !font.fromString(m_pOptions->sDisplayFont))
210                    font = QFont("Sans Serif", 8);
211      // Auto-refresh and maximum volume options.          m_ui.DisplayFontTextLabel->setFont(font);
212      ui.AutoRefreshCheckBox->setChecked(m_pOptions->bAutoRefresh);          m_ui.DisplayFontTextLabel->setText(font.family()
213      ui.AutoRefreshTimeSpinBox->setValue(m_pOptions->iAutoRefreshTime);                  + ' ' + QString::number(font.pointSize()));
214      ui.MaxVolumeSpinBox->setValue(m_pOptions->iMaxVolume);  
215            // Display effect.
216      // Messages font.          m_ui.DisplayEffectCheckBox->setChecked(m_pOptions->bDisplayEffect);
217      if (m_pOptions->sMessagesFont.isEmpty() || !font.fromString(m_pOptions->sMessagesFont))          toggleDisplayEffect(m_pOptions->bDisplayEffect);
218          font = QFont("Fixed", 8);  
219      ui.MessagesFontTextLabel->setFont(font);          // Auto-refresh and maximum volume options.
220      ui.MessagesFontTextLabel->setText(font.family() + " " + QString::number(font.pointSize()));          m_ui.AutoRefreshCheckBox->setChecked(m_pOptions->bAutoRefresh);
221            m_ui.AutoRefreshTimeSpinBox->setValue(m_pOptions->iAutoRefreshTime);
222      // Messages limit option.          m_ui.MaxVolumeSpinBox->setValue(m_pOptions->iMaxVolume);
223      ui.MessagesLimitCheckBox->setChecked(m_pOptions->bMessagesLimit);  
224      ui.MessagesLimitLinesSpinBox->setValue(m_pOptions->iMessagesLimitLines);          // Messages font.
225            if (m_pOptions->sMessagesFont.isEmpty()
226      // Other options finally.                  || !font.fromString(m_pOptions->sMessagesFont))
227      ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove);                  font = QFont("Monospace", 8);
228      ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop);          pal = m_ui.MessagesFontTextLabel->palette();
229      ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture);          pal.setColor(QPalette::Window, pal.base().color());
230      ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath);          m_ui.MessagesFontTextLabel->setPalette(pal);
231      ui.InstrumentNamesCheckBox->setChecked(m_pOptions->bInstrumentNames);          m_ui.MessagesFontTextLabel->setFont(font);
232      ui.MaxRecentFilesSpinBox->setValue(m_pOptions->iMaxRecentFiles);          m_ui.MessagesFontTextLabel->setText(font.family()
233                    + ' ' + QString::number(font.pointSize()));
234    
235            // Messages limit option.
236            m_ui.MessagesLimitCheckBox->setChecked(m_pOptions->bMessagesLimit);
237            m_ui.MessagesLimitLinesSpinBox->setValue(m_pOptions->iMessagesLimitLines);
238    
239            // Other options finally.
240            m_ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove);
241            m_ui.ConfirmRestartCheckBox->setChecked(m_pOptions->bConfirmRestart);
242            m_ui.ConfirmResetCheckBox->setChecked(m_pOptions->bConfirmReset);
243            m_ui.ConfirmErrorCheckBox->setChecked(m_pOptions->bConfirmError);
244            m_ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop);
245            m_ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture);
246            m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath);
247            m_ui.InstrumentNamesCheckBox->setChecked(m_pOptions->bInstrumentNames);
248            m_ui.MaxRecentFilesSpinBox->setValue(m_pOptions->iMaxRecentFiles);
249            if (m_pOptions->iBaseFontSize > 0)
250                    m_ui.BaseFontSizeComboBox->setEditText(QString::number(m_pOptions->iBaseFontSize));
251            else
252                    m_ui.BaseFontSizeComboBox->setCurrentIndex(0);
253    
254  #ifndef CONFIG_LIBGIG  #ifndef CONFIG_LIBGIG
255      ui.InstrumentNamesCheckBox->setEnabled(false);          m_ui.InstrumentNamesCheckBox->setEnabled(false);
256  #endif  #endif
257    
258      // Done.          bMaxVoicesModified = bMaxStreamsModified = false;
259      m_iDirtySetup--;  #ifdef CONFIG_MAX_VOICES
260      stabilizeForm();          const bool bMaxVoicesSupported =
261                    m_pOptions->getEffectiveMaxVoices() >= 0;
262            const bool bMaxStreamsSupported =
263                    m_pOptions->getEffectiveMaxStreams() >= 0;
264    
265            m_ui.MaxVoicesSpinBox->setEnabled(bMaxVoicesSupported);
266            m_ui.MaxVoicesSpinBox->setValue(m_pOptions->getMaxVoices());
267            if (!bMaxVoicesSupported)
268                    m_ui.MaxVoicesSpinBox->setToolTip(
269                            tr("This parameter is not supported by the current sampler "
270                               "version in use.")
271                    );
272            else
273                    m_ui.MaxVoicesSpinBox->setToolTip(
274                            tr("The max. amount of voices the sampler shall process "
275                               "simultaneously.")
276                    );
277    
278            m_ui.MaxStreamsSpinBox->setEnabled(bMaxStreamsSupported);
279            m_ui.MaxStreamsSpinBox->setValue(m_pOptions->getMaxStreams());
280            if (!bMaxStreamsSupported)
281                    m_ui.MaxStreamsSpinBox->setToolTip(
282                            tr("This parameter is not supported by the current sampler "
283                               "version in use.")
284                    );
285            else
286                    m_ui.MaxStreamsSpinBox->setToolTip(
287                            tr("The max. amount of disk streams the sampler shall process "
288                               "simultaneously.")
289                    );
290    #else
291            m_ui.MaxVoicesSpinBox->setEnabled(false);
292            m_ui.MaxStreamsSpinBox->setEnabled(false);
293            m_ui.MaxVoicesSpinBox->setToolTip(
294                    tr("QSampler was built without support for this parameter.")
295            );
296            m_ui.MaxStreamsSpinBox->setToolTip(
297                    tr("QSampler was built without support for this parameter.")
298            );
299    #endif // CONFIG_MAX_VOICES
300    
301            // Custom display options...
302            resetCustomColorThemes(m_pOptions->sCustomColorTheme);
303            resetCustomStyleThemes(m_pOptions->sCustomStyleTheme);
304    
305            // Done.
306            m_iDirtySetup--;
307            stabilizeForm();
308  }  }
309    
310    
311  // Accept settings (OK button slot).  // Accept settings (OK button slot).
312  void OptionsForm::accept (void)  void OptionsForm::accept (void)
313  {  {
314      // Save options...          // Save options...
315      if (m_iDirtyCount > 0) {          if (m_iDirtyCount > 0) {
316          // Server settings....                  // Server settings....
317          m_pOptions->sServerHost         = ui.ServerHostComboBox->currentText().stripWhiteSpace();                  m_pOptions->sServerHost    = m_ui.ServerHostComboBox->currentText().trimmed();
318          m_pOptions->iServerPort         = ui.ServerPortComboBox->currentText().toInt();                  m_pOptions->iServerPort    = m_ui.ServerPortComboBox->currentText().toInt();
319          m_pOptions->iServerTimeout      = ui.ServerTimeoutSpinBox->value();                  m_pOptions->iServerTimeout = m_ui.ServerTimeoutSpinBox->value();
320          m_pOptions->bServerStart        = ui.ServerStartCheckBox->isChecked();                  m_pOptions->bServerStart   = m_ui.ServerStartCheckBox->isChecked();
321          m_pOptions->sServerCmdLine      = ui.ServerCmdLineComboBox->currentText().stripWhiteSpace();                  m_pOptions->sServerCmdLine = m_ui.ServerCmdLineComboBox->currentText().trimmed();
322          m_pOptions->iStartDelay         = ui.StartDelaySpinBox->value();                  m_pOptions->iStartDelay    = m_ui.StartDelaySpinBox->value();
323          // Channels options...                  // Logging options...
324          m_pOptions->sDisplayFont        = ui.DisplayFontTextLabel->font().toString();                  m_pOptions->bMessagesLog   = m_ui.MessagesLogCheckBox->isChecked();
325          m_pOptions->bDisplayEffect      = ui.DisplayEffectCheckBox->isChecked();                  m_pOptions->sMessagesLogPath = m_ui.MessagesLogPathComboBox->currentText();
326          m_pOptions->bAutoRefresh        = ui.AutoRefreshCheckBox->isChecked();                  // Channels options...
327          m_pOptions->iAutoRefreshTime    = ui.AutoRefreshTimeSpinBox->value();                  m_pOptions->sDisplayFont   = m_ui.DisplayFontTextLabel->font().toString();
328          m_pOptions->iMaxVolume          = ui.MaxVolumeSpinBox->value();                  m_pOptions->bDisplayEffect = m_ui.DisplayEffectCheckBox->isChecked();
329          // Messages options...                  m_pOptions->bAutoRefresh   = m_ui.AutoRefreshCheckBox->isChecked();
330          m_pOptions->sMessagesFont       = ui.MessagesFontTextLabel->font().toString();                  m_pOptions->iAutoRefreshTime = m_ui.AutoRefreshTimeSpinBox->value();
331          m_pOptions->bMessagesLimit      = ui.MessagesLimitCheckBox->isChecked();                  m_pOptions->iMaxVolume     = m_ui.MaxVolumeSpinBox->value();
332          m_pOptions->iMessagesLimitLines = ui.MessagesLimitLinesSpinBox->value();                  // Messages options...
333          // Other options...                  m_pOptions->sMessagesFont  = m_ui.MessagesFontTextLabel->font().toString();
334          m_pOptions->bConfirmRemove      = ui.ConfirmRemoveCheckBox->isChecked();                  m_pOptions->bMessagesLimit = m_ui.MessagesLimitCheckBox->isChecked();
335          m_pOptions->bKeepOnTop          = ui.KeepOnTopCheckBox->isChecked();                  m_pOptions->iMessagesLimitLines = m_ui.MessagesLimitLinesSpinBox->value();
336          m_pOptions->bStdoutCapture      = ui.StdoutCaptureCheckBox->isChecked();                  // Other options...
337          m_pOptions->bCompletePath       = ui.CompletePathCheckBox->isChecked();                  m_pOptions->bConfirmRemove = m_ui.ConfirmRemoveCheckBox->isChecked();
338          m_pOptions->bInstrumentNames    = ui.InstrumentNamesCheckBox->isChecked();                  m_pOptions->bConfirmRestart = m_ui.ConfirmRestartCheckBox->isChecked();
339          m_pOptions->iMaxRecentFiles     = ui.MaxRecentFilesSpinBox->value();                  m_pOptions->bConfirmReset  = m_ui.ConfirmResetCheckBox->isChecked();
340          // Reset dirty flag.                  m_pOptions->bConfirmError  = m_ui.ConfirmErrorCheckBox->isChecked();
341          m_iDirtyCount = 0;                  m_pOptions->bKeepOnTop     = m_ui.KeepOnTopCheckBox->isChecked();
342      }                  m_pOptions->bStdoutCapture = m_ui.StdoutCaptureCheckBox->isChecked();
343                    m_pOptions->bCompletePath  = m_ui.CompletePathCheckBox->isChecked();
344      // Save combobox history...                  m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked();
345      m_pOptions->saveComboBoxHistory(ui.ServerHostComboBox);                  m_pOptions->iMaxRecentFiles  = m_ui.MaxRecentFilesSpinBox->value();
346      m_pOptions->saveComboBoxHistory(ui.ServerPortComboBox);                  m_pOptions->iBaseFontSize  = m_ui.BaseFontSizeComboBox->currentText().toInt();
347      m_pOptions->saveComboBoxHistory(ui.ServerCmdLineComboBox);                  // Custom color/style theme options...
348                    if (m_ui.CustomStyleThemeComboBox->currentIndex() > 0)
349                            m_pOptions->sCustomStyleTheme = m_ui.CustomStyleThemeComboBox->currentText();
350                    else
351                            m_pOptions->sCustomStyleTheme.clear();
352                    if (m_ui.CustomColorThemeComboBox->currentIndex() > 0)
353                            m_pOptions->sCustomColorTheme = m_ui.CustomColorThemeComboBox->currentText();
354                    else
355                            m_pOptions->sCustomColorTheme.clear();
356                    // Reset dirty flag.
357                    m_iDirtyCount = 0;
358            }
359    
360            // If the user modified the limits, apply them to the sampler
361            // (and store it later in qsampler's configuration)
362            if (bMaxVoicesModified && m_ui.MaxVoicesSpinBox->isEnabled())
363                    m_pOptions->setMaxVoices(m_ui.MaxVoicesSpinBox->value());
364            if (bMaxStreamsModified && m_ui.MaxStreamsSpinBox->isEnabled())
365                    m_pOptions->setMaxStreams(m_ui.MaxStreamsSpinBox->value());
366    
367            // Save combobox history...
368            m_pOptions->saveComboBoxHistory(m_ui.ServerHostComboBox);
369            m_pOptions->saveComboBoxHistory(m_ui.ServerPortComboBox);
370            m_pOptions->saveComboBoxHistory(m_ui.ServerCmdLineComboBox);
371            m_pOptions->saveComboBoxHistory(m_ui.MessagesLogPathComboBox);
372    
373            // Save/commit to disk.
374            m_pOptions->saveOptions();
375    
376      // Just go with dialog acceptance.          // Just go with dialog acceptance.
377      QDialog::accept();          QDialog::accept();
378  }  }
379    
380    
381  // Reject settings (Cancel button slot).  // Reject settings (Cancel button slot).
382  void OptionsForm::reject (void)  void OptionsForm::reject (void)
383  {  {
384      bool bReject = true;          bool bReject = true;
385    
386      // Check if there's any pending changes...          // Check if there's any pending changes...
387      if (m_iDirtyCount > 0) {          if (m_iDirtyCount > 0) {
388          switch (QMessageBox::warning(this,                  switch (QMessageBox::warning(this,
389                          QSAMPLER_TITLE ": " + tr("Warning"),                          tr("Warning"),
390              tr("Some settings have been changed.\n\n"                          tr("Some settings have been changed.\n\n"
391                 "Do you want to apply the changes?"),                          "Do you want to apply the changes?"),
392              tr("Apply"), tr("Discard"), tr("Cancel"))) {                          QMessageBox::Apply |
393          case 0:     // Apply...                          QMessageBox::Discard |
394              accept();                          QMessageBox::Cancel)) {
395              return;                  case QMessageBox::Apply:
396          case 1:     // Discard                          accept();
397              break;                          return;
398          default:    // Cancel.                  case QMessageBox::Discard:
399              bReject = false;                          break;
400          }                  default:    // Cancel.
401      }                          bReject = false;
402                    }
403            }
404    
405      if (bReject)          if (bReject)
406          QDialog::reject();                  QDialog::reject();
407  }  }
408    
409    
410  // Dirty up settings.  // Dirty up settings.
411  void OptionsForm::optionsChanged (void)  void OptionsForm::optionsChanged (void)
412  {  {
413      if (m_iDirtySetup > 0)          if (m_iDirtySetup > 0)
414          return;                  return;
415    
416      m_iDirtyCount++;          m_iDirtyCount++;
417      stabilizeForm();          stabilizeForm();
418  }  }
419    
420    
421  // Stabilize current form state.  // Stabilize current form state.
422  void OptionsForm::stabilizeForm (void)  void OptionsForm::stabilizeForm (void)
423  {  {
424      bool bEnabled = ui.ServerStartCheckBox->isChecked();          bool bValid = (m_iDirtyCount > 0);
     ui.ServerCmdLineTextLabel->setEnabled(bEnabled);  
     ui.ServerCmdLineComboBox->setEnabled(bEnabled);  
     ui.StartDelayTextLabel->setEnabled(bEnabled);  
     ui.StartDelaySpinBox->setEnabled(bEnabled);  
425    
426      ui.AutoRefreshTimeSpinBox->setEnabled(ui.AutoRefreshCheckBox->isChecked());          bool bEnabled = m_ui.ServerStartCheckBox->isChecked();
427      ui.MessagesLimitLinesSpinBox->setEnabled(ui.MessagesLimitCheckBox->isChecked());          m_ui.ServerCmdLineTextLabel->setEnabled(bEnabled);
428            m_ui.ServerCmdLineComboBox->setEnabled(bEnabled);
429            m_ui.StartDelayTextLabel->setEnabled(bEnabled);
430            m_ui.StartDelaySpinBox->setEnabled(bEnabled);
431    
432            bEnabled = m_ui.MessagesLogCheckBox->isChecked();
433            m_ui.MessagesLogPathComboBox->setEnabled(bEnabled);
434            m_ui.MessagesLogPathToolButton->setEnabled(bEnabled);
435            if (bEnabled && bValid) {
436                    const QString& sPath = m_ui.MessagesLogPathComboBox->currentText();
437                    bValid = !sPath.isEmpty();
438            }
439    
440            m_ui.AutoRefreshTimeSpinBox->setEnabled(
441                    m_ui.AutoRefreshCheckBox->isChecked());
442            m_ui.MessagesLimitLinesSpinBox->setEnabled(
443                    m_ui.MessagesLimitCheckBox->isChecked());
444    
445      ui.OkPushButton->setEnabled(m_iDirtyCount > 0);          m_ui.DialogButtonBox->button(QDialogButtonBox::Ok)->setEnabled(bValid);
446    }
447    
448    
449    // Messages log path browse slot.
450    void OptionsForm::browseMessagesLogPath (void)
451    {
452            QString sFileName = QFileDialog::getSaveFileName(
453                    this,                                                                                   // Parent.
454                    tr("Messages Log"),                                             // Caption.
455                    m_ui.MessagesLogPathComboBox->currentText(),    // Start here.
456                    tr("Log files") + " (*.log)"                    // Filter (log files)
457            );
458    
459            if (!sFileName.isEmpty()) {
460                    m_ui.MessagesLogPathComboBox->setEditText(sFileName);
461                    m_ui.MessagesLogPathComboBox->setFocus();
462                    optionsChanged();
463            }
464  }  }
465    
466    
467  // The channel display font selection dialog.  // The channel display font selection dialog.
468  void OptionsForm::chooseDisplayFont (void)  void OptionsForm::chooseDisplayFont (void)
469  {  {
470      bool  bOk  = false;          bool  bOk  = false;
471      QFont font = QFontDialog::getFont(&bOk, ui.DisplayFontTextLabel->font(), this);          QFont font = QFontDialog::getFont(&bOk,
472      if (bOk) {                  m_ui.DisplayFontTextLabel->font(), this);
473          ui.DisplayFontTextLabel->setFont(font);          if (bOk) {
474          ui.DisplayFontTextLabel->setText(font.family() + " " + QString::number(font.pointSize()));                  m_ui.DisplayFontTextLabel->setFont(font);
475          optionsChanged();                  m_ui.DisplayFontTextLabel->setText(font.family()
476      }                          + ' ' + QString::number(font.pointSize()));
477                    optionsChanged();
478            }
479  }  }
480    
481    
482  // The messages font selection dialog.  // The messages font selection dialog.
483  void OptionsForm::chooseMessagesFont (void)  void OptionsForm::chooseMessagesFont (void)
484  {  {
485      bool  bOk  = false;          bool  bOk  = false;
486      QFont font = QFontDialog::getFont(&bOk, ui.MessagesFontTextLabel->font(), this);          QFont font = QFontDialog::getFont(&bOk,
487      if (bOk) {                  m_ui.MessagesFontTextLabel->font(), this);
488          ui.MessagesFontTextLabel->setFont(font);          if (bOk) {
489          ui.MessagesFontTextLabel->setText(font.family() + " " + QString::number(font.pointSize()));                  m_ui.MessagesFontTextLabel->setFont(font);
490          optionsChanged();                  m_ui.MessagesFontTextLabel->setText(font.family()
491      }                          + ' ' + QString::number(font.pointSize()));
492                    optionsChanged();
493            }
494  }  }
495    
496    
497  // The channel display effect demo changer.  // The channel display effect demo changer.
498  void OptionsForm::toggleDisplayEffect ( bool bOn )  void OptionsForm::toggleDisplayEffect ( bool bOn )
499  {  {
500      QPixmap pm;          QPalette pal;
501      if (bOn)          pal.setColor(QPalette::WindowText, Qt::green);
502          pm = QPixmap(":/qsampler/pixmaps/displaybg1.png");          if (bOn) {
503      ui.DisplayFontTextLabel->setPaletteBackgroundPixmap(pm);                  QPixmap pm(":/images/displaybg1.png");
504                    pal.setBrush(QPalette::Window, QBrush(pm));
505            } else {
506                    pal.setColor(QPalette::Window, Qt::black);
507            }
508            m_ui.DisplayFontTextLabel->setPalette(pal);
509    
510      optionsChanged();          optionsChanged();
511  }  }
512    
513  } // namespace QSampler  void OptionsForm::maxVoicesChanged(int /*iMaxVoices*/)
514    {
515            bMaxVoicesModified = true;
516            optionsChanged();
517    }
518    
519    void OptionsForm::maxStreamsChanged(int /*iMaxStreams*/)
520    {
521            bMaxStreamsModified = true;
522            optionsChanged();
523    }
524    
525    
526    // Custom color palette theme manager.
527    void OptionsForm::editCustomColorThemes (void)
528    {
529            PaletteForm form(this);
530            form.setSettings(&m_pOptions->settings());
531    
532            QString sCustomColorTheme;
533            int iDirtyCustomColorTheme = 0;
534    
535            const int iCustomColorTheme
536                    = m_ui.CustomColorThemeComboBox->currentIndex();
537            if (iCustomColorTheme > 0) {
538                    sCustomColorTheme = m_ui.CustomColorThemeComboBox->itemText(
539                            iCustomColorTheme);
540                    form.setPaletteName(sCustomColorTheme);
541            }
542    
543            if (form.exec() == QDialog::Accepted) {
544                    sCustomColorTheme = form.paletteName();
545                    ++iDirtyCustomColorTheme;
546            }
547    
548            if (iDirtyCustomColorTheme > 0 || form.isDirty()) {
549                    resetCustomColorThemes(sCustomColorTheme);
550                    optionsChanged();
551            }
552    }
553    
554    
555    // Custom color palette themes settler.
556    void OptionsForm::resetCustomColorThemes (
557            const QString& sCustomColorTheme )
558    {
559            m_ui.CustomColorThemeComboBox->clear();
560            m_ui.CustomColorThemeComboBox->addItem(
561                    tr(g_pszDefName));
562            m_ui.CustomColorThemeComboBox->addItems(
563                    PaletteForm::namedPaletteList(&m_pOptions->settings()));
564    
565            int iCustomColorTheme = 0;
566            if (!sCustomColorTheme.isEmpty()) {
567                    iCustomColorTheme = m_ui.CustomColorThemeComboBox->findText(
568                            sCustomColorTheme);
569                    if (iCustomColorTheme < 0)
570                            iCustomColorTheme = 0;
571            }
572            m_ui.CustomColorThemeComboBox->setCurrentIndex(iCustomColorTheme);
573    }
574    
575    
576    // Custom widget style themes settler.
577    void OptionsForm::resetCustomStyleThemes (
578            const QString& sCustomStyleTheme )
579    {
580            m_ui.CustomStyleThemeComboBox->clear();
581            m_ui.CustomStyleThemeComboBox->addItem(
582                    tr(g_pszDefName));
583            m_ui.CustomStyleThemeComboBox->addItems(QStyleFactory::keys());
584    
585            int iCustomStyleTheme = 0;
586            if (!sCustomStyleTheme.isEmpty()) {
587                    iCustomStyleTheme = m_ui.CustomStyleThemeComboBox->findText(
588                            sCustomStyleTheme);
589                    if (iCustomStyleTheme < 0)
590                            iCustomStyleTheme = 0;
591            }
592            m_ui.CustomStyleThemeComboBox->setCurrentIndex(iCustomStyleTheme);
593    }
594    
595    
596    } // namespace QSampler
597    
598  // end of qsamplerOptionsForm.cpp  // end of qsamplerOptionsForm.cpp

Legend:
Removed from v.1474  
changed lines
  Added in v.3794

  ViewVC Help
Powered by ViewVC