Initial import from qtquick2.
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgpathview_p.h
1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
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 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
15 ** this package.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QSGPATHVIEW_P_H
44 #define QSGPATHVIEW_P_H
45
46 #include "qsgitem.h"
47
48 #include <private/qdeclarativepath_p.h>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54 QT_MODULE(Declarative)
55
56 class QSGPathViewPrivate;
57 class QSGPathViewAttached;
58 class Q_AUTOTEST_EXPORT QSGPathView : public QSGItem
59 {
60     Q_OBJECT
61
62     Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
63     Q_PROPERTY(QDeclarativePath *path READ path WRITE setPath NOTIFY pathChanged)
64     Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
65     Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged)
66
67     Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
68     Q_PROPERTY(QSGItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
69
70     Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged)
71     Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged)
72     Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
73     Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
74
75     Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin NOTIFY dragMarginChanged)
76     Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged)
77     Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged)
78
79     Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged)
80     Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged)
81
82     Q_PROPERTY(int count READ count NOTIFY countChanged)
83     Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
84     Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount NOTIFY pathItemCountChanged)
85
86     Q_ENUMS(HighlightRangeMode)
87
88 public:
89     QSGPathView(QSGItem *parent=0);
90     virtual ~QSGPathView();
91
92     QVariant model() const;
93     void setModel(const QVariant &);
94
95     QDeclarativePath *path() const;
96     void setPath(QDeclarativePath *);
97
98     int currentIndex() const;
99     void setCurrentIndex(int idx);
100
101     qreal offset() const;
102     void setOffset(qreal offset);
103
104     QDeclarativeComponent *highlight() const;
105     void setHighlight(QDeclarativeComponent *highlight);
106     QSGItem *highlightItem();
107
108     enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
109     HighlightRangeMode highlightRangeMode() const;
110     void setHighlightRangeMode(HighlightRangeMode mode);
111
112     qreal preferredHighlightBegin() const;
113     void setPreferredHighlightBegin(qreal);
114
115     qreal preferredHighlightEnd() const;
116     void setPreferredHighlightEnd(qreal);
117
118     int highlightMoveDuration() const;
119     void setHighlightMoveDuration(int);
120
121     qreal dragMargin() const;
122     void setDragMargin(qreal margin);
123
124     qreal flickDeceleration() const;
125     void setFlickDeceleration(qreal dec);
126
127     bool isInteractive() const;
128     void setInteractive(bool);
129
130     bool isMoving() const;
131     bool isFlicking() const;
132
133     int count() const;
134
135     QDeclarativeComponent *delegate() const;
136     void setDelegate(QDeclarativeComponent *);
137
138     int pathItemCount() const;
139     void setPathItemCount(int);
140
141     static QSGPathViewAttached *qmlAttachedProperties(QObject *);
142
143 public Q_SLOTS:
144     void incrementCurrentIndex();
145     void decrementCurrentIndex();
146
147 Q_SIGNALS:
148     void currentIndexChanged();
149     void offsetChanged();
150     void modelChanged();
151     void countChanged();
152     void pathChanged();
153     void preferredHighlightBeginChanged();
154     void preferredHighlightEndChanged();
155     void highlightRangeModeChanged();
156     void dragMarginChanged();
157     void snapPositionChanged();
158     void delegateChanged();
159     void pathItemCountChanged();
160     void flickDecelerationChanged();
161     void interactiveChanged();
162     void movingChanged();
163     void flickingChanged();
164     void highlightChanged();
165     void highlightItemChanged();
166     void highlightMoveDurationChanged();
167     void movementStarted();
168     void movementEnded();
169     void flickStarted();
170     void flickEnded();
171
172 protected:
173     virtual void updatePolish();
174     void mousePressEvent(QGraphicsSceneMouseEvent *event);
175     void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
176     void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
177     bool sendMouseEvent(QGraphicsSceneMouseEvent *event);
178     bool childMouseEventFilter(QSGItem *, QEvent *);
179     void componentComplete();
180
181 private Q_SLOTS:
182     void refill();
183     void ticked();
184     void movementEnding();
185     void itemsInserted(int index, int count);
186     void itemsRemoved(int index, int count);
187     void itemsMoved(int,int,int);
188     void modelReset();
189     void createdItem(int index, QSGItem *item);
190     void destroyingItem(QSGItem *item);
191     void pathUpdated();
192
193 private:
194     friend class QSGPathViewAttached;
195     Q_DISABLE_COPY(QSGPathView)
196     Q_DECLARE_PRIVATE(QSGPathView)
197 };
198
199 class QDeclarativeOpenMetaObject;
200 class QSGPathViewAttached : public QObject
201 {
202     Q_OBJECT
203
204     Q_PROPERTY(QSGPathView *view READ view CONSTANT)
205     Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
206     Q_PROPERTY(bool onPath READ isOnPath NOTIFY pathChanged)
207
208 public:
209     QSGPathViewAttached(QObject *parent);
210     ~QSGPathViewAttached();
211
212     QSGPathView *view() { return m_view; }
213
214     bool isCurrentItem() const { return m_isCurrent; }
215     void setIsCurrentItem(bool c) {
216         if (m_isCurrent != c) {
217             m_isCurrent = c;
218             emit currentItemChanged();
219         }
220     }
221
222     QVariant value(const QByteArray &name) const;
223     void setValue(const QByteArray &name, const QVariant &val);
224
225     bool isOnPath() const { return m_onPath; }
226     void setOnPath(bool on) {
227         if (on != m_onPath) {
228             m_onPath = on;
229             emit pathChanged();
230         }
231     }
232     qreal m_percent;
233
234 Q_SIGNALS:
235     void currentItemChanged();
236     void pathChanged();
237
238 private:
239     friend class QSGPathViewPrivate;
240     friend class QSGPathView;
241     QSGPathView *m_view;
242     QDeclarativeOpenMetaObject *m_metaobject;
243     bool m_onPath : 1;
244     bool m_isCurrent : 1;
245 };
246
247
248 QT_END_NAMESPACE
249
250 QML_DECLARE_TYPE(QSGPathView)
251 QML_DECLARE_TYPEINFO(QSGPathView, QML_HAS_ATTACHED_PROPERTIES)
252 QT_END_HEADER
253
254 #endif // QSGPATHVIEW_P_H