]> cloud.milkyroute.net Git - dolphin.git/blob - src/kcategorizedview_p.h
Make use of the newly added KDirSortFilterProxyModel class -- that is, essentially...
[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 DolphinSortFilterProxyModel;
25
26 /**
27 * @internal
28 */
29 class KCategorizedView::Private
30 {
31 public:
32 Private(KCategorizedView *listView);
33 ~Private();
34
35
36 // Methods
37
38 /**
39 * Returns the list of items that intersects with @p rect
40 */
41 const QModelIndexList &intersectionSet(const QRect &rect);
42
43 /**
44 * Gets the item rect in the viewport for @p index
45 */
46 QRect visualRectInViewport(const QModelIndex &index) const;
47
48 /**
49 * Returns the category rect in the viewport for @p category
50 */
51 QRect visualCategoryRectInViewport(const QString &category) const;
52
53 /**
54 * Caches and returns the rect that corresponds to @p index
55 */
56 const QRect &cacheIndex(const QModelIndex &index);
57
58 /**
59 * Caches and returns the rect that corresponds to @p category
60 */
61 const QRect &cacheCategory(const QString &category);
62
63 /**
64 * Returns the rect that corresponds to @p index
65 * @note If the rect is not cached, it becomes cached
66 */
67 const QRect &cachedRectIndex(const QModelIndex &index);
68
69 /**
70 * Returns the rect that corresponds to @p category
71 * @note If the rect is not cached, it becomes cached
72 */
73 const QRect &cachedRectCategory(const QString &category);
74
75 /**
76 * Returns the visual rect (taking in count x and y offsets) for @p index
77 * @note If the rect is not cached, it becomes cached
78 */
79 QRect visualRect(const QModelIndex &index);
80
81 /**
82 * Returns the visual rect (taking in count x and y offsets) for @p category
83 * @note If the rect is not cached, it becomes cached
84 */
85 QRect categoryVisualRect(const QString &category);
86
87 /**
88 * This method will draw a new category represented by index
89 * @param index on the rect specified by @p option.rect, with
90 * painter @p painter
91 */
92 void drawNewCategory(const QModelIndex &index,
93 int sortRole,
94 const QStyleOption &option,
95 QPainter *painter);
96
97 /**
98 * This method will update scrollbars ranges. Called when our model changes
99 * or when the view is resized
100 */
101 void updateScrollbars();
102
103 /**
104 * This method will draw dragged items in the painting operation
105 */
106 void drawDraggedItems(QPainter *painter);
107
108 /**
109 * This method will determine which rect needs to be updated because of a
110 * dragging operation
111 */
112 void drawDraggedItems();
113
114
115 // Attributes
116
117 struct ElementInfo
118 {
119 QString category;
120 int relativeOffsetToCategory;
121 };
122
123 // Basic data
124 KCategorizedView *listView;
125 KItemCategorizer *itemCategorizer;
126 QSize biggestItemSize;
127
128 // Behavior data
129 bool mouseButtonPressed;
130 bool isDragging;
131 bool dragLeftViewport;
132 QModelIndex hovered;
133 QString hoveredCategory;
134 QPoint initialPressPosition;
135 QPoint mousePosition;
136 QItemSelection lastSelection;
137 QModelIndex currentViewIndex;
138 int forcedSelectionPosition;
139
140 // Cache data
141 // We cannot merge some of them into structs because it would affect
142 // performance
143 QHash<QModelIndex, struct ElementInfo> elementsInfo; // in source model
144 QHash<QModelIndex, QRect> elementsPosition; // in source model
145 QHash<QModelIndex, QModelIndex> elementDictionary; // mapped indexes
146 QHash<QModelIndex, QModelIndex> invertedElementDictionary; // mapped indexes
147 QHash<QString, QModelIndexList> categoriesIndexes;
148 QHash<QString, QRect> categoriesPosition;
149 QStringList categories;
150 QModelIndexList intersectedIndexes;
151 QRect lastDraggedItemsRect;
152 QRect lastSelectionRect;
153
154 // Attributes for speed reasons
155 DolphinSortFilterProxyModel *proxyModel;
156 QModelIndexList sourceModelIndexList; // in source model
157 QModelIndex lastIndex;
158 };
159
160 #endif // KCATEGORIZEDVIEW_P_H