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

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_WIDGETS_H
0017 #define DIGIKAM_DCONFIG_DLG_WIDGETS_H
0018 
0019 // Qt includes
0020 
0021 #include <QWidget>
0022 
0023 // Local includes
0024 
0025 #include "dconfigdlgmodels.h"
0026 #include "dconfigdlgview.h"
0027 #include "digikam_export.h"
0028 
0029 namespace Digikam
0030 {
0031 
0032 class DConfigDlgWdgPrivate;
0033 
0034 /**
0035  * @short Page widget with many layouts (faces).
0036  * @see DConfigDlgView with hierarchical page model.
0037  */
0038 class DIGIKAM_EXPORT DConfigDlgWdg : public DConfigDlgView
0039 {
0040     Q_OBJECT
0041     Q_DECLARE_PRIVATE(DConfigDlgWdg)
0042 
0043 public:
0044 
0045     /**
0046      * Creates a new page widget.
0047      *
0048      * @param parent The parent widget.
0049      */
0050     explicit DConfigDlgWdg(QWidget* const parent = nullptr);
0051 
0052     /**
0053      * Destroys the page widget.
0054      */
0055     ~DConfigDlgWdg() override;
0056 
0057     /**
0058      * Adds a new top level page to the widget.
0059      *
0060      * @param widget The widget of the page.
0061      * @param name The name which is displayed in the navigation view.
0062      *
0063      * @returns The associated @see DConfigDlgWdgItem.
0064      */
0065     DConfigDlgWdgItem* addPage(QWidget* widget, const QString& name);
0066 
0067     /**
0068      * Adds a new top level page to the widget.
0069      *
0070      * @param item The @see DConfigDlgWdgItem which describes the page.
0071      */
0072     void addPage(DConfigDlgWdgItem* item);
0073 
0074     /**
0075      * Inserts a new page in the widget.
0076      *
0077      * @param before The new page will be insert before this @see DConfigDlgWdgItem
0078      *               on the same level in hierarchy.
0079      * @param widget The widget of the page.
0080      * @param name The name which is displayed in the navigation view.
0081      *
0082      * @returns The associated @see DConfigDlgWdgItem.
0083      */
0084     DConfigDlgWdgItem* insertPage(DConfigDlgWdgItem* before, QWidget* widget, const QString& name);
0085 
0086     /**
0087      * Inserts a new page in the widget.
0088      *
0089      * @param before The new page will be insert before this @see DConfigDlgWdgItem
0090      *               on the same level in hierarchy.
0091      *
0092      * @param item The @see DConfigDlgWdgItem which describes the page.
0093      */
0094     void insertPage(DConfigDlgWdgItem* before, DConfigDlgWdgItem* item);
0095 
0096     /**
0097      * Inserts a new sub page in the widget.
0098      *
0099      * @param parent The new page will be insert as child of this @see DConfigDlgWdgItem.
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* addSubPage(DConfigDlgWdgItem* parent, QWidget* widget, const QString& name);
0106 
0107     /**
0108      * Inserts a new sub page in the widget.
0109      *
0110      * @param parent The new page will be insert as child of this @see DConfigDlgWdgItem.
0111      *
0112      * @param item The @see DConfigDlgWdgItem which describes the page.
0113      */
0114     void addSubPage(DConfigDlgWdgItem* parent, DConfigDlgWdgItem* item);
0115 
0116     /**
0117      * Removes the page associated with the given @see DConfigDlgWdgItem.
0118      */
0119     void removePage(DConfigDlgWdgItem* item);
0120 
0121     /**
0122      * Sets the page which is associated with the given @see DConfigDlgWdgItem to
0123      * be the current page and emits the currentPageChanged() signal.
0124      */
0125     void setCurrentPage(DConfigDlgWdgItem* item);
0126 
0127     /**
0128      * Returns the @see DConfigDlgWdgItem for the current page or 0 if there is no
0129      * current page.
0130      */
0131     DConfigDlgWdgItem* currentPage() const;
0132 
0133 Q_SIGNALS:
0134 
0135     /**
0136      * This signal is emitted whenever the current page has changed.
0137      *
0138      * @param current The new current page or 0 if no current page is available.
0139      */
0140     void currentPageChanged(DConfigDlgWdgItem* current, DConfigDlgWdgItem* before);
0141 
0142     /**
0143      * This signal is emitted whenever a checkable page changes its state. @param checked is true
0144      * when the @param page is checked, or false if the @param page is unchecked.
0145      */
0146     void pageToggled(DConfigDlgWdgItem* page, bool checked);
0147 
0148     /**
0149      * This signal is emitted when a page is removed.
0150      * @param page The page which is removed
0151      * */
0152     void pageRemoved(DConfigDlgWdgItem* page);
0153 
0154 protected:
0155 
0156     DConfigDlgWdg(DConfigDlgWdgPrivate& dd, QWidget* const parent);
0157 
0158 private:
0159 
0160     Q_PRIVATE_SLOT(d_func(), void _k_slotCurrentPageChanged(const QModelIndex&, const QModelIndex&))
0161 };
0162 
0163 // ----------------------------------------------------------------------------------------------------------------
0164 
0165 /**
0166  * This class provides a widget often used for DConfigDlg titles.
0167  *
0168  * DConfigDlgTitle uses the general application font at 1.4 times its size to
0169  * style the text.
0170  *
0171  * DConfigDlgTitle is very simple to use. You can either use its default text
0172  * (and pixmap) properties or display your own widgets in the title widget.
0173  *
0174  */
0175 class DConfigDlgTitle : public QWidget
0176 {
0177     Q_OBJECT
0178     Q_PROPERTY(QString text READ text WRITE setText)
0179     Q_PROPERTY(QString comment READ comment WRITE setComment)
0180     Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
0181     Q_PROPERTY(int autoHideTimeout READ autoHideTimeout WRITE setAutoHideTimeout)
0182 
0183 public:
0184 
0185     /**
0186      * Possible title pixmap alignments.
0187      *
0188      * @li ImageLeft: Display the pixmap left
0189      * @li ImageRight: Display the pixmap right (default)
0190      */
0191     enum ImageAlignment
0192     {
0193         ImageLeft,      ///< Display the pixmap on the left
0194         ImageRight      ///< Display the pixmap on the right
0195     };
0196     Q_ENUM(ImageAlignment)
0197 
0198     /**
0199      * Comment message types
0200      */
0201     enum MessageType
0202     {
0203         PlainMessage,   ///< Normal comment
0204         InfoMessage,    ///< Information the user should be alerted to
0205         WarningMessage, ///< A warning the user should be alerted to
0206         ErrorMessage    ///< An error message
0207     };
0208 
0209 public:
0210 
0211     /**
0212      * Constructs a title widget with the given @param parent .
0213      */
0214     explicit DConfigDlgTitle(QWidget* const parent = nullptr);
0215 
0216     ~DConfigDlgTitle()                  override;
0217 
0218     /**
0219      * @param widget the widget displayed on the title widget.
0220      */
0221     void setWidget(QWidget* const widget);
0222 
0223     /**
0224      * @return the text displayed in the title
0225      * @see setText()
0226      */
0227     QString text()          const;
0228 
0229     /**
0230      * @return the text displayed in the comment below the title, if any
0231      * @see setComment()
0232      */
0233     QString comment()       const;
0234 
0235     /**
0236      * @return the pixmap displayed in the title
0237      * @see setPixmap()
0238      */
0239     QPixmap pixmap() const;
0240 
0241     /**
0242      * Sets this label's buddy to buddy.
0243      * When the user presses the shortcut key indicated by the label in this
0244      * title widget, the keyboard focus is transferred to the label's buddy
0245      * widget.
0246      * @param buddy the widget to activate when the shortcut key is activated
0247      */
0248     void setBuddy(QWidget* const buddy);
0249 
0250     /**
0251      * Get the current timeout value in milliseconds
0252      * @return timeout value in msecs
0253      */
0254     int autoHideTimeout()   const;
0255 
0256 public Q_SLOTS:
0257 
0258     /**
0259      * @param text Text displayed on the label. It can either be plain text or rich text. If it
0260      * is plain text, the text is displayed as a bold title text.
0261      * @param alignment Alignment of the text. Default is left and vertical centered.
0262      * @see text()
0263      */
0264     void setText(const QString& text, Qt::Alignment alignment = Qt::AlignLeft | Qt::AlignVCenter);
0265     /**
0266      * @param text Text displayed on the label. It can either be plain text or rich text. If it
0267      * is plain text, the text is displayed as a bold title text.
0268      * @param type The sort of message it is; will also set the icon accordingly @see MessageType
0269      * @see text()
0270      */
0271     void setText(const QString& text, MessageType type);
0272 
0273     /**
0274      * @param comment Text displayed beneath the main title as a comment.
0275      *                It can either be plain text or rich text.
0276      * @param type The sort of message it is. @see MessageType
0277      * @see comment()
0278      */
0279     void setComment(const QString& comment, MessageType type = PlainMessage);
0280 
0281     /**
0282      * @param pixmap Pixmap displayed in the header. The pixmap is by default right, but
0283      * @param alignment can be used to display it also left.
0284      * @see pixmap()
0285      */
0286     void setPixmap(const QPixmap& pixmap, ImageAlignment alignment = ImageRight);
0287 
0288     /**
0289      * @param icon name of the icon to display in the header. The pixmap is by default right, but
0290      * @param alignment can be used to display it also left.
0291      * @see pixmap()
0292      */
0293     void setPixmap(const QString& icon, ImageAlignment alignment = ImageRight);
0294 
0295     /**
0296      * @param pixmap the icon to display in the header. The pixmap is by default right, but
0297      * @param alignment can be used to display it also left.
0298      * @see pixmap()
0299      */
0300     void setPixmap(const QIcon& icon, ImageAlignment alignment = ImageRight);
0301 
0302     /**
0303      * @param pixmap the icon to display in the header. The pixmap is by default right, but
0304      * @param alignment can be used to display it also left.
0305      * @see pixmap()
0306      */
0307     void setPixmap(MessageType type, ImageAlignment alignment = ImageRight);
0308 
0309     /**
0310      * Set the autohide timeout of the label
0311      * Set value to 0 to disable autohide, which is the default.
0312      * @param msecs timeout value in milliseconds
0313      */
0314     void setAutoHideTimeout(int msecs);
0315 
0316 protected:
0317 
0318     void changeEvent(QEvent*)           override;
0319     void showEvent(QShowEvent*)         override;
0320     bool eventFilter(QObject*, QEvent*) override;
0321 
0322 private:
0323 
0324     class Private;
0325     Private* const d;
0326 
0327     Q_PRIVATE_SLOT(d, void _k_timeoutFinished())
0328     Q_DISABLE_COPY(DConfigDlgTitle)
0329 };
0330 
0331 } // namespace Digikam
0332 
0333 #endif // DIGIKAM_DCONFIG_DLG_WIDGETS_H