KItemViews

kcategorydrawer.h
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
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 */
32class KITEMVIEWS_EXPORT KCategoryDrawer : public QObject
33{
34 Q_OBJECT
35 friend class KCategorizedView;
36
37public:
38 /*
39 * Construct a category drawer for a given view
40 *
41 * @since 5.0
42 */
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
81 /**
82 * This signal becomes emitted when collapse or expand has been clicked.
83 */
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
95protected:
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
152private:
153 std::unique_ptr<KCategoryDrawerPrivate> const d;
154};
155
156#endif // KCATEGORYDRAWER_H
Item view for listing items in a categorized fashion optionally.
The category drawing is performed by this class.
void collapseOrExpandClicked(const QModelIndex &index)
This signal becomes emitted when collapse or expand has been clicked.
void actionRequested(int action, const QModelIndex &index)
Emit this signal on your subclass implementation to notify that something happened.
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:32 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.