/[svn]/qsampler/trunk/src/qsamplerOptionsForm.cpp
ViewVC logotype

Contents of /qsampler/trunk/src/qsamplerOptionsForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1464 - (show annotations) (download)
Thu Nov 1 17:14:21 2007 UTC (16 years, 4 months ago) by capela
File size: 9121 byte(s)
- Qt4 migration: missing copyright headers update.

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

  ViewVC Help
Powered by ViewVC