/[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 1509 by capela, Thu Nov 22 11:10:44 2007 UTC revision 1840 by capela, Thu Feb 19 11:44:57 2009 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-2009, 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 27  Line 27 
27    
28  #include <QMessageBox>  #include <QMessageBox>
29  #include <QFontDialog>  #include <QFontDialog>
30    #include <QFileDialog>
31    
32    
33  namespace QSampler {  namespace QSampler {
34    
35    //-------------------------------------------------------------------------
36    // QSampler::OptionsForm -- Options form implementation.
37    //
38    
39  OptionsForm::OptionsForm ( QWidget* pParent )  OptionsForm::OptionsForm ( QWidget* pParent )
40          : QDialog(pParent)          : QDialog(pParent)
41  {  {
# Line 68  OptionsForm::OptionsForm ( QWidget* pPar Line 73  OptionsForm::OptionsForm ( QWidget* pPar
73          QObject::connect(m_ui.StartDelaySpinBox,          QObject::connect(m_ui.StartDelaySpinBox,
74                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
75                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
76            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          QObject::connect(m_ui.DisplayFontPushButton,          QObject::connect(m_ui.DisplayFontPushButton,
86                  SIGNAL(clicked()),                  SIGNAL(clicked()),
87                  SLOT(chooseDisplayFont()));                  SLOT(chooseDisplayFont()));
# Line 110  OptionsForm::OptionsForm ( QWidget* pPar Line 124  OptionsForm::OptionsForm ( QWidget* pPar
124          QObject::connect(m_ui.InstrumentNamesCheckBox,          QObject::connect(m_ui.InstrumentNamesCheckBox,
125                  SIGNAL(stateChanged(int)),                  SIGNAL(stateChanged(int)),
126                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
127            QObject::connect(m_ui.BaseFontSizeComboBox,
128                    SIGNAL(editTextChanged(const QString&)),
129                    SLOT(optionsChanged()));
130            QObject::connect(m_ui.MaxVoicesSpinBox,
131                    SIGNAL(valueChanged(int)),
132                    SLOT(maxVoicesChanged(int)));
133            QObject::connect(m_ui.MaxStreamsSpinBox,
134                    SIGNAL(valueChanged(int)),
135                    SLOT(maxStreamsChanged(int)));
136          QObject::connect(m_ui.OkPushButton,          QObject::connect(m_ui.OkPushButton,
137                  SIGNAL(clicked()),                  SIGNAL(clicked()),
138                  SLOT(accept()));                  SLOT(accept()));
# Line 123  OptionsForm::~OptionsForm() Line 146  OptionsForm::~OptionsForm()
146  }  }
147    
148  // Populate (setup) dialog controls from settings descriptors.  // Populate (setup) dialog controls from settings descriptors.
149  void OptionsForm::setup ( qsamplerOptions *pOptions )  void OptionsForm::setup ( Options *pOptions )
150  {  {
151          // Set reference descriptor.          // Set reference descriptor.
152          m_pOptions = pOptions;          m_pOptions = pOptions;
# Line 137  void OptionsForm::setup ( qsamplerOption Line 160  void OptionsForm::setup ( qsamplerOption
160          m_pOptions->loadComboBoxHistory(m_ui.ServerHostComboBox);          m_pOptions->loadComboBoxHistory(m_ui.ServerHostComboBox);
161          m_pOptions->loadComboBoxHistory(m_ui.ServerPortComboBox);          m_pOptions->loadComboBoxHistory(m_ui.ServerPortComboBox);
162          m_pOptions->loadComboBoxHistory(m_ui.ServerCmdLineComboBox);          m_pOptions->loadComboBoxHistory(m_ui.ServerCmdLineComboBox);
163            m_pOptions->loadComboBoxHistory(m_ui.MessagesLogPathComboBox);
164    
165          // Load Server settings...          // Load Server settings...
166          m_ui.ServerHostComboBox->setEditText(m_pOptions->sServerHost);          m_ui.ServerHostComboBox->setEditText(m_pOptions->sServerHost);
# Line 146  void OptionsForm::setup ( qsamplerOption Line 170  void OptionsForm::setup ( qsamplerOption
170          m_ui.ServerCmdLineComboBox->setEditText(m_pOptions->sServerCmdLine);          m_ui.ServerCmdLineComboBox->setEditText(m_pOptions->sServerCmdLine);
171          m_ui.StartDelaySpinBox->setValue(m_pOptions->iStartDelay);          m_ui.StartDelaySpinBox->setValue(m_pOptions->iStartDelay);
172    
173            // Logging options...
174            m_ui.MessagesLogCheckBox->setChecked(m_pOptions->bMessagesLog);
175            m_ui.MessagesLogPathComboBox->setEditText(m_pOptions->sMessagesLogPath);
176    
177          // Load Display options...          // Load Display options...
178          QFont font;          QFont font;
179          QPalette pal;          QPalette pal;
# Line 170  void OptionsForm::setup ( qsamplerOption Line 198  void OptionsForm::setup ( qsamplerOption
198          // Messages font.          // Messages font.
199          if (m_pOptions->sMessagesFont.isEmpty()          if (m_pOptions->sMessagesFont.isEmpty()
200                  || !font.fromString(m_pOptions->sMessagesFont))                  || !font.fromString(m_pOptions->sMessagesFont))
201                  font = QFont("Fixed", 8);                  font = QFont("Monospace", 8);
202          pal = m_ui.MessagesFontTextLabel->palette();          pal = m_ui.MessagesFontTextLabel->palette();
203          pal.setColor(QPalette::Background, Qt::white);          pal.setColor(QPalette::Background, pal.base().color());
204          m_ui.MessagesFontTextLabel->setPalette(pal);          m_ui.MessagesFontTextLabel->setPalette(pal);
205          m_ui.MessagesFontTextLabel->setFont(font);          m_ui.MessagesFontTextLabel->setFont(font);
206          m_ui.MessagesFontTextLabel->setText(font.family()          m_ui.MessagesFontTextLabel->setText(font.family()
# Line 189  void OptionsForm::setup ( qsamplerOption Line 217  void OptionsForm::setup ( qsamplerOption
217          m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath);          m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath);
218          m_ui.InstrumentNamesCheckBox->setChecked(m_pOptions->bInstrumentNames);          m_ui.InstrumentNamesCheckBox->setChecked(m_pOptions->bInstrumentNames);
219          m_ui.MaxRecentFilesSpinBox->setValue(m_pOptions->iMaxRecentFiles);          m_ui.MaxRecentFilesSpinBox->setValue(m_pOptions->iMaxRecentFiles);
220            if (m_pOptions->iBaseFontSize > 0)
221                    m_ui.BaseFontSizeComboBox->setEditText(QString::number(m_pOptions->iBaseFontSize));
222            else
223                    m_ui.BaseFontSizeComboBox->setCurrentIndex(0);
224    
225  #ifndef CONFIG_LIBGIG  #ifndef CONFIG_LIBGIG
226          m_ui.InstrumentNamesCheckBox->setEnabled(false);          m_ui.InstrumentNamesCheckBox->setEnabled(false);
227  #endif  #endif
228    
229            bMaxVoicesModified = bMaxStreamsModified = false;
230    #ifdef CONFIG_MAX_VOICES
231            const bool bMaxVoicesSupported =
232                    m_pOptions->getEffectiveMaxVoices() >= 0;
233            const bool bMaxStreamsSupported =
234                    m_pOptions->getEffectiveMaxStreams() >= 0;
235    
236            m_ui.MaxVoicesSpinBox->setEnabled(bMaxVoicesSupported);
237            m_ui.MaxVoicesSpinBox->setValue(m_pOptions->getMaxVoices());
238            if (!bMaxVoicesSupported)
239                    m_ui.MaxVoicesSpinBox->setToolTip(
240                            tr("This parameter is not supported by the current sampler "
241                               "version in use.")
242                    );
243            else
244                    m_ui.MaxVoicesSpinBox->setToolTip(
245                            tr("The max. amount of voices the sampler shall process "
246                               "simultaniously.")
247                    );
248    
249            m_ui.MaxStreamsSpinBox->setEnabled(bMaxStreamsSupported);
250            m_ui.MaxStreamsSpinBox->setValue(m_pOptions->getMaxStreams());
251            if (!bMaxStreamsSupported)
252                    m_ui.MaxStreamsSpinBox->setToolTip(
253                            tr("This parameter is not supported by the current sampler "
254                               "version in use.")
255                    );
256            else
257                    m_ui.MaxStreamsSpinBox->setToolTip(
258                            tr("The max. amount of disk streams the sampler shall process "
259                               "simultaniously.")
260                    );
261    #else
262            m_ui.MaxVoicesSpinBox->setEnabled(false);
263            m_ui.MaxStreamsSpinBox->setEnabled(false);
264            m_ui.MaxVoicesSpinBox->setToolTip(
265                    tr("QSampler was built without support for this parameter.")
266            );
267            m_ui.MaxStreamsSpinBox->setToolTip(
268                    tr("QSampler was built without support for this parameter.")
269            );
270    #endif // CONFIG_MAX_VOICES
271    
272          // Done.          // Done.
273          m_iDirtySetup--;          m_iDirtySetup--;
274          stabilizeForm();          stabilizeForm();
# Line 211  void OptionsForm::accept (void) Line 286  void OptionsForm::accept (void)
286                  m_pOptions->iServerTimeout = m_ui.ServerTimeoutSpinBox->value();                  m_pOptions->iServerTimeout = m_ui.ServerTimeoutSpinBox->value();
287                  m_pOptions->bServerStart   = m_ui.ServerStartCheckBox->isChecked();                  m_pOptions->bServerStart   = m_ui.ServerStartCheckBox->isChecked();
288                  m_pOptions->sServerCmdLine = m_ui.ServerCmdLineComboBox->currentText().trimmed();                  m_pOptions->sServerCmdLine = m_ui.ServerCmdLineComboBox->currentText().trimmed();
289                  m_pOptions->iStartDelay      = m_ui.StartDelaySpinBox->value();                  m_pOptions->iStartDelay    = m_ui.StartDelaySpinBox->value();
290                    // Logging options...
291                    m_pOptions->bMessagesLog   = m_ui.MessagesLogCheckBox->isChecked();
292                    m_pOptions->sMessagesLogPath = m_ui.MessagesLogPathComboBox->currentText();
293                  // Channels options...                  // Channels options...
294                  m_pOptions->sDisplayFont   = m_ui.DisplayFontTextLabel->font().toString();                  m_pOptions->sDisplayFont   = m_ui.DisplayFontTextLabel->font().toString();
295                  m_pOptions->bDisplayEffect = m_ui.DisplayEffectCheckBox->isChecked();                  m_pOptions->bDisplayEffect = m_ui.DisplayEffectCheckBox->isChecked();
# Line 229  void OptionsForm::accept (void) Line 307  void OptionsForm::accept (void)
307                  m_pOptions->bCompletePath  = m_ui.CompletePathCheckBox->isChecked();                  m_pOptions->bCompletePath  = m_ui.CompletePathCheckBox->isChecked();
308                  m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked();                  m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked();
309                  m_pOptions->iMaxRecentFiles  = m_ui.MaxRecentFilesSpinBox->value();                  m_pOptions->iMaxRecentFiles  = m_ui.MaxRecentFilesSpinBox->value();
310                    m_pOptions->iBaseFontSize  = m_ui.BaseFontSizeComboBox->currentText().toInt();
311                  // Reset dirty flag.                  // Reset dirty flag.
312                  m_iDirtyCount = 0;                  m_iDirtyCount = 0;
313          }          }
314    
315            // if the user modified the limits, apply them to the sampler
316            // (and store it later in qsampler's configuration)
317            if (bMaxVoicesModified && m_ui.MaxVoicesSpinBox->isEnabled())
318                    m_pOptions->setMaxVoices(m_ui.MaxVoicesSpinBox->value());
319            if (bMaxStreamsModified && m_ui.MaxStreamsSpinBox->isEnabled())
320                    m_pOptions->setMaxStreams(m_ui.MaxStreamsSpinBox->value());
321    
322          // Save combobox history...          // Save combobox history...
323          m_pOptions->saveComboBoxHistory(m_ui.ServerHostComboBox);          m_pOptions->saveComboBoxHistory(m_ui.ServerHostComboBox);
324          m_pOptions->saveComboBoxHistory(m_ui.ServerPortComboBox);          m_pOptions->saveComboBoxHistory(m_ui.ServerPortComboBox);
325          m_pOptions->saveComboBoxHistory(m_ui.ServerCmdLineComboBox);          m_pOptions->saveComboBoxHistory(m_ui.ServerCmdLineComboBox);
326            m_pOptions->saveComboBoxHistory(m_ui.MessagesLogPathComboBox);
327    
328          // Just go with dialog acceptance.          // Just go with dialog acceptance.
329          QDialog::accept();          QDialog::accept();
# Line 254  void OptionsForm::reject (void) Line 341  void OptionsForm::reject (void)
341                          QSAMPLER_TITLE ": " + tr("Warning"),                          QSAMPLER_TITLE ": " + tr("Warning"),
342                          tr("Some settings have been changed.\n\n"                          tr("Some settings have been changed.\n\n"
343                          "Do you want to apply the changes?"),                          "Do you want to apply the changes?"),
344                          tr("Apply"), tr("Discard"), tr("Cancel"))) {                          QMessageBox::Apply |
345                  case 0:     // Apply...                          QMessageBox::Discard |
346                            QMessageBox::Cancel)) {
347                    case QMessageBox::Apply:
348                          accept();                          accept();
349                          return;                          return;
350                  case 1:     // Discard                  case QMessageBox::Discard:
351                          break;                          break;
352                  default:    // Cancel.                  default:    // Cancel.
353                          bReject = false;                          bReject = false;
# Line 284  void OptionsForm::optionsChanged (void) Line 373  void OptionsForm::optionsChanged (void)
373  // Stabilize current form state.  // Stabilize current form state.
374  void OptionsForm::stabilizeForm (void)  void OptionsForm::stabilizeForm (void)
375  {  {
376            bool bValid = (m_iDirtyCount > 0);
377    
378          bool bEnabled = m_ui.ServerStartCheckBox->isChecked();          bool bEnabled = m_ui.ServerStartCheckBox->isChecked();
379          m_ui.ServerCmdLineTextLabel->setEnabled(bEnabled);          m_ui.ServerCmdLineTextLabel->setEnabled(bEnabled);
380          m_ui.ServerCmdLineComboBox->setEnabled(bEnabled);          m_ui.ServerCmdLineComboBox->setEnabled(bEnabled);
381          m_ui.StartDelayTextLabel->setEnabled(bEnabled);          m_ui.StartDelayTextLabel->setEnabled(bEnabled);
382          m_ui.StartDelaySpinBox->setEnabled(bEnabled);          m_ui.StartDelaySpinBox->setEnabled(bEnabled);
383    
384            bEnabled = m_ui.MessagesLogCheckBox->isChecked();
385            m_ui.MessagesLogPathComboBox->setEnabled(bEnabled);
386            m_ui.MessagesLogPathToolButton->setEnabled(bEnabled);
387            if (bEnabled && bValid) {
388                    const QString& sPath = m_ui.MessagesLogPathComboBox->currentText();
389                    bValid = !sPath.isEmpty();
390            }
391    
392          m_ui.AutoRefreshTimeSpinBox->setEnabled(          m_ui.AutoRefreshTimeSpinBox->setEnabled(
393                  m_ui.AutoRefreshCheckBox->isChecked());                  m_ui.AutoRefreshCheckBox->isChecked());
394          m_ui.MessagesLimitLinesSpinBox->setEnabled(          m_ui.MessagesLimitLinesSpinBox->setEnabled(
395                  m_ui.MessagesLimitCheckBox->isChecked());                  m_ui.MessagesLimitCheckBox->isChecked());
396    
397          m_ui.OkPushButton->setEnabled(m_iDirtyCount > 0);          m_ui.OkPushButton->setEnabled(bValid);
398    }
399    
400    
401    // Messages log path browse slot.
402    void OptionsForm::browseMessagesLogPath (void)
403    {
404            QString sFileName = QFileDialog::getSaveFileName(
405                    this,                                                                                   // Parent.
406                    tr("Messages Log"),                                             // Caption.
407                    m_ui.MessagesLogPathComboBox->currentText(),    // Start here.
408                    tr("Log files") + " (*.log)"                    // Filter (log files)
409            );
410    
411            if (!sFileName.isEmpty()) {
412                    m_ui.MessagesLogPathComboBox->setEditText(sFileName);
413                    m_ui.MessagesLogPathComboBox->setFocus();
414                    optionsChanged();
415            }
416  }  }
417    
418    
# Line 345  void OptionsForm::toggleDisplayEffect ( Line 462  void OptionsForm::toggleDisplayEffect (
462          optionsChanged();          optionsChanged();
463  }  }
464    
465  } // namespace QSampler  void OptionsForm::maxVoicesChanged(int /*iMaxVoices*/)
466    {
467            bMaxVoicesModified = true;
468            optionsChanged();
469    }
470    
471    void OptionsForm::maxStreamsChanged(int /*iMaxStreams*/)
472    {
473            bMaxStreamsModified = true;
474            optionsChanged();
475    }
476    
477    } // namespace QSampler
478    
479  // end of qsamplerOptionsForm.cpp  // end of qsamplerOptionsForm.cpp

Legend:
Removed from v.1509  
changed lines
  Added in v.1840

  ViewVC Help
Powered by ViewVC