Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / src / declarative / 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 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
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 QDeclarativeDrag : 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     QDeclarativeDrag(QObject *parent=0);
70     ~QDeclarativeDrag();
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(QDeclarativeDrag)
115 };
116
117 class QDeclarativeMouseEvent;
118 class QDeclarativeMouseAreaPrivate;
119 class Q_AUTOTEST_EXPORT QDeclarativeMouseArea : 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(QDeclarativeDrag *drag READ drag CONSTANT) //### add flicking to QDeclarativeDrag or add a QDeclarativeFlick ???
132     Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged REVISION 1)
133     Q_PROPERTY(QDeclarativeListProperty<QGraphicsObject> forwardTo READ forwardTo);
134
135 public:
136     QDeclarativeMouseArea(QDeclarativeItem *parent=0);
137     ~QDeclarativeMouseArea();
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     QDeclarativeDrag *drag();
157
158     bool preventStealing() const;
159     void setPreventStealing(bool prevent);
160
161     QDeclarativeListProperty<QGraphicsObject> forwardTo();
162
163 Q_SIGNALS:
164     void hoveredChanged();
165     void pressedChanged();
166     void enabledChanged();
167     void acceptedButtonsChanged();
168     void hoverEnabledChanged();
169     void positionChanged(QDeclarativeMouseEvent *mouse);
170     void mousePositionChanged(QDeclarativeMouseEvent *mouse);
171     Q_REVISION(1) void preventStealingChanged();
172
173     void pressed(QDeclarativeMouseEvent *mouse);
174     void pressAndHold(QDeclarativeMouseEvent *mouse);
175     void released(QDeclarativeMouseEvent *mouse);
176     void clicked(QDeclarativeMouseEvent *mouse);
177     void doubleClicked(QDeclarativeMouseEvent *mouse);
178     void entered();
179     void exited();
180     void canceled();
181
182 protected:
183     void setHovered(bool);
184     bool setPressed(bool);
185
186     void mousePressEvent(QGraphicsSceneMouseEvent *event);
187     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
188     void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
189     void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
190     void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
191     void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
192     void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
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(QDeclarativeMouseArea)
208     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeMouseArea)
209 };
210
211 QT_END_NAMESPACE
212
213 QML_DECLARE_TYPE(QDeclarativeDrag)
214 QML_DECLARE_TYPE(QDeclarativeMouseArea)
215
216 QT_END_HEADER
217
218 #endif // QDECLARATIVEMOUSEAREA_H