-rw-r--r-- | libkdepim/kprefswidget.cpp | 427 | ||||
-rw-r--r-- | libkdepim/kprefswidget.h | 454 |
2 files changed, 881 insertions, 0 deletions
diff --git a/libkdepim/kprefswidget.cpp b/libkdepim/kprefswidget.cpp new file mode 100644 index 0000000..be9ad30 --- a/dev/null +++ b/libkdepim/kprefswidget.cpp | |||
@@ -0,0 +1,427 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | */ | ||
23 | |||
24 | // $Id$ | ||
25 | |||
26 | #include <qlayout.h> | ||
27 | #include <qlabel.h> | ||
28 | #include <qgroupbox.h> | ||
29 | #include <qbuttongroup.h> | ||
30 | #include <qlineedit.h> | ||
31 | #include <qfont.h> | ||
32 | #include <qslider.h> | ||
33 | #include <qfile.h> | ||
34 | #include <qtextstream.h> | ||
35 | #include <qvbox.h> | ||
36 | #include <qhbox.h> | ||
37 | #include <qspinbox.h> | ||
38 | #include <qdatetime.h> | ||
39 | #include <qframe.h> | ||
40 | #include <qcombobox.h> | ||
41 | #include <qcheckbox.h> | ||
42 | #include <qradiobutton.h> | ||
43 | #include <qpushbutton.h> | ||
44 | #include <qapplication.h> | ||
45 | |||
46 | #include <kcolorbutton.h> | ||
47 | #include <kdebug.h> | ||
48 | #include <klocale.h> | ||
49 | #include <kglobal.h> | ||
50 | #include <kfontdialog.h> | ||
51 | #include <kmessagebox.h> | ||
52 | #include <kcolordialog.h> | ||
53 | #include <kiconloader.h> | ||
54 | |||
55 | #include "kprefs.h" | ||
56 | |||
57 | #include "kprefswidget.h" | ||
58 | //#include "kprefsdialog.moc" | ||
59 | |||
60 | KPrefsWidBool::KPrefsWidBool(const QString &text,bool *reference, | ||
61 | QWidget *parent) | ||
62 | { | ||
63 | mReference = reference; | ||
64 | |||
65 | mCheck = new QCheckBox(text,parent); | ||
66 | |||
67 | connect( mCheck, SIGNAL( toggled( bool ) ), SIGNAL( modified() ) ); | ||
68 | |||
69 | } | ||
70 | |||
71 | void KPrefsWidBool::readConfig() | ||
72 | { | ||
73 | mCheck->setChecked(*mReference); | ||
74 | } | ||
75 | |||
76 | void KPrefsWidBool::writeConfig() | ||
77 | { | ||
78 | *mReference = mCheck->isChecked(); | ||
79 | } | ||
80 | |||
81 | QCheckBox *KPrefsWidBool::checkBox() | ||
82 | { | ||
83 | return mCheck; | ||
84 | } | ||
85 | |||
86 | |||
87 | KPrefsWidColor::KPrefsWidColor(const QString &text,QColor *reference, | ||
88 | QWidget *parent) | ||
89 | { | ||
90 | mReference = reference; | ||
91 | |||
92 | mButton = new KColorButton(parent); | ||
93 | mLabel = new QLabel(mButton, text, parent); | ||
94 | mButton->setColor( *mReference ); | ||
95 | mButton->setColor( Qt::red ); | ||
96 | |||
97 | connect( mButton, SIGNAL( changed(const QColor &)), SIGNAL( modified() ) ); | ||
98 | |||
99 | } | ||
100 | |||
101 | KPrefsWidColor::~KPrefsWidColor() | ||
102 | { | ||
103 | // kdDebug(5300) << "KPrefsWidColor::~KPrefsWidColor()" << endl; | ||
104 | } | ||
105 | |||
106 | void KPrefsWidColor::readConfig() | ||
107 | { | ||
108 | mButton->setColor(*mReference); | ||
109 | } | ||
110 | |||
111 | void KPrefsWidColor::writeConfig() | ||
112 | { | ||
113 | *mReference = mButton->color(); | ||
114 | } | ||
115 | |||
116 | QLabel *KPrefsWidColor::label() | ||
117 | { | ||
118 | return mLabel; | ||
119 | } | ||
120 | |||
121 | KColorButton *KPrefsWidColor::button() | ||
122 | { | ||
123 | return mButton; | ||
124 | } | ||
125 | |||
126 | KPrefsWidFont::KPrefsWidFont(const QString &sampleText,const QString &labelText, | ||
127 | QFont *reference,QWidget *parent) | ||
128 | { | ||
129 | mReference = reference; | ||
130 | |||
131 | mLabel = new QLabel(labelText, parent); | ||
132 | |||
133 | mPreview = new QLabel(sampleText,parent); | ||
134 | mPreview->setFrameStyle(QFrame::Panel|QFrame::Sunken); | ||
135 | |||
136 | mButton = new QPushButton(i18n("Choose..."), parent); | ||
137 | connect(mButton,SIGNAL(clicked()),SLOT(selectFont())); | ||
138 | mPreview->setMaximumHeight( QApplication::desktop()->height() / 12 ); | ||
139 | mPreview->setMaximumWidth( (QApplication::desktop()->width() / 2)-10 ); | ||
140 | } | ||
141 | |||
142 | KPrefsWidFont::~KPrefsWidFont() | ||
143 | { | ||
144 | } | ||
145 | |||
146 | void KPrefsWidFont::readConfig() | ||
147 | { | ||
148 | mPreview->setFont(*mReference); | ||
149 | } | ||
150 | |||
151 | void KPrefsWidFont::writeConfig() | ||
152 | { | ||
153 | *mReference = mPreview->font(); | ||
154 | } | ||
155 | |||
156 | QLabel *KPrefsWidFont::label() | ||
157 | { | ||
158 | return mLabel; | ||
159 | } | ||
160 | |||
161 | QLabel *KPrefsWidFont::preview() | ||
162 | { | ||
163 | return mPreview; | ||
164 | } | ||
165 | |||
166 | QPushButton *KPrefsWidFont::button() | ||
167 | { | ||
168 | return mButton; | ||
169 | } | ||
170 | |||
171 | void KPrefsWidFont::selectFont() | ||
172 | { | ||
173 | QFont myFont(mPreview->font()); | ||
174 | bool ok; | ||
175 | myFont = KFontDialog::getFont(myFont, ok); | ||
176 | if ( ok ) { | ||
177 | mPreview->setFont(myFont); | ||
178 | emit modified(); | ||
179 | } | ||
180 | } | ||
181 | |||
182 | |||
183 | KPrefsWidTime::KPrefsWidTime(const QString &text,int *reference, | ||
184 | QWidget *parent) | ||
185 | { | ||
186 | mReference = reference; | ||
187 | |||
188 | mLabel = new QLabel(text,parent); | ||
189 | mSpin = new QSpinBox(0,23,1,parent); | ||
190 | mSpin->setSuffix(":00"); | ||
191 | connect( mSpin, SIGNAL( valueChanged(int)), SIGNAL( modified() ) ); | ||
192 | |||
193 | } | ||
194 | |||
195 | void KPrefsWidTime::readConfig() | ||
196 | { | ||
197 | mSpin->setValue(*mReference); | ||
198 | } | ||
199 | |||
200 | void KPrefsWidTime::writeConfig() | ||
201 | { | ||
202 | *mReference = mSpin->value(); | ||
203 | } | ||
204 | |||
205 | QLabel *KPrefsWidTime::label() | ||
206 | { | ||
207 | return mLabel; | ||
208 | } | ||
209 | |||
210 | QSpinBox *KPrefsWidTime::spinBox() | ||
211 | { | ||
212 | return mSpin; | ||
213 | } | ||
214 | |||
215 | |||
216 | KPrefsWidRadios::KPrefsWidRadios(const QString &text,int *reference, | ||
217 | QWidget *parent) | ||
218 | { | ||
219 | mReference = reference; | ||
220 | |||
221 | mBox = new QButtonGroup(1,Qt::Horizontal,text,parent); | ||
222 | connect( mBox, SIGNAL( clicked(int)), SIGNAL( modified() ) ); | ||
223 | } | ||
224 | |||
225 | KPrefsWidRadios::~KPrefsWidRadios() | ||
226 | { | ||
227 | } | ||
228 | |||
229 | void KPrefsWidRadios::addRadio(const QString &text) | ||
230 | { | ||
231 | new QRadioButton(text,mBox); | ||
232 | } | ||
233 | |||
234 | QButtonGroup *KPrefsWidRadios::groupBox() | ||
235 | { | ||
236 | return mBox; | ||
237 | } | ||
238 | |||
239 | void KPrefsWidRadios::readConfig() | ||
240 | { | ||
241 | mBox->setButton(*mReference); | ||
242 | } | ||
243 | |||
244 | void KPrefsWidRadios::writeConfig() | ||
245 | { | ||
246 | *mReference = mBox->id(mBox->selected()); | ||
247 | } | ||
248 | |||
249 | |||
250 | KPrefsWidString::KPrefsWidString(const QString &text,QString *reference, | ||
251 | QWidget *parent, QLineEdit::EchoMode echomode) | ||
252 | { | ||
253 | mReference = reference; | ||
254 | |||
255 | mLabel = new QLabel(text,parent); | ||
256 | mEdit = new QLineEdit(parent); | ||
257 | mEdit->setEchoMode( echomode ); | ||
258 | connect( mEdit, SIGNAL( textChanged(const QString&) ), SIGNAL( modified() ) ); | ||
259 | |||
260 | } | ||
261 | |||
262 | KPrefsWidString::~KPrefsWidString() | ||
263 | { | ||
264 | } | ||
265 | |||
266 | void KPrefsWidString::readConfig() | ||
267 | { | ||
268 | mEdit->setText(*mReference); | ||
269 | } | ||
270 | |||
271 | void KPrefsWidString::writeConfig() | ||
272 | { | ||
273 | *mReference = mEdit->text(); | ||
274 | } | ||
275 | |||
276 | QLabel *KPrefsWidString::label() | ||
277 | { | ||
278 | return mLabel; | ||
279 | } | ||
280 | |||
281 | QLineEdit *KPrefsWidString::lineEdit() | ||
282 | { | ||
283 | return mEdit; | ||
284 | } | ||
285 | |||
286 | |||
287 | KPrefsWidget::KPrefsWidget(KPrefs *prefs,QWidget *parent,const char *name) : | ||
288 | QWidget(parent, name ) | ||
289 | { | ||
290 | mPrefs = prefs; | ||
291 | } | ||
292 | |||
293 | KPrefsWidget::~KPrefsWidget() | ||
294 | { | ||
295 | } | ||
296 | |||
297 | void KPrefsWidget::addWid(KPrefsWid *wid) | ||
298 | { | ||
299 | mPrefsWids.append(wid); | ||
300 | connect( wid, SIGNAL( modified() ), this, SLOT( modified() ) ); | ||
301 | |||
302 | } | ||
303 | |||
304 | KPrefsWidBool *KPrefsWidget::addWidBool(const QString &text,bool *reference,QWidget *parent) | ||
305 | { | ||
306 | KPrefsWidBool *w = new KPrefsWidBool(text,reference,parent); | ||
307 | addWid(w); | ||
308 | return w; | ||
309 | } | ||
310 | |||
311 | KPrefsWidTime *KPrefsWidget::addWidTime(const QString &text,int *reference,QWidget *parent) | ||
312 | { | ||
313 | KPrefsWidTime *w = new KPrefsWidTime(text,reference,parent); | ||
314 | addWid(w); | ||
315 | return w; | ||
316 | } | ||
317 | |||
318 | KPrefsWidColor *KPrefsWidget::addWidColor(const QString &text,QColor *reference,QWidget *parent) | ||
319 | { | ||
320 | KPrefsWidColor *w = new KPrefsWidColor(text,reference,parent); | ||
321 | addWid(w); | ||
322 | return w; | ||
323 | } | ||
324 | |||
325 | KPrefsWidRadios *KPrefsWidget::addWidRadios(const QString &text,int *reference,QWidget *parent) | ||
326 | { | ||
327 | KPrefsWidRadios *w = new KPrefsWidRadios(text,reference,parent); | ||
328 | addWid(w); | ||
329 | return w; | ||
330 | } | ||
331 | |||
332 | KPrefsWidString *KPrefsWidget::addWidString(const QString &text,QString *reference,QWidget *parent) | ||
333 | { | ||
334 | KPrefsWidString *w = new KPrefsWidString(text,reference,parent); | ||
335 | addWid(w); | ||
336 | return w; | ||
337 | } | ||
338 | |||
339 | KPrefsWidString *KPrefsWidget::addWidPassword(const QString &text,QString *reference,QWidget *parent) | ||
340 | { | ||
341 | KPrefsWidString *w = new KPrefsWidString(text,reference,parent,QLineEdit::Password); | ||
342 | addWid(w); | ||
343 | return w; | ||
344 | } | ||
345 | |||
346 | KPrefsWidFont *KPrefsWidget::addWidFont(const QString &sampleText,const QString &buttonText, | ||
347 | QFont *reference,QWidget *parent) | ||
348 | { | ||
349 | KPrefsWidFont *w = new KPrefsWidFont(sampleText,buttonText,reference,parent); | ||
350 | addWid(w); | ||
351 | return w; | ||
352 | } | ||
353 | |||
354 | void KPrefsWidget::setDefaults() | ||
355 | { | ||
356 | mPrefs->setDefaults(); | ||
357 | |||
358 | readConfig(); | ||
359 | } | ||
360 | |||
361 | void KPrefsWidget::readConfig() | ||
362 | { | ||
363 | // kdDebug(5300) << "KPrefsDialog::readConfig()" << endl; | ||
364 | |||
365 | KPrefsWid *wid; | ||
366 | for(wid = mPrefsWids.first();wid;wid=mPrefsWids.next()) { | ||
367 | wid->readConfig(); | ||
368 | } | ||
369 | |||
370 | usrReadConfig(); | ||
371 | |||
372 | emit changed( false ); | ||
373 | |||
374 | } | ||
375 | |||
376 | void KPrefsWidget::writeConfig() | ||
377 | { | ||
378 | // kdDebug(5300) << "KPrefsDialog::writeConfig()" << endl; | ||
379 | |||
380 | KPrefsWid *wid; | ||
381 | for(wid = mPrefsWids.first();wid;wid=mPrefsWids.next()) { | ||
382 | wid->writeConfig(); | ||
383 | } | ||
384 | |||
385 | usrWriteConfig(); | ||
386 | |||
387 | // kdDebug(5300) << "KPrefsDialog::writeConfig() now writing..." << endl; | ||
388 | |||
389 | mPrefs->writeConfig(); | ||
390 | |||
391 | emit changed( false ); | ||
392 | |||
393 | // kdDebug(5300) << "KPrefsDialog::writeConfig() done" << endl; | ||
394 | } | ||
395 | |||
396 | /*US | ||
397 | void KPrefsWidget::slotApply() | ||
398 | { | ||
399 | writeConfig(); | ||
400 | emit configChanged(); | ||
401 | } | ||
402 | |||
403 | void KPrefsDialog::slotOk() | ||
404 | { | ||
405 | slotApply(); | ||
406 | QDialog::accept(); | ||
407 | } | ||
408 | void KPrefsDialog::accept() | ||
409 | { | ||
410 | slotOk(); | ||
411 | } | ||
412 | |||
413 | void KPrefsDialog::slotDefault() | ||
414 | { | ||
415 | if (KMessageBox::warningContinueCancel(this, | ||
416 | i18n("You are about to set all\npreferences to default values.\nAll " | ||
417 | "custom modifications will be lost."),i18n("Setting Default Preferences"), | ||
418 | i18n("Continue")) | ||
419 | == KMessageBox::Continue) setDefaults(); | ||
420 | } | ||
421 | */ | ||
422 | |||
423 | void KPrefsWidget::modified() | ||
424 | { | ||
425 | emit changed( true ); | ||
426 | } | ||
427 | |||
diff --git a/libkdepim/kprefswidget.h b/libkdepim/kprefswidget.h new file mode 100644 index 0000000..8a24515 --- a/dev/null +++ b/libkdepim/kprefswidget.h | |||
@@ -0,0 +1,454 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | As a special exception, permission is given to link this program | ||
20 | with any edition of Qt, and distribute the resulting executable, | ||
21 | without including the source code for Qt in the source distribution. | ||
22 | */ | ||
23 | // $Id$ | ||
24 | |||
25 | #ifndef _KPREFSWIDGET_H | ||
26 | #define _KPREFSWIDGET_H | ||
27 | |||
28 | #include <qptrlist.h> | ||
29 | #include <qlineedit.h> | ||
30 | |||
31 | #include <qwidget.h> | ||
32 | |||
33 | class KPrefs; | ||
34 | |||
35 | class KColorButton; | ||
36 | class QCheckBox; | ||
37 | class QLabel; | ||
38 | class QSpinBox; | ||
39 | class QButtonGroup; | ||
40 | |||
41 | /** | ||
42 | @short Base class for widgets used by @ref KPrefsDialog. | ||
43 | @author Cornelius Schumacher | ||
44 | @see KPrefsDialog | ||
45 | |||
46 | This class provides the interface for the preferences widgets used by | ||
47 | KPrefsDialog. | ||
48 | */ | ||
49 | class KPrefsWid : public QObject | ||
50 | { | ||
51 | Q_OBJECT | ||
52 | public: | ||
53 | /** | ||
54 | This function is called to read value of the setting from the | ||
55 | stored configuration and display it in the widget. | ||
56 | */ | ||
57 | virtual void readConfig() = 0; | ||
58 | /** | ||
59 | This function is called to write the current setting of the widget to the | ||
60 | stored configuration. | ||
61 | */ | ||
62 | virtual void writeConfig() = 0; | ||
63 | |||
64 | //connect to this signal if you want to be notified of changes | ||
65 | signals: | ||
66 | void modified(); | ||
67 | |||
68 | }; | ||
69 | |||
70 | /** | ||
71 | @short Widget for bool settings in @ref KPrefsDialog. | ||
72 | |||
73 | This class provides a widget for configuring bool values. It is meant to be | ||
74 | used by KPrefsDialog. The user is responsible for the layout management. | ||
75 | */ | ||
76 | class KPrefsWidBool : public KPrefsWid | ||
77 | { | ||
78 | public: | ||
79 | /** | ||
80 | Create a bool widget consisting of a QCheckbox. | ||
81 | |||
82 | @param text Text of QCheckBox. | ||
83 | @param reference Pointer to variable read and written by this widget. | ||
84 | @param parent Parent widget. | ||
85 | */ | ||
86 | KPrefsWidBool(const QString &text,bool *reference,QWidget *parent); | ||
87 | |||
88 | /** | ||
89 | Return the QCheckbox used by this widget. | ||
90 | */ | ||
91 | QCheckBox *checkBox(); | ||
92 | |||
93 | void readConfig(); | ||
94 | void writeConfig(); | ||
95 | |||
96 | private: | ||
97 | bool *mReference; | ||
98 | |||
99 | QCheckBox *mCheck; | ||
100 | }; | ||
101 | |||
102 | /** | ||
103 | @short Widget for time settings in @ref KPrefsDialog. | ||
104 | |||
105 | This class provides a widget for configuring time values. It is meant to be | ||
106 | used by KPrefsDialog. The user is responsible for the layout management. | ||
107 | */ | ||
108 | class KPrefsWidTime : public KPrefsWid | ||
109 | { | ||
110 | public: | ||
111 | /** | ||
112 | Create a time widget consisting of a label and a spinbox. | ||
113 | |||
114 | @param text Text of Label. | ||
115 | @param reference Pointer to variable read and written by this widget. | ||
116 | @param parent Parent widget. | ||
117 | */ | ||
118 | KPrefsWidTime(const QString &text,int *reference,QWidget *parent); | ||
119 | |||
120 | /** | ||
121 | Return QLabel used by this widget. | ||
122 | */ | ||
123 | QLabel *label(); | ||
124 | /** | ||
125 | Return QSpinBox used by this widget. | ||
126 | */ | ||
127 | QSpinBox *spinBox(); | ||
128 | |||
129 | void readConfig(); | ||
130 | void writeConfig(); | ||
131 | |||
132 | private: | ||
133 | int *mReference; | ||
134 | |||
135 | QLabel *mLabel; | ||
136 | QSpinBox *mSpin; | ||
137 | }; | ||
138 | |||
139 | /** | ||
140 | @short Widget for color settings in @ref KPrefsDialog. | ||
141 | |||
142 | This class provides a widget for configuring color values. It is meant to be | ||
143 | used by KPrefsDialog. The user is responsible for the layout management. | ||
144 | */ | ||
145 | class KPrefsWidColor : public KPrefsWid | ||
146 | { | ||
147 | public: | ||
148 | /** | ||
149 | Create a color widget consisting of a test field and a button for opening | ||
150 | a color dialog. | ||
151 | |||
152 | @param text Text of button. | ||
153 | @param reference Pointer to variable read and written by this widget. | ||
154 | @param parent Parent widget. | ||
155 | */ | ||
156 | KPrefsWidColor(const QString &text,QColor *reference,QWidget *parent); | ||
157 | /** | ||
158 | Destruct color setting widget. | ||
159 | */ | ||
160 | ~KPrefsWidColor(); | ||
161 | |||
162 | /** | ||
163 | Return QLabel for the button | ||
164 | */ | ||
165 | QLabel *label(); | ||
166 | /** | ||
167 | Return button opening the color dialog. | ||
168 | */ | ||
169 | KColorButton *button(); | ||
170 | |||
171 | void readConfig(); | ||
172 | void writeConfig(); | ||
173 | |||
174 | private: | ||
175 | QColor *mReference; | ||
176 | |||
177 | QLabel *mLabel; | ||
178 | KColorButton *mButton; | ||
179 | }; | ||
180 | |||
181 | /** | ||
182 | @short Widget for font settings in @ref KPrefsDialog. | ||
183 | |||
184 | This class provides a widget for configuring font values. It is meant to be | ||
185 | used by KPrefsDialog. The user is responsible for the layout management. | ||
186 | */ | ||
187 | class KPrefsWidFont : public KPrefsWid | ||
188 | { | ||
189 | Q_OBJECT | ||
190 | public: | ||
191 | /** | ||
192 | Create a font widget consisting of a test field and a button for opening | ||
193 | a font dialog. | ||
194 | |||
195 | @param label Text of label. | ||
196 | @param reference Pointer to variable read and written by this widget. | ||
197 | @param parent Parent widget. | ||
198 | */ | ||
199 | KPrefsWidFont(const QString &sampleText,const QString &labelText, | ||
200 | QFont *reference,QWidget *parent); | ||
201 | /** | ||
202 | Destruct font setting widget. | ||
203 | */ | ||
204 | ~KPrefsWidFont(); | ||
205 | |||
206 | /** | ||
207 | Return label. | ||
208 | */ | ||
209 | QLabel *label(); | ||
210 | /** | ||
211 | Return QFrame used as preview field. | ||
212 | */ | ||
213 | QLabel *preview(); | ||
214 | /** | ||
215 | Return button opening the font dialog. | ||
216 | */ | ||
217 | QPushButton *button(); | ||
218 | |||
219 | void readConfig(); | ||
220 | void writeConfig(); | ||
221 | |||
222 | protected slots: | ||
223 | void selectFont(); | ||
224 | |||
225 | private: | ||
226 | QFont *mReference; | ||
227 | |||
228 | QLabel *mLabel; | ||
229 | QLabel *mPreview; | ||
230 | QPushButton *mButton; | ||
231 | }; | ||
232 | |||
233 | /** | ||
234 | @short Widget for settings represented by a group of radio buttons in | ||
235 | @ref KPrefsDialog. | ||
236 | |||
237 | This class provides a widget for configuring selections. It is meant to be | ||
238 | used by KPrefsDialog. The user is responsible for the layout management. The | ||
239 | setting is interpreted as an int value, corresponding to the position of the | ||
240 | radio button. The position of the button is defined by the sequence of @ref | ||
241 | addRadio() calls, starting with 0. | ||
242 | */ | ||
243 | class KPrefsWidRadios : public KPrefsWid | ||
244 | { | ||
245 | public: | ||
246 | /** | ||
247 | Create a widget for selection of an option. It consists of a box with | ||
248 | several radio buttons. | ||
249 | |||
250 | @param text Text of main box. | ||
251 | @param reference Pointer to variable read and written by this widget. | ||
252 | @param parent Parent widget. | ||
253 | */ | ||
254 | KPrefsWidRadios(const QString &text,int *reference,QWidget *parent); | ||
255 | virtual ~KPrefsWidRadios(); | ||
256 | |||
257 | /** | ||
258 | Add a radio button. | ||
259 | |||
260 | @param text Text of the button. | ||
261 | */ | ||
262 | void addRadio(const QString &text); | ||
263 | |||
264 | /** | ||
265 | Return the box widget used by this widget. | ||
266 | */ | ||
267 | QButtonGroup *groupBox(); | ||
268 | |||
269 | void readConfig(); | ||
270 | void writeConfig(); | ||
271 | |||
272 | private: | ||
273 | int *mReference; | ||
274 | |||
275 | QButtonGroup *mBox; | ||
276 | }; | ||
277 | |||
278 | |||
279 | /** | ||
280 | @short Widget for string settings in @ref KPrefsDialog. | ||
281 | |||
282 | This class provides a widget for configuring string values. It is meant to be | ||
283 | used by KPrefsDialog. The user is responsible for the layout management. | ||
284 | */ | ||
285 | class KPrefsWidString : public KPrefsWid | ||
286 | { | ||
287 | public: | ||
288 | /** | ||
289 | Create a string widget consisting of a test label and a line edit. | ||
290 | |||
291 | @param text Text of label. | ||
292 | @param reference Pointer to variable read and written by this widget. | ||
293 | @param parent Parent widget. | ||
294 | */ | ||
295 | KPrefsWidString(const QString &text,QString *reference,QWidget *parent,QLineEdit::EchoMode echomode=QLineEdit::Normal); | ||
296 | /** | ||
297 | Destructor. | ||
298 | */ | ||
299 | virtual ~KPrefsWidString(); | ||
300 | |||
301 | /** | ||
302 | Return label used by this widget. | ||
303 | */ | ||
304 | QLabel *label(); | ||
305 | /** | ||
306 | Return QLineEdit used by this widget. | ||
307 | */ | ||
308 | QLineEdit *lineEdit(); | ||
309 | |||
310 | void readConfig(); | ||
311 | void writeConfig(); | ||
312 | |||
313 | private: | ||
314 | QString *mReference; | ||
315 | |||
316 | QLabel *mLabel; | ||
317 | QLineEdit *mEdit; | ||
318 | }; | ||
319 | |||
320 | |||
321 | /** | ||
322 | @short Base class for a preferences widget. | ||
323 | |||
324 | This class provides the framework for a preferences widget. You have to | ||
325 | subclass it and add the code to create the actual configuration widgets and | ||
326 | do the layout management. | ||
327 | |||
328 | KPrefsWidget provides functions to add subclasses of @ref KPrefsWid. For | ||
329 | these widgets the reading, writing and setting to default values is handled | ||
330 | automatically. Custom widgets have to be handled in the functions @ref | ||
331 | usrReadConfig() and @ref usrWriteConfig(). | ||
332 | */ | ||
333 | class KPrefsWidget : public QWidget | ||
334 | { | ||
335 | Q_OBJECT | ||
336 | public: | ||
337 | /** | ||
338 | Create a KPrefsDialog for a KPrefs object. | ||
339 | |||
340 | @param prefs KPrefs object used to access te configuration. | ||
341 | @param parent Parent widget. | ||
342 | @param name Widget name. | ||
343 | */ | ||
344 | KPrefsWidget(KPrefs *prefs,QWidget *parent=0,const char *name=0); | ||
345 | /** | ||
346 | Destructor. | ||
347 | */ | ||
348 | virtual ~KPrefsWidget(); | ||
349 | |||
350 | /** | ||
351 | Register a custom KPrefsWid object. | ||
352 | */ | ||
353 | void addWid(KPrefsWid *); | ||
354 | /** | ||
355 | Register a @ref KPrefsWidBool object. | ||
356 | |||
357 | @param text Text of bool widget. | ||
358 | @param reference Reference to variable storing the setting. | ||
359 | @param parent Parent widget. | ||
360 | */ | ||
361 | KPrefsWidBool *addWidBool(const QString &text,bool *reference,QWidget *parent); | ||
362 | /** | ||
363 | Register a @ref KPrefsWidTime object. | ||
364 | |||
365 | @param text Text of time widget. | ||
366 | @param reference Reference to variable storing the setting. | ||
367 | @param parent Parent widget. | ||
368 | */ | ||
369 | KPrefsWidTime *addWidTime(const QString &text,int *reference,QWidget *parent); | ||
370 | /** | ||
371 | Register a @ref KPrefsWidColor object. | ||
372 | |||
373 | @param text Text of color widget. | ||
374 | @param reference Reference to variable storing the setting. | ||
375 | @param parent Parent widget. | ||
376 | */ | ||
377 | KPrefsWidColor *addWidColor(const QString &text,QColor *reference,QWidget *parent); | ||
378 | /** | ||
379 | Register a @ref KPrefsWidRadios object. | ||
380 | |||
381 | @param text Text of radio button box widget. | ||
382 | @param reference Reference to variable storing the setting. | ||
383 | @param parent Parent widget. | ||
384 | */ | ||
385 | KPrefsWidRadios *addWidRadios(const QString &text,int *reference,QWidget *parent); | ||
386 | /** | ||
387 | Register a @ref KPrefsWidString object. | ||
388 | |||
389 | @param text Text of string widget. | ||
390 | @param reference Reference to variable storing the setting. | ||
391 | @param parent Parent widget. | ||
392 | */ | ||
393 | KPrefsWidString *addWidString(const QString &text,QString *reference,QWidget *parent); | ||
394 | /** | ||
395 | Register a password @ref KPrefsWidString object, with echomode set to QLineEdit::Password. | ||
396 | |||
397 | @param text Text of string widget. | ||
398 | @param reference Reference to variable storing the setting. | ||
399 | @param parent Parent widget. | ||
400 | */ | ||
401 | KPrefsWidString *addWidPassword (const QString &text,QString *reference,QWidget *parent); | ||
402 | /** | ||
403 | Register a @ref KPrefsWidFont object. | ||
404 | |||
405 | @param sampleText Sample text of font widget. | ||
406 | @param buttonText Button text of font widget. | ||
407 | @param reference Reference to variable storing the setting. | ||
408 | @param parent Parent widget. | ||
409 | */ | ||
410 | KPrefsWidFont *addWidFont(const QString &sampleText,const QString &buttonText, | ||
411 | QFont *reference,QWidget *parent); | ||
412 | |||
413 | public slots: | ||
414 | /** Set all widgets to default values. */ | ||
415 | void setDefaults(); | ||
416 | |||
417 | /** Read preferences from config file. */ | ||
418 | void readConfig(); | ||
419 | |||
420 | /** Write preferences to config file. */ | ||
421 | void writeConfig(); | ||
422 | |||
423 | /** connect this slot to all UI elements */ | ||
424 | void modified(); | ||
425 | |||
426 | signals: | ||
427 | /** Emitted when the a changed configuration has been stored. */ | ||
428 | //US void configChanged(); | ||
429 | void changed( bool ); | ||
430 | |||
431 | protected slots: | ||
432 | /** Apply changes to preferences */ | ||
433 | //US void slotApply(); | ||
434 | |||
435 | //US void accept(); | ||
436 | /** Accept changes to preferences and close dialog */ | ||
437 | //US void slotOk(); | ||
438 | |||
439 | /** Set preferences to default values */ | ||
440 | //US void slotDefault(); | ||
441 | |||
442 | protected: | ||
443 | /** Implement this to read custom configuration widgets. */ | ||
444 | virtual void usrReadConfig() {} | ||
445 | /** Implement this to write custom configuration widgets. */ | ||
446 | virtual void usrWriteConfig() {} | ||
447 | |||
448 | private: | ||
449 | KPrefs *mPrefs; | ||
450 | |||
451 | QPtrList<KPrefsWid> mPrefsWids; | ||
452 | }; | ||
453 | |||
454 | #endif | ||