Initial import from qtquick2.
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgmousearea_p.h
1 // Commit: 57676c237992e0aa5a93a4e8fa66b3e7b90c2c90
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
15 ** this package.
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, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QSGMOUSEAREA_P_H
44 #define QSGMOUSEAREA_P_H
45
46 #include "qsgitem.h"
47
48 QT_BEGIN_HEADER
49
50 QT_BEGIN_NAMESPACE
51
52 QT_MODULE(Declarative)
53
54 class Q_AUTOTEST_EXPORT QSGDrag : public QObject
55 {
56     Q_OBJECT
57
58     Q_ENUMS(Axis)
59     Q_PROPERTY(QSGItem *target READ target WRITE setTarget NOTIFY targetChanged RESET resetTarget)
60     Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged)
61     Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged)
62     Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged)
63     Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged)
64     Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged)
65     Q_PROPERTY(bool active READ active NOTIFY activeChanged)
66     Q_PROPERTY(bool filterChildren READ filterChildren WRITE setFilterChildren NOTIFY filterChildrenChanged)
67     //### consider drag and drop
68
69 public:
70     QSGDrag(QObject *parent=0);
71     ~QSGDrag();
72
73     QSGItem *target() const;
74     void setTarget(QSGItem *);
75     void resetTarget();
76
77     enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 };
78     Axis axis() const;
79     void setAxis(Axis);
80
81     qreal xmin() const;
82     void setXmin(qreal);
83     qreal xmax() const;
84     void setXmax(qreal);
85     qreal ymin() const;
86     void setYmin(qreal);
87     qreal ymax() const;
88     void setYmax(qreal);
89
90     bool active() const;
91     void setActive(bool);
92
93     bool filterChildren() const;
94     void setFilterChildren(bool);
95
96 Q_SIGNALS:
97     void targetChanged();
98     void axisChanged();
99     void minimumXChanged();
100     void maximumXChanged();
101     void minimumYChanged();
102     void maximumYChanged();
103     void activeChanged();
104     void filterChildrenChanged();
105
106 private:
107     QSGItem *_target;
108     Axis _axis;
109     qreal _xmin;
110     qreal _xmax;
111     qreal _ymin;
112     qreal _ymax;
113     bool _active : 1;
114     bool _filterChildren: 1;
115     Q_DISABLE_COPY(QSGDrag)
116 };
117
118 class QSGMouseEvent;
119 class QSGMouseAreaPrivate;
120 class Q_AUTOTEST_EXPORT QSGMouseArea : public QSGItem
121 {
122     Q_OBJECT
123
124     Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mousePositionChanged)
125     Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mousePositionChanged)
126     Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged)
127     Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
128     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
129     Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged)
130     Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged)
131     Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
132     Q_PROPERTY(QSGDrag *drag READ drag CONSTANT) //### add flicking to QSGDrag or add a QDeclarativeFlick ???
133     Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged)
134
135 public:
136     QSGMouseArea(QSGItem *parent=0);
137     ~QSGMouseArea();
138
139     qreal mouseX() const;
140     qreal mouseY() const;
141
142     bool isEnabled() const;
143     void setEnabled(bool);
144
145     bool hovered() const;
146     bool pressed() const;
147
148     Qt::MouseButtons pressedButtons() const;
149
150     Qt::MouseButtons acceptedButtons() const;
151     void setAcceptedButtons(Qt::MouseButtons buttons);
152
153     bool hoverEnabled() const;
154     void setHoverEnabled(bool h);
155
156     QSGDrag *drag();
157
158     bool preventStealing() const;
159     void setPreventStealing(bool prevent);
160
161 Q_SIGNALS:
162     void hoveredChanged();
163     void pressedChanged();
164     void enabledChanged();
165     void acceptedButtonsChanged();
166     void hoverEnabledChanged();
167     void positionChanged(QSGMouseEvent *mouse);
168     void mousePositionChanged(QSGMouseEvent *mouse);
169     void preventStealingChanged();
170
171     void pressed(QSGMouseEvent *mouse);
172     void pressAndHold(QSGMouseEvent *mouse);
173     void released(QSGMouseEvent *mouse);
174     void clicked(QSGMouseEvent *mouse);
175     void doubleClicked(QSGMouseEvent *mouse);
176     void entered();
177     void exited();
178     void canceled();
179
180 protected:
181     void setHovered(bool);
182     bool setPressed(bool);
183     bool sendMouseEvent(QGraphicsSceneMouseEvent *event);
184
185     virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
186     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
187     virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
188     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
189     virtual void mouseUngrabEvent();
190     virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
191     virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
192     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
193     virtual bool childMouseEventFilter(QSGItem *i, QEvent *e);
194     virtual void timerEvent(QTimerEvent *event);
195
196     virtual void geometryChanged(const QRectF &newGeometry,
197                                  const QRectF &oldGeometry);
198     virtual void itemChange(ItemChange change, const ItemChangeData& value);
199
200 private:
201     void handlePress();
202     void handleRelease();
203
204 private:
205     Q_DISABLE_COPY(QSGMouseArea)
206     Q_DECLARE_PRIVATE(QSGMouseArea)
207 };
208
209 QT_END_NAMESPACE
210
211 QML_DECLARE_TYPE(QSGDrag)
212 QML_DECLARE_TYPE(QSGMouseArea)
213
214 QT_END_HEADER
215
216 #endif // QSGMOUSEAREA_P_H