Merge branch 'master' into refactor
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativemousearea_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 QDECLARATIVEMOUSEAREA_H
43 #define QDECLARATIVEMOUSEAREA_H
44
45 #include "qdeclarativeitem.h"
46
47 QT_BEGIN_HEADER
48
49 QT_BEGIN_NAMESPACE
50
51 QT_MODULE(Declarative)
52
53 class Q_AUTOTEST_EXPORT QDeclarative1Drag : public QObject
54 {
55     Q_OBJECT
56
57     Q_ENUMS(Axis)
58     Q_PROPERTY(QGraphicsObject *target READ target WRITE setTarget NOTIFY targetChanged RESET resetTarget)
59     Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged)
60     Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged)
61     Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged)
62     Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged)
63     Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged)
64     Q_PROPERTY(bool active READ active NOTIFY activeChanged)
65     Q_PROPERTY(bool filterChildren READ filterChildren WRITE setFilterChildren NOTIFY filterChildrenChanged)
66     //### consider drag and drop
67
68 public:
69     QDeclarative1Drag(QObject *parent=0);
70     ~QDeclarative1Drag();
71
72     QGraphicsObject *target() const;
73     void setTarget(QGraphicsObject *);
74     void resetTarget();
75
76     enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 };
77     Axis axis() const;
78     void setAxis(Axis);
79
80     qreal xmin() const;
81     void setXmin(qreal);
82     qreal xmax() const;
83     void setXmax(qreal);
84     qreal ymin() const;
85     void setYmin(qreal);
86     qreal ymax() const;
87     void setYmax(qreal);
88
89     bool active() const;
90     void setActive(bool);
91
92     bool filterChildren() const;
93     void setFilterChildren(bool);
94
95 Q_SIGNALS:
96     void targetChanged();
97     void axisChanged();
98     void minimumXChanged();
99     void maximumXChanged();
100     void minimumYChanged();
101     void maximumYChanged();
102     void activeChanged();
103     void filterChildrenChanged();
104
105 private:
106     QGraphicsObject *_target;
107     Axis _axis;
108     qreal _xmin;
109     qreal _xmax;
110     qreal _ymin;
111     qreal _ymax;
112     bool _active : 1;
113     bool _filterChildren: 1;
114     Q_DISABLE_COPY(QDeclarative1Drag)
115 };
116
117 class QDeclarative1MouseEvent;
118 class QDeclarative1MouseAreaPrivate;
119 class Q_AUTOTEST_EXPORT QDeclarative1MouseArea : public QDeclarativeItem
120 {
121     Q_OBJECT
122
123     Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mousePositionChanged)
124     Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mousePositionChanged)
125     Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged)
126     Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
127     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
128     Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged)
129     Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged)
130     Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
131     Q_PROPERTY(QDeclarative1Drag *drag READ drag CONSTANT) //### add flicking to QDeclarative1Drag or add a QDeclarative1Flick ???
132     Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged REVISION 1)
133
134 public:
135     QDeclarative1MouseArea(QDeclarativeItem *parent=0);
136     ~QDeclarative1MouseArea();
137
138     qreal mouseX() const;
139     qreal mouseY() const;
140
141     bool isEnabled() const;
142     void setEnabled(bool);
143
144     bool hovered() const;
145     bool pressed() const;
146
147     Qt::MouseButtons pressedButtons() const;
148
149     Qt::MouseButtons acceptedButtons() const;
150     void setAcceptedButtons(Qt::MouseButtons buttons);
151
152     bool hoverEnabled() const;
153     void setHoverEnabled(bool h);
154
155     QDeclarative1Drag *drag();
156
157     bool preventStealing() const;
158     void setPreventStealing(bool prevent);
159
160 Q_SIGNALS:
161     void hoveredChanged();
162     void pressedChanged();
163     void enabledChanged();
164     void acceptedButtonsChanged();
165     void hoverEnabledChanged();
166     void positionChanged(QDeclarative1MouseEvent *mouse);
167     void mousePositionChanged(QDeclarative1MouseEvent *mouse);
168     Q_REVISION(1) void preventStealingChanged();
169
170     void pressed(QDeclarative1MouseEvent *mouse);
171     void pressAndHold(QDeclarative1MouseEvent *mouse);
172     void released(QDeclarative1MouseEvent *mouse);
173     void clicked(QDeclarative1MouseEvent *mouse);
174     void doubleClicked(QDeclarative1MouseEvent *mouse);
175     void entered();
176     void exited();
177     void canceled();
178
179 protected:
180     void setHovered(bool);
181     bool setPressed(bool);
182
183     void mousePressEvent(QGraphicsSceneMouseEvent *event);
184     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
185     void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
186     void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
187     void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
188     void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
189     void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
190 #ifndef QT_NO_CONTEXTMENU
191     void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
192 #endif // QT_NO_CONTEXTMENU
193     bool sceneEvent(QEvent *);
194     bool sendMouseEvent(QGraphicsSceneMouseEvent *event);
195     bool sceneEventFilter(QGraphicsItem *i, QEvent *e);
196     void timerEvent(QTimerEvent *event);
197
198     virtual void geometryChanged(const QRectF &newGeometry,
199                                  const QRectF &oldGeometry);
200     virtual QVariant itemChange(GraphicsItemChange change, const QVariant& value);
201
202 private:
203     void handlePress();
204     void handleRelease();
205
206 private:
207     Q_DISABLE_COPY(QDeclarative1MouseArea)
208     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1MouseArea)
209 };
210
211 QT_END_NAMESPACE
212
213 QML_DECLARE_TYPE(QDeclarative1Drag)
214 QML_DECLARE_TYPE(QDeclarative1MouseArea)
215
216 QT_END_HEADER
217
218 #endif // QDECLARATIVEMOUSEAREA_H