1 |
schoenebeck |
1461 |
#include "qsamplerOptionsForm.h" |
2 |
|
|
|
3 |
|
|
#include "qsamplerAbout.h" |
4 |
|
|
#include "qsamplerOptions.h" |
5 |
|
|
|
6 |
|
|
#include <QMessageBox> |
7 |
|
|
#include <QFontDialog> |
8 |
|
|
|
9 |
|
|
namespace QSampler { |
10 |
|
|
|
11 |
|
|
OptionsForm::OptionsForm(QWidget* parent) : QDialog(parent) { |
12 |
|
|
ui.setupUi(this); |
13 |
|
|
|
14 |
|
|
// No settings descriptor initially (the caller will set it). |
15 |
|
|
m_pOptions = NULL; |
16 |
|
|
|
17 |
|
|
// Initialize dirty control state. |
18 |
|
|
m_iDirtySetup = 0; |
19 |
|
|
m_iDirtyCount = 0; |
20 |
|
|
|
21 |
|
|
// Set dialog validators... |
22 |
|
|
ui.ServerPortComboBox->setValidator(new QIntValidator(ui.ServerPortComboBox)); |
23 |
|
|
|
24 |
|
|
// Try to restore old window positioning. |
25 |
|
|
adjustSize(); |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
OptionsForm::~OptionsForm() { |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
// Populate (setup) dialog controls from settings descriptors. |
32 |
|
|
void OptionsForm::setup ( qsamplerOptions *pOptions ) |
33 |
|
|
{ |
34 |
|
|
// Set reference descriptor. |
35 |
|
|
m_pOptions = pOptions; |
36 |
|
|
|
37 |
|
|
// Start clean. |
38 |
|
|
m_iDirtyCount = 0; |
39 |
|
|
// Avoid nested changes. |
40 |
|
|
m_iDirtySetup++; |
41 |
|
|
|
42 |
|
|
// Load combo box history... |
43 |
|
|
m_pOptions->loadComboBoxHistory(ui.ServerHostComboBox); |
44 |
|
|
m_pOptions->loadComboBoxHistory(ui.ServerPortComboBox); |
45 |
|
|
m_pOptions->loadComboBoxHistory(ui.ServerCmdLineComboBox); |
46 |
|
|
|
47 |
|
|
// Load Server settings... |
48 |
|
|
ui.ServerHostComboBox->setCurrentText(m_pOptions->sServerHost); |
49 |
|
|
ui.ServerPortComboBox->setCurrentText(QString::number(m_pOptions->iServerPort)); |
50 |
|
|
ui.ServerTimeoutSpinBox->setValue(m_pOptions->iServerTimeout); |
51 |
|
|
ui.ServerStartCheckBox->setChecked(m_pOptions->bServerStart); |
52 |
|
|
ui.ServerCmdLineComboBox->setCurrentText(m_pOptions->sServerCmdLine); |
53 |
|
|
ui.StartDelaySpinBox->setValue(m_pOptions->iStartDelay); |
54 |
|
|
|
55 |
|
|
// Load Display options... |
56 |
|
|
QFont font; |
57 |
|
|
|
58 |
|
|
// Display font. |
59 |
|
|
if (m_pOptions->sDisplayFont.isEmpty() || !font.fromString(m_pOptions->sDisplayFont)) |
60 |
|
|
font = QFont("Sans Serif", 8); |
61 |
|
|
ui.DisplayFontTextLabel->setFont(font); |
62 |
|
|
ui.DisplayFontTextLabel->setText(font.family() + " " + QString::number(font.pointSize())); |
63 |
|
|
|
64 |
|
|
// Display effect. |
65 |
|
|
ui.DisplayEffectCheckBox->setChecked(m_pOptions->bDisplayEffect); |
66 |
|
|
toggleDisplayEffect(m_pOptions->bDisplayEffect); |
67 |
|
|
|
68 |
|
|
// Auto-refresh and maximum volume options. |
69 |
|
|
ui.AutoRefreshCheckBox->setChecked(m_pOptions->bAutoRefresh); |
70 |
|
|
ui.AutoRefreshTimeSpinBox->setValue(m_pOptions->iAutoRefreshTime); |
71 |
|
|
ui.MaxVolumeSpinBox->setValue(m_pOptions->iMaxVolume); |
72 |
|
|
|
73 |
|
|
// Messages font. |
74 |
|
|
if (m_pOptions->sMessagesFont.isEmpty() || !font.fromString(m_pOptions->sMessagesFont)) |
75 |
|
|
font = QFont("Fixed", 8); |
76 |
|
|
ui.MessagesFontTextLabel->setFont(font); |
77 |
|
|
ui.MessagesFontTextLabel->setText(font.family() + " " + QString::number(font.pointSize())); |
78 |
|
|
|
79 |
|
|
// Messages limit option. |
80 |
|
|
ui.MessagesLimitCheckBox->setChecked(m_pOptions->bMessagesLimit); |
81 |
|
|
ui.MessagesLimitLinesSpinBox->setValue(m_pOptions->iMessagesLimitLines); |
82 |
|
|
|
83 |
|
|
// Other options finally. |
84 |
|
|
ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove); |
85 |
|
|
ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop); |
86 |
|
|
ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture); |
87 |
|
|
ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath); |
88 |
|
|
ui.InstrumentNamesCheckBox->setChecked(m_pOptions->bInstrumentNames); |
89 |
|
|
ui.MaxRecentFilesSpinBox->setValue(m_pOptions->iMaxRecentFiles); |
90 |
|
|
|
91 |
|
|
#ifndef CONFIG_LIBGIG |
92 |
|
|
ui.InstrumentNamesCheckBox->setEnabled(false); |
93 |
|
|
#endif |
94 |
|
|
|
95 |
|
|
// Done. |
96 |
|
|
m_iDirtySetup--; |
97 |
|
|
stabilizeForm(); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
|
101 |
|
|
// Accept settings (OK button slot). |
102 |
|
|
void OptionsForm::accept (void) |
103 |
|
|
{ |
104 |
|
|
// Save options... |
105 |
|
|
if (m_iDirtyCount > 0) { |
106 |
|
|
// Server settings.... |
107 |
|
|
m_pOptions->sServerHost = ui.ServerHostComboBox->currentText().stripWhiteSpace(); |
108 |
|
|
m_pOptions->iServerPort = ui.ServerPortComboBox->currentText().toInt(); |
109 |
|
|
m_pOptions->iServerTimeout = ui.ServerTimeoutSpinBox->value(); |
110 |
|
|
m_pOptions->bServerStart = ui.ServerStartCheckBox->isChecked(); |
111 |
|
|
m_pOptions->sServerCmdLine = ui.ServerCmdLineComboBox->currentText().stripWhiteSpace(); |
112 |
|
|
m_pOptions->iStartDelay = ui.StartDelaySpinBox->value(); |
113 |
|
|
// Channels options... |
114 |
|
|
m_pOptions->sDisplayFont = ui.DisplayFontTextLabel->font().toString(); |
115 |
|
|
m_pOptions->bDisplayEffect = ui.DisplayEffectCheckBox->isChecked(); |
116 |
|
|
m_pOptions->bAutoRefresh = ui.AutoRefreshCheckBox->isChecked(); |
117 |
|
|
m_pOptions->iAutoRefreshTime = ui.AutoRefreshTimeSpinBox->value(); |
118 |
|
|
m_pOptions->iMaxVolume = ui.MaxVolumeSpinBox->value(); |
119 |
|
|
// Messages options... |
120 |
|
|
m_pOptions->sMessagesFont = ui.MessagesFontTextLabel->font().toString(); |
121 |
|
|
m_pOptions->bMessagesLimit = ui.MessagesLimitCheckBox->isChecked(); |
122 |
|
|
m_pOptions->iMessagesLimitLines = ui.MessagesLimitLinesSpinBox->value(); |
123 |
|
|
// Other options... |
124 |
|
|
m_pOptions->bConfirmRemove = ui.ConfirmRemoveCheckBox->isChecked(); |
125 |
|
|
m_pOptions->bKeepOnTop = ui.KeepOnTopCheckBox->isChecked(); |
126 |
|
|
m_pOptions->bStdoutCapture = ui.StdoutCaptureCheckBox->isChecked(); |
127 |
|
|
m_pOptions->bCompletePath = ui.CompletePathCheckBox->isChecked(); |
128 |
|
|
m_pOptions->bInstrumentNames = ui.InstrumentNamesCheckBox->isChecked(); |
129 |
|
|
m_pOptions->iMaxRecentFiles = ui.MaxRecentFilesSpinBox->value(); |
130 |
|
|
// Reset dirty flag. |
131 |
|
|
m_iDirtyCount = 0; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
// Save combobox history... |
135 |
|
|
m_pOptions->saveComboBoxHistory(ui.ServerHostComboBox); |
136 |
|
|
m_pOptions->saveComboBoxHistory(ui.ServerPortComboBox); |
137 |
|
|
m_pOptions->saveComboBoxHistory(ui.ServerCmdLineComboBox); |
138 |
|
|
|
139 |
|
|
// Just go with dialog acceptance. |
140 |
|
|
QDialog::accept(); |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
|
144 |
|
|
// Reject settings (Cancel button slot). |
145 |
|
|
void OptionsForm::reject (void) |
146 |
|
|
{ |
147 |
|
|
bool bReject = true; |
148 |
|
|
|
149 |
|
|
// Check if there's any pending changes... |
150 |
|
|
if (m_iDirtyCount > 0) { |
151 |
|
|
switch (QMessageBox::warning(this, |
152 |
|
|
QSAMPLER_TITLE ": " + tr("Warning"), |
153 |
|
|
tr("Some settings have been changed.\n\n" |
154 |
|
|
"Do you want to apply the changes?"), |
155 |
|
|
tr("Apply"), tr("Discard"), tr("Cancel"))) { |
156 |
|
|
case 0: // Apply... |
157 |
|
|
accept(); |
158 |
|
|
return; |
159 |
|
|
case 1: // Discard |
160 |
|
|
break; |
161 |
|
|
default: // Cancel. |
162 |
|
|
bReject = false; |
163 |
|
|
} |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
if (bReject) |
167 |
|
|
QDialog::reject(); |
168 |
|
|
} |
169 |
|
|
|
170 |
|
|
|
171 |
|
|
// Dirty up settings. |
172 |
|
|
void OptionsForm::optionsChanged (void) |
173 |
|
|
{ |
174 |
|
|
if (m_iDirtySetup > 0) |
175 |
|
|
return; |
176 |
|
|
|
177 |
|
|
m_iDirtyCount++; |
178 |
|
|
stabilizeForm(); |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
|
182 |
|
|
// Stabilize current form state. |
183 |
|
|
void OptionsForm::stabilizeForm (void) |
184 |
|
|
{ |
185 |
|
|
bool bEnabled = ui.ServerStartCheckBox->isChecked(); |
186 |
|
|
ui.ServerCmdLineTextLabel->setEnabled(bEnabled); |
187 |
|
|
ui.ServerCmdLineComboBox->setEnabled(bEnabled); |
188 |
|
|
ui.StartDelayTextLabel->setEnabled(bEnabled); |
189 |
|
|
ui.StartDelaySpinBox->setEnabled(bEnabled); |
190 |
|
|
|
191 |
|
|
ui.AutoRefreshTimeSpinBox->setEnabled(ui.AutoRefreshCheckBox->isChecked()); |
192 |
|
|
ui.MessagesLimitLinesSpinBox->setEnabled(ui.MessagesLimitCheckBox->isChecked()); |
193 |
|
|
|
194 |
|
|
ui.OkPushButton->setEnabled(m_iDirtyCount > 0); |
195 |
|
|
} |
196 |
|
|
|
197 |
|
|
|
198 |
|
|
// The channel display font selection dialog. |
199 |
|
|
void OptionsForm::chooseDisplayFont (void) |
200 |
|
|
{ |
201 |
|
|
bool bOk = false; |
202 |
|
|
QFont font = QFontDialog::getFont(&bOk, ui.DisplayFontTextLabel->font(), this); |
203 |
|
|
if (bOk) { |
204 |
|
|
ui.DisplayFontTextLabel->setFont(font); |
205 |
|
|
ui.DisplayFontTextLabel->setText(font.family() + " " + QString::number(font.pointSize())); |
206 |
|
|
optionsChanged(); |
207 |
|
|
} |
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
|
211 |
|
|
// The messages font selection dialog. |
212 |
|
|
void OptionsForm::chooseMessagesFont (void) |
213 |
|
|
{ |
214 |
|
|
bool bOk = false; |
215 |
|
|
QFont font = QFontDialog::getFont(&bOk, ui.MessagesFontTextLabel->font(), this); |
216 |
|
|
if (bOk) { |
217 |
|
|
ui.MessagesFontTextLabel->setFont(font); |
218 |
|
|
ui.MessagesFontTextLabel->setText(font.family() + " " + QString::number(font.pointSize())); |
219 |
|
|
optionsChanged(); |
220 |
|
|
} |
221 |
|
|
} |
222 |
|
|
|
223 |
|
|
|
224 |
|
|
// The channel display effect demo changer. |
225 |
|
|
void OptionsForm::toggleDisplayEffect ( bool bOn ) |
226 |
|
|
{ |
227 |
|
|
QPixmap pm; |
228 |
|
|
if (bOn) |
229 |
|
|
pm = QPixmap(":/qsampler/pixmaps/displaybg1.png"); |
230 |
|
|
ui.DisplayFontTextLabel->setPaletteBackgroundPixmap(pm); |
231 |
|
|
|
232 |
|
|
optionsChanged(); |
233 |
|
|
} |
234 |
|
|
|
235 |
|
|
} // namespace QSampler |