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"
31 #include <KConfigSkeleton>
34 #include <KPageDialog>
36 #include <QVariantList>
55 @short Base class for GUI control elements used by @ref KPrefsDialog.
56 @author Cornelius Schumacher
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
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;
73 This function is called to write the current setting of the widget to the
76 virtual void writeConfig() = 0;
79 Return a list of widgets used by this control element.
81 virtual QList
<QWidget
*> widgets() const;
85 Emitted when widget value has changed.
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
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();
115 QList
<QWidget
*> widgets() const;
118 KConfigSkeleton::ItemBool
*mItem
;
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
130 class KDEPIM_EXPORT KPrefsWidInt
: public KPrefsWid
134 Create a integer value control element consisting of a label and a
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.
148 Return the QSpinBox used by this control element.
155 QList
<QWidget
*> widgets() const;
158 KConfigSkeleton::ItemInt
*mItem
;
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
171 class KDEPIM_EXPORT KPrefsWidTime
: public KPrefsWid
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.
187 Return QSpinBox used by this widget.
189 KTimeEdit
*timeEdit();
195 KConfigSkeleton::ItemDateTime
*mItem
;
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
208 class KDEPIM_EXPORT KPrefsWidDuration
: public KPrefsWid
212 Create a duration value control element consisting of a label and a
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.
226 Return QSpinBox used by this widget.
228 QTimeEdit
*timeEdit();
234 KConfigSkeleton::ItemDateTime
*mItem
;
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
247 class KDEPIM_EXPORT KPrefsWidDate
: public KPrefsWid
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.
263 Return QSpinBox used by this widget.
265 KDateEdit
*dateEdit();
271 KConfigSkeleton::ItemDateTime
*mItem
;
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
284 class KDEPIM_EXPORT KPrefsWidColor
: public KPrefsWid
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.
303 Return QLabel for the button
307 Return button opening the color dialog.
309 KColorButton
*button();
315 KConfigSkeleton::ItemColor
*mItem
;
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
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.
352 Return QFrame used as preview field.
357 Return button opening the font dialog.
359 QPushButton
*button();
368 KConfigSkeleton::ItemFont
*mItem
;
372 QPushButton
*mButton
;
376 @short Widgets for settings represented by a group of radio buttons in
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
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();
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();
418 QList
<QWidget
*> widgets() const;
421 KConfigSkeleton::ItemEnum
*mItem
;
427 @short Widgets for settings represented by a combo box in
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
436 class KDE_EXPORT KPrefsWidCombo
: public KPrefsWid
440 Create a control element for selection of an option. It consists of a
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();
452 KComboBox
*comboBox();
453 QList
<QWidget
*> widgets() const;
456 KConfigSkeleton::ItemEnum
*mItem
;
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
467 class KDEPIM_EXPORT KPrefsWidString
: public KPrefsWid
471 Create a string value control element consisting of a test label and a
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
,
480 KLineEdit::EchoMode echomode
=KLineEdit::Normal
);
484 virtual ~KPrefsWidString();
487 Return QLabel used by this widget.
491 Return KLineEdit used by this widget.
493 KLineEdit
*lineEdit();
498 QList
<QWidget
*> widgets() const;
501 KConfigSkeleton::ItemString
*mItem
;
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
514 class KDEPIM_EXPORT KPrefsWidPath
: public KPrefsWid
518 Create a string value control element consisting of a test label and a
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
,
528 const QString
&filter
= QString(),
529 KFile::Modes
= KFile::File
);
534 virtual ~KPrefsWidPath();
537 Return QLabel used by this widget.
542 Return KUrlRequester used by this widget.
544 KUrlRequester
*urlRequester();
549 QList
<QWidget
*> widgets() const;
552 KConfigSkeleton::ItemPath
*mItem
;
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
570 Create a KPrefsWidManager object for a KPrefs object.
572 @param prefs KPrefs object used to access te configuration.
574 explicit KPrefsWidManager( KConfigSkeleton
*prefs
);
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
,
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
700 @param parent Parent widget.
701 @param sampleText Sample text for previewing the selected font.
703 KPrefsWidFont
*addWidFont( KConfigSkeleton::ItemFont
*item
,
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();
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
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 );
752 virtual ~KPrefsDialog();
757 /** Set all widgets to default values. */
760 /** Read preferences from config file. */
763 /** Write preferences to config file. */
767 /** Emitted when the a changed configuration has been stored. */
768 void configChanged();
771 /** Apply changes to preferences */
774 /** Accept changes to preferences and close dialog */
777 /** Set preferences to default values */
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
791 KPrefsModule( KConfigSkeleton
*, const KComponentData
&instance
,
792 QWidget
*parent
=0, const QVariantList
&args
=QVariantList() );
794 virtual void addWid( KPrefsWid
* );
801 void slotWidChanged();
804 /** Implement this to read custom configuration widgets. */
805 virtual void usrReadConfig() {}
806 /** Implement this to write custom configuration widgets. */
807 virtual void usrWriteConfig() {}