File indexing completed on 2025-04-27 03:58:28

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-01-16
0007  * Description : drawing item view based on DCategorizedView
0008  *
0009  * SPDX-FileCopyrightText: 2007      by Rafael Fernández López <ereslibre at kde dot org>
0010  * SPDX-FileCopyrightText: 2009-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0011  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_DCATEGORY_DRAWER_H
0018 #define DIGIKAM_DCATEGORY_DRAWER_H
0019 
0020 // Qt includes
0021 
0022 #include <QObject>
0023 #include <QMouseEvent>
0024 
0025 // Local includes
0026 
0027 #include "digikam_export.h"
0028 
0029 class QPainter;
0030 class QModelIndex;
0031 class QStyleOption;
0032 
0033 namespace Digikam
0034 {
0035 
0036 class DCategorizedView;
0037 
0038 /**
0039  * The category drawing is performed by this class. It also gives information about the category
0040  * height and margins.
0041  */
0042 class DIGIKAM_EXPORT DCategoryDrawer : public QObject       // clazy:exclude=ctor-missing-parent-argument
0043 {
0044     Q_OBJECT
0045 
0046     friend class DCategorizedView;
0047 
0048 public:
0049     /**
0050      * Construct a category drawer for a given view
0051      *
0052      * @since 5.0
0053      */
0054     explicit DCategoryDrawer(DCategorizedView* const view);
0055     ~DCategoryDrawer()                                            override;
0056 
0057     /**
0058      * @return The view this category drawer is associated with.
0059      */
0060     DCategorizedView* view()                                const;
0061 
0062     /**
0063      * This method purpose is to draw a category represented by the given
0064      * @param index with the given @param sortRole sorting role
0065      *
0066      * @note This method will be called one time per category, always with the
0067      *       first element in that category
0068      */
0069     virtual void drawCategory(const QModelIndex& index,
0070                               int sortRole,
0071                               const QStyleOption& option,
0072                               QPainter* painter)            const;
0073 
0074     /**
0075      * @return The category height for the category represented by index @p index with
0076      *         style options @p option.
0077      */
0078     virtual int categoryHeight(const QModelIndex& index,
0079                                const QStyleOption& option)  const;
0080 
0081     /**
0082      * @note 0 by default
0083      */
0084     virtual int leftMargin()                                const;
0085 
0086     /**
0087      * @note 0 by default
0088      */
0089     virtual int rightMargin()                               const;
0090 
0091 Q_SIGNALS:
0092 
0093     /**
0094      * This signal becomes emitted when collapse or expand has been clicked.
0095      */
0096     void collapseOrExpandClicked(const QModelIndex& index);
0097 
0098     /**
0099      * Emit this signal on your subclass implementation to notify that something happened. Usually
0100      * this will be triggered when you have received an event, and its position matched some "hot spot".
0101      *
0102      * You give this action the integer you want, and having connected this signal to your code,
0103      * the connected slot can perform the needed changes (view, model, selection model, delegate...)
0104      */
0105     void actionRequested(int action, const QModelIndex& index);
0106 
0107 protected:
0108 
0109     /**
0110      * Method called when the mouse button has been pressed.
0111      *
0112      * @param index The representative index of the block of items.
0113      * @param blockRect The rect occupied by the block of items.
0114      * @param event The mouse event.
0115      *
0116      * @warning You explicitly have to determine whether the event has been accepted or not. You
0117      *          have to call event->accept() or event->ignore() at all possible case branches in
0118      *          your code.
0119      */
0120     virtual void mouseButtonPressed(const QModelIndex& index, const QRect& blockRect, QMouseEvent* event);
0121 
0122     /**
0123      * Method called when the mouse button has been released.
0124      *
0125      * @param index The representative index of the block of items.
0126      * @param blockRect The rect occupied by the block of items.
0127      * @param event The mouse event.
0128      *
0129      * @warning You explicitly have to determine whether the event has been accepted or not. You
0130      *          have to call event->accept() or event->ignore() at all possible case branches in
0131      *          your code.
0132      */
0133     virtual void mouseButtonReleased(const QModelIndex& index, const QRect& blockRect, QMouseEvent* event);
0134 
0135     /**
0136      * Method called when the mouse has been moved.
0137      *
0138      * @param index The representative index of the block of items.
0139      * @param blockRect The rect occupied by the block of items.
0140      * @param event The mouse event.
0141      */
0142     virtual void mouseMoved(const QModelIndex& index, const QRect& blockRect, QMouseEvent* event);
0143 
0144     /**
0145      * Method called when the mouse button has been double clicked.
0146      *
0147      * @param index The representative index of the block of items.
0148      * @param blockRect The rect occupied by the block of items.
0149      * @param event The mouse event.
0150      *
0151      * @warning You explicitly have to determine whether the event has been accepted or not. You
0152      *          have to call event->accept() or event->ignore() at all possible case branches in
0153      *          your code.
0154      */
0155     virtual void mouseButtonDoubleClicked(const QModelIndex& index, const QRect& blockRect, QMouseEvent* event);
0156 
0157     /**
0158      * Method called when the mouse button has left this block.
0159      *
0160      * @param index The representative index of the block of items.
0161      * @param blockRect The rect occupied by the block of items.
0162      */
0163     virtual void mouseLeft(const QModelIndex& index, const QRect& blockRect);
0164 
0165 private:
0166 
0167     class Private;
0168     Private* const d;
0169 };
0170 
0171 } // namespace Digikam
0172 
0173 #endif // DIGIKAM_DCATEGORY_DRAWER_H