1 | /* |
2 | This file is part of the KDE project |
3 | SPDX-FileCopyrightText: 2007, 2009 Rafael Fernández López <ereslibre@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef KCATEGORYDRAWER_H |
9 | #define KCATEGORYDRAWER_H |
10 | |
11 | #include <kitemviews_export.h> |
12 | |
13 | #include <QMouseEvent> |
14 | #include <QObject> |
15 | #include <memory> |
16 | |
17 | class KCategoryDrawerPrivate; |
18 | |
19 | class QPainter; |
20 | class QModelIndex; |
21 | class QStyleOption; |
22 | |
23 | class KCategorizedView; |
24 | |
25 | /** |
26 | * @class KCategoryDrawer kcategorydrawer.h KCategoryDrawer |
27 | * |
28 | * The category drawing is performed by this class. It also gives information about the category |
29 | * height and margins. |
30 | * |
31 | */ |
32 | class KITEMVIEWS_EXPORT KCategoryDrawer : public QObject |
33 | { |
34 | Q_OBJECT |
35 | friend class KCategorizedView; |
36 | |
37 | public: |
38 | /* |
39 | * Construct a category drawer for a given view |
40 | * |
41 | * @since 5.0 |
42 | */ |
43 | KCategoryDrawer(KCategorizedView *view); |
44 | ~KCategoryDrawer() override; |
45 | |
46 | /** |
47 | * @return The view this category drawer is associated with. |
48 | */ |
49 | KCategorizedView *view() const; |
50 | |
51 | /** |
52 | * This method purpose is to draw a category represented by the given |
53 | * @param index with the given @param sortRole sorting role |
54 | * |
55 | * @note This method will be called one time per category, always with the |
56 | * first element in that category |
57 | */ |
58 | virtual void drawCategory(const QModelIndex &index, int sortRole, const QStyleOption &option, QPainter *painter) const; |
59 | |
60 | /** |
61 | * @return The category height for the category represented by index @p index with |
62 | * style options @p option. |
63 | */ |
64 | virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) const; |
65 | |
66 | /** |
67 | * @note 0 by default |
68 | * |
69 | * @since 4.4 |
70 | */ |
71 | virtual int leftMargin() const; |
72 | |
73 | /** |
74 | * @note 0 by default |
75 | * |
76 | * @since 4.4 |
77 | */ |
78 | virtual int rightMargin() const; |
79 | |
80 | Q_SIGNALS: |
81 | /** |
82 | * This signal becomes emitted when collapse or expand has been clicked. |
83 | */ |
84 | void collapseOrExpandClicked(const QModelIndex &index); |
85 | |
86 | /** |
87 | * Emit this signal on your subclass implementation to notify that something happened. Usually |
88 | * this will be triggered when you have received an event, and its position matched some "hot spot". |
89 | * |
90 | * You give this action the integer you want, and having connected this signal to your code, |
91 | * the connected slot can perform the needed changes (view, model, selection model, delegate...) |
92 | */ |
93 | void actionRequested(int action, const QModelIndex &index); |
94 | |
95 | protected: |
96 | /** |
97 | * Method called when the mouse button has been pressed. |
98 | * |
99 | * @param index The representative index of the block of items. |
100 | * @param blockRect The rect occupied by the block of items. |
101 | * @param event The mouse event. |
102 | * |
103 | * @warning You explicitly have to determine whether the event has been accepted or not. You |
104 | * have to call event->accept() or event->ignore() at all possible case branches in |
105 | * your code. |
106 | */ |
107 | virtual void mouseButtonPressed(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event); |
108 | |
109 | /** |
110 | * Method called when the mouse button has been released. |
111 | * |
112 | * @param index The representative index of the block of items. |
113 | * @param blockRect The rect occupied by the block of items. |
114 | * @param event The mouse event. |
115 | * |
116 | * @warning You explicitly have to determine whether the event has been accepted or not. You |
117 | * have to call event->accept() or event->ignore() at all possible case branches in |
118 | * your code. |
119 | */ |
120 | virtual void mouseButtonReleased(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event); |
121 | |
122 | /** |
123 | * Method called when the mouse has been moved. |
124 | * |
125 | * @param index The representative index of the block of items. |
126 | * @param blockRect The rect occupied by the block of items. |
127 | * @param event The mouse event. |
128 | */ |
129 | virtual void mouseMoved(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event); |
130 | |
131 | /** |
132 | * Method called when the mouse button has been double clicked. |
133 | * |
134 | * @param index The representative index of the block of items. |
135 | * @param blockRect The rect occupied by the block of items. |
136 | * @param event The mouse event. |
137 | * |
138 | * @warning You explicitly have to determine whether the event has been accepted or not. You |
139 | * have to call event->accept() or event->ignore() at all possible case branches in |
140 | * your code. |
141 | */ |
142 | virtual void mouseButtonDoubleClicked(const QModelIndex &index, const QRect &blockRect, QMouseEvent *event); |
143 | |
144 | /** |
145 | * Method called when the mouse button has left this block. |
146 | * |
147 | * @param index The representative index of the block of items. |
148 | * @param blockRect The rect occupied by the block of items. |
149 | */ |
150 | virtual void mouseLeft(const QModelIndex &index, const QRect &blockRect); |
151 | |
152 | private: |
153 | std::unique_ptr<KCategoryDrawerPrivate> const d; |
154 | }; |
155 | |
156 | #endif // KCATEGORYDRAWER_H |
157 | |