3255210eedb80439e729622b135629037367b1c6
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgmousearea_p.h
1 // Commit: c6e6a35aeb8794d68a3ca0c4e27a3a1181c066b5
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
15 ** this package.
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, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QSGMOUSEAREA_P_H
44 #define QSGMOUSEAREA_P_H
45
46 #include "qsgitem.h"
47
48 QT_BEGIN_HEADER
49
50 QT_BEGIN_NAMESPACE
51
52 QT_MODULE(Declarative)
53
54 class QSGMouseEvent;
55 class Q_AUTOTEST_EXPORT QSGDrag : public QObject
56 {
57     Q_OBJECT
58
59     Q_ENUMS(Axis)
60     Q_PROPERTY(QSGItem *target READ target WRITE setTarget NOTIFY targetChanged RESET resetTarget)
61     Q_PROPERTY(QSGItem *dropItem READ dropItem NOTIFY dropItemChanged)
62     Q_PROPERTY(QVariant data READ data WRITE setData NOTIFY dataChanged RESET resetData)
63     Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged)
64     Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged)
65     Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged)
66     Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged)
67     Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged)
68     Q_PROPERTY(bool active READ active NOTIFY activeChanged)
69     Q_PROPERTY(bool filterChildren READ filterChildren WRITE setFilterChildren NOTIFY filterChildrenChanged)
70     Q_PROPERTY(QStringList keys READ keys WRITE setKeys NOTIFY keysChanged)
71     //### consider drag and drop
72
73 public:
74     QSGDrag(QObject *parent=0);
75     ~QSGDrag();
76
77     QSGItem *target() const;
78     void setTarget(QSGItem *);
79     void resetTarget();
80
81     QSGItem *dropItem() const;
82     void setDropItem(QSGItem *item);
83
84     QSGItem *grabItem() const;
85     void setGrabItem(QSGItem *grabItem);
86
87     QVariant data() const;
88     void setData(const QVariant &data);
89     void resetData();
90
91     enum Axis { XAxis=0x01, YAxis=0x02, XandYAxis=0x03 };
92     Axis axis() const;
93     void setAxis(Axis);
94
95     qreal xmin() const;
96     void setXmin(qreal);
97     qreal xmax() const;
98     void setXmax(qreal);
99     qreal ymin() const;
100     void setYmin(qreal);
101     qreal ymax() const;
102     void setYmax(qreal);
103
104     bool active() const;
105     void setActive(bool);
106
107     bool filterChildren() const;
108     void setFilterChildren(bool);
109
110     QStringList keys() const;
111     void setKeys(const QStringList &keys);
112
113     void emitDragged(QSGMouseEvent *event) { emit dragged(event); }
114     void emitDropped(QSGItem *dropItem) { emit dropped(dropItem); }
115     void emitCanceled() { emit canceled(); }
116
117 Q_SIGNALS:
118     void targetChanged();
119     void dropItemChanged();
120     void dataChanged();
121     void axisChanged();
122     void minimumXChanged();
123     void maximumXChanged();
124     void minimumYChanged();
125     void maximumYChanged();
126     void activeChanged();
127     void filterChildrenChanged();
128     void keysChanged();
129     void dragged(QSGMouseEvent *mouse);
130     void dropped(QSGItem *dropItem);
131     void canceled();
132
133 private:
134     QStringList _keys;
135     QVariant _data;
136     QSGItem *_target;
137     QSGItem *_dropItem;
138     QSGItem *_grabItem;
139     Axis _axis;
140     qreal _xmin;
141     qreal _xmax;
142     qreal _ymin;
143     qreal _ymax;
144     bool _active : 1;
145     bool _filterChildren: 1;
146     Q_DISABLE_COPY(QSGDrag)
147 };
148
149 class QSGMouseAreaPrivate;
150 class Q_AUTOTEST_EXPORT QSGMouseArea : public QSGItem
151 {
152     Q_OBJECT
153
154     Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mousePositionChanged)
155     Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mousePositionChanged)
156     Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged)
157     Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged)
158     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
159     Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedChanged)
160     Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged)
161     Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
162     Q_PROPERTY(QSGDrag *drag READ drag CONSTANT) //### add flicking to QSGDrag or add a QDeclarativeFlick ???
163     Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged)
164     Q_PROPERTY(QDeclarativeListProperty<QSGItem> forwardTo READ forwardTo);
165
166 public:
167     QSGMouseArea(QSGItem *parent=0);
168     ~QSGMouseArea();
169
170     qreal mouseX() const;
171     qreal mouseY() const;
172
173     bool isEnabled() const;
174     void setEnabled(bool);
175
176     bool hovered() const;
177     bool pressed() const;
178
179     Qt::MouseButtons pressedButtons() const;
180
181     Qt::MouseButtons acceptedButtons() const;
182     void setAcceptedButtons(Qt::MouseButtons buttons);
183
184     bool hoverEnabled() const;
185     void setHoverEnabled(bool h);
186
187     QSGDrag *drag();
188
189     bool preventStealing() const;
190     void setPreventStealing(bool prevent);
191
192     QDeclarativeListProperty<QSGItem> forwardTo();
193
194 Q_SIGNALS:
195     void hoveredChanged();
196     void pressedChanged();
197     void enabledChanged();
198     void acceptedButtonsChanged();
199     void hoverEnabledChanged();
200     void positionChanged(QSGMouseEvent *mouse);
201     void mousePositionChanged(QSGMouseEvent *mouse);
202     void preventStealingChanged();
203
204     void pressed(QSGMouseEvent *mouse);
205     void pressAndHold(QSGMouseEvent *mouse);
206     void released(QSGMouseEvent *mouse);
207     void clicked(QSGMouseEvent *mouse);
208     void doubleClicked(QSGMouseEvent *mouse);
209     void entered();
210     void exited();
211     void canceled();
212
213 protected:
214     void setHovered(bool);
215     bool setPressed(bool);
216     bool sendMouseEvent(QGraphicsSceneMouseEvent *event);
217
218     virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
219     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
220     virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
221     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
222     virtual void mouseUngrabEvent();
223     virtual void hoverEnterEvent(QHoverEvent *event);
224     virtual void hoverMoveEvent(QHoverEvent *event);
225     virtual void hoverLeaveEvent(QHoverEvent *event);
226     virtual bool childMouseEventFilter(QSGItem *i, QEvent *e);
227     virtual void timerEvent(QTimerEvent *event);
228
229     virtual void geometryChanged(const QRectF &newGeometry,
230                                  const QRectF &oldGeometry);
231     virtual void itemChange(ItemChange change, const ItemChangeData& value);
232
233 private:
234     void handlePress();
235     void handleRelease();
236
237 private:
238     Q_DISABLE_COPY(QSGMouseArea)
239     Q_DECLARE_PRIVATE(QSGMouseArea)
240 };
241
242 QT_END_NAMESPACE
243
244 QML_DECLARE_TYPE(QSGDrag)
245 QML_DECLARE_TYPE(QSGMouseArea)
246
247 QT_END_HEADER
248
249 #endif // QSGMOUSEAREA_P_H