]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistviewlayouter_p.h
Improve group-header layout
[dolphin.git] / src / kitemviews / kitemlistviewlayouter_p.h
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef KITEMLISTVIEWLAYOUTER_H
21 #define KITEMLISTVIEWLAYOUTER_H
22
23 #include <libdolphin_export.h>
24
25 #include <QObject>
26 #include <QRectF>
27 #include <QSet>
28 #include <QSizeF>
29
30 class KItemModelBase;
31 class KItemListSizeHintResolver;
32
33 class LIBDOLPHINPRIVATE_EXPORT KItemListViewLayouter : public QObject
34 {
35 Q_OBJECT
36
37 public:
38 KItemListViewLayouter(QObject* parent = 0);
39 virtual ~KItemListViewLayouter();
40
41 void setScrollOrientation(Qt::Orientation orientation);
42 Qt::Orientation scrollOrientation() const;
43
44 void setSize(const QSizeF& size);
45 QSizeF size() const;
46
47 void setItemSize(const QSizeF& size);
48 QSizeF itemSize() const;
49
50 /**
51 * Sets the height of the header that is always aligned
52 * at the top. A height of <= 0.0 means that no header is
53 * used.
54 */
55 void setHeaderHeight(qreal height);
56 qreal headerHeight() const;
57
58 /**
59 * Sets the height of the group header that is used
60 * to indicate a new item group.
61 */
62 void setGroupHeaderHeight(qreal height);
63 qreal groupHeaderHeight() const;
64
65 // TODO: add note that offset can be < 0 or > maximumOffset!
66 void setScrollOffset(qreal scrollOffset);
67 qreal scrollOffset() const;
68
69 qreal maximumScrollOffset() const;
70
71 void setItemOffset(qreal scrollOffset);
72 qreal itemOffset() const;
73
74 qreal maximumItemOffset() const;
75
76 void setModel(const KItemModelBase* model);
77 const KItemModelBase* model() const;
78
79 void setSizeHintResolver(const KItemListSizeHintResolver* sizeHintResolver);
80 const KItemListSizeHintResolver* sizeHintResolver() const;
81
82 /**
83 * @return The first (at least partly) visible index. -1 is returned
84 * if the item count is 0.
85 */
86 int firstVisibleIndex() const;
87
88 /**
89 * @return The last (at least partly) visible index. -1 is returned
90 * if the item count is 0.
91 */
92 int lastVisibleIndex() const;
93
94 /**
95 * @return Rectangle of the item with the index \a index.
96 * The top/left of the bounding rectangle is related to
97 * the top/left of the KItemListView. An empty rectangle
98 * is returned if an invalid index is given.
99 */
100 QRectF itemRect(int index) const;
101
102 QRectF groupHeaderRect(int index) const;
103
104 /**
105 * @return Maximum number of (at least partly) visible items for
106 * the given size.
107 */
108 int maximumVisibleItems() const;
109
110 /**
111 * @return Maximum number of items that can be shown in the same row
112 * (= vertical scrolldirection) or same column
113 * (= horizontal scrolldirection).
114 */
115 int itemsPerOffset() const;
116
117 /**
118 * @return True if the item with the index \p itemIndex
119 * is the first item within a group.
120 */
121 bool isFirstGroupItem(int itemIndex) const;
122
123 void markAsDirty();
124
125 private:
126 void doLayout();
127 void updateVisibleIndexes();
128 bool createGroupHeaders();
129
130 private:
131 bool m_dirty;
132 bool m_visibleIndexesDirty;
133
134 Qt::Orientation m_scrollOrientation;
135 QSizeF m_size;
136
137 QSizeF m_itemSize;
138 qreal m_headerHeight;
139 const KItemModelBase* m_model;
140 const KItemListSizeHintResolver* m_sizeHintResolver;
141
142 qreal m_scrollOffset;
143 qreal m_maximumScrollOffset;
144
145 qreal m_itemOffset;
146 qreal m_maximumItemOffset;
147
148 int m_firstVisibleIndex;
149 int m_lastVisibleIndex;
150
151 qreal m_columnWidth;
152 qreal m_xPosInc;
153 int m_columnCount;
154
155 // Stores all item indexes that are the first item of a group.
156 // Assures fast access for KItemListViewLayouter::isFirstGroupItem().
157 QSet<int> m_groupItemIndexes;
158 qreal m_groupHeaderHeight;
159
160 QList<QRectF> m_itemRects;
161 };
162
163 #endif
164
165