]> cloud.milkyroute.net Git - dolphin.git/blob - src/kcategorizedview_p.h
Factorize all the view-related action handling to DolphinViewActionHandler, to remove...
[dolphin.git] / src / kcategorizedview_p.h
1 /**
2 * This file is part of the KDE project
3 * Copyright (C) 2007 Rafael Fernández López <ereslibre@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #ifndef KCATEGORIZEDVIEW_P_H
22 #define KCATEGORIZEDVIEW_P_H
23
24 class KCategorizedSortFilterProxyModel;
25 class KCategoryDrawer;
26
27 /**
28 * @internal
29 */
30 class KCategorizedView::Private
31 {
32 public:
33 Private(KCategorizedView *listView);
34 ~Private();
35
36
37 // Methods
38
39 /**
40 * Returns the list of items that intersects with @p rect
41 */
42 const QModelIndexList &intersectionSet(const QRect &rect);
43
44 /**
45 * Gets the item rect in the viewport for @p index
46 */
47 QRect visualRectInViewport(const QModelIndex &index) const;
48
49 /**
50 * Returns the category rect in the viewport for @p category
51 */
52 QRect visualCategoryRectInViewport(const QString &category) const;
53
54 /**
55 * Caches and returns the rect that corresponds to @p index
56 */
57 const QRect &cacheIndex(const QModelIndex &index);
58
59 /**
60 * Caches and returns the rect that corresponds to @p category
61 */
62 const QRect &cacheCategory(const QString &category);
63
64 /**
65 * Returns the rect that corresponds to @p index
66 * @note If the rect is not cached, it becomes cached
67 */
68 const QRect &cachedRectIndex(const QModelIndex &index);
69
70 /**
71 * Returns the rect that corresponds to @p category
72 * @note If the rect is not cached, it becomes cached
73 */
74 const QRect &cachedRectCategory(const QString &category);
75
76 /**
77 * Returns the visual rect (taking in count x and y offsets) for @p index
78 * @note If the rect is not cached, it becomes cached
79 */
80 QRect visualRect(const QModelIndex &index);
81
82 /**
83 * Returns the visual rect (taking in count x and y offsets) for @p category
84 * @note If the rect is not cached, it becomes cached
85 */
86 QRect categoryVisualRect(const QString &category);
87
88 /**
89 * This method will draw a new category represented by index
90 * @param index on the rect specified by @p option.rect, with
91 * painter @p painter
92 */
93 void drawNewCategory(const QModelIndex &index,
94 int sortRole,
95 const QStyleOption &option,
96 QPainter *painter);
97
98 /**
99 * This method will update scrollbars ranges. Called when our model changes
100 * or when the view is resized
101 */
102 void updateScrollbars();
103
104 /**
105 * This method will draw dragged items in the painting operation
106 */
107 void drawDraggedItems(QPainter *painter);
108
109 /**
110 * This method will determine which rect needs to be updated because of a
111 * dragging operation
112 */
113 void drawDraggedItems();
114
115 void layoutChanged(bool forceItemReload = false);
116
117
118 // Attributes
119
120 struct ElementInfo
121 {
122 QString category;
123 int relativeOffsetToCategory;
124 };
125
126 // Basic data
127 KCategorizedView *listView;
128 KCategoryDrawer *categoryDrawer;
129 QSize biggestItemSize;
130
131 // Behavior data
132 bool mouseButtonPressed;
133 bool rightMouseButtonPressed;
134 bool isDragging;
135 bool dragLeftViewport;
136 QModelIndex hovered;
137 QString hoveredCategory;
138 QPoint initialPressPosition;
139 QPoint mousePosition;
140 int forcedSelectionPosition;
141
142 // Cache data
143 // We cannot merge some of them into structs because it would affect
144 // performance
145 QHash<int, struct ElementInfo> elementsInfo;
146 QHash<int, QRect> elementsPosition;
147 QHash<QString, QModelIndexList> categoriesIndexes;
148 QHash<QString, QRect> categoriesPosition;
149 QStringList categories;
150 QModelIndexList intersectedIndexes;
151 QRect lastDraggedItemsRect;
152 int modelSortRole;
153 int modelSortColumn;
154 int modelLastRowCount;
155 bool modelCategorized;
156 Qt::SortOrder modelSortOrder;
157 QItemSelection lastSelection;
158
159 // Attributes for speed reasons
160 KCategorizedSortFilterProxyModel *proxyModel;
161 QModelIndexList modelIndexList;
162 };
163
164 #endif // KCATEGORIZEDVIEW_P_H