cfcba510645e851cfefe6fe712cc5af262020c3e
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickdrag_p.h
1 // Commit: c6e6a35aeb8794d68a3ca0c4e27a3a1181c066b5
2 /****************************************************************************
3 **
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: http://www.qt-project.org/
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
30 **
31 ** Other Usage
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QQUICKDRAG_P_H
44 #define QQUICKDRAG_P_H
45
46 #include <QtQuick/qquickitem.h>
47
48 #include <private/qv8engine_p.h>
49
50 #include <QtCore/qmimedata.h>
51 #include <QtCore/qstringlist.h>
52
53
54 QT_BEGIN_HEADER
55
56 QT_BEGIN_NAMESPACE
57
58 class QQuickItem;
59 class QQuickDrag;
60 class QQuickDragPrivate;
61
62 class QQuickDragGrabber
63 {
64     class Item : public QDeclarativeGuard<QQuickItem>
65     {
66     public:
67         Item(QQuickItem *item) : QDeclarativeGuard<QQuickItem>(item) {}
68
69         QIntrusiveListNode node;
70     protected:
71         void objectDestroyed(QQuickItem *) { delete this; }
72     };
73
74     typedef QIntrusiveList<Item, &Item::node> ItemList;
75
76 public:
77     QQuickDragGrabber() : m_target(0) {}
78     ~QQuickDragGrabber() { while (!m_items.isEmpty()) delete m_items.first(); }
79
80
81     QObject *target() const
82     {
83         if (m_target)
84             return m_target;
85         else if (!m_items.isEmpty())
86             return *m_items.first();
87         else
88             return 0;
89     }
90     void setTarget(QObject *target) { m_target = target; }
91     void resetTarget() { m_target = 0; }
92
93     typedef ItemList::iterator iterator;
94     iterator begin() { return m_items.begin(); }
95     iterator end() { return m_items.end(); }
96
97     void grab(QQuickItem *item) { m_items.insert(new Item(item)); }
98     iterator release(iterator at) { Item *item = *at; at = at.erase(); delete item; return at; }
99
100 private:
101
102     ItemList m_items;
103     QObject *m_target;
104 };
105
106 class QQuickDropEventEx : public QDropEvent
107 {
108 public:
109     void setProposedAction(Qt::DropAction action) { default_action = action; drop_action = action; }
110
111     static void setProposedAction(QDropEvent *event, Qt::DropAction action) {
112         static_cast<QQuickDropEventEx *>(event)->setProposedAction(action);
113     }
114
115     void copyActions(const QDropEvent &from) {
116         default_action = from.proposedAction(); drop_action = from.dropAction(); }
117
118     static void copyActions(QDropEvent *to, const QDropEvent &from) {
119         static_cast<QQuickDropEventEx *>(to)->copyActions(from);
120     }
121 };
122
123 class QQuickDragMimeData : public QMimeData
124 {
125     Q_OBJECT
126 public:
127     QQuickDragMimeData()
128         : m_source(0)
129     {
130     }
131
132     QStringList keys() const { return m_keys; }
133     QObject *source() const { return m_source; }
134
135 private:
136     QObject *m_source;
137     Qt::DropActions m_supportedActions;
138     QStringList m_keys;
139
140     friend class QQuickDragAttached;
141     friend class QQuickDragAttachedPrivate;
142 };
143
144 class QDeclarativeV8Function;
145
146 class QQuickDragAttachedPrivate;
147 class QQuickDragAttached : public QObject
148 {
149     Q_OBJECT
150     Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
151     Q_PROPERTY(QObject *source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource)
152     Q_PROPERTY(QObject *target READ target NOTIFY targetChanged)
153     Q_PROPERTY(QPointF hotSpot READ hotSpot WRITE setHotSpot NOTIFY hotSpotChanged)
154     Q_PROPERTY(QStringList keys READ keys WRITE setKeys NOTIFY keysChanged)
155     Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions WRITE setSupportedActions NOTIFY supportedActionsChanged)
156     Q_PROPERTY(Qt::DropAction proposedAction READ proposedAction WRITE setProposedAction NOTIFY proposedActionChanged)
157 public:
158     QQuickDragAttached(QObject *parent);
159     ~QQuickDragAttached();
160
161     bool isActive() const;
162     void setActive(bool active);
163
164     QObject *source() const;
165     void setSource(QObject *item);
166     void resetSource();
167
168     QObject *target() const;
169
170     QPointF hotSpot() const;
171     void setHotSpot(const QPointF &hotSpot);
172
173     QStringList keys() const;
174     void setKeys(const QStringList &keys);
175
176     Qt::DropActions supportedActions() const;
177     void setSupportedActions(Qt::DropActions actions);
178
179     Qt::DropAction proposedAction() const;
180     void setProposedAction(Qt::DropAction action);
181
182     Q_INVOKABLE int drop();
183
184 public Q_SLOTS:
185     void start(QDeclarativeV8Function *);
186     void cancel();
187
188 Q_SIGNALS:
189     void activeChanged();
190     void sourceChanged();
191     void targetChanged();
192     void hotSpotChanged();
193     void keysChanged();
194     void supportedActionsChanged();
195     void proposedActionChanged();
196
197 private:
198     Q_DECLARE_PRIVATE(QQuickDragAttached)
199 };
200
201
202 QT_END_NAMESPACE
203
204 QT_END_HEADER
205
206 #endif