summaryrefslogtreecommitdiffstats
path: root/depends/groupview/src/categorizedview_p.h
blob: 524bba3ab1e28f12011852b7fb86667fe6918fdf (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
/**
  * 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 KCATEGORIZEDVIEW_P_H
#define KCATEGORIZEDVIEW_P_H

class KCategorizedSortFilterProxyModel;
class KCategoryDrawer;
class KCategoryDrawerV2;
class KCategoryDrawerV3;

/**
  * @internal
  */
class KCategorizedView::Private
{
public:
	struct Block;
	struct Item;

	Private(KCategorizedView *q);
	~Private();

	/**
	  * @return whether this view has all required elements to be categorized.
	  */
	bool isCategorized() const;

	/**
	  * @return the block rect for the representative @p representative.
	  */
	QStyleOptionViewItemV4 blockRect(const QModelIndex &representative);

	/**
	  * Returns the first and last element that intersects with rect.
	  *
	  * @note see that here we cannot take out items between first and last (as we could
	  *       do with the rubberband).
	  *
	  * Complexity: O(log(n)) where n is model()->rowCount().
	  */
	QPair<QModelIndex, QModelIndex> intersectingIndexesWithRect(const QRect &rect) const;

	/**
	  * Returns the position of the block of @p category.
	  *
	  * Complexity: O(n) where n is the number of different categories when the block has been
	  *             marked as in quarantine. O(1) the rest of the times (the vast majority).
	  */
	QPoint blockPosition(const QString &category);

	/**
	  * Returns the height of the block determined by @p category.
	  */
	int blockHeight(const QString &category);

	/**
	  * Returns the actual viewport width.
	  */
	int viewportWidth() const;

	/**
	  * Marks all elements as in quarantine.
	  *
	  * Complexity: O(n) where n is model()->rowCount().
	  *
	  * @warning this is an expensive operation
	  */
	void regenerateAllElements();

	/**
	  * Update internal information, and keep sync with the real information that the model contains.
	  */
	void rowsInserted(const QModelIndex &parent, int start, int end);

	/**
	  * Returns @p rect in viewport terms, taking in count horizontal and vertical offsets.
	  */
	QRect mapToViewport(const QRect &rect) const;

	/**
	  * Returns @p rect in absolute terms, converted from viewport position.
	  */
	QRect mapFromViewport(const QRect &rect) const;

	/**
	  * Returns the height of the highest element in last row. This is only applicable if there is
	  * no grid set and uniformItemSizes is false.
	  *
	  * @param block in which block are we searching. Necessary to stop the search if we hit the
	  *              first item in this block.
	  */
	int highestElementInLastRow(const Block &block) const;

	/**
	  * Returns whether the view has a valid grid size.
	  */
	bool hasGrid() const;

	/**
	  * Returns the category for the given index.
	  */
	QString categoryForIndex(const QModelIndex &index) const;

	/**
	  * Updates the visual rect for item when flow is LeftToRight.
	  */
	void leftToRightVisualRect(const QModelIndex &index, Item &item,
							const Block &block, const QPoint &blockPos) const;

	/**
	  * Updates the visual rect for item when flow is TopToBottom.
	  * @note we only support viewMode == ListMode in this case.
	  */
	void topToBottomVisualRect(const QModelIndex &index, Item &item,
							const Block &block, const QPoint &blockPos) const;

	/**
	  * Called when expand or collapse has been clicked on the category drawer.
	  */
	void _k_slotCollapseOrExpandClicked(QModelIndex);

	KCategorizedView *q = nullptr;
	KCategorizedSortFilterProxyModel *proxyModel = nullptr;
	KCategoryDrawer *categoryDrawer = nullptr;
	int categorySpacing = 5;
	bool alternatingBlockColors = false;
	bool collapsibleBlocks = false;
	bool constantItemWidth = false;

	// FIXME: this is some really weird logic. Investigate.
	Block *hoveredBlock;
	QString hoveredCategory;
	QModelIndex hoveredIndex;

	QPoint pressedPosition;
	QRect rubberBandRect;

	QHash<QString, Block> blocks;
};

#endif // KCATEGORIZEDVIEW_P_H