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