0723f8326fdf50277f3de58ef61c372ccee77fd1
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickmousearea_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
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
47 #include <QtCore/qstringlist.h>
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 class QQuickDragAttached;
54 class QQuickMouseEvent;
55 class Q_AUTOTEST_EXPORT QQuickDrag : public QObject
56 {
57     Q_OBJECT
58
59     Q_ENUMS(Axis)
60     Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged RESET resetTarget)
61     Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged)
62     Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged)
63     Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged)
64     Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged)
65     Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged)
66     Q_PROPERTY(bool active READ active NOTIFY activeChanged)
67     Q_PROPERTY(bool filterChildren READ filterChildren WRITE setFilterChildren NOTIFY filterChildrenChanged)
68     //### consider drag and drop
69
70 public:
71     QQuickDrag(QObject *parent=0);
72     ~QQuickDrag();
73
74     QQuickItem *target() const;
75     void setTarget(QQuickItem *target);
76     void resetTarget();
77
78     enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 };
79     Axis axis() const;
80     void setAxis(Axis);
81
82     qreal xmin() const;
83     void setXmin(qreal);
84     qreal xmax() const;
85     void setXmax(qreal);
86     qreal ymin() const;
87     void setYmin(qreal);
88     qreal ymax() const;
89     void setYmax(qreal);
90
91     bool active() const;
92     void setActive(bool);
93
94     bool filterChildren() const;
95     void setFilterChildren(bool);
96
97     static QQuickDragAttached *qmlAttachedProperties(QObject *obj);
98
99 Q_SIGNALS:
100     void targetChanged();
101     void axisChanged();
102     void minimumXChanged();
103     void maximumXChanged();
104     void minimumYChanged();
105     void maximumYChanged();
106     void activeChanged();
107     void filterChildrenChanged();
108
109 private:
110     QQuickItem *_target;
111     Axis _axis;
112     qreal _xmin;
113     qreal _xmax;
114     qreal _ymin;
115     qreal _ymax;
116     bool _active : 1;
117     bool _filterChildren: 1;
118     Q_DISABLE_COPY(QQuickDrag)
119 };
120
121 class QQuickMouseAreaPrivate;
122 // used in QtLocation
123 class Q_QUICK_EXPORT QQuickMouseArea : public QQuickItem
124 {
125     Q_OBJECT
126
127     Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mouseXChanged)
128     Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mouseYChanged)
129     Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged)
130     Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
131     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
132     Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged)
133     Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged)
134     Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
135     Q_PROPERTY(QQuickDrag *drag READ drag CONSTANT) //### add flicking to QQuickDrag or add a QDeclarativeFlick ???
136     Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged)
137     Q_PROPERTY(bool propagateComposedEvents READ propagateComposedEvents WRITE setPropagateComposedEvents NOTIFY propagateComposedEventsChanged)
138
139 public:
140     QQuickMouseArea(QQuickItem *parent=0);
141     ~QQuickMouseArea();
142
143     qreal mouseX() const;
144     qreal mouseY() const;
145
146     bool isEnabled() const;
147     void setEnabled(bool);
148
149     bool hovered() const;
150     bool pressed() const;
151
152     Qt::MouseButtons pressedButtons() const;
153
154     Qt::MouseButtons acceptedButtons() const;
155     void setAcceptedButtons(Qt::MouseButtons buttons);
156
157     bool hoverEnabled() const;
158     void setHoverEnabled(bool h);
159
160     QQuickDrag *drag();
161
162     bool preventStealing() const;
163     void setPreventStealing(bool prevent);
164
165     bool propagateComposedEvents() const;
166     void setPropagateComposedEvents(bool propagate);
167
168 Q_SIGNALS:
169     void hoveredChanged();
170     void pressedChanged();
171     void enabledChanged();
172     void acceptedButtonsChanged();
173     void hoverEnabledChanged();
174     void positionChanged(QQuickMouseEvent *mouse);
175     void mouseXChanged(QQuickMouseEvent *mouse);
176     void mouseYChanged(QQuickMouseEvent *mouse);
177     void preventStealingChanged();
178     void propagateComposedEventsChanged();
179
180     void pressed(QQuickMouseEvent *mouse);
181     void pressAndHold(QQuickMouseEvent *mouse);
182     void released(QQuickMouseEvent *mouse);
183     void clicked(QQuickMouseEvent *mouse);
184     void doubleClicked(QQuickMouseEvent *mouse);
185     void entered();
186     void exited();
187     void canceled();
188
189 protected:
190     void setHovered(bool);
191     bool setPressed(bool);
192     bool sendMouseEvent(QMouseEvent *event);
193
194     virtual void mousePressEvent(QMouseEvent *event);
195     virtual void mouseReleaseEvent(QMouseEvent *event);
196     virtual void mouseDoubleClickEvent(QMouseEvent *event);
197     virtual void mouseMoveEvent(QMouseEvent *event);
198     virtual void mouseUngrabEvent();
199     virtual void hoverEnterEvent(QHoverEvent *event);
200     virtual void hoverMoveEvent(QHoverEvent *event);
201     virtual void hoverLeaveEvent(QHoverEvent *event);
202     virtual bool childMouseEventFilter(QQuickItem *i, QEvent *e);
203     virtual void timerEvent(QTimerEvent *event);
204     virtual void windowDeactivateEvent();
205
206     virtual void geometryChanged(const QRectF &newGeometry,
207                                  const QRectF &oldGeometry);
208     virtual void itemChange(ItemChange change, const ItemChangeData& value);
209     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
210
211 private:
212     void handlePress();
213     void handleRelease();
214     void ungrabMouse();
215
216 private:
217     Q_DISABLE_COPY(QQuickMouseArea)
218     Q_DECLARE_PRIVATE(QQuickMouseArea)
219 };
220
221 QT_END_NAMESPACE
222
223 QML_DECLARE_TYPE(QQuickDrag)
224 QML_DECLARE_TYPEINFO(QQuickDrag, QML_HAS_ATTACHED_PROPERTIES)
225 QML_DECLARE_TYPE(QQuickMouseArea)
226
227 QT_END_HEADER
228
229 #endif // QQUICKMOUSEAREA_P_H