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

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: 2006      by Tobias Koenig <tokoe at kde dot org>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_DCONFIG_DLG_VIEW_H
0017 #define DIGIKAM_DCONFIG_DLG_VIEW_H
0018 
0019 // Qt includes
0020 
0021 #include <QWidget>
0022 
0023 // Local includes
0024 
0025 #include "digikam_export.h"
0026 
0027 class QAbstractItemDelegate;
0028 class QAbstractItemView;
0029 class QModelIndex;
0030 class QAbstractItemModel;
0031 
0032 namespace Digikam
0033 {
0034 
0035 class DConfigDlgViewPrivate;
0036 class DConfigDlgModel;
0037 
0038 /**
0039  * @short A base class which can handle multiple pages.
0040  *
0041  * This class provides a widget 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 DConfigDlgWdg
0047  *
0048  */
0049 class DIGIKAM_EXPORT DConfigDlgView : public QWidget
0050 {
0051     Q_OBJECT
0052     Q_PROPERTY(FaceType faceType READ faceType WRITE setFaceType)
0053     Q_DECLARE_PRIVATE(DConfigDlgView)
0054 
0055 public:
0056 
0057     /**
0058      * This enum is used to decide which type of navigation view
0059      * shall be used in the page view.
0060      *
0061      * @li Auto   - Depending on the number of pages in the model,
0062      *              the Plain (one page), the List (several pages)
0063      *              or the Tree face (nested pages) will be used.
0064      *              This is the default face type.
0065      * @li Plain  - No navigation view will be visible and only the
0066      *              first page of the model will be shown.
0067      *
0068      * @li List   - An icon list is used as navigation view.
0069      *
0070      * @li Tree   - A tree list is used as navigation view.
0071      *
0072      * @li Tabbed - A tab widget is used as navigation view.
0073      */
0074     enum FaceType
0075     {
0076         Auto,
0077         Plain,
0078         List,
0079         Tree,
0080         Tabbed
0081     };
0082     Q_ENUM(FaceType)
0083 
0084 public:
0085 
0086     /**
0087      * Creates a page view with given parent.
0088      */
0089     explicit DConfigDlgView(QWidget* const parent = nullptr);
0090 
0091     /**
0092      * Destroys the page view.
0093      */
0094     ~DConfigDlgView() override;
0095 
0096     /**
0097      * Sets the @p model of the page view.
0098      *
0099      * The model has to provide data for the roles defined in DConfigDlgModel::Role.
0100      */
0101     void setModel(QAbstractItemModel* model);
0102 
0103     /**
0104      * Returns the model of the page view.
0105      */
0106     QAbstractItemModel* model() const;
0107 
0108     /**
0109      * Sets the face type of the page view.
0110      */
0111     void setFaceType(FaceType faceType);
0112 
0113     /**
0114      * Returns the face type of the page view.
0115      */
0116     FaceType faceType() const;
0117 
0118     /**
0119      * Sets the page with @param index to be the current page and emits
0120      * the @see currentPageChanged signal.
0121      */
0122     void setCurrentPage(const QModelIndex& index);
0123 
0124     /**
0125      * Returns the index for the current page or an invalid index
0126      * if no current page exists.
0127      */
0128     QModelIndex currentPage() const;
0129 
0130     /**
0131      * Sets the item @param delegate which can be used customize
0132      * the page view.
0133      */
0134     void setItemDelegate(QAbstractItemDelegate* delegate);
0135 
0136     /**
0137      * Returns the item delegate of the page view.
0138      */
0139     QAbstractItemDelegate* itemDelegate() const;
0140 
0141     /**
0142      * Sets the @p widget which will be shown when a page is selected
0143      * that has no own widget set.
0144      */
0145     void setDefaultWidget(QWidget* widget);
0146 
0147 Q_SIGNALS:
0148 
0149     /**
0150      * This signal is emitted whenever the current page changes.
0151      * The previous page index is replaced by the current index.
0152      */
0153     void currentPageChanged(const QModelIndex& current, const QModelIndex& previous);
0154 
0155 protected:
0156 
0157     /**
0158      * Returns the navigation view, depending on the current
0159      * face type.
0160      *
0161      * This method can be reimplemented to provide custom
0162      * navigation views.
0163      */
0164     virtual QAbstractItemView* createView();
0165 
0166     /**
0167      * Returns whether the page header should be visible.
0168      *
0169      * This method can be reimplemented for adapting custom
0170      * views.
0171      */
0172     virtual bool showPageHeader() const;
0173 
0174     /**
0175      * Returns the position where the navigation view should be
0176      * located according to the page stack.
0177      *
0178      * This method can be reimplemented for adapting custom
0179      * views.
0180      */
0181     virtual Qt::Alignment viewPosition() const;
0182 
0183     DConfigDlgView(DConfigDlgViewPrivate& dd, QWidget* const parent);
0184 
0185 protected:
0186 
0187     DConfigDlgViewPrivate* const d_ptr;
0188 
0189 private:
0190 
0191     Q_PRIVATE_SLOT(d_func(), void _k_rebuildGui())
0192     Q_PRIVATE_SLOT(d_func(), void _k_modelChanged())
0193     Q_PRIVATE_SLOT(d_func(), void _k_pageSelected(const QItemSelection&, const QItemSelection&))
0194     Q_PRIVATE_SLOT(d_func(), void _k_dataChanged(const QModelIndex&, const QModelIndex&))
0195 };
0196 
0197 } // namespace Digikam
0198 
0199 #endif // DIGIKAM_DCONFIG_DLG_VIEW_H