KDialogBase Class Reference
Provides basic functionality needed by nearly all dialogs. A dialog base class with standard buttons and predefined layouts. More...
#include <kdialogbase.h>
Inheritance diagram for KDialogBase:


Public Types | |
| enum | ButtonCode { Help = 0x00000001, Default = 0x00000002, Ok = 0x00000004, Apply = 0x00000008, Try = 0x00000010, Cancel = 0x00000020, Close = 0x00000040, User1 = 0x00000080, User2 = 0x00000100, User3 = 0x00000200, No = 0x00000080, Yes = 0x00000100, Details = 0x00000400, Filler = 0x40000000, Stretch = 0x80000000 } |
| enum | ActionButtonStyle { ActionStyle0 = 0, ActionStyle1, ActionStyle2, ActionStyle3, ActionStyle4, ActionStyleMAX } |
| enum | DialogType { TreeList = KJanusWidget::TreeList, Tabbed = KJanusWidget::Tabbed, Plain = KJanusWidget::Plain, Swallow = KJanusWidget::Swallow, IconList = KJanusWidget::IconList } |
Public Slots | |
| void | enableButton (ButtonCode id, bool state) |
| void | enableButtonOK (bool state) |
| void | enableButtonApply (bool state) |
| void | enableButtonCancel (bool state) |
| void | enableLinkedHelp (bool state) |
| void | delayedDestruct () |
| void | setHelpLinkText (const QString &text) |
| void | setHelp (const QString &anchor, const QString &appname=QString::null) |
| void | helpClickedSlot (const QString &) |
| void | setDetails (bool showDetails) |
| void | setDetailsWidget (QWidget *detailsWidget) |
| void | updateBackground () |
| void | cancel () |
Signals | |
| void | helpClicked () |
| void | defaultClicked () |
| void | user3Clicked () |
| void | user2Clicked () |
| void | user1Clicked () |
| void | applyClicked () |
| void | tryClicked () |
| void | okClicked () |
| void | yesClicked () |
| void | noClicked () |
| void | cancelClicked () |
| void | closeClicked () |
| void | apply () KDE_DEPRECATED |
| void | backgroundChanged () |
| void | hidden () |
| void | finished () |
| void | aboutToShowDetails () |
| void | aboutToShowPage (QWidget *page) |
Public Member Functions | |
| KDialogBase (QWidget *parent=0, const char *name=0, bool modal=true, const QString &caption=QString::null, int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem()) | |
| KDialogBase (int dialogFace, const QString &caption, int buttonMask, ButtonCode defaultButton, QWidget *parent=0, const char *name=0, bool modal=true, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem()) | |
| KDialogBase (KDialogBase::DialogType dialogFace, WFlags f, QWidget *parent=0, const char *name=0, bool modal=true, const QString &caption=QString::null, int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem()) | |
| KDialogBase (const QString &caption, int buttonMask=Yes|No|Cancel, ButtonCode defaultButton=Yes, ButtonCode escapeButton=Cancel, QWidget *parent=0, const char *name=0, bool modal=true, bool separator=false, const KGuiItem &yes=KStdGuiItem::yes(), const KGuiItem &no=KStdGuiItem::no(), const KGuiItem &cancel=KStdGuiItem::cancel()) | |
| ~KDialogBase () | |
| void | setButtonBoxOrientation (int orientation) |
| void | setEscapeButton (ButtonCode id) |
| virtual void | adjustSize () |
| virtual QSize | sizeHint () const |
| virtual QSize | minimumSizeHint () const |
| QFrame * | plainPage () |
| QFrame * | addPage (const QString &itemName, const QString &header=QString::null, const QPixmap &pixmap=QPixmap()) |
| QFrame * | addPage (const QStringList &items, const QString &header=QString::null, const QPixmap &pixmap=QPixmap()) |
| QVBox * | addVBoxPage (const QString &itemName, const QString &header=QString::null, const QPixmap &pixmap=QPixmap()) |
| QVBox * | addVBoxPage (const QStringList &items, const QString &header=QString::null, const QPixmap &pixmap=QPixmap()) |
| QHBox * | addHBoxPage (const QString &itemName, const QString &header=QString::null, const QPixmap &pixmap=QPixmap()) |
| QHBox * | addHBoxPage (const QStringList &items, const QString &header=QString::null, const QPixmap &pixmap=QPixmap()) |
| QGrid * | addGridPage (int n, Orientation dir, const QString &itemName, const QString &header=QString::null, const QPixmap &pixmap=QPixmap()) |
| QGrid * | addGridPage (int n, Orientation dir, const QStringList &items, const QString &header=QString::null, const QPixmap &pixmap=QPixmap()) |
| void | setFolderIcon (const QStringList &path, const QPixmap &pixmap) |
| QFrame * | makeMainWidget () |
| QVBox * | makeVBoxMainWidget () |
| QHBox * | makeHBoxMainWidget () |
| QGrid * | makeGridMainWidget (int n, Orientation dir) |
| void | enableButtonSeparator (bool state) |
| void | showButton (ButtonCode id, bool state) |
| void | showButtonOK (bool state) |
| void | showButtonApply (bool state) |
| void | showButtonCancel (bool state) |
| bool | showPage (int index) |
| int | activePageIndex () const |
| int | pageIndex (QWidget *widget) const |
| void | setMainWidget (QWidget *widget) |
| QWidget * | mainWidget () |
| void | disableResize () |
| void | setInitialSize (const QSize &s, bool noResize=false) |
| void | incInitialSize (const QSize &s, bool noResize=false) |
| QSize | configDialogSize (const QString &groupName) const |
| QSize | configDialogSize (KConfig &config, const QString &groupName) const |
| void | saveDialogSize (const QString &groupName, bool global=false) |
| void | saveDialogSize (KConfig &config, const QString &groupName, bool global=false) const |
| void | setButtonOK (const KGuiItem &item=KStdGuiItem::ok()) |
| void | setButtonOKText (const QString &text=QString::null, const QString &tooltip=QString::null, const QString &quickhelp=QString::null) KDE_DEPRECATED |
| void | setButtonApply (const KGuiItem &item=KStdGuiItem::apply()) |
| void | setButtonApplyText (const QString &text=QString::null, const QString &tooltip=QString::null, const QString &quickhelp=QString::null) KDE_DEPRECATED |
| void | setButtonCancel (const KGuiItem &item=KStdGuiItem::cancel()) |
| void | setButtonCancelText (const QString &text=QString::null, const QString &tooltip=QString::null, const QString &quickhelp=QString::null) KDE_DEPRECATED |
| void | setButtonText (ButtonCode id, const QString &text) |
| void | setButtonTip (ButtonCode id, const QString &text) |
| void | setButtonWhatsThis (ButtonCode id, const QString &text) |
| void | setTreeListAutoResize (bool state) |
| void | setShowIconsInTreeList (bool state) |
| void | setRootIsDecorated (bool state) |
| void | unfoldTreeList (bool persist=false) |
| void | addWidgetBelowList (QWidget *widget) |
| void | addButtonBelowList (const QString &text, QObject *recv, const char *slot) |
| void | addButtonBelowList (const KGuiItem &guiitem, QObject *recv, const char *slot) |
| void | setIconListAllVisible (bool state) |
| void | showTile (bool state) |
| void | getBorderWidths (int &ulx, int &uly, int &lrx, int &lry) const KDE_DEPRECATED |
| QRect | getContentsRect () const KDE_DEPRECATED |
| QSize | calculateSize (int w, int h) const |
| QString | helpLinkText () const |
| QPushButton * | actionButton (ButtonCode id) |
Static Public Member Functions | |
| bool | haveBackgroundTile () |
| const QPixmap * | backgroundTile () |
| const QPixmap * | getBackgroundTile () KDE_DEPRECATED |
| void | setBackgroundTile (const QPixmap *pix) |
Protected Slots | |
| virtual void | slotHelp () |
| virtual void | slotDefault () |
| virtual void | slotDetails () |
| virtual void | slotUser3 () |
| virtual void | slotUser2 () |
| virtual void | slotUser1 () |
| virtual void | slotOk () |
| virtual void | slotApply () |
| virtual void | slotTry () |
| virtual void | slotYes () |
| virtual void | slotNo () |
| virtual void | slotCancel () |
| virtual void | slotClose () |
| virtual void | applyPressed () KDE_DEPRECATED |
| void | updateGeometry () |
| void | slotDelayedDestruct () |
Protected Member Functions | |
| virtual void | keyPressEvent (QKeyEvent *e) |
| virtual void | hideEvent (QHideEvent *) |
| virtual void | closeEvent (QCloseEvent *e) |
| virtual void | virtual_hook (int id, void *data) |
Detailed Description
Provides basic functionality needed by nearly all dialogs. A dialog base class with standard buttons and predefined layouts.
It offers the standard action buttons you'd expect to find in a dialog as well as the capability to define at most three configurable buttons. You can define a main widget that contains your specific dialog layout or you can use a predefined layout. Currently, TreeList/Paged, Tabbed, Plain, Swallow and IconList mode layouts (faces) are available.
The class takes care of the geometry management. You only need to define a minimum size for the widget you want to use as the main widget.
You can set a background tile (pixmap) for parts of the dialog. The tile you select is shared by all instances of this class in your application so that they all get the same look and feel.
There is a tutorial available on http://developer.kde.org/ (NOT YET) that contains copy/paste examples as well a screenshots on how to use this class.
Standard buttons (action buttons):
You select which buttons should be displayed, but you do not choose the order in which they are displayed. This ensures a standard interface in KDE. The button order can be changed, but this ability is only available for a central KDE control tool. The following buttons are available: OK, Cancel/Close, Apply/Try, Default, Help and three user definable buttons: User1, User2 and User3. You must specify the text of the UserN buttons. Each button has a virtual slot so you can overload the method when required. The default slots emit a signal as well, so you can choose to connect a signal instead of overriding the slot. The default implementation of slotHelp() will automatically enable the help system if you have provided a path to the help text. slotCancel() and slotClose() will run QDialog::reject() while slotOk() will run QDialog::accept(). You define a default button in the constructor.
If you don't want any buttons at all because your dialog is special in some way, then set the buttonMask argument in the constructor to zero (0). The optional button box separator line should not be enabled in this case. Note that the KDialogBase will animate a button press when the user press Escape. The button that is enabled is either Cancel, Close or the button that is defined by setEscapeButton() The animation will not take place when the buttonMask is zero. Your custom dialog code should reimplement the keyPressEvent and animate the cancel button so that the dialog behaves like regular dialogs. NOTE: None of the regular slots (like slotOk() ) or signals that are related to the standard action buttons will be used when you don't use these buttons.
sect Dialog shapes:
You can either use one of the prebuilt, easy to use, faces or define your own main widget. The dialog provides ready to use TreeList, Tabbed, Plain, Swallow and IconList faces. KDialogBase uses the KJanusWidget class internally to accomplish this. If you use TreeList, Tabbed or IconList mode, then add pages with addPage().
Pages that have been added can be removed again by simply deleting the page.
If you want complete control of how the dialog contents should look, then you can define a main widget by using setMainWidget(). You only need to set the minimum size of that widget and the dialog will resize itself to fit this minimum size. The dialog is resizeable, but cannot be made smaller than its minimum size.
Layout:
The dialog consists of a help area on top (becomes visible if you define a help path and use enableLinkedHelp()), the main area which is the built-in dialog face or your own widget in the middle and by default a button box at the bottom. The button box can also be placed at the right edge (to the right of the main widget). Use setButtonBoxOrientation() to control this behavior. A separator can be placed above the button box (or to the left when the button box is at the right edge). Normally you specify that you want a separator in the constructor, but you can use enableButtonSeparator() as well.
Standard compliance:
The class is derived from KDialog, so you get automatic access to the KDialog::marginHint(), KDialog::spacingHint() and the extended KDialog::setCaption() method. NOTE: The main widget you use will be positioned inside the dialog using a margin (or border) equal to KDialog::marginHint(). You should not add a margin yourself, since one will be added automatically. The example below (from kedit) shows how you use the top level widget and its layout. The second argument (the border) to QVBoxLayout is 0. This situation is valid for addPage , addVBoxPage , addHBoxPage , addGridPage , makeMainWidget , makeVBoxMainWidget , makeHBoxMainWidget and makeGridMainWidget as well.
Example:
UrlDlg::UrlDlg( QWidget *parent, const QString& caption, const QString& urltext) : KDialogBase( parent, "urldialog", true, caption, KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ) { QWidget *page = new QWidget( this ); setMainWidget(page); QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() ); QLabel *label = new QLabel( caption, page, "caption" ); topLayout->addWidget( label ); lineedit = new QLineEdit( urltext, page, "lineedit" ); lineedit->setMinimumWidth(fontMetrics().maxWidth()*20); topLayout->addWidget( lineedit ); topLayout->addStretch(10); }
If you use makeVBoxMainWidget(), then the dialog above can be made simpler but you lose the ability to add a stretchable area:
UrlDlg::UrlDlg( QWidget *parent, const QString& caption, const QString& urltext) : KDialogBase( parent, "urldialog", true, caption, KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, true ) { QVBox *page = makeVBoxMainWidget(); QLabel *label = new QLabel( caption, page, "caption" ); lineedit = new QLineEdit( urltext, page, "lineedit" ); lineedit->setMinimumWidth(fontMetrics().maxWidth()*20); }
This class can be used in many ways. Note that most KDE ui widgets and many of KDE core applications use the KDialogBase so for more inspiration you should study the code for these.
- Author:
- Mirko Boehm (mirko@kde.org) and Espen Sand (espen@kde.org)
Definition at line 193 of file kdialogbase.h.
Member Enumeration Documentation
|
|
Definition at line 216 of file kdialogbase.h. |
|
|
Definition at line 254 of file kdialogbase.h. |
Constructor & Destructor Documentation
|
||||||||||||||||||||||||||||||||||||||||||||
|
Constructor for the standard mode where you must specify the main widget with setMainWidget() .
Definition at line 98 of file kdialogbase.cpp. References enableButtonSeparator(), KDialog::layoutHintChanged(), KDialog::setCaption(), and updateGeometry(). |
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
In KDE4 a WFlag paramater should be added after modal and next function can be removed. Constructor for the predefined layout mode where you specify the kind of layout (face).
Definition at line 121 of file kdialogbase.cpp. References aboutToShowPage(), enableButtonSeparator(), KJanusWidget::isValid(), KDialog::layoutHintChanged(), KDialog::setCaption(), and updateGeometry(). |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constructor for the predefined layout mode where you specify the kind of layout (face).
Definition at line 150 of file kdialogbase.cpp. References aboutToShowPage(), enableButtonSeparator(), KJanusWidget::isValid(), KDialog::layoutHintChanged(), KDialog::setCaption(), and updateGeometry(). |
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Constructor for a message box mode where the If you need other names you can rename the buttons with setButtonText(). The dialog box is not resizable by default but this can be changed by setInitialSize(). If you select 'modal' to be true, the dialog will return Yes, No, or Cancel when closed otherwise you can use the signals yesClicked(), noClicked(), or cancelClicked() to determine the state.
Definition at line 180 of file kdialogbase.cpp. References enableButtonSeparator(), KDialog::layoutHintChanged(), setButtonCancel(), KDialog::setCaption(), and updateGeometry(). |
|
|
Destructor.
Definition at line 214 of file kdialogbase.cpp. |
Member Function Documentation
|
|
Sets the orientation of the button box.
It can be
Definition at line 346 of file kdialogbase.cpp. References enableLinkedHelp(), and KSeparator::setOrientation(). |
|
|
Sets the button that will be activated when the Escape key is pressed. Normally you should not use this function. By default, the Escape key is mapped to either the Cancel or the Close button if one of these buttons are defined. The user expects that Escape will cancel an operation so use this function with caution.
Definition at line 366 of file kdialogbase.cpp. |
|
|
Adjust the size of the dialog to fit the contents just before QDialog::exec() or QDialog::show() is called. This method will not be called if the dialog has been explicitly resized before showing it. Definition at line 428 of file kdialogbase.cpp. Referenced by incInitialSize(), setDetails(), and setInitialSize(). |
|
|
Retrieve the empty page when the predefined layout is used in This widget must be used as the toplevel widget of your dialog code.
Definition at line 421 of file kdialogbase.cpp. References KJanusWidget::plainPage(). Referenced by KConfigDialog::addPage(), KBugReport::KBugReport(), KLineEditDlg::KLineEditDlg(), and KProgressDialog::KProgressDialog(). |
|
||||||||||||||||
|
Add a page to the dialog when the class is used in The returned widget must be used as the toplevel widget for this particular page. Note: The returned frame widget has no layout manager associated with it. In order to use it you must create a layout yourself as the example below illustrates:
Definition at line 1297 of file kdialogbase.cpp. References KJanusWidget::addPage(). |
|
||||||||||||||||
|
This is like addPage() just above, with the difference that the first element is a list of strings.
These strings are used to form a path of folders down to the given page. The initial elements are names for the folders, while the last element is the name of the page. Note: This does yet only work for the Definition at line 1303 of file kdialogbase.cpp. References KJanusWidget::addPage(). |
|
||||||||||||||||
|
Add a page to the dialog when the class is used in The returned widget must be used as the toplevel widget for this particular page. The widget contains a QVBoxLayout layout so the widget children are lined up vertically. You can use it as follows:
Definition at line 1310 of file kdialogbase.cpp. References KJanusWidget::addVBoxPage(). Referenced by KConfigDialog::addPage(). |
|
||||||||||||||||
|
This is like addVBoxPage() just above, with the difference that the first element is a list of strings.
These strings are used to form a path of folders down to the given page. The initial elements are names for the folders, while the last element is the name of the page. Note: This does yet only work for the Definition at line 1316 of file kdialogbase.cpp. References KJanusWidget::addVBoxPage(). |
|
||||||||||||||||
|
Add a page to the dialog when the class is used in The returned widget must be used as the toplevel widget for this particular page. The widget contains a QHBoxLayout layout so the widget children are lined up horizontally. You can use it as follows:
Definition at line 1323 of file kdialogbase.cpp. References KJanusWidget::addHBoxPage(). |
|
||||||||||||||||
|
This is like addHBoxPage() just above, with the difference that the first element is a list of strings.
These strings are used to form a path of folders down to the given page. The initial elements are names for the folders, while the last element is the name of the page. Note: This does yet only work for the Definition at line 1330 of file kdialogbase.cpp. References KJanusWidget::addHBoxPage(). |
|
||||||||||||||||||||||||
|
Add a page to the dialog when the class is used in The returned widget must be used as the toplevel widget for this particular page. The widget contains a QGridLayout layout so the widget children are positioned in a grid.
Definition at line 1338 of file kdialogbase.cpp. References KJanusWidget::addGridPage(). |
|
||||||||||||||||||||||||
|
This is like addGridPage() just above, with the difference that the first element is a list of strings.
These strings are used to form a path of folders down to the given page. The initial elements are names for the folders, while the last element is the name of the page. Note: This does yet only work for the Definition at line 1346 of file kdialogbase.cpp. References KJanusWidget::addGridPage(). |
|
||||||||||||
|
Sets the icon used in
Definition at line 1354 of file kdialogbase.cpp. References KJanusWidget::setFolderIcon(). |
|
|
Make a main widget.
The function will make a QFrame widget and use setMainWidget() to register it. You can not use this function more than once, not if you have already defined a main widget with setMainWidget() and not if you have used the constructor where you define the face (
Definition at line 1362 of file kdialogbase.cpp. References setMainWidget(). |
|
|
Make a main widget.
The function will make a QVBox widget and use setMainWidget() to register it. You can use this function more than once, not if you have already defined a main widget with setMainWidget() and not if you have used the constructor where you define the face (
Definition at line 1376 of file kdialogbase.cpp. References setMainWidget(), and KDialog::spacingHint(). |
|
|
Make a main widget.
The function will make a QHBox widget and use setMainWidget() to register it. You can not use this function more than once, not if you have already defined a main widget with setMainWidget() and
Definition at line 1391 of file kdialogbase.cpp. References setMainWidget(), QHBox::setSpacing(), and KDialog::spacingHint(). |
|
||||||||||||
|
Make a main widget. The function will make a QGrid widget and use setMainWidget() to register it. You can not use this function more than once, not if you have already defined a main widget with setMainWidget and not if you have used the constructor where you define the face (Plain, Swallow, Tabbed, TreeList, IconList).
Definition at line 1406 of file kdialogbase.cpp. References setMainWidget(), QGrid::setSpacing(), and KDialog::spacingHint(). |
|
| &nbs |
