1 |
// qsamplerOptionsForm.cpp |
// qsamplerOptionsForm.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2009, 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 |
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 |
|
|
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 |
|
|
55 |
m_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; |
122 |
QObject::connect(m_ui.ConfirmRemoveCheckBox, |
QObject::connect(m_ui.ConfirmRemoveCheckBox, |
123 |
SIGNAL(stateChanged(int)), |
SIGNAL(stateChanged(int)), |
124 |
SLOT(optionsChanged())); |
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)), |
133 |
|
SLOT(optionsChanged())); |
134 |
QObject::connect(m_ui.KeepOnTopCheckBox, |
QObject::connect(m_ui.KeepOnTopCheckBox, |
135 |
SIGNAL(stateChanged(int)), |
SIGNAL(stateChanged(int)), |
136 |
SLOT(optionsChanged())); |
SLOT(optionsChanged())); |
146 |
QObject::connect(m_ui.InstrumentNamesCheckBox, |
QObject::connect(m_ui.InstrumentNamesCheckBox, |
147 |
SIGNAL(stateChanged(int)), |
SIGNAL(stateChanged(int)), |
148 |
SLOT(optionsChanged())); |
SLOT(optionsChanged())); |
149 |
|
QObject::connect(m_ui.CustomColorThemeComboBox, |
150 |
|
SIGNAL(activated(int)), |
151 |
|
SLOT(optionsChanged())); |
152 |
|
QObject::connect(m_ui.CustomColorThemeToolButton, |
153 |
|
SIGNAL(clicked()), |
154 |
|
SLOT(editCustomColorThemes())); |
155 |
|
QObject::connect(m_ui.CustomStyleThemeComboBox, |
156 |
|
SIGNAL(activated(int)), |
157 |
|
SLOT(optionsChanged())); |
158 |
QObject::connect(m_ui.BaseFontSizeComboBox, |
QObject::connect(m_ui.BaseFontSizeComboBox, |
159 |
SIGNAL(editTextChanged(const QString&)), |
SIGNAL(editTextChanged(const QString&)), |
160 |
SLOT(optionsChanged())); |
SLOT(optionsChanged())); |
164 |
QObject::connect(m_ui.MaxStreamsSpinBox, |
QObject::connect(m_ui.MaxStreamsSpinBox, |
165 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
166 |
SLOT(maxStreamsChanged(int))); |
SLOT(maxStreamsChanged(int))); |
167 |
QObject::connect(m_ui.OkPushButton, |
QObject::connect(m_ui.DialogButtonBox, |
168 |
SIGNAL(clicked()), |
SIGNAL(accepted()), |
169 |
SLOT(accept())); |
SLOT(accept())); |
170 |
QObject::connect(m_ui.CancelPushButton, |
QObject::connect(m_ui.DialogButtonBox, |
171 |
SIGNAL(clicked()), |
SIGNAL(rejected()), |
172 |
SLOT(reject())); |
SLOT(reject())); |
173 |
} |
} |
174 |
|
|
243 |
|
|
244 |
// Other options finally. |
// Other options finally. |
245 |
m_ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove); |
m_ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove); |
246 |
|
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); |
m_ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop); |
250 |
m_ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture); |
m_ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture); |
251 |
m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath); |
m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath); |
277 |
else |
else |
278 |
m_ui.MaxVoicesSpinBox->setToolTip( |
m_ui.MaxVoicesSpinBox->setToolTip( |
279 |
tr("The max. amount of voices the sampler shall process " |
tr("The max. amount of voices the sampler shall process " |
280 |
"simultaniously.") |
"simultaneously.") |
281 |
); |
); |
282 |
|
|
283 |
m_ui.MaxStreamsSpinBox->setEnabled(bMaxStreamsSupported); |
m_ui.MaxStreamsSpinBox->setEnabled(bMaxStreamsSupported); |
290 |
else |
else |
291 |
m_ui.MaxStreamsSpinBox->setToolTip( |
m_ui.MaxStreamsSpinBox->setToolTip( |
292 |
tr("The max. amount of disk streams the sampler shall process " |
tr("The max. amount of disk streams the sampler shall process " |
293 |
"simultaniously.") |
"simultaneously.") |
294 |
); |
); |
295 |
#else |
#else |
296 |
m_ui.MaxVoicesSpinBox->setEnabled(false); |
m_ui.MaxVoicesSpinBox->setEnabled(false); |
303 |
); |
); |
304 |
#endif // CONFIG_MAX_VOICES |
#endif // CONFIG_MAX_VOICES |
305 |
|
|
306 |
|
// Custom display options... |
307 |
|
resetCustomColorThemes(m_pOptions->sCustomColorTheme); |
308 |
|
resetCustomStyleThemes(m_pOptions->sCustomStyleTheme); |
309 |
|
|
310 |
// Done. |
// Done. |
311 |
m_iDirtySetup--; |
m_iDirtySetup--; |
312 |
stabilizeForm(); |
stabilizeForm(); |
340 |
m_pOptions->iMessagesLimitLines = m_ui.MessagesLimitLinesSpinBox->value(); |
m_pOptions->iMessagesLimitLines = m_ui.MessagesLimitLinesSpinBox->value(); |
341 |
// Other options... |
// Other options... |
342 |
m_pOptions->bConfirmRemove = m_ui.ConfirmRemoveCheckBox->isChecked(); |
m_pOptions->bConfirmRemove = m_ui.ConfirmRemoveCheckBox->isChecked(); |
343 |
|
m_pOptions->bConfirmRestart = m_ui.ConfirmRestartCheckBox->isChecked(); |
344 |
|
m_pOptions->bConfirmReset = m_ui.ConfirmResetCheckBox->isChecked(); |
345 |
|
m_pOptions->bConfirmError = m_ui.ConfirmErrorCheckBox->isChecked(); |
346 |
m_pOptions->bKeepOnTop = m_ui.KeepOnTopCheckBox->isChecked(); |
m_pOptions->bKeepOnTop = m_ui.KeepOnTopCheckBox->isChecked(); |
347 |
m_pOptions->bStdoutCapture = m_ui.StdoutCaptureCheckBox->isChecked(); |
m_pOptions->bStdoutCapture = m_ui.StdoutCaptureCheckBox->isChecked(); |
348 |
m_pOptions->bCompletePath = m_ui.CompletePathCheckBox->isChecked(); |
m_pOptions->bCompletePath = m_ui.CompletePathCheckBox->isChecked(); |
349 |
m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked(); |
m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked(); |
350 |
m_pOptions->iMaxRecentFiles = m_ui.MaxRecentFilesSpinBox->value(); |
m_pOptions->iMaxRecentFiles = m_ui.MaxRecentFilesSpinBox->value(); |
351 |
m_pOptions->iBaseFontSize = m_ui.BaseFontSizeComboBox->currentText().toInt(); |
m_pOptions->iBaseFontSize = m_ui.BaseFontSizeComboBox->currentText().toInt(); |
352 |
|
// 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. |
// Reset dirty flag. |
392 |
m_iDirtyCount = 0; |
m_iDirtyCount = 0; |
393 |
} |
} |
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 |
QMessageBox::Apply | |
QMessageBox::Apply | |
477 |
m_ui.MessagesLimitLinesSpinBox->setEnabled( |
m_ui.MessagesLimitLinesSpinBox->setEnabled( |
478 |
m_ui.MessagesLimitCheckBox->isChecked()); |
m_ui.MessagesLimitCheckBox->isChecked()); |
479 |
|
|
480 |
m_ui.OkPushButton->setEnabled(bValid); |
m_ui.DialogButtonBox->button(QDialogButtonBox::Ok)->setEnabled(bValid); |
481 |
} |
} |
482 |
|
|
483 |
|
|
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); |
557 |
optionsChanged(); |
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 |
} // namespace QSampler |
632 |
|
|
633 |
// end of qsamplerOptionsForm.cpp |
// end of qsamplerOptionsForm.cpp |