-rw-r--r-- | libkdepim/kprefswidget.h | 454 |
1 files changed, 454 insertions, 0 deletions
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 | ||