Fix test fails related to QTBUG-22237
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsglistview_p.h
1 // Commit: 95814418f9d6adeba365c795462e8afb00138211
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
30 **
31 ** Other Usage
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QSGLISTVIEW_P_H
44 #define QSGLISTVIEW_P_H
45
46 #include "qsgitemview_p.h"
47
48 #include <private/qdeclarativeguard_p.h>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54 QT_MODULE(Declarative)
55
56 class QSGListView;
57 class QSGListViewPrivate;
58 class Q_AUTOTEST_EXPORT QSGViewSection : public QObject
59 {
60     Q_OBJECT
61     Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
62     Q_PROPERTY(SectionCriteria criteria READ criteria WRITE setCriteria NOTIFY criteriaChanged)
63     Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
64     Q_PROPERTY(int labelPositioning READ labelPositioning WRITE setLabelPositioning NOTIFY labelPositioningChanged)
65     Q_ENUMS(SectionCriteria)
66     Q_ENUMS(LabelPositioning)
67 public:
68     QSGViewSection(QSGListView *parent=0);
69
70     QString property() const { return m_property; }
71     void setProperty(const QString &);
72
73     enum SectionCriteria { FullString, FirstCharacter };
74     SectionCriteria criteria() const { return m_criteria; }
75     void setCriteria(SectionCriteria);
76
77     QDeclarativeComponent *delegate() const { return m_delegate; }
78     void setDelegate(QDeclarativeComponent *delegate);
79
80     QString sectionString(const QString &value);
81
82     enum LabelPositioning { InlineLabels = 0x01, CurrentLabelAtStart = 0x02, NextLabelAtEnd = 0x04 };
83     int labelPositioning() { return m_labelPositioning; }
84     void setLabelPositioning(int pos);
85
86 Q_SIGNALS:
87     void propertyChanged();
88     void criteriaChanged();
89     void delegateChanged();
90     void labelPositioningChanged();
91
92 private:
93     QString m_property;
94     SectionCriteria m_criteria;
95     QDeclarativeComponent *m_delegate;
96     int m_labelPositioning;
97     QSGListViewPrivate *m_view;
98 };
99
100
101 class QSGVisualModel;
102 class QSGListViewAttached;
103 class Q_AUTOTEST_EXPORT QSGListView : public QSGItemView
104 {
105     Q_OBJECT
106     Q_DECLARE_PRIVATE(QSGListView)
107
108     // XXX deprecate these two properties (only duration should be necessary)
109     Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged)
110     Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged)
111
112     Q_PROPERTY(int highlightResizeDuration READ highlightResizeDuration WRITE setHighlightResizeDuration NOTIFY highlightResizeDurationChanged)
113
114     Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
115     Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
116
117     Q_PROPERTY(QSGViewSection *section READ sectionCriteria CONSTANT)
118     Q_PROPERTY(QString currentSection READ currentSection NOTIFY currentSectionChanged)
119
120     Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
121
122     Q_ENUMS(Orientation)
123     Q_ENUMS(SnapMode)
124     Q_CLASSINFO("DefaultProperty", "data")
125
126 public:
127     QSGListView(QSGItem *parent=0);
128     ~QSGListView();
129
130     qreal spacing() const;
131     void setSpacing(qreal spacing);
132
133     enum Orientation { Horizontal = Qt::Horizontal, Vertical = Qt::Vertical };
134     Orientation orientation() const;
135     void setOrientation(Orientation);
136
137     QSGViewSection *sectionCriteria();
138     QString currentSection() const;
139
140     virtual void setHighlightFollowsCurrentItem(bool);
141
142     qreal highlightMoveSpeed() const;
143     void setHighlightMoveSpeed(qreal);
144
145     qreal highlightResizeSpeed() const;
146     void setHighlightResizeSpeed(qreal);
147
148     int highlightResizeDuration() const;
149     void setHighlightResizeDuration(int);
150
151     virtual void setHighlightMoveDuration(int);
152
153     enum SnapMode { NoSnap, SnapToItem, SnapOneItem };
154     SnapMode snapMode() const;
155     void setSnapMode(SnapMode mode);
156
157     static QSGListViewAttached *qmlAttachedProperties(QObject *);
158
159 public Q_SLOTS:
160     void incrementCurrentIndex();
161     void decrementCurrentIndex();
162
163 Q_SIGNALS:
164     void spacingChanged();
165     void orientationChanged();
166     void currentSectionChanged();
167     void highlightMoveSpeedChanged();
168     void highlightResizeSpeedChanged();
169     void highlightResizeDurationChanged();
170     void snapModeChanged();
171
172 protected:
173     virtual void viewportMoved();
174     virtual void keyPressEvent(QKeyEvent *);
175     virtual void geometryChanged(const QRectF &newGeometry,const QRectF &oldGeometry);
176
177 protected Q_SLOTS:
178     void updateSections();
179 };
180
181 class QSGListViewAttached : public QSGItemViewAttached
182 {
183     Q_OBJECT
184
185 public:
186     QSGListViewAttached(QObject *parent)
187         : QSGItemViewAttached(parent), m_view(0) {}
188     ~QSGListViewAttached() {}
189
190     Q_PROPERTY(QSGListView *view READ view NOTIFY viewChanged)
191     QSGListView *view() { return m_view; }
192     void setView(QSGListView *view) {
193         if (view != m_view) {
194             m_view = view;
195             emit viewChanged();
196         }
197     }
198
199 Q_SIGNALS:
200     void viewChanged();
201
202 public:
203     QDeclarativeGuard<QSGListView> m_view;
204 };
205
206
207 QT_END_NAMESPACE
208
209 QML_DECLARE_TYPEINFO(QSGListView, QML_HAS_ATTACHED_PROPERTIES)
210 QML_DECLARE_TYPE(QSGListView)
211 QML_DECLARE_TYPE(QSGViewSection)
212
213 QT_END_HEADER
214
215 #endif // QSGLISTVIEW_P_H