1 // Commit: c6e6a35aeb8794d68a3ca0c4e27a3a1181c066b5
2 /****************************************************************************
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
41 ****************************************************************************/
43 #ifndef QQUICKDRAG_P_H
44 #define QQUICKDRAG_P_H
46 #include <QtQuick/qquickitem.h>
48 #include <private/qv8engine_p.h>
50 #include <QtCore/qmimedata.h>
51 #include <QtCore/qstringlist.h>
60 class QQuickDragPrivate;
62 class QQuickDragGrabber
64 class Item : public QDeclarativeGuard<QQuickItem>
67 Item(QQuickItem *item) : QDeclarativeGuard<QQuickItem>(item) {}
69 QIntrusiveListNode node;
71 void objectDestroyed(QQuickItem *) { delete this; }
74 typedef QIntrusiveList<Item, &Item::node> ItemList;
77 QQuickDragGrabber() : m_target(0) {}
78 ~QQuickDragGrabber() { while (!m_items.isEmpty()) delete m_items.first(); }
81 QObject *target() const
85 else if (!m_items.isEmpty())
86 return *m_items.first();
90 void setTarget(QObject *target) { m_target = target; }
91 void resetTarget() { m_target = 0; }
93 typedef ItemList::iterator iterator;
94 iterator begin() { return m_items.begin(); }
95 iterator end() { return m_items.end(); }
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; }
106 class QQuickDropEventEx : public QDropEvent
109 void setProposedAction(Qt::DropAction action) { default_action = action; drop_action = action; }
111 static void setProposedAction(QDropEvent *event, Qt::DropAction action) {
112 static_cast<QQuickDropEventEx *>(event)->setProposedAction(action);
115 void copyActions(const QDropEvent &from) {
116 default_action = from.proposedAction(); drop_action = from.dropAction(); }
118 static void copyActions(QDropEvent *to, const QDropEvent &from) {
119 static_cast<QQuickDropEventEx *>(to)->copyActions(from);
123 class QQuickDragMimeData : public QMimeData
132 QStringList keys() const { return m_keys; }
133 QObject *source() const { return m_source; }
137 Qt::DropActions m_supportedActions;
140 friend class QQuickDragAttached;
141 friend class QQuickDragAttachedPrivate;
144 class QDeclarativeV8Function;
146 class QQuickDragAttachedPrivate;
147 class QQuickDragAttached : public QObject
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)
158 QQuickDragAttached(QObject *parent);
159 ~QQuickDragAttached();
161 bool isActive() const;
162 void setActive(bool active);
164 QObject *source() const;
165 void setSource(QObject *item);
168 QObject *target() const;
170 QPointF hotSpot() const;
171 void setHotSpot(const QPointF &hotSpot);
173 QStringList keys() const;
174 void setKeys(const QStringList &keys);
176 Qt::DropActions supportedActions() const;
177 void setSupportedActions(Qt::DropActions actions);
179 Qt::DropAction proposedAction() const;
180 void setProposedAction(Qt::DropAction action);
182 Q_INVOKABLE int drop();
185 void start(QDeclarativeV8Function *);
189 void activeChanged();
190 void sourceChanged();
191 void targetChanged();
192 void hotSpotChanged();
194 void supportedActionsChanged();
195 void proposedActionChanged();
198 Q_DECLARE_PRIVATE(QQuickDragAttached)