1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #ifndef KITEMLISTVIEWLAYOUTER_H
21 #define KITEMLISTVIEWLAYOUTER_H
23 #include <libdolphin_export.h>
31 class KItemListSizeHintResolver
;
33 class LIBDOLPHINPRIVATE_EXPORT KItemListViewLayouter
: public QObject
38 KItemListViewLayouter(QObject
* parent
= 0);
39 virtual ~KItemListViewLayouter();
41 void setScrollOrientation(Qt::Orientation orientation
);
42 Qt::Orientation
scrollOrientation() const;
44 void setSize(const QSizeF
& size
);
47 void setItemSize(const QSizeF
& size
);
48 QSizeF
itemSize() const;
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
55 void setHeaderHeight(qreal height
);
56 qreal
headerHeight() const;
59 * Sets the height of the group header that is used
60 * to indicate a new item group.
62 void setGroupHeaderHeight(qreal height
);
63 qreal
groupHeaderHeight() const;
65 // TODO: add note that offset can be < 0 or > maximumOffset!
66 void setScrollOffset(qreal scrollOffset
);
67 qreal
scrollOffset() const;
69 qreal
maximumScrollOffset() const;
71 void setItemOffset(qreal scrollOffset
);
72 qreal
itemOffset() const;
74 qreal
maximumItemOffset() const;
76 void setModel(const KItemModelBase
* model
);
77 const KItemModelBase
* model() const;
79 void setSizeHintResolver(const KItemListSizeHintResolver
* sizeHintResolver
);
80 const KItemListSizeHintResolver
* sizeHintResolver() const;
83 * @return The first (at least partly) visible index. -1 is returned
84 * if the item count is 0.
86 int firstVisibleIndex() const;
89 * @return The last (at least partly) visible index. -1 is returned
90 * if the item count is 0.
92 int lastVisibleIndex() const;
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.
100 QRectF
itemRect(int index
) const;
102 QRectF
groupHeaderRect(int index
) const;
105 * @return Maximum number of (at least partly) visible items for
108 int maximumVisibleItems() const;
111 * @return True if the item with the index \p itemIndex
112 * is the first item within a group.
114 bool isFirstGroupItem(int itemIndex
) const;
120 void updateVisibleIndexes();
121 bool createGroupHeaders();
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
131 qreal
minimumGroupHeaderWidth() const;
135 bool m_visibleIndexesDirty
;
137 Qt::Orientation m_scrollOrientation
;
141 qreal m_headerHeight
;
142 const KItemModelBase
* m_model
;
143 const KItemListSizeHintResolver
* m_sizeHintResolver
;
145 qreal m_scrollOffset
;
146 qreal m_maximumScrollOffset
;
149 qreal m_maximumItemOffset
;
151 int m_firstVisibleIndex
;
152 int m_lastVisibleIndex
;
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
;
163 QList
<QRectF
> m_itemRects
;