File indexing completed on 2025-02-16 13:11:46
0001 /* 0002 This file is part of the KDE Libraries 0003 SPDX-FileCopyrightText: 1999-2001 Mirko Boehm <mirko@kde.org> 0004 SPDX-FileCopyrightText: 1999-2001 Espen Sand <espen@kde.org> 0005 SPDX-FileCopyrightText: 1999-2001 Holger Freyther <freyther@kde.org> 0006 SPDX-FileCopyrightText: 2005-2006 Olivier Goffart <ogoffart at kde.org> 0007 SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org> 0008 0009 SPDX-License-Identifier: LGPL-2.0-or-later 0010 */ 0011 #ifndef KPAGEDIALOG_H 0012 #define KPAGEDIALOG_H 0013 0014 #include <QDialog> 0015 #include <QDialogButtonBox> 0016 #include <kpagewidget.h> 0017 #include <memory> 0018 0019 class KPageDialogPrivate; 0020 0021 /** 0022 * @class KPageDialog kpagedialog.h KPageDialog 0023 * 0024 * @short A dialog base class which can handle multiple pages. 0025 * 0026 * This class provides a dialog base class which handles multiple 0027 * pages and allows the user to switch between these pages in 0028 * different ways. 0029 * 0030 * Currently, @p Auto, @p Plain, @p List, @p Tree and @p Tabbed face 0031 * types are available (cmp. KPageView). 0032 * 0033 * By default a QDialogButtonBox is added to the dialog with two buttons, 0034 * OK (@c QDialogButtonBox::Ok) and Cancel (@c QDialogButtonBox::Cancel). 0035 * You can customize which buttons are added to the dialog by using any of the 0036 * available buttons-related methods. 0037 * 0038 * Note that if there is a QDialogButtonBox (either the one added by default, or 0039 * one you added manually) some logical connections are created: 0040 * - @c QDialogButtonBox::accepted() is connected to @c QDialog::accept() 0041 * - @c QDialogButtonBox::rejected() is connected to @c QDialog::reject() 0042 * this means that you shouldn't create these connections again (otherwise you 0043 * would end up receiving two duplicate accepted() signals for example). 0044 * 0045 * <b>Example:</b>\n 0046 * 0047 * @code 0048 * UrlDialog::UrlDialog( QWidget *parent ) 0049 * : KPageDialog( parent ) 0050 * { 0051 * setFaceType(List); 0052 * 0053 * QLabel *label = new QLabel("Test Page"); 0054 * addPage(label, i18n("My Test Page")); 0055 * 0056 * label = new QLabel("Second Test Page"); 0057 * KPageWidgetItem *page = new KPageWidgetItem(label, i18n("My Second Test Page")); 0058 * page->setHeader(i18n("My header string")); 0059 * page->setIcon(QIcon::fromTheme("file")); 0060 * 0061 * addPage(page); 0062 * 0063 * // Change the buttons added to the dialog 0064 * setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel); 0065 * 0066 * // Alternatively you can create a QDialogButtonBox, add the buttons you want to it, 0067 * // then add that button box to the dialog 0068 * QDialogButtonBox *btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel, 0069 * Qt::Horizontal, 0070 * this); 0071 * setButtonBox(btnBox); 0072 * } 0073 * @endcode 0074 * 0075 * @author Tobias Koenig (tokoe@kde.org) 0076 */ 0077 class KWIDGETSADDONS_EXPORT KPageDialog : public QDialog 0078 { 0079 Q_OBJECT 0080 Q_DECLARE_PRIVATE(KPageDialog) 0081 0082 public: 0083 /** 0084 * The face types supported. 0085 */ 0086 enum FaceType { 0087 /** 0088 * A dialog with a face based on the structure of the available pages. 0089 * If only a single page is added, the dialog behaves like 0090 * in @c Plain mode, with multiple pages without sub pages 0091 * it behaves like in @c List mode and like in @c Tree mode otherwise. 0092 */ 0093 Auto = KPageView::Auto, 0094 /** 0095 * A normal dialog 0096 */ 0097 Plain = KPageView::Plain, 0098 /** 0099 * A dialog with an icon list on the left side and a 0100 * representation of the contents on the right side 0101 */ 0102 List = KPageView::List, 0103 /** 0104 * A dialog with a tree on the left side and a 0105 * representation of the contents on the right side 0106 */ 0107 Tree = KPageView::Tree, 0108 /** 0109 * A dialog with a tab bar above the representation 0110 * of the contents 0111 */ 0112 Tabbed = KPageView::Tabbed, 0113 /** 0114 * A dialog with an flat list with small icons on the left side 0115 * and a representation of the contents on the right side 0116 */ 0117 FlatList = KPageView::FlatList, 0118 }; 0119 0120 public: 0121 /** 0122 * Creates a new page dialog. 0123 */ 0124 explicit KPageDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); 0125 0126 /** 0127 * Destroys the page dialog. 0128 */ 0129 ~KPageDialog() override; 0130 0131 /** 0132 * Sets the face type of the dialog. 0133 */ 0134 void setFaceType(FaceType faceType); 0135 0136 /** 0137 * Adds a new top level page to the dialog. 0138 * 0139 * @param widget The widget of the page. 0140 * @param name The name which is displayed in the navigation view. 0141 * 0142 * @returns The associated KPageWidgetItem. 0143 */ 0144 KPageWidgetItem *addPage(QWidget *widget, const QString &name); 0145 0146 /** 0147 * Adds a new top level page to the dialog. 0148 * 0149 * @param item The KPageWidgetItem which describes the page. 0150 */ 0151 void addPage(KPageWidgetItem *item); 0152 0153 /** 0154 * Inserts a new page in the dialog. 0155 * 0156 * @param before The new page will be insert before this KPageWidgetItem 0157 * on the same level in hierarchy. 0158 * @param widget The widget of the page. 0159 * @param name The name which is displayed in the navigation view. 0160 * 0161 * @returns The associated KPageWidgetItem. 0162 */ 0163 KPageWidgetItem *insertPage(KPageWidgetItem *before, QWidget *widget, const QString &name); 0164 0165 /** 0166 * Inserts a new page in the dialog. 0167 * 0168 * @param before The new page will be insert before this KPageWidgetItem 0169 * on the same level in hierarchy. 0170 * 0171 * @param item The KPageWidgetItem which describes the page. 0172 */ 0173 void insertPage(KPageWidgetItem *before, KPageWidgetItem *item); 0174 0175 /** 0176 * Inserts a new sub page in the dialog. 0177 * 0178 * @param parent The new page will be insert as child of this KPageWidgetItem. 0179 * @param widget The widget of the page. 0180 * @param name The name which is displayed in the navigation view. 0181 * 0182 * @returns The associated KPageWidgetItem. 0183 */ 0184 KPageWidgetItem *addSubPage(KPageWidgetItem *parent, QWidget *widget, const QString &name); 0185 0186 /** 0187 * Inserts a new sub page in the dialog. 0188 * 0189 * @param parent The new page will be insert as child of this KPageWidgetItem. 0190 * 0191 * @param item The KPageWidgetItem which describes the page. 0192 */ 0193 void addSubPage(KPageWidgetItem *parent, KPageWidgetItem *item); 0194 0195 /** 0196 * Removes the page associated with the given KPageWidgetItem. 0197 */ 0198 void removePage(KPageWidgetItem *item); 0199 0200 /** 0201 * Sets the page which is associated with the given KPageWidgetItem to 0202 * be the current page and emits the currentPageChanged() signal. 0203 */ 0204 void setCurrentPage(KPageWidgetItem *item); 0205 0206 /** 0207 * Returns the KPageWidgetItem for the current page or a null pointer if there is no 0208 * current page. 0209 */ 0210 KPageWidgetItem *currentPage() const; 0211 0212 /** 0213 * Sets the collection of standard buttons displayed by this dialog. 0214 */ 0215 void setStandardButtons(QDialogButtonBox::StandardButtons buttons); 0216 0217 /** 0218 * Returns the QPushButton corresponding to the standard button which, or a null pointer if the standard 0219 * button doesn't exist in this dialog. 0220 */ 0221 QPushButton *button(QDialogButtonBox::StandardButton which) const; 0222 0223 /** 0224 * Set an action button. 0225 */ 0226 void addActionButton(QAbstractButton *button); 0227 0228 Q_SIGNALS: 0229 /** 0230 * This signal is emitted whenever the current page has changed. 0231 * 0232 * @param current The new current page or a null pointer if no current page is available. 0233 * @param before The page that was current before the new current page has changed. 0234 */ 0235 void currentPageChanged(KPageWidgetItem *current, KPageWidgetItem *before); 0236 0237 /** 0238 * This signal is emitted whenever a page has been removed. 0239 * 0240 * @param page The page which has been removed 0241 */ 0242 void pageRemoved(KPageWidgetItem *page); 0243 0244 protected: 0245 /** 0246 * This constructor can be used by subclasses to provide a custom page widget. 0247 * 0248 * \param widget The KPageWidget object will be reparented to this object, so you can create 0249 * it without parent and you are not allowed to delete it. 0250 */ 0251 KPageDialog(KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags = Qt::WindowFlags()); 0252 KWIDGETSADDONS_NO_EXPORT KPageDialog(KPageDialogPrivate &dd, KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags = Qt::WindowFlags()); 0253 0254 /** 0255 * Returns the page widget of the dialog or a null pointer if no page widget is set. 0256 */ 0257 KPageWidget *pageWidget(); 0258 0259 /** 0260 * Returns the page widget of the dialog or a null pointer if no page widget is set. 0261 */ 0262 const KPageWidget *pageWidget() const; 0263 0264 /** 0265 * Set the page widget of the dialog. 0266 * 0267 * @note the previous pageWidget will be deleted. 0268 * 0269 * @param widget The KPageWidget object will be reparented to this object, so you can create 0270 * it without parent and you are not allowed to delete it. 0271 */ 0272 void setPageWidget(KPageWidget *widget); 0273 0274 /** 0275 * Returns the button box of the dialog or a null pointer if no button box is set. 0276 */ 0277 QDialogButtonBox *buttonBox(); 0278 0279 /** 0280 * Returns the button box of the dialog or a null pointer if no button box is set. 0281 */ 0282 const QDialogButtonBox *buttonBox() const; 0283 0284 /** 0285 * Set the button box of the dialog 0286 * 0287 * @note the previous buttonBox will be deleted. 0288 * 0289 * @param box The QDialogButtonBox object will be reparented to this object, so you can create 0290 * it without parent and you are not allowed to delete it. 0291 */ 0292 void setButtonBox(QDialogButtonBox *box); 0293 0294 protected: 0295 std::unique_ptr<class KPageDialogPrivate> const d_ptr; 0296 }; 0297 0298 #endif