File indexing completed on 2025-01-19 03:53:49

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-11-03
0007  * Description : A dialog base class which can handle multiple pages.
0008  *
0009  * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 1999-2001 by Mirko Boehm <mirko at kde dot org>
0011  * SPDX-FileCopyrightText: 1999-2001 by Espen Sand <espen at kde dot org>
0012  * SPDX-FileCopyrightText: 1999-2001 by Holger Freyther <freyther at kde dot org>
0013  * SPDX-FileCopyrightText: 2005-2006 by Olivier Goffart <ogoffart at kde dot org>
0014  * SPDX-FileCopyrightText: 2006      by Tobias Koenig <tokoe at kde dot org>
0015  *
0016  * SPDX-License-Identifier: GPL-2.0-or-later
0017  *
0018  * ============================================================ */
0019 
0020 #ifndef DIGIKAM_DCONFIG_DLG_H
0021 #define DIGIKAM_DCONFIG_DLG_H
0022 
0023 // Qt includes
0024 
0025 #include <QDialog>
0026 #include <QDialogButtonBox>
0027 
0028 // Local includes
0029 
0030 #include "dconfigdlgwidgets.h"
0031 #include "digikam_export.h"
0032 
0033 namespace Digikam
0034 {
0035 
0036 class DConfigDlgPrivate;
0037 
0038 /**
0039  * @short A dialog base class which can handle multiple pages.
0040  *
0041  * This class provides a dialog base class which handles multiple
0042  * pages and allows the user to switch between these pages in
0043  * different ways.
0044  *
0045  * Currently, @p Auto, @p Plain, @p List, @p Tree and @p Tabbed face
0046  * types are available (@see DConfigDlgView).
0047  *
0048  */
0049 class DIGIKAM_EXPORT DConfigDlg : public QDialog
0050 {
0051     Q_OBJECT
0052     Q_DECLARE_PRIVATE(DConfigDlg)
0053 
0054 public:
0055 
0056     /**
0057      * @li @p Auto   - A dialog with a face based on the structure of the
0058      *                 available pages.
0059      *                 If only a single page is added, the dialog behaves like
0060      *                 in @p Plain mode, with multiple pages without sub pages
0061      *                 it behaves like in @p List mode and like in @p Tree mode
0062      *                 otherwise.
0063      * @li @p Plain  - A normal dialog.
0064      * @li @p List   - A dialog with an icon list on the left side and a
0065      *                 representation of the contents on the right side.
0066      * @li @p Tree   - A dialog with a tree on the left side and a
0067      *                 representation of the contents on the right side.
0068      * @li @p Tabbed - A dialog with a tab bar above the representation
0069      *                 of the contents.
0070      */
0071     enum FaceType
0072     {
0073         Auto   = DConfigDlgView::Auto,
0074         Plain  = DConfigDlgView::Plain,
0075         List   = DConfigDlgView::List,
0076         Tree   = DConfigDlgView::Tree,
0077         Tabbed = DConfigDlgView::Tabbed
0078     };
0079 
0080 public:
0081 
0082     /**
0083      * Creates a new page dialog.
0084      */
0085     explicit DConfigDlg(QWidget* const parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
0086 
0087     /**
0088      * Destroys the page dialog.
0089      */
0090     ~DConfigDlg()                                                     override;
0091 
0092     /**
0093      * Sets the face type of the dialog.
0094      */
0095     void setFaceType(FaceType faceType);
0096 
0097     /**
0098      * Adds a new top level page to the dialog.
0099      *
0100      * @param widget The widget of the page.
0101      * @param name The name which is displayed in the navigation view.
0102      *
0103      * @returns The associated @see DConfigDlgWdgItem.
0104      */
0105     DConfigDlgWdgItem* addPage(QWidget* const widget, const QString& name);
0106 
0107     /**
0108      * Adds a new top level page to the dialog.
0109      *
0110      * @param item The @see DConfigDlgWdgItem which describes the page.
0111      */
0112     void addPage(DConfigDlgWdgItem* const item);
0113 
0114     /**
0115      * Inserts a new page in the dialog.
0116      *
0117      * @param before The new page will be insert before this @see DConfigDlgWdgItem
0118      *               on the same level in hierarchy.
0119      * @param widget The widget of the page.
0120      * @param name The name which is displayed in the navigation view.
0121      *
0122      * @returns The associated @see DConfigDlgWdgItem.
0123      */
0124     DConfigDlgWdgItem* insertPage(DConfigDlgWdgItem* const before, QWidget* const widget, const QString& name);
0125 
0126     /**
0127      * Inserts a new page in the dialog.
0128      *
0129      * @param before The new page will be insert before this @see DConfigDlgWdgItem
0130      *               on the same level in hierarchy.
0131      *
0132      * @param item The @see DConfigDlgWdgItem which describes the page.
0133      */
0134     void insertPage(DConfigDlgWdgItem* const before, DConfigDlgWdgItem* const item);
0135 
0136     /**
0137      * Inserts a new sub page in the dialog.
0138      *
0139      * @param parent The new page will be insert as child of this @see DConfigDlgWdgItem.
0140      * @param widget The widget of the page.
0141      * @param name The name which is displayed in the navigation view.
0142      *
0143      * @returns The associated @see DConfigDlgWdgItem.
0144      */
0145     DConfigDlgWdgItem* addSubPage(DConfigDlgWdgItem* const parent, QWidget* const widget, const QString& name);
0146 
0147     /**
0148      * Inserts a new sub page in the dialog.
0149      *
0150      * @param parent The new page will be insert as child of this @see DConfigDlgWdgItem.
0151      *
0152      * @param item The @see DConfigDlgWdgItem which describes the page.
0153      */
0154     void addSubPage(DConfigDlgWdgItem* const parent, DConfigDlgWdgItem* const item);
0155 
0156     /**
0157      * Removes the page associated with the given @see DConfigDlgWdgItem.
0158      */
0159     void removePage(DConfigDlgWdgItem* const item);
0160 
0161     /**
0162      * Sets the page which is associated with the given @see DConfigDlgWdgItem to
0163      * be the current page and emits the currentPageChanged() signal.
0164      */
0165     void setCurrentPage(DConfigDlgWdgItem* const item);
0166 
0167     /**
0168      * Returns the @see DConfigDlgWdgItem for the current page or 0 if there is no
0169      * current page.
0170      */
0171     DConfigDlgWdgItem* currentPage()                            const;
0172 
0173     /**
0174      * Sets the collection of standard buttons displayed by this dialog.
0175      */
0176     void setStandardButtons(QDialogButtonBox::StandardButtons buttons);
0177 
0178     /**
0179      * Returns the QPushButton corresponding to the standard button which, or 0 if the standard
0180      * button doesn't exist in this dialog.
0181      */
0182     QPushButton* button(QDialogButtonBox::StandardButton which) const;
0183 
0184     /**
0185       * Set an action button.
0186       */
0187     void addActionButton(QAbstractButton* const button);
0188 
0189 Q_SIGNALS:
0190 
0191     /**
0192      * This signal is emitted whenever the current page has changed.
0193      *
0194      * @param current The new current page or 0 if no current page is available.
0195      */
0196     void currentPageChanged(DConfigDlgWdgItem* current, DConfigDlgWdgItem* before);
0197 
0198     /**
0199      * This signal is emitted whenever a page has been removed.
0200      *
0201      * @param page The page which has been removed
0202      */
0203     void pageRemoved(DConfigDlgWdgItem* page);
0204 
0205 protected:
0206 
0207     /**
0208      * This constructor can be used by subclasses to provide a custom page widget.
0209      *
0210      * \param widget The DConfigDlgWdg object will be reparented to this object, so you can create
0211      * it without parent and you are not allowed to delete it.
0212      */
0213     DConfigDlg(DConfigDlgWdg* const widget, QWidget* const parent, Qt::WindowFlags flags = Qt::WindowFlags());
0214     DConfigDlg(DConfigDlgPrivate& dd, DConfigDlgWdg* const widget, QWidget* const parent, Qt::WindowFlags flags = Qt::WindowFlags());
0215 
0216     /**
0217      * Returns the page widget of the dialog or 0 if no page widget is set.
0218      */
0219     DConfigDlgWdg* pageWidget();
0220 
0221     /**
0222      * Returns the page widget of the dialog or 0 if no page widget is set.
0223      */
0224     const DConfigDlgWdg* pageWidget()                           const;
0225 
0226     /**
0227      * Set the page widget of the dialog.
0228      *
0229      * @note the previous pageWidget will be deleted.
0230      *
0231      * @param widget The DConfigDlgWdg object will be reparented to this object, so you can create
0232      * it without parent and you are not allowed to delete it.
0233      */
0234     void setPageWidget(DConfigDlgWdg* const widget);
0235 
0236     /**
0237      * Returns the button box of the dialog or 0 if no button box is set.
0238      */
0239     QDialogButtonBox* buttonBox();
0240 
0241     /**
0242      * Returns the button box of the dialog or 0 if no button box is set.
0243      */
0244     const QDialogButtonBox* buttonBox()                         const;
0245 
0246     /**
0247      * Set the button box of the dialog
0248      *
0249      * @note the previous buttonBox will be deleted.
0250      *
0251      * @param box The QDialogButtonBox object will be reparented to this object, so you can create
0252      * it without parent and you are not allowed to delete it.
0253      */
0254     void setButtonBox(QDialogButtonBox* const box);
0255 
0256 protected:
0257 
0258     DConfigDlgPrivate* const d_ptr;
0259 };
0260 
0261 } // namespace Digikam
0262 
0263 #endif // DIGIKAM_DCONFIG_DLG_H