summaryrefslogtreecommitdiffstats
path: root/depends/groupview/include/categorydrawer.h
blob: f37422ec07197bad2a0d0938964c75e1ceca578f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**
  * This file is part of the KDE project
  * Copyright (C) 2007, 2009 Rafael Fernández López <ereslibre@kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public License
  * along with this library; see the file COPYING.LIB.  If not, write to
  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.
  */

#ifndef KCATEGORYDRAWER_H
#define KCATEGORYDRAWER_H

#include <groupview_config.h>

#include <QtCore/QObject>
#include <QtGui/QMouseEvent>

class QPainter;
class QModelIndex;
class QStyleOption;
class KCategorizedView;


/**
  * @since 4.5
  */
class LIBGROUPVIEW_EXPORT KCategoryDrawer
	: public QObject
{
	friend class KCategorizedView;
	Q_OBJECT


public:
	KCategoryDrawer ( KCategorizedView *view );
	virtual ~KCategoryDrawer();

	/**
	  * @return The view this category drawer is associated with.
	  */
	KCategorizedView *view() const;

	/**
	     * This method purpose is to draw a category represented by the given
	     * @param index with the given @param sortRole sorting role
	     *
	     * @note This method will be called one time per category, always with the
	     *       first element in that category
	     */
	virtual void drawCategory ( const QModelIndex &index,
	                            int sortRole,
	                            const QStyleOption &option,
	                            QPainter *painter ) const;

	/**
	  * @return The category height for the category representated by index @p index with
	  *         style options @p option.
	  */
	virtual int categoryHeight ( const QModelIndex &index, const QStyleOption &option ) const;

	//TODO KDE5: make virtual as leftMargin
	/**
	  * @note 0 by default
	  *
	  * @since 4.4
	  */
	int leftMargin() const;

	/**
	  * @note call to this method on the KCategoryDrawer constructor to set the left margin
	  *
	  * @since 4.4
	  */
	void setLeftMargin ( int leftMargin );

	//TODO KDE5: make virtual as rightMargin
	/**
	  * @note 0 by default
	  *
	  * @since 4.4
	  */
	int rightMargin() const;

	/**
	  * @note call to this method on the KCategoryDrawer constructor to set the right margin
	  *
	  * @since 4.4
	  */
	void setRightMargin ( int rightMargin );

	KCategoryDrawer &operator= ( const KCategoryDrawer &cd );
protected:
	/**
	  * Method called when the mouse button has been pressed.
	  *
	  * @param index The representative index of the block of items.
	  * @param blockRect The rect occupied by the block of items.
	  * @param event The mouse event.
	  *
	  * @warning You explicitly have to determine whether the event has been accepted or not. You
	  *          have to call event->accept() or event->ignore() at all possible case branches in
	  *          your code.
	  */
	virtual void mouseButtonPressed ( const QModelIndex &index, const QRect &blockRect, QMouseEvent *event );

	/**
	  * Method called when the mouse button has been released.
	  *
	  * @param index The representative index of the block of items.
	  * @param blockRect The rect occupied by the block of items.
	  * @param event The mouse event.
	  *
	  * @warning You explicitly have to determine whether the event has been accepted or not. You
	  *          have to call event->accept() or event->ignore() at all possible case branches in
	  *          your code.
	  */
	virtual void mouseButtonReleased ( const QModelIndex &index, const QRect &blockRect, QMouseEvent *event );

	/**
	  * Method called when the mouse has been moved.
	  *
	  * @param index The representative index of the block of items.
	  * @param blockRect The rect occupied by the block of items.
	  * @param event The mouse event.
	  */
	virtual void mouseMoved ( const QModelIndex &index, const QRect &blockRect, QMouseEvent *event );

	/**
	  * Method called when the mouse button has been double clicked.
	  *
	  * @param index The representative index of the block of items.
	  * @param blockRect The rect occupied by the block of items.
	  * @param event The mouse event.
	  *
	  * @warning You explicitly have to determine whether the event has been accepted or not. You
	  *          have to call event->accept() or event->ignore() at all possible case branches in
	  *          your code.
	  */
	virtual void mouseButtonDoubleClicked ( const QModelIndex &index, const QRect &blockRect, QMouseEvent *event );

	/**
	  * Method called when the mouse button has left this block.
	  *
	  * @param index The representative index of the block of items.
	  * @param blockRect The rect occupied by the block of items.
	  */
	virtual void mouseLeft ( const QModelIndex &index, const QRect &blockRect );

private:
	class Private;
	Private *const d;
Q_SIGNALS:
	/**
	  * This signal becomes emitted when collapse or expand has been clicked.
	  */
	void collapseOrExpandClicked ( const QModelIndex &index );

	/**
	  * Emit this signal on your subclass implementation to notify that something happened. Usually
	  * this will be triggered when you have received an event, and its position matched some "hot spot".
	  *
	  * You give this action the integer you want, and having connected this signal to your code,
	  * the connected slot can perform the needed changes (view, model, selection model, delegate...)
	  */
	void actionRequested ( int action, const QModelIndex &index );
};

#endif // KCATEGORYDRAWER_H