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 |
|
// Default (empty/blank) name. |
38 |
|
static const char *g_pszDefName = QT_TRANSLATE_NOOP("qsamplerOptionsForm", "(default)"); |
39 |
|
|
40 |
|
|
41 |
namespace QSampler { |
namespace QSampler { |
42 |
|
|
50 |
m_ui.setupUi(this); |
m_ui.setupUi(this); |
51 |
|
|
52 |
// No settings descriptor initially (the caller will set it). |
// No settings descriptor initially (the caller will set it). |
53 |
m_pOptions = NULL; |
m_pOptions = nullptr; |
54 |
|
|
55 |
// Initialize dirty control state. |
// Initialize dirty control state. |
56 |
m_iDirtySetup = 0; |
m_iDirtySetup = 0; |
117 |
QObject::connect(m_ui.ConfirmRemoveCheckBox, |
QObject::connect(m_ui.ConfirmRemoveCheckBox, |
118 |
SIGNAL(stateChanged(int)), |
SIGNAL(stateChanged(int)), |
119 |
SLOT(optionsChanged())); |
SLOT(optionsChanged())); |
120 |
|
QObject::connect(m_ui.ConfirmResetCheckBox, |
121 |
|
SIGNAL(stateChanged(int)), |
122 |
|
SLOT(optionsChanged())); |
123 |
|
QObject::connect(m_ui.ConfirmRestartCheckBox, |
124 |
|
SIGNAL(stateChanged(int)), |
125 |
|
SLOT(optionsChanged())); |
126 |
|
QObject::connect(m_ui.ConfirmErrorCheckBox, |
127 |
|
SIGNAL(stateChanged(int)), |
128 |
|
SLOT(optionsChanged())); |
129 |
QObject::connect(m_ui.KeepOnTopCheckBox, |
QObject::connect(m_ui.KeepOnTopCheckBox, |
130 |
SIGNAL(stateChanged(int)), |
SIGNAL(stateChanged(int)), |
131 |
SLOT(optionsChanged())); |
SLOT(optionsChanged())); |
141 |
QObject::connect(m_ui.InstrumentNamesCheckBox, |
QObject::connect(m_ui.InstrumentNamesCheckBox, |
142 |
SIGNAL(stateChanged(int)), |
SIGNAL(stateChanged(int)), |
143 |
SLOT(optionsChanged())); |
SLOT(optionsChanged())); |
144 |
|
QObject::connect(m_ui.CustomColorThemeComboBox, |
145 |
|
SIGNAL(activated(int)), |
146 |
|
SLOT(optionsChanged())); |
147 |
|
QObject::connect(m_ui.CustomColorThemeToolButton, |
148 |
|
SIGNAL(clicked()), |
149 |
|
SLOT(editCustomColorThemes())); |
150 |
|
QObject::connect(m_ui.CustomStyleThemeComboBox, |
151 |
|
SIGNAL(activated(int)), |
152 |
|
SLOT(optionsChanged())); |
153 |
QObject::connect(m_ui.BaseFontSizeComboBox, |
QObject::connect(m_ui.BaseFontSizeComboBox, |
154 |
SIGNAL(editTextChanged(const QString&)), |
SIGNAL(editTextChanged(const QString&)), |
155 |
SLOT(optionsChanged())); |
SLOT(optionsChanged())); |
159 |
QObject::connect(m_ui.MaxStreamsSpinBox, |
QObject::connect(m_ui.MaxStreamsSpinBox, |
160 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
161 |
SLOT(maxStreamsChanged(int))); |
SLOT(maxStreamsChanged(int))); |
162 |
QObject::connect(m_ui.OkPushButton, |
QObject::connect(m_ui.DialogButtonBox, |
163 |
SIGNAL(clicked()), |
SIGNAL(accepted()), |
164 |
SLOT(accept())); |
SLOT(accept())); |
165 |
QObject::connect(m_ui.CancelPushButton, |
QObject::connect(m_ui.DialogButtonBox, |
166 |
SIGNAL(clicked()), |
SIGNAL(rejected()), |
167 |
SLOT(reject())); |
SLOT(reject())); |
168 |
} |
} |
169 |
|
|
238 |
|
|
239 |
// Other options finally. |
// Other options finally. |
240 |
m_ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove); |
m_ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove); |
241 |
|
m_ui.ConfirmRestartCheckBox->setChecked(m_pOptions->bConfirmRestart); |
242 |
|
m_ui.ConfirmResetCheckBox->setChecked(m_pOptions->bConfirmReset); |
243 |
|
m_ui.ConfirmErrorCheckBox->setChecked(m_pOptions->bConfirmError); |
244 |
m_ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop); |
m_ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop); |
245 |
m_ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture); |
m_ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture); |
246 |
m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath); |
m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath); |
272 |
else |
else |
273 |
m_ui.MaxVoicesSpinBox->setToolTip( |
m_ui.MaxVoicesSpinBox->setToolTip( |
274 |
tr("The max. amount of voices the sampler shall process " |
tr("The max. amount of voices the sampler shall process " |
275 |
"simultaniously.") |
"simultaneously.") |
276 |
); |
); |
277 |
|
|
278 |
m_ui.MaxStreamsSpinBox->setEnabled(bMaxStreamsSupported); |
m_ui.MaxStreamsSpinBox->setEnabled(bMaxStreamsSupported); |
285 |
else |
else |
286 |
m_ui.MaxStreamsSpinBox->setToolTip( |
m_ui.MaxStreamsSpinBox->setToolTip( |
287 |
tr("The max. amount of disk streams the sampler shall process " |
tr("The max. amount of disk streams the sampler shall process " |
288 |
"simultaniously.") |
"simultaneously.") |
289 |
); |
); |
290 |
#else |
#else |
291 |
m_ui.MaxVoicesSpinBox->setEnabled(false); |
m_ui.MaxVoicesSpinBox->setEnabled(false); |
298 |
); |
); |
299 |
#endif // CONFIG_MAX_VOICES |
#endif // CONFIG_MAX_VOICES |
300 |
|
|
301 |
|
// Custom display options... |
302 |
|
resetCustomColorThemes(m_pOptions->sCustomColorTheme); |
303 |
|
resetCustomStyleThemes(m_pOptions->sCustomStyleTheme); |
304 |
|
|
305 |
// Done. |
// Done. |
306 |
m_iDirtySetup--; |
m_iDirtySetup--; |
307 |
stabilizeForm(); |
stabilizeForm(); |
335 |
m_pOptions->iMessagesLimitLines = m_ui.MessagesLimitLinesSpinBox->value(); |
m_pOptions->iMessagesLimitLines = m_ui.MessagesLimitLinesSpinBox->value(); |
336 |
// Other options... |
// Other options... |
337 |
m_pOptions->bConfirmRemove = m_ui.ConfirmRemoveCheckBox->isChecked(); |
m_pOptions->bConfirmRemove = m_ui.ConfirmRemoveCheckBox->isChecked(); |
338 |
|
m_pOptions->bConfirmRestart = m_ui.ConfirmRestartCheckBox->isChecked(); |
339 |
|
m_pOptions->bConfirmReset = m_ui.ConfirmResetCheckBox->isChecked(); |
340 |
|
m_pOptions->bConfirmError = m_ui.ConfirmErrorCheckBox->isChecked(); |
341 |
m_pOptions->bKeepOnTop = m_ui.KeepOnTopCheckBox->isChecked(); |
m_pOptions->bKeepOnTop = m_ui.KeepOnTopCheckBox->isChecked(); |
342 |
m_pOptions->bStdoutCapture = m_ui.StdoutCaptureCheckBox->isChecked(); |
m_pOptions->bStdoutCapture = m_ui.StdoutCaptureCheckBox->isChecked(); |
343 |
m_pOptions->bCompletePath = m_ui.CompletePathCheckBox->isChecked(); |
m_pOptions->bCompletePath = m_ui.CompletePathCheckBox->isChecked(); |
344 |
m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked(); |
m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked(); |
345 |
m_pOptions->iMaxRecentFiles = m_ui.MaxRecentFilesSpinBox->value(); |
m_pOptions->iMaxRecentFiles = m_ui.MaxRecentFilesSpinBox->value(); |
346 |
m_pOptions->iBaseFontSize = m_ui.BaseFontSizeComboBox->currentText().toInt(); |
m_pOptions->iBaseFontSize = m_ui.BaseFontSizeComboBox->currentText().toInt(); |
347 |
|
// Custom color/style theme options... |
348 |
|
const QString sOldCustomStyleTheme = m_pOptions->sCustomStyleTheme; |
349 |
|
if (m_ui.CustomStyleThemeComboBox->currentIndex() > 0) |
350 |
|
m_pOptions->sCustomStyleTheme = m_ui.CustomStyleThemeComboBox->currentText(); |
351 |
|
else |
352 |
|
m_pOptions->sCustomStyleTheme.clear(); |
353 |
|
const QString sOldCustomColorTheme = m_pOptions->sCustomColorTheme; |
354 |
|
if (m_ui.CustomColorThemeComboBox->currentIndex() > 0) |
355 |
|
m_pOptions->sCustomColorTheme = m_ui.CustomColorThemeComboBox->currentText(); |
356 |
|
else |
357 |
|
m_pOptions->sCustomColorTheme.clear(); |
358 |
|
// Check whether restart is needed or whether |
359 |
|
// custom options maybe set up immediately... |
360 |
|
int iNeedRestart = 0; |
361 |
|
if (m_pOptions->sCustomStyleTheme != sOldCustomStyleTheme) { |
362 |
|
if (m_pOptions->sCustomStyleTheme.isEmpty()) { |
363 |
|
++iNeedRestart; |
364 |
|
} else { |
365 |
|
QApplication::setStyle( |
366 |
|
QStyleFactory::create(m_pOptions->sCustomStyleTheme)); |
367 |
|
} |
368 |
|
} |
369 |
|
if (m_pOptions->sCustomColorTheme != sOldCustomColorTheme) { |
370 |
|
if (m_pOptions->sCustomColorTheme.isEmpty()) { |
371 |
|
++iNeedRestart; |
372 |
|
} else { |
373 |
|
QPalette pal; |
374 |
|
if (PaletteForm::namedPalette( |
375 |
|
&m_pOptions->settings(), m_pOptions->sCustomColorTheme, pal)) |
376 |
|
QApplication::setPalette(pal); |
377 |
|
} |
378 |
|
} |
379 |
|
// Show restart message if needed... |
380 |
|
if (iNeedRestart > 0) { |
381 |
|
QMessageBox::information(this, |
382 |
|
tr("Information"), |
383 |
|
tr("Some settings may be only effective\n" |
384 |
|
"next time you start this application.")); |
385 |
|
} |
386 |
// Reset dirty flag. |
// Reset dirty flag. |
387 |
m_iDirtyCount = 0; |
m_iDirtyCount = 0; |
388 |
} |
} |
400 |
m_pOptions->saveComboBoxHistory(m_ui.ServerCmdLineComboBox); |
m_pOptions->saveComboBoxHistory(m_ui.ServerCmdLineComboBox); |
401 |
m_pOptions->saveComboBoxHistory(m_ui.MessagesLogPathComboBox); |
m_pOptions->saveComboBoxHistory(m_ui.MessagesLogPathComboBox); |
402 |
|
|
403 |
|
// Save/commit to disk. |
404 |
|
m_pOptions->saveOptions(); |
405 |
|
|
406 |
// Just go with dialog acceptance. |
// Just go with dialog acceptance. |
407 |
QDialog::accept(); |
QDialog::accept(); |
408 |
} |
} |
416 |
// Check if there's any pending changes... |
// Check if there's any pending changes... |
417 |
if (m_iDirtyCount > 0) { |
if (m_iDirtyCount > 0) { |
418 |
switch (QMessageBox::warning(this, |
switch (QMessageBox::warning(this, |
419 |
QSAMPLER_TITLE ": " + tr("Warning"), |
tr("Warning"), |
420 |
tr("Some settings have been changed.\n\n" |
tr("Some settings have been changed.\n\n" |
421 |
"Do you want to apply the changes?"), |
"Do you want to apply the changes?"), |
422 |
QMessageBox::Apply | |
QMessageBox::Apply | |
472 |
m_ui.MessagesLimitLinesSpinBox->setEnabled( |
m_ui.MessagesLimitLinesSpinBox->setEnabled( |
473 |
m_ui.MessagesLimitCheckBox->isChecked()); |
m_ui.MessagesLimitCheckBox->isChecked()); |
474 |
|
|
475 |
m_ui.OkPushButton->setEnabled(bValid); |
m_ui.DialogButtonBox->button(QDialogButtonBox::Ok)->setEnabled(bValid); |
476 |
} |
} |
477 |
|
|
478 |
|
|
530 |
QPalette pal; |
QPalette pal; |
531 |
pal.setColor(QPalette::Foreground, Qt::green); |
pal.setColor(QPalette::Foreground, Qt::green); |
532 |
if (bOn) { |
if (bOn) { |
533 |
QPixmap pm(":/icons/displaybg1.png"); |
QPixmap pm(":/images/displaybg1.png"); |
534 |
pal.setBrush(QPalette::Background, QBrush(pm)); |
pal.setBrush(QPalette::Background, QBrush(pm)); |
535 |
} else { |
} else { |
536 |
pal.setColor(QPalette::Background, Qt::black); |
pal.setColor(QPalette::Background, Qt::black); |
552 |
optionsChanged(); |
optionsChanged(); |
553 |
} |
} |
554 |
|
|
555 |
|
|
556 |
|
// Custom color palette theme manager. |
557 |
|
void OptionsForm::editCustomColorThemes (void) |
558 |
|
{ |
559 |
|
PaletteForm form(this); |
560 |
|
form.setSettings(&m_pOptions->settings()); |
561 |
|
|
562 |
|
QString sCustomColorTheme; |
563 |
|
int iDirtyCustomColorTheme = 0; |
564 |
|
|
565 |
|
const int iCustomColorTheme |
566 |
|
= m_ui.CustomColorThemeComboBox->currentIndex(); |
567 |
|
if (iCustomColorTheme > 0) { |
568 |
|
sCustomColorTheme = m_ui.CustomColorThemeComboBox->itemText( |
569 |
|
iCustomColorTheme); |
570 |
|
form.setPaletteName(sCustomColorTheme); |
571 |
|
} |
572 |
|
|
573 |
|
if (form.exec() == QDialog::Accepted) { |
574 |
|
sCustomColorTheme = form.paletteName(); |
575 |
|
++iDirtyCustomColorTheme; |
576 |
|
} |
577 |
|
|
578 |
|
if (iDirtyCustomColorTheme > 0 || form.isDirty()) { |
579 |
|
resetCustomColorThemes(sCustomColorTheme); |
580 |
|
optionsChanged(); |
581 |
|
} |
582 |
|
} |
583 |
|
|
584 |
|
|
585 |
|
// Custom color palette themes settler. |
586 |
|
void OptionsForm::resetCustomColorThemes ( |
587 |
|
const QString& sCustomColorTheme ) |
588 |
|
{ |
589 |
|
m_ui.CustomColorThemeComboBox->clear(); |
590 |
|
m_ui.CustomColorThemeComboBox->addItem( |
591 |
|
tr(g_pszDefName)); |
592 |
|
m_ui.CustomColorThemeComboBox->addItems( |
593 |
|
PaletteForm::namedPaletteList(&m_pOptions->settings())); |
594 |
|
|
595 |
|
int iCustomColorTheme = 0; |
596 |
|
if (!sCustomColorTheme.isEmpty()) { |
597 |
|
iCustomColorTheme = m_ui.CustomColorThemeComboBox->findText( |
598 |
|
sCustomColorTheme); |
599 |
|
if (iCustomColorTheme < 0) |
600 |
|
iCustomColorTheme = 0; |
601 |
|
} |
602 |
|
m_ui.CustomColorThemeComboBox->setCurrentIndex(iCustomColorTheme); |
603 |
|
} |
604 |
|
|
605 |
|
|
606 |
|
// Custom widget style themes settler. |
607 |
|
void OptionsForm::resetCustomStyleThemes ( |
608 |
|
const QString& sCustomStyleTheme ) |
609 |
|
{ |
610 |
|
m_ui.CustomStyleThemeComboBox->clear(); |
611 |
|
m_ui.CustomStyleThemeComboBox->addItem( |
612 |
|
tr(g_pszDefName)); |
613 |
|
m_ui.CustomStyleThemeComboBox->addItems(QStyleFactory::keys()); |
614 |
|
|
615 |
|
int iCustomStyleTheme = 0; |
616 |
|
if (!sCustomStyleTheme.isEmpty()) { |
617 |
|
iCustomStyleTheme = m_ui.CustomStyleThemeComboBox->findText( |
618 |
|
sCustomStyleTheme); |
619 |
|
if (iCustomStyleTheme < 0) |
620 |
|
iCustomStyleTheme = 0; |
621 |
|
} |
622 |
|
m_ui.CustomStyleThemeComboBox->setCurrentIndex(iCustomStyleTheme); |
623 |
|
} |
624 |
|
|
625 |
|
|
626 |
} // namespace QSampler |
} // namespace QSampler |
627 |
|
|
628 |
// end of qsamplerOptionsForm.cpp |
// end of qsamplerOptionsForm.cpp |