Merge branch 'master' into refactor
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativeflickable_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 QDECLARATIVEFLICKABLE_H
43 #define QDECLARATIVEFLICKABLE_H
44
45 #include "qdeclarativeitem.h"
46
47 QT_BEGIN_HEADER
48
49 QT_BEGIN_NAMESPACE
50
51 QT_MODULE(Declarative)
52
53 class QDeclarative1FlickablePrivate;
54 class QDeclarative1FlickableVisibleArea;
55 class Q_AUTOTEST_EXPORT QDeclarative1Flickable : public QDeclarativeItem
56 {
57     Q_OBJECT
58
59     Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged)
60     Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged)
61     Q_PROPERTY(qreal contentX READ contentX WRITE setContentX NOTIFY contentXChanged)
62     Q_PROPERTY(qreal contentY READ contentY WRITE setContentY NOTIFY contentYChanged)
63     Q_PROPERTY(QDeclarativeItem *contentItem READ contentItem CONSTANT)
64
65     Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged)
66     Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged)
67
68     Q_PROPERTY(BoundsBehavior boundsBehavior READ boundsBehavior WRITE setBoundsBehavior NOTIFY boundsBehaviorChanged)
69     Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity NOTIFY maximumFlickVelocityChanged)
70     Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged)
71     Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged)
72     Q_PROPERTY(bool movingHorizontally READ isMovingHorizontally NOTIFY movingHorizontallyChanged)
73     Q_PROPERTY(bool movingVertically READ isMovingVertically NOTIFY movingVerticallyChanged)
74     Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged)
75     Q_PROPERTY(bool flickingHorizontally READ isFlickingHorizontally NOTIFY flickingHorizontallyChanged)
76     Q_PROPERTY(bool flickingVertically READ isFlickingVertically NOTIFY flickingVerticallyChanged)
77     Q_PROPERTY(FlickableDirection flickableDirection READ flickableDirection WRITE setFlickableDirection NOTIFY flickableDirectionChanged)
78
79     Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged)
80     Q_PROPERTY(int pressDelay READ pressDelay WRITE setPressDelay NOTIFY pressDelayChanged)
81
82     Q_PROPERTY(bool atXEnd READ isAtXEnd NOTIFY isAtBoundaryChanged)
83     Q_PROPERTY(bool atYEnd READ isAtYEnd NOTIFY isAtBoundaryChanged)
84     Q_PROPERTY(bool atXBeginning READ isAtXBeginning NOTIFY isAtBoundaryChanged)
85     Q_PROPERTY(bool atYBeginning READ isAtYBeginning NOTIFY isAtBoundaryChanged)
86
87     Q_PROPERTY(QDeclarative1FlickableVisibleArea *visibleArea READ visibleArea CONSTANT)
88
89     Q_PROPERTY(QDeclarativeListProperty<QObject> flickableData READ flickableData)
90     Q_PROPERTY(QDeclarativeListProperty<QGraphicsObject> flickableChildren READ flickableChildren)
91     Q_CLASSINFO("DefaultProperty", "flickableData")
92
93     Q_ENUMS(FlickableDirection)
94     Q_ENUMS(BoundsBehavior)
95
96 public:
97     QDeclarative1Flickable(QDeclarativeItem *parent=0);
98     ~QDeclarative1Flickable();
99
100     QDeclarativeListProperty<QObject> flickableData();
101     QDeclarativeListProperty<QGraphicsObject> flickableChildren();
102
103     enum BoundsBehavior { StopAtBounds, DragOverBounds, DragAndOvershootBounds };
104     BoundsBehavior boundsBehavior() const;
105     void setBoundsBehavior(BoundsBehavior);
106
107     qreal contentWidth() const;
108     void setContentWidth(qreal);
109
110     qreal contentHeight() const;
111     void setContentHeight(qreal);
112
113     qreal contentX() const;
114     virtual void setContentX(qreal pos);
115
116     qreal contentY() const;
117     virtual void setContentY(qreal pos);
118
119     bool isMoving() const;
120     bool isMovingHorizontally() const;
121     bool isMovingVertically() const;
122     bool isFlicking() const;
123     bool isFlickingHorizontally() const;
124     bool isFlickingVertically() const;
125
126     int pressDelay() const;
127     void setPressDelay(int delay);
128
129     qreal maximumFlickVelocity() const;
130     void setMaximumFlickVelocity(qreal);
131
132     qreal flickDeceleration() const;
133     void setFlickDeceleration(qreal);
134
135     bool isInteractive() const;
136     void setInteractive(bool);
137
138     qreal horizontalVelocity() const;
139     qreal verticalVelocity() const;
140
141     bool isAtXEnd() const;
142     bool isAtXBeginning() const;
143     bool isAtYEnd() const;
144     bool isAtYBeginning() const;
145
146     QDeclarativeItem *contentItem();
147
148     enum FlickableDirection { AutoFlickDirection=0x00, HorizontalFlick=0x01, VerticalFlick=0x02, HorizontalAndVerticalFlick=0x03 };
149     FlickableDirection flickableDirection() const;
150     void setFlickableDirection(FlickableDirection);
151
152     Q_INVOKABLE Q_REVISION(1) void resizeContent(qreal w, qreal h, QPointF center);
153     Q_INVOKABLE Q_REVISION(1) void returnToBounds();
154
155 Q_SIGNALS:
156     void contentWidthChanged();
157     void contentHeightChanged();
158     void contentXChanged();
159     void contentYChanged();
160     void movingChanged();
161     void movingHorizontallyChanged();
162     void movingVerticallyChanged();
163     void flickingChanged();
164     void flickingHorizontallyChanged();
165     void flickingVerticallyChanged();
166     void horizontalVelocityChanged();
167     void verticalVelocityChanged();
168     void isAtBoundaryChanged();
169     void flickableDirectionChanged();
170     void interactiveChanged();
171     void boundsBehaviorChanged();
172     void maximumFlickVelocityChanged();
173     void flickDecelerationChanged();
174     void pressDelayChanged();
175     void movementStarted();
176     void movementEnded();
177     void flickStarted();
178     void flickEnded();
179
180 protected:
181     virtual bool sceneEventFilter(QGraphicsItem *, QEvent *);
182     void mousePressEvent(QGraphicsSceneMouseEvent *event);
183     void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
184     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
185     void wheelEvent(QGraphicsSceneWheelEvent *event);
186     void timerEvent(QTimerEvent *event);
187
188     QDeclarative1FlickableVisibleArea *visibleArea();
189
190 protected Q_SLOTS:
191     virtual void ticked();
192     void movementStarting();
193     void movementEnding();
194
195 protected:
196     void movementXEnding();
197     void movementYEnding();
198     virtual qreal minXExtent() const;
199     virtual qreal minYExtent() const;
200     virtual qreal maxXExtent() const;
201     virtual qreal maxYExtent() const;
202     qreal vWidth() const;
203     qreal vHeight() const;
204     virtual void viewportMoved();
205     virtual void geometryChanged(const QRectF &newGeometry,
206                                  const QRectF &oldGeometry);
207     bool sceneEvent(QEvent *event);
208     bool sendMouseEvent(QGraphicsSceneMouseEvent *event);
209
210     bool xflick() const;
211     bool yflick() const;
212     void cancelFlick();
213
214 protected:
215     QDeclarative1Flickable(QDeclarative1FlickablePrivate &dd, QDeclarativeItem *parent);
216
217 private:
218     Q_DISABLE_COPY(QDeclarative1Flickable)
219     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1Flickable)
220     friend class QDeclarative1FlickableVisibleArea;
221 };
222
223 QT_END_NAMESPACE
224
225 QML_DECLARE_TYPE(QDeclarative1Flickable)
226
227 QT_END_HEADER
228
229 #endif