Change copyrights from Nokia to Digia
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickmousearea_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 QQUICKMOUSEAREA_P_H
43 #define QQUICKMOUSEAREA_P_H
44
45 #include "qquickitem.h"
46 #include <private/qtquickglobal_p.h>
47 #include <QtCore/qstringlist.h>
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 class QQuickMouseEvent;
54
55 #ifndef QT_NO_DRAGANDDROP
56
57 class QQuickDragAttached;
58 class Q_AUTOTEST_EXPORT QQuickDrag : public QObject
59 {
60     Q_OBJECT
61
62     Q_ENUMS(Axis)
63     Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged RESET resetTarget)
64     Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged)
65     Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged)
66     Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged)
67     Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged)
68     Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged)
69     Q_PROPERTY(bool active READ active NOTIFY activeChanged)
70     Q_PROPERTY(bool filterChildren READ filterChildren WRITE setFilterChildren NOTIFY filterChildrenChanged)
71     //### consider drag and drop
72
73 public:
74     QQuickDrag(QObject *parent=0);
75     ~QQuickDrag();
76
77     QQuickItem *target() const;
78     void setTarget(QQuickItem *target);
79     void resetTarget();
80
81     enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 };
82     Axis axis() const;
83     void setAxis(Axis);
84
85     qreal xmin() const;
86     void setXmin(qreal);
87     qreal xmax() const;
88     void setXmax(qreal);
89     qreal ymin() const;
90     void setYmin(qreal);
91     qreal ymax() const;
92     void setYmax(qreal);
93
94     bool active() const;
95     void setActive(bool);
96
97     bool filterChildren() const;
98     void setFilterChildren(bool);
99
100     static QQuickDragAttached *qmlAttachedProperties(QObject *obj);
101
102 Q_SIGNALS:
103     void targetChanged();
104     void axisChanged();
105     void minimumXChanged();
106     void maximumXChanged();
107     void minimumYChanged();
108     void maximumYChanged();
109     void activeChanged();
110     void filterChildrenChanged();
111
112 private:
113     QQuickItem *_target;
114     Axis _axis;
115     qreal _xmin;
116     qreal _xmax;
117     qreal _ymin;
118     qreal _ymax;
119     bool _active : 1;
120     bool _filterChildren: 1;
121     Q_DISABLE_COPY(QQuickDrag)
122 };
123
124 #endif // QT_NO_DRAGANDDROP
125
126 class QQuickMouseAreaPrivate;
127 class QQuickWheelEvent;
128 // used in QtLocation
129 class Q_QUICK_PRIVATE_EXPORT QQuickMouseArea : public QQuickItem
130 {
131     Q_OBJECT
132
133     Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mouseXChanged)
134     Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mouseYChanged)
135     Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged)
136     Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
137     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
138     Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedButtonsChanged)
139     Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged)
140     Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
141 #ifndef QT_NO_DRAGANDDROP
142     Q_PROPERTY(QQuickDrag *drag READ drag CONSTANT) //### add flicking to QQuickDrag or add a QQuickFlick ???
143 #endif
144     Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged)
145     Q_PROPERTY(bool propagateComposedEvents READ propagateComposedEvents WRITE setPropagateComposedEvents NOTIFY propagateComposedEventsChanged)
146 #ifndef QT_NO_CURSOR
147     Q_PROPERTY(Qt::CursorShape cursorShape READ cursorShape WRITE setCursorShape RESET unsetCursor NOTIFY cursorShapeChanged)
148 #endif
149
150 public:
151     QQuickMouseArea(QQuickItem *parent=0);
152     ~QQuickMouseArea();
153
154     qreal mouseX() const;
155     qreal mouseY() const;
156
157     bool isEnabled() const;
158     void setEnabled(bool);
159
160     bool hovered() const;
161     bool pressed() const;
162
163     Qt::MouseButtons pressedButtons() const;
164
165     Qt::MouseButtons acceptedButtons() const;
166     void setAcceptedButtons(Qt::MouseButtons buttons);
167
168     bool hoverEnabled() const;
169     void setHoverEnabled(bool h);
170
171 #ifndef QT_NO_DRAGANDDROP
172     QQuickDrag *drag();
173 #endif
174
175     bool preventStealing() const;
176     void setPreventStealing(bool prevent);
177
178     bool propagateComposedEvents() const;
179     void setPropagateComposedEvents(bool propagate);
180
181 #ifndef QT_NO_CURSOR
182     Qt::CursorShape cursorShape() const;
183     void setCursorShape(Qt::CursorShape shape);
184 #endif
185
186 Q_SIGNALS:
187     void hoveredChanged();
188     void pressedChanged();
189     void enabledChanged();
190     void pressedButtonsChanged();
191     void acceptedButtonsChanged();
192     void hoverEnabledChanged();
193 #ifndef QT_NO_CURSOR
194     void cursorShapeChanged();
195 #endif
196     void positionChanged(QQuickMouseEvent *mouse);
197     void mouseXChanged(QQuickMouseEvent *mouse);
198     void mouseYChanged(QQuickMouseEvent *mouse);
199     void preventStealingChanged();
200     void propagateComposedEventsChanged();
201
202     void pressed(QQuickMouseEvent *mouse);
203     void pressAndHold(QQuickMouseEvent *mouse);
204     void released(QQuickMouseEvent *mouse);
205     void clicked(QQuickMouseEvent *mouse);
206     void doubleClicked(QQuickMouseEvent *mouse);
207     void wheel(QQuickWheelEvent *wheel);
208     void entered();
209     void exited();
210     void canceled();
211
212 protected:
213     void setHovered(bool);
214     bool setPressed(Qt::MouseButton button, bool);
215     bool sendMouseEvent(QMouseEvent *event);
216
217     virtual void mousePressEvent(QMouseEvent *event);
218     virtual void mouseReleaseEvent(QMouseEvent *event);
219     virtual void mouseDoubleClickEvent(QMouseEvent *event);
220     virtual void mouseMoveEvent(QMouseEvent *event);
221     virtual void mouseUngrabEvent();
222     virtual void hoverEnterEvent(QHoverEvent *event);
223     virtual void hoverMoveEvent(QHoverEvent *event);
224     virtual void hoverLeaveEvent(QHoverEvent *event);
225     virtual void wheelEvent(QWheelEvent *event);
226     virtual bool childMouseEventFilter(QQuickItem *i, QEvent *e);
227     virtual void timerEvent(QTimerEvent *event);
228     virtual void windowDeactivateEvent();
229
230     virtual void geometryChanged(const QRectF &newGeometry,
231                                  const QRectF &oldGeometry);
232     virtual void itemChange(ItemChange change, const ItemChangeData& value);
233     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
234
235 private:
236     void handlePress();
237     void handleRelease();
238     void ungrabMouse();
239
240 private:
241     Q_DISABLE_COPY(QQuickMouseArea)
242     Q_DECLARE_PRIVATE(QQuickMouseArea)
243 };
244
245 QT_END_NAMESPACE
246
247 #ifndef QT_NO_DRAGANDDROP
248 QML_DECLARE_TYPE(QQuickDrag)
249 QML_DECLARE_TYPEINFO(QQuickDrag, QML_HAS_ATTACHED_PROPERTIES)
250 #endif
251 QML_DECLARE_TYPE(QQuickMouseArea)
252
253 QT_END_HEADER
254
255 #endif // QQUICKMOUSEAREA_P_H