/[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 1558 by capela, Thu Dec 6 09:35:33 2007 UTC revision 2074 by capela, Mon Mar 29 17:00:30 2010 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-2010, 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 {
# Line 72  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 114  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 141  void OptionsForm::setup ( Options *pOpti Line 160  void OptionsForm::setup ( Options *pOpti
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 150  void OptionsForm::setup ( Options *pOpti Line 170  void OptionsForm::setup ( Options *pOpti
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 174  void OptionsForm::setup ( Options *pOpti Line 198  void OptionsForm::setup ( Options *pOpti
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 193  void OptionsForm::setup ( Options *pOpti Line 217  void OptionsForm::setup ( Options *pOpti
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 215  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 233  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            // Save/commit to disk.
329            m_pOptions->saveOptions();
330    
331          // Just go with dialog acceptance.          // Just go with dialog acceptance.
332          QDialog::accept();          QDialog::accept();
# Line 258  void OptionsForm::reject (void) Line 344  void OptionsForm::reject (void)
344                          QSAMPLER_TITLE ": " + tr("Warning"),                          QSAMPLER_TITLE ": " + tr("Warning"),
345                          tr("Some settings have been changed.\n\n"                          tr("Some settings have been changed.\n\n"
346                          "Do you want to apply the changes?"),                          "Do you want to apply the changes?"),
347                          tr("Apply"), tr("Discard"), tr("Cancel"))) {                          QMessageBox::Apply |
348                  case 0:     // Apply...                          QMessageBox::Discard |
349                            QMessageBox::Cancel)) {
350                    case QMessageBox::Apply:
351                          accept();                          accept();
352                          return;                          return;
353                  case 1:     // Discard                  case QMessageBox::Discard:
354                          break;                          break;
355                  default:    // Cancel.                  default:    // Cancel.
356                          bReject = false;                          bReject = false;
# Line 288  void OptionsForm::optionsChanged (void) Line 376  void OptionsForm::optionsChanged (void)
376  // Stabilize current form state.  // Stabilize current form state.
377  void OptionsForm::stabilizeForm (void)  void OptionsForm::stabilizeForm (void)
378  {  {
379            bool bValid = (m_iDirtyCount > 0);
380    
381          bool bEnabled = m_ui.ServerStartCheckBox->isChecked();          bool bEnabled = m_ui.ServerStartCheckBox->isChecked();
382          m_ui.ServerCmdLineTextLabel->setEnabled(bEnabled);          m_ui.ServerCmdLineTextLabel->setEnabled(bEnabled);
383          m_ui.ServerCmdLineComboBox->setEnabled(bEnabled);          m_ui.ServerCmdLineComboBox->setEnabled(bEnabled);
384          m_ui.StartDelayTextLabel->setEnabled(bEnabled);          m_ui.StartDelayTextLabel->setEnabled(bEnabled);
385          m_ui.StartDelaySpinBox->setEnabled(bEnabled);          m_ui.StartDelaySpinBox->setEnabled(bEnabled);
386    
387            bEnabled = m_ui.MessagesLogCheckBox->isChecked();
388            m_ui.MessagesLogPathComboBox->setEnabled(bEnabled);
389            m_ui.MessagesLogPathToolButton->setEnabled(bEnabled);
390            if (bEnabled && bValid) {
391                    const QString& sPath = m_ui.MessagesLogPathComboBox->currentText();
392                    bValid = !sPath.isEmpty();
393            }
394    
395          m_ui.AutoRefreshTimeSpinBox->setEnabled(          m_ui.AutoRefreshTimeSpinBox->setEnabled(
396                  m_ui.AutoRefreshCheckBox->isChecked());                  m_ui.AutoRefreshCheckBox->isChecked());
397          m_ui.MessagesLimitLinesSpinBox->setEnabled(          m_ui.MessagesLimitLinesSpinBox->setEnabled(
398                  m_ui.MessagesLimitCheckBox->isChecked());                  m_ui.MessagesLimitCheckBox->isChecked());
399    
400          m_ui.OkPushButton->setEnabled(m_iDirtyCount > 0);          m_ui.OkPushButton->setEnabled(bValid);
401    }
402    
403    
404    // Messages log path browse slot.
405    void OptionsForm::browseMessagesLogPath (void)
406    {
407            QString sFileName = QFileDialog::getSaveFileName(
408                    this,                                                                                   // Parent.
409                    tr("Messages Log"),                                             // Caption.
410                    m_ui.MessagesLogPathComboBox->currentText(),    // Start here.
411                    tr("Log files") + " (*.log)"                    // Filter (log files)
412            );
413    
414            if (!sFileName.isEmpty()) {
415                    m_ui.MessagesLogPathComboBox->setEditText(sFileName);
416                    m_ui.MessagesLogPathComboBox->setFocus();
417                    optionsChanged();
418            }
419  }  }
420    
421    
# Line 339  void OptionsForm::toggleDisplayEffect ( Line 455  void OptionsForm::toggleDisplayEffect (
455          QPalette pal;          QPalette pal;
456          pal.setColor(QPalette::Foreground, Qt::green);          pal.setColor(QPalette::Foreground, Qt::green);
457          if (bOn) {          if (bOn) {
458                  QPixmap pm(":/icons/displaybg1.png");                  QPixmap pm(":/images/displaybg1.png");
459                  pal.setBrush(QPalette::Background, QBrush(pm));                  pal.setBrush(QPalette::Background, QBrush(pm));
460          } else {          } else {
461                  pal.setColor(QPalette::Background, Qt::black);                  pal.setColor(QPalette::Background, Qt::black);
# Line 349  void OptionsForm::toggleDisplayEffect ( Line 465  void OptionsForm::toggleDisplayEffect (
465          optionsChanged();          optionsChanged();
466  }  }
467    
468  } // namespace QSampler  void OptionsForm::maxVoicesChanged(int /*iMaxVoices*/)
469    {
470            bMaxVoicesModified = true;
471            optionsChanged();
472    }
473    
474    void OptionsForm::maxStreamsChanged(int /*iMaxStreams*/)
475    {
476            bMaxStreamsModified = true;
477            optionsChanged();
478    }
479    
480    } // namespace QSampler
481    
482  // end of qsamplerOptionsForm.cpp  // end of qsamplerOptionsForm.cpp

Legend:
Removed from v.1558  
changed lines
  Added in v.2074

  ViewVC Help
Powered by ViewVC