47ce66873c91eb704081062516b17a89c02654b1
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickpathview_p.h
1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
2 /****************************************************************************
3 **
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: http://www.qt-project.org/
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 QQUICKPATHVIEW_P_H
44 #define QQUICKPATHVIEW_P_H
45
46 #include "qquickitem.h"
47
48 #include <private/qdeclarativepath_p.h>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54 class QDeclarativeChangeSet;
55
56 class QQuickPathViewPrivate;
57 class QQuickPathViewAttached;
58 class Q_AUTOTEST_EXPORT QQuickPathView : public QQuickItem
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(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged)
66     Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged)
67
68     Q_PROPERTY(QDeclarativeComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged)
69     Q_PROPERTY(QQuickItem *highlightItem READ highlightItem NOTIFY highlightItemChanged)
70
71     Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged)
72     Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged)
73     Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged)
74     Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged)
75
76     Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin NOTIFY dragMarginChanged)
77     Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged)
78     Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged)
79
80     Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged)
81     Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged)
82
83     Q_PROPERTY(int count READ count NOTIFY countChanged)
84     Q_PROPERTY(QDeclarativeComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
85     Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount NOTIFY pathItemCountChanged)
86
87     Q_ENUMS(HighlightRangeMode)
88
89 public:
90     QQuickPathView(QQuickItem *parent=0);
91     virtual ~QQuickPathView();
92
93     QVariant model() const;
94     void setModel(const QVariant &);
95
96     QDeclarativePath *path() const;
97     void setPath(QDeclarativePath *);
98
99     int currentIndex() const;
100     void setCurrentIndex(int idx);
101
102     QQuickItem *currentItem() const;
103
104     qreal offset() const;
105     void setOffset(qreal offset);
106
107     QDeclarativeComponent *highlight() const;
108     void setHighlight(QDeclarativeComponent *highlight);
109     QQuickItem *highlightItem();
110
111     enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange };
112     HighlightRangeMode highlightRangeMode() const;
113     void setHighlightRangeMode(HighlightRangeMode mode);
114
115     qreal preferredHighlightBegin() const;
116     void setPreferredHighlightBegin(qreal);
117
118     qreal preferredHighlightEnd() const;
119     void setPreferredHighlightEnd(qreal);
120
121     int highlightMoveDuration() const;
122     void setHighlightMoveDuration(int);
123
124     qreal dragMargin() const;
125     void setDragMargin(qreal margin);
126
127     qreal flickDeceleration() const;
128     void setFlickDeceleration(qreal dec);
129
130     bool isInteractive() const;
131     void setInteractive(bool);
132
133     bool isMoving() const;
134     bool isFlicking() const;
135
136     int count() const;
137
138     QDeclarativeComponent *delegate() const;
139     void setDelegate(QDeclarativeComponent *);
140
141     int pathItemCount() const;
142     void setPathItemCount(int);
143
144     static QQuickPathViewAttached *qmlAttachedProperties(QObject *);
145
146 public Q_SLOTS:
147     void incrementCurrentIndex();
148     void decrementCurrentIndex();
149
150 Q_SIGNALS:
151     void currentIndexChanged();
152     void currentItemChanged();
153     void offsetChanged();
154     void modelChanged();
155     void countChanged();
156     void pathChanged();
157     void preferredHighlightBeginChanged();
158     void preferredHighlightEndChanged();
159     void highlightRangeModeChanged();
160     void dragMarginChanged();
161     void snapPositionChanged();
162     void delegateChanged();
163     void pathItemCountChanged();
164     void flickDecelerationChanged();
165     void interactiveChanged();
166     void movingChanged();
167     void flickingChanged();
168     void highlightChanged();
169     void highlightItemChanged();
170     void highlightMoveDurationChanged();
171     void movementStarted();
172     void movementEnded();
173     void flickStarted();
174     void flickEnded();
175
176 protected:
177     virtual void updatePolish();
178     void mousePressEvent(QMouseEvent *event);
179     void mouseMoveEvent(QMouseEvent *event);
180     void mouseReleaseEvent(QMouseEvent *);
181     bool sendMouseEvent(QMouseEvent *event);
182     bool childMouseEventFilter(QQuickItem *, QEvent *);
183     void mouseUngrabEvent();
184     void componentComplete();
185
186 private Q_SLOTS:
187     void refill();
188     void ticked();
189     void movementEnding();
190     void modelUpdated(const QDeclarativeChangeSet &changeSet, bool reset);
191     void createdItem(int index, QQuickItem *item);
192     void initItem(int index, QQuickItem *item);
193     void destroyingItem(QQuickItem *item);
194     void pathUpdated();
195
196 private:
197     friend class QQuickPathViewAttached;
198     Q_DISABLE_COPY(QQuickPathView)
199     Q_DECLARE_PRIVATE(QQuickPathView)
200 };
201
202 class QDeclarativeOpenMetaObject;
203 class QQuickPathViewAttached : public QObject
204 {
205     Q_OBJECT
206
207     Q_PROPERTY(QQuickPathView *view READ view CONSTANT)
208     Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged)
209     Q_PROPERTY(bool onPath READ isOnPath NOTIFY pathChanged)
210
211 public:
212     QQuickPathViewAttached(QObject *parent);
213     ~QQuickPathViewAttached();
214
215     QQuickPathView *view() { return m_view; }
216
217     bool isCurrentItem() const { return m_isCurrent; }
218     void setIsCurrentItem(bool c) {
219         if (m_isCurrent != c) {
220             m_isCurrent = c;
221             emit currentItemChanged();
222         }
223     }
224
225     QVariant value(const QByteArray &name) const;
226     void setValue(const QByteArray &name, const QVariant &val);
227
228     bool isOnPath() const { return m_onPath; }
229     void setOnPath(bool on) {
230         if (on != m_onPath) {
231             m_onPath = on;
232             emit pathChanged();
233         }
234     }
235     qreal m_percent;
236
237 Q_SIGNALS:
238     void currentItemChanged();
239     void pathChanged();
240
241 private:
242     friend class QQuickPathViewPrivate;
243     friend class QQuickPathView;
244     QQuickPathView *m_view;
245     QDeclarativeOpenMetaObject *m_metaobject;
246     bool m_onPath : 1;
247     bool m_isCurrent : 1;
248 };
249
250
251 QT_END_NAMESPACE
252
253 QML_DECLARE_TYPE(QQuickPathView)
254 QML_DECLARE_TYPEINFO(QQuickPathView, QML_HAS_ATTACHED_PROPERTIES)
255 QT_END_HEADER
256
257 #endif // QQUICKPATHVIEW_P_H