Fix typo found by Yuri Chornoivan
[kdepim.git] / libkdepim / kprefsdialog.h
blob27d9095c0fc8eb1fa0569b335bd55b236c20660b
1 /*
2 This file is part of libkdepim.
4 Copyright (c) 2001-2003 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 Copyright (C) 2005,2008 Allen Winter <winter@kde.org>
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
23 #ifndef KDEPIM_KPREFSDIALOG_H
24 #define KDEPIM_KPREFSDIALOG_H
26 #include "kdepim_export.h"
28 #define KDE3_SUPPORT
29 #include <KCModule>
30 #undef KDE3_SUPPORT
31 #include <KConfigSkeleton>
32 #include <KFile>
33 #include <KLineEdit>
34 #include <KPageDialog>
36 #include <QVariantList>
38 class KColorButton;
39 class KComboBox;
40 class KComponentData;
41 class KUrlRequester;
43 class QCheckBox;
44 class QLabel;
45 class QSpinBox;
46 class QTimeEdit;
47 class Q3ButtonGroup;
49 namespace KPIM {
51 class KDateEdit;
52 class KTimeEdit;
54 /**
55 @short Base class for GUI control elements used by @ref KPrefsDialog.
56 @author Cornelius Schumacher
57 @see KPrefsDialog
59 This class provides the interface for the GUI control elements used by
60 KPrefsDialog. The control element consists of a set of widgets for handling
61 a certain type of configuration information.
63 class KDEPIM_EXPORT KPrefsWid : public QObject
65 Q_OBJECT
66 public:
67 /**
68 This function is called to read value of the setting from the
69 stored configuration and display it in the widget.
71 virtual void readConfig() = 0;
72 /**
73 This function is called to write the current setting of the widget to the
74 stored configuration.
76 virtual void writeConfig() = 0;
78 /**
79 Return a list of widgets used by this control element.
81 virtual QList<QWidget *> widgets() const;
83 Q_SIGNALS:
84 /**
85 Emitted when widget value has changed.
87 void changed();
90 /**
91 @short Widgets for bool settings in @ref KPrefsDialog.
93 This class provides a control element for configuring bool values. It is meant
94 to be used by KPrefsDialog. The user is responsible for the layout management.
96 class KDEPIM_EXPORT KPrefsWidBool : public KPrefsWid
98 public:
99 /**
100 Create a bool value control element consisting of a QCheckbox.
102 @param item The KConfigSkeletonItem representing the preferences entry.
103 @param parent Parent widget.
105 explicit KPrefsWidBool( KConfigSkeleton::ItemBool *item, QWidget *parent = 0 );
108 Return the QCheckbox used by this control element.
110 QCheckBox *checkBox();
112 void readConfig();
113 void writeConfig();
115 QList<QWidget *> widgets() const;
117 private:
118 KConfigSkeleton::ItemBool *mItem;
120 QCheckBox *mCheck;
124 @short Widgets for int settings in @ref KPrefsDialog.
126 This class provides a control element for configuring integer values. It is
127 meant to be used by KPrefsDialog. The user is responsible for the layout
128 management.
130 class KDEPIM_EXPORT KPrefsWidInt : public KPrefsWid
132 public:
134 Create a integer value control element consisting of a label and a
135 spinbox.
137 @param item The KConfigSkeletonItem representing the preferences entry.
138 @param parent Parent widget.
140 explicit KPrefsWidInt( KConfigSkeleton::ItemInt *item, QWidget *parent = 0 );
143 Return QLabel used by this control element.
145 QLabel *label();
148 Return the QSpinBox used by this control element.
150 QSpinBox *spinBox();
152 void readConfig();
153 void writeConfig();
155 QList<QWidget *> widgets() const;
157 private:
158 KConfigSkeleton::ItemInt *mItem;
160 QLabel *mLabel;
161 QSpinBox *mSpin;
165 @short Widgets for time settings in @ref KPrefsDialog.
167 This class provides a control element for configuring time values. It is
168 meant to be used by KPrefsDialog. The user is responsible for the layout
169 management.
171 class KDEPIM_EXPORT KPrefsWidTime : public KPrefsWid
173 public:
175 Create a time value control element consisting of a label and a spinbox.
177 @param item The KConfigSkeletonItem representing the preferences entry.
178 @param parent Parent widget.
180 explicit KPrefsWidTime( KConfigSkeleton::ItemDateTime *item, QWidget *parent = 0 );
183 Return QLabel used by this widget.
185 QLabel *label();
187 Return QSpinBox used by this widget.
189 KTimeEdit *timeEdit();
191 void readConfig();
192 void writeConfig();
194 private:
195 KConfigSkeleton::ItemDateTime *mItem;
197 QLabel *mLabel;
198 KTimeEdit *mTimeEdit;
202 @short Widgets for duration settings in @ref KPrefsDialog.
204 This class provides a control element for configuring duration values. It is
205 meant to be used by KPrefsDialog. The user is responsible for the layout
206 management.
208 class KDEPIM_EXPORT KPrefsWidDuration : public KPrefsWid
210 public:
212 Create a duration value control element consisting of a label and a
213 spinbox.
215 @param item The KConfigSkeletonItem representing the preferences entry.
216 @param format display format. default is "hh:mm:ss"
217 @param parent Parent widget.
219 explicit KPrefsWidDuration( KConfigSkeleton::ItemDateTime *item, const QString &format, QWidget *parent = 0 );
222 Return QLabel used by this widget.
224 QLabel *label();
226 Return QSpinBox used by this widget.
228 QTimeEdit *timeEdit();
230 void readConfig();
231 void writeConfig();
233 private:
234 KConfigSkeleton::ItemDateTime *mItem;
236 QLabel *mLabel;
237 QTimeEdit *mTimeEdit;
241 @short Widgets for time settings in @ref KPrefsDialog.
243 This class provides a control element for configuring date values. It is
244 meant to be used by KPrefsDialog. The user is responsible for the layout
245 management.
247 class KDEPIM_EXPORT KPrefsWidDate : public KPrefsWid
249 public:
251 Create a time value control element consisting of a label and a date box.
253 @param item The KConfigSkeletonItem representing the preferences entry.
254 @param parent Parent widget.
256 explicit KPrefsWidDate( KConfigSkeleton::ItemDateTime *item, QWidget *parent = 0 );
259 Return QLabel used by this widget.
261 QLabel *label();
263 Return QSpinBox used by this widget.
265 KDateEdit *dateEdit();
267 void readConfig();
268 void writeConfig();
270 private:
271 KConfigSkeleton::ItemDateTime *mItem;
273 QLabel *mLabel;
274 KDateEdit *mDateEdit;
278 @short Widgets for color settings in @ref KPrefsDialog.
280 This class provides a control element for configuring color values. It is
281 meant to be used by KPrefsDialog. The user is responsible for the layout
282 management.
284 class KDEPIM_EXPORT KPrefsWidColor : public KPrefsWid
286 Q_OBJECT
287 public:
289 Create a color value control element consisting of a test field and a
290 button for opening a color dialog.
292 @param item The KConfigSkeletonItem representing the preferences entry.
293 @param parent Parent widget.
295 explicit KPrefsWidColor( KConfigSkeleton::ItemColor *item, QWidget *parent = 0 );
298 Destruct color setting widget.
300 ~KPrefsWidColor();
303 Return QLabel for the button
305 QLabel *label();
307 Return button opening the color dialog.
309 KColorButton *button();
311 void readConfig();
312 void writeConfig();
314 private:
315 KConfigSkeleton::ItemColor *mItem;
317 QLabel *mLabel;
318 KColorButton *mButton;
322 @short Widgets for font settings in @ref KPrefsDialog.
324 This class provides a control element for configuring font values. It is meant
325 to be used by KPrefsDialog. The user is responsible for the layout management.
327 class KDEPIM_EXPORT KPrefsWidFont : public KPrefsWid
329 Q_OBJECT
330 public:
332 Create a font value control element consisting of a test field and a
333 button for opening a font dialog.
335 @param item The KConfigSkeletonItem representing the preferences entry.
336 @param parent Parent widget.
337 @param sampleText Sample text for previewing the selected font.
339 explicit KPrefsWidFont( KConfigSkeleton::ItemFont *item,
340 QWidget *parent = 0, const QString &sampleText = QString() );
342 Destruct font setting widget.
344 ~KPrefsWidFont();
347 Return QLabel.
349 QLabel *label();
352 Return QFrame used as preview field.
354 QFrame *preview();
357 Return button opening the font dialog.
359 QPushButton *button();
361 void readConfig();
362 void writeConfig();
364 protected Q_SLOTS:
365 void selectFont();
367 private:
368 KConfigSkeleton::ItemFont *mItem;
370 QLabel *mLabel;
371 QLabel *mPreview;
372 QPushButton *mButton;
376 @short Widgets for settings represented by a group of radio buttons in
377 @ref KPrefsDialog.
379 This class provides a control element for configuring selections. It is meant
380 to be used by KPrefsDialog. The user is responsible for the layout management.
382 The setting is interpreted as an int value, corresponding to the position of
383 the radio button. The position of the button is defined by the sequence of
384 @ref addRadio() calls, starting with 0.
386 class KDEPIM_EXPORT KPrefsWidRadios : public KPrefsWid
388 public:
390 Create a control element for selection of an option. It consists of a box
391 with several radio buttons.
393 @param item The KConfigSkeletonItem representing the preferences entry.
394 @param parent Parent widget.
396 explicit KPrefsWidRadios( KConfigSkeleton::ItemEnum *item, QWidget *parent = 0 );
397 virtual ~KPrefsWidRadios();
400 Add a radio button.
402 @param text Text of the button.
403 @param toolTip ToolTip help for the button.
404 @param whatsThis What's This help for the button.
406 void addRadio( const QString &text,
407 const QString &toolTip = QString(),
408 const QString &whatsThis = QString() );
411 Return the box widget used by this widget.
413 Q3ButtonGroup *groupBox();
415 void readConfig();
416 void writeConfig();
418 QList<QWidget *> widgets() const;
420 private:
421 KConfigSkeleton::ItemEnum *mItem;
423 Q3ButtonGroup *mBox;
427 @short Widgets for settings represented by a combo box in
428 @ref KPrefsDialog.
430 This class provides a control element for configuring selections. It is meant
431 to be used by KPrefsDialog. The user is responsible for the layout management.
433 The setting is interpreted as an int value, corresponding to the index in
434 the combo box.
436 class KDE_EXPORT KPrefsWidCombo : public KPrefsWid
438 public:
440 Create a control element for selection of an option. It consists of a
441 combo box.
443 @param item The KConfigSkeletonItem representing the preferences entry.
444 @param parent Parent widget.
446 explicit KPrefsWidCombo( KConfigSkeleton::ItemEnum *item, QWidget *parent );
447 virtual ~KPrefsWidCombo();
449 void readConfig();
450 void writeConfig();
452 KComboBox *comboBox();
453 QList<QWidget *> widgets() const;
455 private:
456 KConfigSkeleton::ItemEnum *mItem;
457 KComboBox *mCombo;
461 @short Widgets for string settings in @ref KPrefsDialog.
463 This class provides a control element for configuring string values. It is
464 meant to be used by KPrefsDialog. The user is responsible for the layout
465 management.
467 class KDEPIM_EXPORT KPrefsWidString : public KPrefsWid
469 public:
471 Create a string value control element consisting of a test label and a
472 line edit.
474 @param item The KConfigSkeletonItem representing the preferences entry.
475 @param parent Parent widget.
476 @param echomode Describes how a line edit should display its contents.
478 explicit KPrefsWidString( KConfigSkeleton::ItemString *item,
479 QWidget *parent = 0,
480 KLineEdit::EchoMode echomode=KLineEdit::Normal );
482 Destructor.
484 virtual ~KPrefsWidString();
487 Return QLabel used by this widget.
489 QLabel *label();
491 Return KLineEdit used by this widget.
493 KLineEdit *lineEdit();
495 void readConfig();
496 void writeConfig();
498 QList<QWidget *> widgets() const;
500 private:
501 KConfigSkeleton::ItemString *mItem;
503 QLabel *mLabel;
504 KLineEdit *mEdit;
508 @short Widgets for string settings in @ref KPrefsDialog.
510 This class provides a control element for configuring string values. It is
511 meant to be used by KPrefsDialog. The user is responsible for the layout
512 management.
514 class KDEPIM_EXPORT KPrefsWidPath : public KPrefsWid
516 public:
518 Create a string value control element consisting of a test label and a
519 line edit.
521 @param item The KConfigSkeletonItem representing the preferences entry.
522 @param parent Parent widget.
523 @param filter URLRequester filter
524 @param mode Describes how a line edit should display its contents.
526 explicit KPrefsWidPath( KConfigSkeleton::ItemPath *item,
527 QWidget *parent = 0,
528 const QString &filter = QString(),
529 KFile::Modes = KFile::File );
532 Destructor.
534 virtual ~KPrefsWidPath();
537 Return QLabel used by this widget.
539 QLabel *label();
542 Return KUrlRequester used by this widget.
544 KUrlRequester *urlRequester();
546 void readConfig();
547 void writeConfig();
549 QList<QWidget *> widgets() const;
551 private:
552 KConfigSkeleton::ItemPath *mItem;
554 QLabel *mLabel;
555 KUrlRequester *mURLRequester;
559 @short Class for managing KPrefsWid objects.
561 This class manages standard configuration widgets provided bz the KPrefsWid
562 subclasses. It handles creation, loading, saving and default values in a
563 transparent way. The user has to add the widgets by the corresponding addWid
564 functions and KPrefsWidManager handles the rest automatically.
566 class KDEPIM_EXPORT KPrefsWidManager
568 public:
570 Create a KPrefsWidManager object for a KPrefs object.
572 @param prefs KPrefs object used to access te configuration.
574 explicit KPrefsWidManager( KConfigSkeleton *prefs );
577 Destructor.
579 virtual ~KPrefsWidManager();
581 KConfigSkeleton *prefs() const { return mPrefs; }
584 Register a custom KPrefsWid object.
586 virtual void addWid( KPrefsWid * );
589 Register a @ref KPrefsWidBool object.
591 @param item The KConfigSkeletonItem representing the preferences entry.
592 @param parent Parent widget.
594 KPrefsWidBool *addWidBool( KConfigSkeleton::ItemBool *item,
595 QWidget *parent = 0 );
598 Register a @ref KPrefsWidInt object.
600 @param item The KConfigSkeletonItem representing the preferences entry.
601 @param parent Parent widget.
603 KPrefsWidInt *addWidInt( KConfigSkeleton::ItemInt *item,
604 QWidget *parent = 0 );
607 Register a @ref KPrefsWidDate object.
609 @param item The KConfigSkeletonItem representing the preferences entry.
610 @param parent Parent widget.
612 KPrefsWidDate *addWidDate( KConfigSkeleton::ItemDateTime *item,
613 QWidget *parent = 0 );
616 Register a @ref KPrefsWidTime object.
618 @param item The KConfigSkeletonItem representing the preferences entry.
619 @param parent Parent widget.
621 KPrefsWidTime *addWidTime( KConfigSkeleton::ItemDateTime *item,
622 QWidget *parent = 0 );
625 Register a @ref KPrefsWidDuration object.
627 @param item The KConfigSkeletonItem representing the preferences entry.
628 @param format display format. default is "hh:mm:ss"
629 @param parent Parent widget.
631 KPrefsWidDuration *addWidDuration( KConfigSkeleton::ItemDateTime *item,
632 const QString &format,
633 QWidget *parent = 0 );
636 Register a @ref KPrefsWidColor object.
638 @param item The KConfigSkeletonItem representing the preferences entry.
639 @param parent Parent widget.
641 KPrefsWidColor *addWidColor( KConfigSkeleton::ItemColor *item,
642 QWidget *parent = 0 );
645 Register a @ref KPrefsWidRadios object. The choices represented by the
646 given item object are automatically added as radio buttons.
648 @param item The KConfigSkeletonItem representing the preferences entry.
649 @param parent Parent widget.
651 KPrefsWidRadios *addWidRadios( KConfigSkeleton::ItemEnum *item,
652 QWidget *parent = 0 );
655 Register a @ref KPrefsWidCombo object. The choices represented by the
656 given item object are automatically added to the combo box.
658 @param item The KConfigSkeletonItem representing the preferences entry.
659 @param parent Parent widget.
661 KPrefsWidCombo *addWidCombo( KConfigSkeleton::ItemEnum *item,
662 QWidget *parent = 0 );
665 Register a @ref KPrefsWidString object.
667 @param item The KConfigSkeletonItem representing the preferences entry.
668 @param parent Parent widget.
670 KPrefsWidString *addWidString( KConfigSkeleton::ItemString *item,
671 QWidget *parent = 0 );
674 Register a path @ref KPrefsWidPath object.
676 @param item The KConfigSkeletonItem representing the preferences entry.
677 @param parent Parent widget.
678 @param filter URLRequester filter
679 @param mode URLRequester mode
681 KPrefsWidPath *addWidPath ( KConfigSkeleton::ItemPath *item,
682 QWidget *parent = 0,
683 const QString &filter = QString(),
684 KFile::Modes mode = KFile::File );
687 Register a password @ref KPrefsWidString object, with echomode set to KLineEdit::Password.
689 @param item The KConfigSkeletonItem representing the preferences entry.
690 @param parent Parent widget.
692 KPrefsWidString *addWidPassword ( KConfigSkeleton::ItemString *item,
693 QWidget *parent = 0 );
696 Register a @ref KPrefsWidFont object.
698 @param item The KConfigSkeletonItem representing the preferences
699 entry.
700 @param parent Parent widget.
701 @param sampleText Sample text for previewing the selected font.
703 KPrefsWidFont *addWidFont( KConfigSkeleton::ItemFont *item,
704 QWidget *parent = 0,
705 const QString &sampleText = QString() );
707 /** Set all widgets to default values. */
708 void setWidDefaults();
710 /** Read preferences from config file. */
711 void readWidConfig();
713 /** Write preferences to config file. */
714 void writeWidConfig();
716 private:
717 KConfigSkeleton *mPrefs;
719 QList<KPrefsWid*> mPrefsWids;
723 @short Base class for a preferences dialog.
725 This class provides the framework for a preferences dialog. You have to
726 subclass it and add the code to create the actual configuration widgets and
727 do the layout management.
729 KPrefsDialog provides functions to add subclasses of @ref KPrefsWid via
730 KPrefsWidManager. For these widgets the reading, writing and setting to
731 default values is handled automatically. Custom widgets have to be handled in
732 the functions @ref usrReadConfig() and @ref usrWriteConfig().
734 class KDEPIM_EXPORT KPrefsDialog : public KPageDialog, public KPrefsWidManager
736 Q_OBJECT
737 public:
739 Create a KPrefsDialog for a KPrefs object.
741 @param prefs KPrefs object used to access te configuration.
742 @param parent Parent widget.
743 @param name Widget name.
744 @param modal true, if dialog has to be modal, false for non-modal.
746 explicit KPrefsDialog( KConfigSkeleton *prefs, QWidget *parent = 0,
747 bool modal = false );
750 Destructor.
752 virtual ~KPrefsDialog();
754 void autoCreate();
756 public Q_SLOTS:
757 /** Set all widgets to default values. */
758 void setDefaults();
760 /** Read preferences from config file. */
761 void readConfig();
763 /** Write preferences to config file. */
764 void writeConfig();
766 Q_SIGNALS:
767 /** Emitted when the a changed configuration has been stored. */
768 void configChanged();
770 protected Q_SLOTS:
771 /** Apply changes to preferences */
772 void slotApply();
774 /** Accept changes to preferences and close dialog */
775 void slotOk();
777 /** Set preferences to default values */
778 void slotDefault();
780 protected:
781 /** Implement this to read custom configuration widgets. */
782 virtual void usrReadConfig() {}
783 /** Implement this to write custom configuration widgets. */
784 virtual void usrWriteConfig() {}
787 class KDEPIM_EXPORT KPrefsModule : public KCModule, public KPrefsWidManager
789 Q_OBJECT
790 public:
791 KPrefsModule( KConfigSkeleton *, const KComponentData &instance,
792 QWidget *parent=0, const QVariantList &args=QVariantList() );
794 virtual void addWid( KPrefsWid * );
796 void load();
797 void save();
798 void defaults();
800 protected Q_SLOTS:
801 void slotWidChanged();
803 protected:
804 /** Implement this to read custom configuration widgets. */
805 virtual void usrReadConfig() {}
806 /** Implement this to write custom configuration widgets. */
807 virtual void usrWriteConfig() {}
812 #endif