1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQUICKLISTVIEW_P_H
43 #define QQUICKLISTVIEW_P_H
45 #include "qquickitemview_p.h"
47 #include <private/qqmlguard_p.h>
54 class QQuickListViewPrivate;
55 class Q_AUTOTEST_EXPORT QQuickViewSection : public QObject
58 Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
59 Q_PROPERTY(SectionCriteria criteria READ criteria WRITE setCriteria NOTIFY criteriaChanged)
60 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
61 Q_PROPERTY(int labelPositioning READ labelPositioning WRITE setLabelPositioning NOTIFY labelPositioningChanged)
62 Q_ENUMS(SectionCriteria)
63 Q_ENUMS(LabelPositioning)
65 QQuickViewSection(QQuickListView *parent=0);
67 QString property() const { return m_property; }
68 void setProperty(const QString &);
70 enum SectionCriteria { FullString, FirstCharacter };
71 SectionCriteria criteria() const { return m_criteria; }
72 void setCriteria(SectionCriteria);
74 QQmlComponent *delegate() const { return m_delegate; }
75 void setDelegate(QQmlComponent *delegate);
77 QString sectionString(const QString &value);
79 enum LabelPositioning { InlineLabels = 0x01, CurrentLabelAtStart = 0x02, NextLabelAtEnd = 0x04 };
80 int labelPositioning() { return m_labelPositioning; }
81 void setLabelPositioning(int pos);
84 void sectionsChanged();
85 void propertyChanged();
86 void criteriaChanged();
87 void delegateChanged();
88 void labelPositioningChanged();
92 SectionCriteria m_criteria;
93 QQmlComponent *m_delegate;
94 int m_labelPositioning;
95 QQuickListViewPrivate *m_view;
99 class QQuickVisualModel;
100 class QQuickListViewAttached;
101 class Q_AUTOTEST_EXPORT QQuickListView : public QQuickItemView
104 Q_DECLARE_PRIVATE(QQuickListView)
106 Q_PROPERTY(qreal highlightMoveVelocity READ highlightMoveVelocity WRITE setHighlightMoveVelocity NOTIFY highlightMoveVelocityChanged)
107 Q_PROPERTY(qreal highlightResizeVelocity READ highlightResizeVelocity WRITE setHighlightResizeVelocity NOTIFY highlightResizeVelocityChanged)
108 Q_PROPERTY(int highlightResizeDuration READ highlightResizeDuration WRITE setHighlightResizeDuration NOTIFY highlightResizeDurationChanged)
110 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
111 Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
113 Q_PROPERTY(QQuickViewSection *section READ sectionCriteria CONSTANT)
114 Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged)
116 Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
120 Q_CLASSINFO("DefaultProperty", "data")
123 QQuickListView(QQuickItem *parent=0);
126 qreal spacing() const;
127 void setSpacing(qreal spacing);
129 enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical };
130 Orientation orientation() const;
131 void setOrientation(Orientation);
133 QQuickViewSection *sectionCriteria();
134 QString currentSection() const;
136 virtual void setHighlightFollowsCurrentItem(bool);
138 qreal highlightMoveVelocity() const;
139 void setHighlightMoveVelocity(qreal);
141 qreal highlightResizeVelocity() const;
142 void setHighlightResizeVelocity(qreal);
144 int highlightResizeDuration() const;
145 void setHighlightResizeDuration(int);
147 virtual void setHighlightMoveDuration(int);
149 enum SnapMode { NoSnap, SnapToItem, SnapOneItem };
150 SnapMode snapMode() const;
151 void setSnapMode(SnapMode mode);
153 static QQuickListViewAttached *qmlAttachedProperties(QObject *);
156 void incrementCurrentIndex();
157 void decrementCurrentIndex();
160 void spacingChanged();
161 void orientationChanged();
162 void currentSectionChanged();
163 void highlightMoveVelocityChanged();
164 void highlightResizeVelocityChanged();
165 void highlightResizeDurationChanged();
166 void snapModeChanged();
169 virtual void viewportMoved(Qt::Orientations orient);
170 virtual void keyPressEvent(QKeyEvent *);
171 virtual void geometryChanged(const QRectF &newGeometry,const QRectF &oldGeometry);
172 virtual void initItem(int index, QQuickItem *item);
175 class QQuickListViewAttached : public QQuickItemViewAttached
180 QQuickListViewAttached(QObject *parent)
181 : QQuickItemViewAttached(parent), m_view(0), m_sectionItem(0) {}
182 ~QQuickListViewAttached() {}
184 Q_PROPERTY(QQuickListView *view READ view NOTIFY viewChanged)
185 QQuickListView *view() { return m_view; }
186 void setView(QQuickListView *view) {
187 if (view != m_view) {
197 QQmlGuard<QQuickListView> m_view;
198 QQuickItem *m_sectionItem;
204 QML_DECLARE_TYPEINFO(QQuickListView, QML_HAS_ATTACHED_PROPERTIES)
205 QML_DECLARE_TYPE(QQuickListView)
206 QML_DECLARE_TYPE(QQuickViewSection)
210 #endif // QQUICKLISTVIEW_P_H