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