a97af9ce5016ef269b1b13ccc9035e11ebb5ea82
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickflickable_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKFLICKABLE_P_H
43 #define QQUICKFLICKABLE_P_H
44
45 #include "qquickitem.h"
46 #include <private/qtquickglobal_p.h>
47
48 QT_BEGIN_HEADER
49
50 QT_BEGIN_NAMESPACE
51
52 class QQuickFlickablePrivate;
53 class QQuickFlickableVisibleArea;
54 class Q_QUICK_PRIVATE_EXPORT QQuickFlickable : public QQuickItem
55 {
56     Q_OBJECT
57
58     Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged)
59     Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged)
60     Q_PROPERTY(qreal contentX READ contentX WRITE setContentX NOTIFY contentXChanged)
61     Q_PROPERTY(qreal contentY READ contentY WRITE setContentY NOTIFY contentYChanged)
62     Q_PROPERTY(QQuickItem *contentItem READ contentItem CONSTANT)
63
64     Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged)
65     Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged)
66     Q_PROPERTY(qreal originY READ originY NOTIFY originYChanged)
67
68     Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged)
69     Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged)
70     Q_PROPERTY(qreal originX READ originX NOTIFY originXChanged)
71
72     Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged)
73     Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged)
74
75     Q_PROPERTY(BoundsBehavior boundsBehavior READ boundsBehavior WRITE setBoundsBehavior NOTIFY boundsBehaviorChanged)
76     Q_PROPERTY(QQuickTransition *rebound READ rebound WRITE setRebound NOTIFY reboundChanged)
77     Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity NOTIFY maximumFlickVelocityChanged)
78     Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged)
79     Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged)
80     Q_PROPERTY(bool movingHorizontally READ isMovingHorizontally NOTIFY movingHorizontallyChanged)
81     Q_PROPERTY(bool movingVertically READ isMovingVertically NOTIFY movingVerticallyChanged)
82     Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged)
83     Q_PROPERTY(bool flickingHorizontally READ isFlickingHorizontally NOTIFY flickingHorizontallyChanged)
84     Q_PROPERTY(bool flickingVertically READ isFlickingVertically NOTIFY flickingVerticallyChanged)
85     Q_PROPERTY(bool dragging READ isDragging NOTIFY draggingChanged)
86     Q_PROPERTY(bool draggingHorizontally READ isDraggingHorizontally NOTIFY draggingHorizontallyChanged)
87     Q_PROPERTY(bool draggingVertically READ isDraggingVertically NOTIFY draggingVerticallyChanged)
88     Q_PROPERTY(FlickableDirection flickableDirection READ flickableDirection WRITE setFlickableDirection NOTIFY flickableDirectionChanged)
89
90     Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged)
91     Q_PROPERTY(int pressDelay READ pressDelay WRITE setPressDelay NOTIFY pressDelayChanged)
92
93     Q_PROPERTY(bool atXEnd READ isAtXEnd NOTIFY isAtBoundaryChanged)
94     Q_PROPERTY(bool atYEnd READ isAtYEnd NOTIFY isAtBoundaryChanged)
95     Q_PROPERTY(bool atXBeginning READ isAtXBeginning NOTIFY isAtBoundaryChanged)
96     Q_PROPERTY(bool atYBeginning READ isAtYBeginning NOTIFY isAtBoundaryChanged)
97
98     Q_PROPERTY(QQuickFlickableVisibleArea *visibleArea READ visibleArea CONSTANT)
99
100     Q_PROPERTY(bool pixelAligned READ pixelAligned WRITE setPixelAligned NOTIFY pixelAlignedChanged)
101
102     Q_PROPERTY(QQmlListProperty<QObject> flickableData READ flickableData)
103     Q_PROPERTY(QQmlListProperty<QQuickItem> flickableChildren READ flickableChildren)
104     Q_CLASSINFO("DefaultProperty", "flickableData")
105
106     Q_ENUMS(FlickableDirection)
107     Q_ENUMS(BoundsBehavior)
108
109 public:
110     QQuickFlickable(QQuickItem *parent=0);
111     ~QQuickFlickable();
112
113     QQmlListProperty<QObject> flickableData();
114     QQmlListProperty<QQuickItem> flickableChildren();
115
116     enum BoundsBehavior { StopAtBounds, DragOverBounds, DragAndOvershootBounds };
117     BoundsBehavior boundsBehavior() const;
118     void setBoundsBehavior(BoundsBehavior);
119
120     QQuickTransition *rebound() const;
121     void setRebound(QQuickTransition *transition);
122
123     qreal contentWidth() const;
124     void setContentWidth(qreal);
125
126     qreal contentHeight() const;
127     void setContentHeight(qreal);
128
129     qreal contentX() const;
130     virtual void setContentX(qreal pos);
131
132     qreal contentY() const;
133     virtual void setContentY(qreal pos);
134
135     qreal topMargin() const;
136     void setTopMargin(qreal m);
137
138     qreal bottomMargin() const;
139     void setBottomMargin(qreal m);
140
141     qreal leftMargin() const;
142     void setLeftMargin(qreal m);
143
144     qreal rightMargin() const;
145     void setRightMargin(qreal m);
146
147     virtual qreal originY() const;
148     virtual qreal originX() const;
149
150     bool isMoving() const;
151     bool isMovingHorizontally() const;
152     bool isMovingVertically() const;
153     bool isFlicking() const;
154     bool isFlickingHorizontally() const;
155     bool isFlickingVertically() const;
156     bool isDragging() const;
157     bool isDraggingHorizontally() const;
158     bool isDraggingVertically() const;
159
160     int pressDelay() const;
161     void setPressDelay(int delay);
162
163     qreal maximumFlickVelocity() const;
164     void setMaximumFlickVelocity(qreal);
165
166     qreal flickDeceleration() const;
167     void setFlickDeceleration(qreal);
168
169     bool isInteractive() const;
170     void setInteractive(bool);
171
172     qreal horizontalVelocity() const;
173     qreal verticalVelocity() const;
174
175     bool isAtXEnd() const;
176     bool isAtXBeginning() const;
177     bool isAtYEnd() const;
178     bool isAtYBeginning() const;
179
180     QQuickItem *contentItem();
181
182     enum FlickableDirection { AutoFlickDirection=0x00, HorizontalFlick=0x01, VerticalFlick=0x02, HorizontalAndVerticalFlick=0x03 };
183     FlickableDirection flickableDirection() const;
184     void setFlickableDirection(FlickableDirection);
185
186     bool pixelAligned() const;
187     void setPixelAligned(bool align);
188
189     Q_INVOKABLE void resizeContent(qreal w, qreal h, QPointF center);
190     Q_INVOKABLE void returnToBounds();
191     Q_INVOKABLE void flick(qreal xVelocity, qreal yVelocity);
192     Q_INVOKABLE void cancelFlick();
193
194 Q_SIGNALS:
195     void contentWidthChanged();
196     void contentHeightChanged();
197     void contentXChanged();
198     void contentYChanged();
199     void topMarginChanged();
200     void bottomMarginChanged();
201     void leftMarginChanged();
202     void rightMarginChanged();
203     void originYChanged();
204     void originXChanged();
205     void movingChanged();
206     void movingHorizontallyChanged();
207     void movingVerticallyChanged();
208     void flickingChanged();
209     void flickingHorizontallyChanged();
210     void flickingVerticallyChanged();
211     void draggingChanged();
212     void draggingHorizontallyChanged();
213     void draggingVerticallyChanged();
214     void horizontalVelocityChanged();
215     void verticalVelocityChanged();
216     void isAtBoundaryChanged();
217     void flickableDirectionChanged();
218     void interactiveChanged();
219     void boundsBehaviorChanged();
220     void reboundChanged();
221     void maximumFlickVelocityChanged();
222     void flickDecelerationChanged();
223     void pressDelayChanged();
224     void movementStarted();
225     void movementEnded();
226     void flickStarted();
227     void flickEnded();
228     void dragStarted();
229     void dragEnded();
230     void pixelAlignedChanged();
231
232 protected:
233     virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
234     virtual void mousePressEvent(QMouseEvent *event);
235     virtual void mouseMoveEvent(QMouseEvent *event);
236     virtual void mouseReleaseEvent(QMouseEvent *event);
237     virtual void wheelEvent(QWheelEvent *event);
238     virtual void timerEvent(QTimerEvent *event);
239
240     QQuickFlickableVisibleArea *visibleArea();
241
242 protected Q_SLOTS:
243     void movementStarting();
244     void movementEnding();
245     void movementEnding(bool hMovementEnding, bool vMovementEnding);
246     void timelineCompleted();
247
248 protected:
249     virtual qreal minXExtent() const;
250     virtual qreal minYExtent() const;
251     virtual qreal maxXExtent() const;
252     virtual qreal maxYExtent() const;
253     qreal vWidth() const;
254     qreal vHeight() const;
255     virtual void componentComplete();
256     virtual void viewportMoved(Qt::Orientations orient);
257     virtual void geometryChanged(const QRectF &newGeometry,
258                                  const QRectF &oldGeometry);
259     void mouseUngrabEvent();
260     bool sendMouseEvent(QMouseEvent *event);
261
262     bool xflick() const;
263     bool yflick() const;
264
265 protected:
266     QQuickFlickable(QQuickFlickablePrivate &dd, QQuickItem *parent);
267
268 private:
269     Q_DISABLE_COPY(QQuickFlickable)
270     Q_DECLARE_PRIVATE(QQuickFlickable)
271     friend class QQuickFlickableVisibleArea;
272     friend class QQuickFlickableReboundTransition;
273 };
274
275 QT_END_NAMESPACE
276
277 QML_DECLARE_TYPE(QQuickFlickable)
278
279 QT_END_HEADER
280
281 #endif // QQUICKFLICKABLE_P_H