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

source code of kitemviews/src/kcategorydrawer.h