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

Legend:
Removed from v.1505  
changed lines
  Added in v.3651

  ViewVC Help
Powered by ViewVC