]> cloud.milkyroute.net Git - dolphin.git/blob - src/kcategorizedview_p.h
Create the new architecture for KCategorizedView. Now DolphinModel is created, inheri...
[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@gmail.com>
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
116 // Attributes
117
118 struct ElementInfo
119 {
120 QString category;
121 int relativeOffsetToCategory;
122 };
123
124 // Basic data
125 KCategorizedView *listView;
126 KCategoryDrawer *categoryDrawer;
127 QSize biggestItemSize;
128
129 // Behavior data
130 bool mouseButtonPressed;
131 bool isDragging;
132 bool dragLeftViewport;
133 QModelIndex hovered;
134 QString hoveredCategory;
135 QPoint initialPressPosition;
136 QPoint mousePosition;
137 QItemSelection lastSelection;
138 QModelIndex currentViewIndex;
139 int forcedSelectionPosition;
140
141 // Cache data
142 // We cannot merge some of them into structs because it would affect
143 // performance
144 QHash<int, struct ElementInfo> elementsInfo;
145 QHash<int, QRect> elementsPosition;
146 QHash<QString, QModelIndexList> categoriesIndexes;
147 QHash<QString, QRect> categoriesPosition;
148 QStringList categories;
149 QModelIndexList intersectedIndexes;
150 QRect lastDraggedItemsRect;
151 QRect lastSelectionRect;
152
153 // Attributes for speed reasons
154 KCategorizedSortFilterProxyModel *proxyModel;
155 QModelIndexList modelIndexList;
156 };
157
158 #endif // KCATEGORIZEDVIEW_P_H