/[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 2074 by capela, Mon Mar 29 17:00:30 2010 UTC revision 3648 by capela, Tue Dec 10 10:34:06 2019 UTC
# Line 1  Line 1 
1  // qsamplerOptionsForm.cpp  // qsamplerOptionsForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2010, 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>  #include <QFileDialog>
33    
34    #include <QStyleFactory>
35    
36  namespace QSampler {  namespace QSampler {
37    
38    // Default (empty/blank) name.
39    static const char *g_pszDefName = QT_TR_NOOP("(default)");
40    
41  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
42  // QSampler::OptionsForm -- Options form implementation.  // QSampler::OptionsForm -- Options form implementation.
43  //  //
# Line 42  OptionsForm::OptionsForm ( QWidget* pPar Line 48  OptionsForm::OptionsForm ( QWidget* pPar
48          m_ui.setupUi(this);          m_ui.setupUi(this);
49    
50          // No settings descriptor initially (the caller will set it).          // No settings descriptor initially (the caller will set it).
51          m_pOptions = NULL;          m_pOptions = nullptr;
52    
53          // Initialize dirty control state.          // Initialize dirty control state.
54          m_iDirtySetup = 0;          m_iDirtySetup = 0;
# Line 109  OptionsForm::OptionsForm ( QWidget* pPar Line 115  OptionsForm::OptionsForm ( QWidget* pPar
115          QObject::connect(m_ui.ConfirmRemoveCheckBox,          QObject::connect(m_ui.ConfirmRemoveCheckBox,
116                  SIGNAL(stateChanged(int)),                  SIGNAL(stateChanged(int)),
117                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
118            QObject::connect(m_ui.ConfirmResetCheckBox,
119                    SIGNAL(stateChanged(int)),
120                    SLOT(optionsChanged()));
121            QObject::connect(m_ui.ConfirmRestartCheckBox,
122                    SIGNAL(stateChanged(int)),
123                    SLOT(optionsChanged()));
124            QObject::connect(m_ui.ConfirmErrorCheckBox,
125                    SIGNAL(stateChanged(int)),
126                    SLOT(optionsChanged()));
127          QObject::connect(m_ui.KeepOnTopCheckBox,          QObject::connect(m_ui.KeepOnTopCheckBox,
128                  SIGNAL(stateChanged(int)),                  SIGNAL(stateChanged(int)),
129                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
# Line 124  OptionsForm::OptionsForm ( QWidget* pPar Line 139  OptionsForm::OptionsForm ( QWidget* pPar
139          QObject::connect(m_ui.InstrumentNamesCheckBox,          QObject::connect(m_ui.InstrumentNamesCheckBox,
140                  SIGNAL(stateChanged(int)),                  SIGNAL(stateChanged(int)),
141                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
142            QObject::connect(m_ui.CustomColorThemeComboBox,
143                    SIGNAL(activated(int)),
144                    SLOT(optionsChanged()));
145            QObject::connect(m_ui.CustomColorThemeToolButton,
146                    SIGNAL(clicked()),
147                    SLOT(editCustomColorThemes()));
148            QObject::connect(m_ui.CustomStyleThemeComboBox,
149                    SIGNAL(activated(int)),
150                    SLOT(optionsChanged()));
151          QObject::connect(m_ui.BaseFontSizeComboBox,          QObject::connect(m_ui.BaseFontSizeComboBox,
152                  SIGNAL(editTextChanged(const QString&)),                  SIGNAL(editTextChanged(const QString&)),
153                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
# Line 133  OptionsForm::OptionsForm ( QWidget* pPar Line 157  OptionsForm::OptionsForm ( QWidget* pPar
157          QObject::connect(m_ui.MaxStreamsSpinBox,          QObject::connect(m_ui.MaxStreamsSpinBox,
158                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
159                  SLOT(maxStreamsChanged(int)));                  SLOT(maxStreamsChanged(int)));
160          QObject::connect(m_ui.OkPushButton,          QObject::connect(m_ui.DialogButtonBox,
161                  SIGNAL(clicked()),                  SIGNAL(accepted()),
162                  SLOT(accept()));                  SLOT(accept()));
163          QObject::connect(m_ui.CancelPushButton,          QObject::connect(m_ui.DialogButtonBox,
164                  SIGNAL(clicked()),                  SIGNAL(rejected()),
165                  SLOT(reject()));                  SLOT(reject()));
166  }  }
167    
# Line 212  void OptionsForm::setup ( Options *pOpti Line 236  void OptionsForm::setup ( Options *pOpti
236    
237          // Other options finally.          // Other options finally.
238          m_ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove);          m_ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove);
239            m_ui.ConfirmRestartCheckBox->setChecked(m_pOptions->bConfirmRestart);
240            m_ui.ConfirmResetCheckBox->setChecked(m_pOptions->bConfirmReset);
241            m_ui.ConfirmErrorCheckBox->setChecked(m_pOptions->bConfirmError);
242          m_ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop);          m_ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop);
243          m_ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture);          m_ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture);
244          m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath);          m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath);
# Line 243  void OptionsForm::setup ( Options *pOpti Line 270  void OptionsForm::setup ( Options *pOpti
270          else          else
271                  m_ui.MaxVoicesSpinBox->setToolTip(                  m_ui.MaxVoicesSpinBox->setToolTip(
272                          tr("The max. amount of voices the sampler shall process "                          tr("The max. amount of voices the sampler shall process "
273                             "simultaniously.")                             "simultaneously.")
274                  );                  );
275    
276          m_ui.MaxStreamsSpinBox->setEnabled(bMaxStreamsSupported);          m_ui.MaxStreamsSpinBox->setEnabled(bMaxStreamsSupported);
# Line 256  void OptionsForm::setup ( Options *pOpti Line 283  void OptionsForm::setup ( Options *pOpti
283          else          else
284                  m_ui.MaxStreamsSpinBox->setToolTip(                  m_ui.MaxStreamsSpinBox->setToolTip(
285                          tr("The max. amount of disk streams the sampler shall process "                          tr("The max. amount of disk streams the sampler shall process "
286                             "simultaniously.")                             "simultaneously.")
287                  );                  );
288  #else  #else
289          m_ui.MaxVoicesSpinBox->setEnabled(false);          m_ui.MaxVoicesSpinBox->setEnabled(false);
# Line 269  void OptionsForm::setup ( Options *pOpti Line 296  void OptionsForm::setup ( Options *pOpti
296          );          );
297  #endif // CONFIG_MAX_VOICES  #endif // CONFIG_MAX_VOICES
298    
299            // Custom display options...
300            resetCustomColorThemes(m_pOptions->sCustomColorTheme);
301            resetCustomStyleThemes(m_pOptions->sCustomStyleTheme);
302    
303          // Done.          // Done.
304          m_iDirtySetup--;          m_iDirtySetup--;
305          stabilizeForm();          stabilizeForm();
# Line 302  void OptionsForm::accept (void) Line 333  void OptionsForm::accept (void)
333                  m_pOptions->iMessagesLimitLines = m_ui.MessagesLimitLinesSpinBox->value();                  m_pOptions->iMessagesLimitLines = m_ui.MessagesLimitLinesSpinBox->value();
334                  // Other options...                  // Other options...
335                  m_pOptions->bConfirmRemove = m_ui.ConfirmRemoveCheckBox->isChecked();                  m_pOptions->bConfirmRemove = m_ui.ConfirmRemoveCheckBox->isChecked();
336                    m_pOptions->bConfirmRestart = m_ui.ConfirmRestartCheckBox->isChecked();
337                    m_pOptions->bConfirmReset  = m_ui.ConfirmResetCheckBox->isChecked();
338                    m_pOptions->bConfirmError  = m_ui.ConfirmErrorCheckBox->isChecked();
339                  m_pOptions->bKeepOnTop     = m_ui.KeepOnTopCheckBox->isChecked();                  m_pOptions->bKeepOnTop     = m_ui.KeepOnTopCheckBox->isChecked();
340                  m_pOptions->bStdoutCapture = m_ui.StdoutCaptureCheckBox->isChecked();                  m_pOptions->bStdoutCapture = m_ui.StdoutCaptureCheckBox->isChecked();
341                  m_pOptions->bCompletePath  = m_ui.CompletePathCheckBox->isChecked();                  m_pOptions->bCompletePath  = m_ui.CompletePathCheckBox->isChecked();
342                  m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked();                  m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked();
343                  m_pOptions->iMaxRecentFiles  = m_ui.MaxRecentFilesSpinBox->value();                  m_pOptions->iMaxRecentFiles  = m_ui.MaxRecentFilesSpinBox->value();
344                  m_pOptions->iBaseFontSize  = m_ui.BaseFontSizeComboBox->currentText().toInt();                  m_pOptions->iBaseFontSize  = m_ui.BaseFontSizeComboBox->currentText().toInt();
345                    // Custom color/style theme options...
346                    const QString sOldCustomStyleTheme = m_pOptions->sCustomStyleTheme;
347                    if (m_ui.CustomStyleThemeComboBox->currentIndex() > 0)
348                            m_pOptions->sCustomStyleTheme = m_ui.CustomStyleThemeComboBox->currentText();
349                    else
350                            m_pOptions->sCustomStyleTheme.clear();
351                    const QString sOldCustomColorTheme = m_pOptions->sCustomColorTheme;
352                    if (m_ui.CustomColorThemeComboBox->currentIndex() > 0)
353                            m_pOptions->sCustomColorTheme = m_ui.CustomColorThemeComboBox->currentText();
354                    else
355                            m_pOptions->sCustomColorTheme.clear();
356                    // Check whether restart is needed or whether
357                    // custom options maybe set up immediately...
358                    int iNeedRestart = 0;
359                    if (m_pOptions->sCustomStyleTheme != sOldCustomStyleTheme) {
360                            if (m_pOptions->sCustomStyleTheme.isEmpty()) {
361                                    ++iNeedRestart;
362                            } else {
363                                    QApplication::setStyle(
364                                            QStyleFactory::create(m_pOptions->sCustomStyleTheme));
365                            }
366                    }
367                    if (m_pOptions->sCustomColorTheme != sOldCustomColorTheme) {
368                            if (m_pOptions->sCustomColorTheme.isEmpty()) {
369                                    ++iNeedRestart;
370                            } else {
371                                    QPalette pal;
372                                    if (PaletteForm::namedPalette(
373                                                    &m_pOptions->settings(), m_pOptions->sCustomColorTheme, pal))
374                                            QApplication::setPalette(pal);
375                            }
376                    }
377                    // Show restart message if needed...
378                    if (iNeedRestart > 0) {
379                            QMessageBox::information(this,
380                                    tr("Information"),
381                                    tr("Some settings may be only effective\n"
382                                    "next time you start this application."));
383                    }
384                  // Reset dirty flag.                  // Reset dirty flag.
385                  m_iDirtyCount = 0;                  m_iDirtyCount = 0;
386          }          }
# Line 341  void OptionsForm::reject (void) Line 414  void OptionsForm::reject (void)
414          // Check if there's any pending changes...          // Check if there's any pending changes...
415          if (m_iDirtyCount > 0) {          if (m_iDirtyCount > 0) {
416                  switch (QMessageBox::warning(this,                  switch (QMessageBox::warning(this,
417                          QSAMPLER_TITLE ": " + tr("Warning"),                          tr("Warning"),
418                          tr("Some settings have been changed.\n\n"                          tr("Some settings have been changed.\n\n"
419                          "Do you want to apply the changes?"),                          "Do you want to apply the changes?"),
420                          QMessageBox::Apply |                          QMessageBox::Apply |
# Line 397  void OptionsForm::stabilizeForm (void) Line 470  void OptionsForm::stabilizeForm (void)
470          m_ui.MessagesLimitLinesSpinBox->setEnabled(          m_ui.MessagesLimitLinesSpinBox->setEnabled(
471                  m_ui.MessagesLimitCheckBox->isChecked());                  m_ui.MessagesLimitCheckBox->isChecked());
472    
473          m_ui.OkPushButton->setEnabled(bValid);          m_ui.DialogButtonBox->button(QDialogButtonBox::Ok)->setEnabled(bValid);
474  }  }
475    
476    
# Line 477  void OptionsForm::maxStreamsChanged(int Line 550  void OptionsForm::maxStreamsChanged(int
550          optionsChanged();          optionsChanged();
551  }  }
552    
553    
554    // Custom color palette theme manager.
555    void OptionsForm::editCustomColorThemes (void)
556    {
557            PaletteForm form(this);
558            form.setSettings(&m_pOptions->settings());
559    
560            QString sCustomColorTheme;
561            int iDirtyCustomColorTheme = 0;
562    
563            const int iCustomColorTheme
564                    = m_ui.CustomColorThemeComboBox->currentIndex();
565            if (iCustomColorTheme > 0) {
566                    sCustomColorTheme = m_ui.CustomColorThemeComboBox->itemText(
567                            iCustomColorTheme);
568                    form.setPaletteName(sCustomColorTheme);
569            }
570    
571            if (form.exec() == QDialog::Accepted) {
572                    sCustomColorTheme = form.paletteName();
573                    ++iDirtyCustomColorTheme;
574            }
575    
576            if (iDirtyCustomColorTheme > 0 || form.isDirty()) {
577                    resetCustomColorThemes(sCustomColorTheme);
578                    optionsChanged();
579            }
580    }
581    
582    
583    // Custom color palette themes settler.
584    void OptionsForm::resetCustomColorThemes (
585            const QString& sCustomColorTheme )
586    {
587            m_ui.CustomColorThemeComboBox->clear();
588            m_ui.CustomColorThemeComboBox->addItem(
589                    tr(g_pszDefName));
590            m_ui.CustomColorThemeComboBox->addItems(
591                    PaletteForm::namedPaletteList(&m_pOptions->settings()));
592    
593            int iCustomColorTheme = 0;
594            if (!sCustomColorTheme.isEmpty())
595                    iCustomColorTheme = m_ui.CustomColorThemeComboBox->findText(
596                            sCustomColorTheme);
597            m_ui.CustomColorThemeComboBox->setCurrentIndex(iCustomColorTheme);
598    }
599    
600    
601    // Custom widget style themes settler.
602    void OptionsForm::resetCustomStyleThemes (
603            const QString& sCustomStyleTheme )
604    {
605            m_ui.CustomStyleThemeComboBox->clear();
606            m_ui.CustomStyleThemeComboBox->addItem(
607                    tr(g_pszDefName));
608            m_ui.CustomStyleThemeComboBox->addItems(QStyleFactory::keys());
609    
610            int iCustomStyleTheme = 0;
611            if (!sCustomStyleTheme.isEmpty())
612                    iCustomStyleTheme = m_ui.CustomStyleThemeComboBox->findText(
613                            sCustomStyleTheme);
614            m_ui.CustomStyleThemeComboBox->setCurrentIndex(iCustomStyleTheme);
615    }
616    
617    
618  } // namespace QSampler  } // namespace QSampler
619    
620  // end of qsamplerOptionsForm.cpp  // end of qsamplerOptionsForm.cpp

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

  ViewVC Help
Powered by ViewVC