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 KCATEGORIZEDVIEW_P_H |
9 | #define KCATEGORIZEDVIEW_P_H |
10 | |
11 | #include "kcategorizedview.h" |
12 | |
13 | class KCategorizedSortFilterProxyModel; |
14 | class KCategoryDrawer; |
15 | class KCategoryDrawerV2; |
16 | class KCategoryDrawerV3; |
17 | |
18 | /** |
19 | * @internal |
20 | */ |
21 | class KCategorizedViewPrivate |
22 | { |
23 | public: |
24 | struct Block; |
25 | struct Item; |
26 | |
27 | explicit KCategorizedViewPrivate(KCategorizedView *qq); |
28 | ~KCategorizedViewPrivate(); |
29 | |
30 | /** |
31 | * @return whether this view has all required elements to be categorized. |
32 | */ |
33 | bool isCategorized() const; |
34 | |
35 | /** |
36 | * Wrapper that returns the view's QStyleOptionViewItem, in Qt5 using viewOptions(), and |
37 | * in Qt6 using initViewItemOption(). |
38 | */ |
39 | QStyleOptionViewItem viewOpts(); |
40 | |
41 | /** |
42 | * @return the block rect for the representative @p representative. |
43 | */ |
44 | QStyleOptionViewItem blockRect(const QModelIndex &representative); |
45 | |
46 | /** |
47 | * Returns the first and last element that intersects with rect. |
48 | * |
49 | * @note see that here we cannot take out items between first and last (as we could |
50 | * do with the rubberband). |
51 | * |
52 | * Complexity: O(log(n)) where n is model()->rowCount(). |
53 | */ |
54 | std::pair<QModelIndex, QModelIndex> intersectingIndexesWithRect(const QRect &rect) const; |
55 | |
56 | /** |
57 | * Returns the position of the block of @p category. |
58 | * |
59 | * Complexity: O(n) where n is the number of different categories when the block has been |
60 | * marked as in quarantine. O(1) the rest of the times (the vast majority). |
61 | */ |
62 | QPoint blockPosition(const QString &category); |
63 | |
64 | /** |
65 | * Returns the height of the block determined by @p category. |
66 | */ |
67 | int blockHeight(const QString &category); |
68 | |
69 | /** |
70 | * Returns the actual viewport width. |
71 | */ |
72 | int viewportWidth() const; |
73 | |
74 | /** |
75 | * Marks all elements as in quarantine. |
76 | * |
77 | * Complexity: O(n) where n is model()->rowCount(). |
78 | * |
79 | * @warning this is an expensive operation |
80 | */ |
81 | void regenerateAllElements(); |
82 | |
83 | /** |
84 | * Update internal information, and keep sync with the real information that the model contains. |
85 | */ |
86 | void rowsInserted(const QModelIndex &parent, int start, int end); |
87 | |
88 | /** |
89 | * Returns @p rect in viewport terms, taking in count horizontal and vertical offsets. |
90 | */ |
91 | QRect mapToViewport(const QRect &rect) const; |
92 | |
93 | /** |
94 | * Returns @p rect in absolute terms, converted from viewport position. |
95 | */ |
96 | QRect mapFromViewport(const QRect &rect) const; |
97 | |
98 | /** |
99 | * Returns the height of the highest element in last row. This is only applicable if there is |
100 | * no grid set and uniformItemSizes is false. |
101 | * |
102 | * @param block in which block are we searching. Necessary to stop the search if we hit the |
103 | * first item in this block. |
104 | */ |
105 | int highestElementInLastRow(const Block &block) const; |
106 | |
107 | /** |
108 | * Returns whether the view has a valid grid size. |
109 | */ |
110 | bool hasGrid() const; |
111 | |
112 | /** |
113 | * Returns the category for the given index. |
114 | */ |
115 | QString categoryForIndex(const QModelIndex &index) const; |
116 | |
117 | /** |
118 | * Updates the visual rect for item when flow is LeftToRight. |
119 | */ |
120 | void leftToRightVisualRect(const QModelIndex &index, Item &item, const Block &block, const QPoint &blockPos) const; |
121 | |
122 | /** |
123 | * Updates the visual rect for item when flow is TopToBottom. |
124 | * @note we only support viewMode == ListMode in this case. |
125 | */ |
126 | void topToBottomVisualRect(const QModelIndex &index, Item &item, const Block &block, const QPoint &blockPos) const; |
127 | |
128 | /** |
129 | * Called when expand or collapse has been clicked on the category drawer. |
130 | */ |
131 | void _k_slotCollapseOrExpandClicked(QModelIndex); |
132 | |
133 | KCategorizedView *const q; |
134 | KCategorizedSortFilterProxyModel *proxyModel = nullptr; |
135 | KCategoryDrawer *categoryDrawer = nullptr; |
136 | int categorySpacing = 0; |
137 | bool alternatingBlockColors = false; |
138 | bool collapsibleBlocks = false; |
139 | |
140 | Block *const hoveredBlock; |
141 | QString hoveredCategory; |
142 | QModelIndex hoveredIndex; |
143 | |
144 | QPoint pressedPosition; |
145 | QRect rubberBandRect; |
146 | |
147 | QHash<QString, Block> blocks; |
148 | }; |
149 | |
150 | #endif // KCATEGORIZEDVIEW_P_H |
151 | |