]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistviewlayouter_p.h
dec99d0542a1a4ea82c926dd09dc845aab169070
[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 True if the item with the index \p itemIndex
112 * is the first item within a group.
113 */
114 bool isFirstGroupItem(int itemIndex) const;
115
116 void markAsDirty();
117
118 private:
119 void doLayout();
120 void updateVisibleIndexes();
121 bool createGroupHeaders();
122
123 /**
124 * @return Minimum width of group headers when grouping is enabled in the horizontal
125 * alignment mode. The header alignment is done like this:
126 * Header-1 Header-2 Header-3
127 * Item 1 Item 4 Item 7
128 * Item 2 Item 5 Item 8
129 * Item 3 Item 6 Item 9
130 */
131 qreal minimumGroupHeaderWidth() const;
132
133 private:
134 bool m_dirty;
135 bool m_visibleIndexesDirty;
136
137 Qt::Orientation m_scrollOrientation;
138 QSizeF m_size;
139
140 QSizeF m_itemSize;
141 qreal m_headerHeight;
142 const KItemModelBase* m_model;
143 const KItemListSizeHintResolver* m_sizeHintResolver;
144
145 qreal m_scrollOffset;
146 qreal m_maximumScrollOffset;
147
148 qreal m_itemOffset;
149 qreal m_maximumItemOffset;
150
151 int m_firstVisibleIndex;
152 int m_lastVisibleIndex;
153
154 qreal m_columnWidth;
155 qreal m_xPosInc;
156 int m_columnCount;
157
158 // Stores all item indexes that are the first item of a group.
159 // Assures fast access for KItemListViewLayouter::isFirstGroupItem().
160 QSet<int> m_groupItemIndexes;
161 qreal m_groupHeaderHeight;
162
163 QList<QRectF> m_itemRects;
164 };
165
166 #endif
167
168