Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / src / declarative / graphicsitems / qdeclarativemousearea_p_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 QDECLARATIVEMOUSEREGION_P_H
43 #define QDECLARATIVEMOUSEREGION_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include "private/qdeclarativeitem_p.h"
57
58 #include <qdatetime.h>
59 #include <qbasictimer.h>
60 #include <qgraphicssceneevent.h>
61
62 QT_BEGIN_NAMESPACE
63
64 class QDeclarativeMouseAreaPrivate : public QDeclarativeItemPrivate
65 {
66     Q_DECLARE_PUBLIC(QDeclarativeMouseArea)
67
68 public:
69     QDeclarativeMouseAreaPrivate()
70       : absorb(true), hovered(false), pressed(false), longPress(false),
71       moved(false), stealMouse(false), doubleClick(false), preventStealing(false), drag(0)
72     {
73         Q_Q(QDeclarativeMouseArea);
74         forwardTo = QDeclarativeListProperty<QGraphicsObject>(q, forwardToList);
75     }
76
77     ~QDeclarativeMouseAreaPrivate();
78
79     void init()
80     {
81         Q_Q(QDeclarativeMouseArea);
82         q->setAcceptedMouseButtons(Qt::LeftButton);
83         q->setFiltersChildEvents(true);
84     }
85
86     void saveEvent(QGraphicsSceneMouseEvent *event) {
87         lastPos = event->pos();
88         lastScenePos = event->scenePos();
89         lastButton = event->button();
90         lastButtons = event->buttons();
91         lastModifiers = event->modifiers();
92     }
93
94     void forwardEvent(QGraphicsSceneMouseEvent* event)
95     {
96         Q_Q(QDeclarativeMouseArea);
97         for(int i=0; i < forwardToList.count(); i++){
98             event->setPos(forwardToList[i]->mapFromScene(event->scenePos()));
99             forwardToList[i]->scene()->sendEvent(forwardToList[i], event);
100             if(event->isAccepted())
101                 break;
102         }
103         event->setPos(q->mapFromScene(event->scenePos()));
104     }
105
106     bool isPressAndHoldConnected() {
107         Q_Q(QDeclarativeMouseArea);
108         static int idx = QObjectPrivate::get(q)->signalIndex("pressAndHold(QDeclarativeMouseEvent*)");
109         return QObjectPrivate::get(q)->isSignalConnected(idx);
110     }
111
112     bool isDoubleClickConnected() {
113         Q_Q(QDeclarativeMouseArea);
114         static int idx = QObjectPrivate::get(q)->signalIndex("doubleClicked(QDeclarativeMouseEvent*)");
115         return QObjectPrivate::get(q)->isSignalConnected(idx);
116     }
117
118     bool absorb : 1;
119     bool hovered : 1;
120     bool pressed : 1;
121     bool longPress : 1;
122     bool moved : 1;
123     bool dragX : 1;
124     bool dragY : 1;
125     bool stealMouse : 1;
126     bool doubleClick : 1;
127     bool preventStealing : 1;
128     QDeclarativeDrag *drag;
129     QPointF startScene;
130     qreal startX;
131     qreal startY;
132     QPointF lastPos;
133     QDeclarativeNullableValue<QPointF> lastScenePos;
134     Qt::MouseButton lastButton;
135     Qt::MouseButtons lastButtons;
136     Qt::KeyboardModifiers lastModifiers;
137     QBasicTimer pressAndHoldTimer;
138
139     QDeclarativeListProperty<QGraphicsObject> forwardTo;
140     QList<QGraphicsObject*> forwardToList;
141 };
142
143 QT_END_NAMESPACE
144
145 #endif // QDECLARATIVEMOUSEREGION_P_H