summaryrefslogtreecommitdiffabout
path: root/libkdepim/kprefsdialog.h
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /libkdepim/kprefsdialog.h
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'libkdepim/kprefsdialog.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kprefsdialog.h446
1 files changed, 446 insertions, 0 deletions
diff --git a/libkdepim/kprefsdialog.h b/libkdepim/kprefsdialog.h
new file mode 100644
index 0000000..dceab01
--- a/dev/null
+++ b/libkdepim/kprefsdialog.h
@@ -0,0 +1,446 @@
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#ifndef _KPREFSDIALOG_H
24#define _KPREFSDIALOG_H
25// $Id$
26
27#include <qptrlist.h>
28#include <qlineedit.h>
29
30#include <kdialogbase.h>
31
32class KPrefs;
33class KPrefsDialog;
34
35class KColorButton;
36class QCheckBox;
37class QLabel;
38class QSpinBox;
39class 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*/
49class KPrefsWid
50{
51 public:
52 /**
53 This function is called to read value of the setting from the
54 stored configuration and display it in the widget.
55 */
56 virtual void readConfig() = 0;
57 /**
58 This function is called to write the current setting of the widget to the
59 stored configuration.
60 */
61 virtual void writeConfig() = 0;
62};
63
64/**
65 @short Widget for bool settings in @ref KPrefsDialog.
66
67 This class provides a widget for configuring bool values. It is meant to be
68 used by KPrefsDialog. The user is responsible for the layout management.
69*/
70class KPrefsWidBool : public KPrefsWid
71{
72 public:
73 /**
74 Create a bool widget consisting of a QCheckbox.
75
76 @param text Text of QCheckBox.
77 @param reference Pointer to variable read and written by this widget.
78 @param parent Parent widget.
79 */
80 KPrefsWidBool(const QString &text,bool *reference,QWidget *parent);
81
82 /**
83 Return the QCheckbox used by this widget.
84 */
85 QCheckBox *checkBox();
86
87 void readConfig();
88 void writeConfig();
89
90 private:
91 bool *mReference;
92
93 QCheckBox *mCheck;
94};
95
96/**
97 @short Widget for time settings in @ref KPrefsDialog.
98
99 This class provides a widget for configuring time values. It is meant to be
100 used by KPrefsDialog. The user is responsible for the layout management.
101*/
102class KPrefsWidTime : public KPrefsWid
103{
104 public:
105 /**
106 Create a time widget consisting of a label and a spinbox.
107
108 @param text Text of Label.
109 @param reference Pointer to variable read and written by this widget.
110 @param parent Parent widget.
111 */
112 KPrefsWidTime(const QString &text,int *reference,QWidget *parent);
113
114 /**
115 Return QLabel used by this widget.
116 */
117 QLabel *label();
118 /**
119 Return QSpinBox used by this widget.
120 */
121 QSpinBox *spinBox();
122
123 void readConfig();
124 void writeConfig();
125
126 private:
127 int *mReference;
128
129 QLabel *mLabel;
130 QSpinBox *mSpin;
131};
132
133/**
134 @short Widget for color settings in @ref KPrefsDialog.
135
136 This class provides a widget for configuring color values. It is meant to be
137 used by KPrefsDialog. The user is responsible for the layout management.
138*/
139class KPrefsWidColor : public QObject, public KPrefsWid
140{
141 Q_OBJECT
142 public:
143 /**
144 Create a color widget consisting of a test field and a button for opening
145 a color dialog.
146
147 @param text Text of button.
148 @param reference Pointer to variable read and written by this widget.
149 @param parent Parent widget.
150 */
151 KPrefsWidColor(const QString &text,QColor *reference,QWidget *parent);
152 /**
153 Destruct color setting widget.
154 */
155 ~KPrefsWidColor();
156
157 /**
158 Return QLabel for the button
159 */
160 QLabel *label();
161 /**
162 Return button opening the color dialog.
163 */
164 KColorButton *button();
165
166 void readConfig();
167 void writeConfig();
168
169 private:
170 QColor *mReference;
171
172 QLabel *mLabel;
173 KColorButton *mButton;
174};
175
176/**
177 @short Widget for font settings in @ref KPrefsDialog.
178
179 This class provides a widget for configuring font values. It is meant to be
180 used by KPrefsDialog. The user is responsible for the layout management.
181*/
182class KPrefsWidFont : public QObject, public KPrefsWid
183{
184 Q_OBJECT
185 public:
186 /**
187 Create a font widget consisting of a test field and a button for opening
188 a font dialog.
189
190 @param label Text of label.
191 @param reference Pointer to variable read and written by this widget.
192 @param parent Parent widget.
193 */
194 KPrefsWidFont(const QString &sampleText,const QString &labelText,
195 QFont *reference,QWidget *parent);
196 /**
197 Destruct font setting widget.
198 */
199 ~KPrefsWidFont();
200
201 /**
202 Return label.
203 */
204 QLabel *label();
205 /**
206 Return QFrame used as preview field.
207 */
208 QLabel *preview();
209 /**
210 Return button opening the font dialog.
211 */
212 QPushButton *button();
213
214 void readConfig();
215 void writeConfig();
216
217 protected slots:
218 void selectFont();
219
220 private:
221 QFont *mReference;
222
223 QLabel *mLabel;
224 QLabel *mPreview;
225 QPushButton *mButton;
226};
227
228/**
229 @short Widget for settings represented by a group of radio buttons in
230 @ref KPrefsDialog.
231
232 This class provides a widget for configuring selections. It is meant to be
233 used by KPrefsDialog. The user is responsible for the layout management. The
234 setting is interpreted as an int value, corresponding to the position of the
235 radio button. The position of the button is defined by the sequence of @ref
236 addRadio() calls, starting with 0.
237*/
238class KPrefsWidRadios : public KPrefsWid
239{
240 public:
241 /**
242 Create a widget for selection of an option. It consists of a box with
243 several radio buttons.
244
245 @param text Text of main box.
246 @param reference Pointer to variable read and written by this widget.
247 @param parent Parent widget.
248 */
249 KPrefsWidRadios(const QString &text,int *reference,QWidget *parent);
250 virtual ~KPrefsWidRadios();
251
252 /**
253 Add a radio button.
254
255 @param text Text of the button.
256 */
257 void addRadio(const QString &text);
258
259 /**
260 Return the box widget used by this widget.
261 */
262 QButtonGroup *groupBox();
263
264 void readConfig();
265 void writeConfig();
266
267 private:
268 int *mReference;
269
270 QButtonGroup *mBox;
271};
272
273
274/**
275 @short Widget for string settings in @ref KPrefsDialog.
276
277 This class provides a widget for configuring string values. It is meant to be
278 used by KPrefsDialog. The user is responsible for the layout management.
279*/
280class KPrefsWidString : public KPrefsWid
281{
282 public:
283 /**
284 Create a string widget consisting of a test label and a line edit.
285
286 @param text Text of label.
287 @param reference Pointer to variable read and written by this widget.
288 @param parent Parent widget.
289 */
290 KPrefsWidString(const QString &text,QString *reference,QWidget *parent,QLineEdit::EchoMode echomode=QLineEdit::Normal);
291 /**
292 Destructor.
293 */
294 virtual ~KPrefsWidString();
295
296 /**
297 Return label used by this widget.
298 */
299 QLabel *label();
300 /**
301 Return QLineEdit used by this widget.
302 */
303 QLineEdit *lineEdit();
304
305 void readConfig();
306 void writeConfig();
307
308 private:
309 QString *mReference;
310
311 QLabel *mLabel;
312 QLineEdit *mEdit;
313};
314
315
316/**
317 @short Base class for a preferences dialog.
318
319 This class provides the framework for a preferences dialog. You have to
320 subclass it and add the code to create the actual configuration widgets and
321 do the layout management.
322
323 KPrefsDialog provides functions to add subclasses of @ref KPrefsWid. For
324 these widgets the reading, writing and setting to default values is handled
325 automatically. Custom widgets have to be handled in the functions @ref
326 usrReadConfig() and @ref usrWriteConfig().
327*/
328class KPrefsDialog : public KDialogBase
329{
330 Q_OBJECT
331 public:
332 /**
333 Create a KPrefsDialog for a KPrefs object.
334
335 @param prefs KPrefs object used to access te configuration.
336 @param parent Parent widget.
337 @param name Widget name.
338 @param modal true, if dialog has to be modal, false for non-modal.
339 */
340 KPrefsDialog(KPrefs *prefs,QWidget *parent=0,char *name=0,bool modal=false);
341 /**
342 Destructor.
343 */
344 virtual ~KPrefsDialog();
345
346 /**
347 Register a custom KPrefsWid object.
348 */
349 void addWid(KPrefsWid *);
350 /**
351 Register a @ref KPrefsWidBool object.
352
353 @param text Text of bool widget.
354 @param reference Reference to variable storing the setting.
355 @param parent Parent widget.
356 */
357 KPrefsWidBool *addWidBool(const QString &text,bool *reference,QWidget *parent);
358 /**
359 Register a @ref KPrefsWidTime object.
360
361 @param text Text of time widget.
362 @param reference Reference to variable storing the setting.
363 @param parent Parent widget.
364 */
365 KPrefsWidTime *addWidTime(const QString &text,int *reference,QWidget *parent);
366 /**
367 Register a @ref KPrefsWidColor object.
368
369 @param text Text of color widget.
370 @param reference Reference to variable storing the setting.
371 @param parent Parent widget.
372 */
373 KPrefsWidColor *addWidColor(const QString &text,QColor *reference,QWidget *parent);
374 /**
375 Register a @ref KPrefsWidRadios object.
376
377 @param text Text of radio button box widget.
378 @param reference Reference to variable storing the setting.
379 @param parent Parent widget.
380 */
381 KPrefsWidRadios *addWidRadios(const QString &text,int *reference,QWidget *parent);
382 /**
383 Register a @ref KPrefsWidString object.
384
385 @param text Text of string widget.
386 @param reference Reference to variable storing the setting.
387 @param parent Parent widget.
388 */
389 KPrefsWidString *addWidString(const QString &text,QString *reference,QWidget *parent);
390 /**
391 Register a password @ref KPrefsWidString object, with echomode set to QLineEdit::Password.
392
393 @param text Text of string widget.
394 @param reference Reference to variable storing the setting.
395 @param parent Parent widget.
396 */
397 KPrefsWidString *addWidPassword (const QString &text,QString *reference,QWidget *parent);
398 /**
399 Register a @ref KPrefsWidFont object.
400
401 @param sampleText Sample text of font widget.
402 @param buttonText Button text of font widget.
403 @param reference Reference to variable storing the setting.
404 @param parent Parent widget.
405 */
406 KPrefsWidFont *addWidFont(const QString &sampleText,const QString &buttonText,
407 QFont *reference,QWidget *parent);
408
409 public slots:
410 /** Set all widgets to default values. */
411 void setDefaults();
412
413 /** Read preferences from config file. */
414 void readConfig();
415
416 /** Write preferences to config file. */
417 void writeConfig();
418
419 signals:
420 /** Emitted when the a changed configuration has been stored. */
421 void configChanged();
422
423 protected slots:
424 /** Apply changes to preferences */
425 void slotApply();
426
427 void accept();
428 /** Accept changes to preferences and close dialog */
429 void slotOk();
430
431 /** Set preferences to default values */
432 void slotDefault();
433
434 protected:
435 /** Implement this to read custom configuration widgets. */
436 virtual void usrReadConfig() {}
437 /** Implement this to write custom configuration widgets. */
438 virtual void usrWriteConfig() {}
439
440 private:
441 KPrefs *mPrefs;
442
443 QPtrList<KPrefsWid> mPrefsWids;
444};
445
446#endif