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