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 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QDECLARATIVEPATHVIEW_H
|
---|
43 | #define QDECLARATIVEPATHVIEW_H
|
---|
44 |
|
---|
45 | #include "qdeclarativeitem.h"
|
---|
46 | #include "private/qdeclarativepath_p.h"
|
---|
47 |
|
---|
48 | QT_BEGIN_HEADER
|
---|
49 |
|
---|
50 | QT_BEGIN_NAMESPACE
|
---|
51 |
|
---|
52 | QT_MODULE(Declarative)
|
---|
53 |
|
---|
54 | class QDeclarativePathViewPrivate;
|
---|
55 | class QDeclarativePathViewAttached;
|
---|
56 | class Q_AUTOTEST_EXPORT QDeclarativePathView : public QDeclarativeItem
|
---|
57 | {
|
---|
58 | Q_OBJECT
|
---|
59 |
|
---|
60 | Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
|
---|
61 | Q_PROPERTY(QDeclarativePath *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 | QDeclarativePathView(QDeclarativeItem *parent=0);
|
---|
88 | virtual ~QDeclarativePathView();
|
---|
89 |
|
---|
90 | QVariant model() const;
|
---|
91 | void setModel(const QVariant &);
|
---|
92 |
|
---|
93 | QDeclarativePath *path() const;
|
---|
94 | void setPath(QDeclarativePath *);
|
---|
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 QDeclarativePathViewAttached *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 QDeclarativePathViewAttached;
|
---|
193 | Q_DISABLE_COPY(QDeclarativePathView)
|
---|
194 | Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativePathView)
|
---|
195 | };
|
---|
196 |
|
---|
197 | class QDeclarativeOpenMetaObject;
|
---|
198 | class QDeclarativePathViewAttached : public QObject
|
---|
199 | {
|
---|
200 | Q_OBJECT
|
---|
201 |
|
---|
202 | Q_PROPERTY(QDeclarativePathView *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 | QDeclarativePathViewAttached(QObject *parent);
|
---|
208 | ~QDeclarativePathViewAttached();
|
---|
209 |
|
---|
210 | QDeclarativePathView *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 QDeclarativePathViewPrivate;
|
---|
238 | friend class QDeclarativePathView;
|
---|
239 | QDeclarativePathView *m_view;
|
---|
240 | QDeclarativeOpenMetaObject *m_metaobject;
|
---|
241 | bool m_onPath : 1;
|
---|
242 | bool m_isCurrent : 1;
|
---|
243 | };
|
---|
244 |
|
---|
245 |
|
---|
246 | QT_END_NAMESPACE
|
---|
247 |
|
---|
248 | QML_DECLARE_TYPE(QDeclarativePathView)
|
---|
249 | QML_DECLARE_TYPEINFO(QDeclarativePathView, QML_HAS_ATTACHED_PROPERTIES)
|
---|
250 | QT_END_HEADER
|
---|
251 |
|
---|
252 | #endif // QDECLARATIVEPATHVIEW_H
|
---|