aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris Meyer <cmeyer1969@gmail.com>2013-08-26 16:15:23 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-09 22:58:45 +0200
commit391459210de53e342ba5e9c44360754e86d7625c (patch)
treef68fca8e2f059f8e07b2638245451137af79b479 /src
parent2dcb0adc3a0a9b93b4cd09f26f2d1bac0e8cd110 (diff)
Add support for external drag and drop in Quick items.
Add dragType enums with values of None, Automatic, Internal (default). Setting to Automatic allows startDrag to be called automatically. Setting to Internal (default) retains old behavior. Add mimeData to Drag item to enable external drags. Call startDrag to start drag manually or change from internal drag to external drag. Added events dragStarted and dragFinished that get invoked from startDrag. Mime data must be specified in the mimeData property as mime-type / data pairs. Moved QQuickDrag from qquickmousearea* files to qquickdrag* files to reduce header interdependencies that caused linking errors in other modules and also to improve code organization. Allow DropArea to receive and process external data. Introduced new variable containsDrag to QQuickDropAreaPrivate. This replaces mimeData which was previously being used to determine if a drop operation was currently occurring. The problem was that mimeData was being externally destructed. Also introduced accessor methods for getting color, html, image, text, and urls out of the drop. This facilitates dropping of external data of those types onto a DropArea. Added example quick/externaldraganddrop. Task-number: QTBUG-27498 Change-Id: I1420df7c161ea3399e49a23305273e106baa246f Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquickdrag.cpp304
-rw-r--r--src/quick/items/qquickdrag_p.h91
-rw-r--r--src/quick/items/qquickdroparea.cpp223
-rw-r--r--src/quick/items/qquickdroparea_p.h23
-rw-r--r--src/quick/items/qquickmousearea.cpp131
-rw-r--r--src/quick/items/qquickmousearea_p.h77
-rw-r--r--src/quick/items/qquicktextinput.cpp1
-rw-r--r--src/quick/items/qquickwindow.cpp14
-rw-r--r--src/quick/items/qquickwindow_p.h4
9 files changed, 615 insertions, 253 deletions
diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp
index f145ce259f..0ae26cb5c3 100644
--- a/src/quick/items/qquickdrag.cpp
+++ b/src/quick/items/qquickdrag.cpp
@@ -46,7 +46,9 @@
#include <private/qquickitemchangelistener_p.h>
#include <private/qv8engine_p.h>
#include <QtCore/qcoreapplication.h>
+#include <QtCore/qmimedata.h>
#include <QtQml/qqmlinfo.h>
+#include <QtGui/qdrag.h>
#include <QtGui/qevent.h>
#ifndef QT_NO_DRAGANDDROP
@@ -72,6 +74,7 @@ public:
, itemMoved(false)
, eventQueued(false)
, overrideActions(false)
+ , dragType(QQuickDrag::Internal)
{
}
@@ -83,8 +86,8 @@ public:
void deliverMoveEvent();
void deliverLeaveEvent();
void deliverEvent(QQuickWindow *window, QEvent *event);
- void start() { start(supportedActions); }
void start(Qt::DropActions supportedActions);
+ Qt::DropAction startDrag(Qt::DropActions supportedActions);
void setTarget(QQuickItem *item);
QQuickDragGrabber dragGrabber;
@@ -105,6 +108,8 @@ public:
bool overrideActions : 1;
QPointF hotSpot;
QStringList keys;
+ QVariantMap externalMimeData;
+ QQuickDrag::DragType dragType;
};
/*!
@@ -272,7 +277,10 @@ QQuickDragAttached::~QQuickDragAttached()
This property holds whether a drag event sequence is currently active.
- Setting this property to true will send a QDragEnter event to the scene
+ Binding this property to the active property of \l MouseArea::drag will
+ cause \l startDrag to be called when the user starts dragging.
+
+ Setting this property to true will also send a QDragEnter event to the scene
with the item's current position. Setting it to false will send a
QDragLeave event.
@@ -292,8 +300,18 @@ void QQuickDragAttached::setActive(bool active)
if (d->active != active) {
if (d->inEvent)
qmlInfo(this) << "active cannot be changed from within a drag event handler";
- else if (active)
- d->start(d->supportedActions);
+ else if (active) {
+ if (d->dragType == QQuickDrag::Internal) {
+ d->start(d->supportedActions);
+ }
+ else if (d->dragType == QQuickDrag::Automatic) {
+ // There are different semantics than start() since startDrag()
+ // may be called after an internal drag is already started.
+ active = true;
+ emit activeChanged();
+ d->startDrag(d->supportedActions);
+ }
+ }
else
cancel();
}
@@ -411,6 +429,28 @@ void QQuickDragAttached::setKeys(const QStringList &keys)
}
/*!
+ \qmlattachedproperty stringlist QtQuick2::Drag::mimeData
+ \since QtQuick 2.2
+
+ This property holds a map of mimeData that is used during startDrag.
+*/
+
+QVariantMap QQuickDragAttached::mimeData() const
+{
+ Q_D(const QQuickDragAttached);
+ return d->externalMimeData;
+}
+
+void QQuickDragAttached::setMimeData(const QVariantMap &mimeData)
+{
+ Q_D(QQuickDragAttached);
+ if (d->externalMimeData != mimeData) {
+ d->externalMimeData = mimeData;
+ emit mimeDataChanged();
+ }
+}
+
+/*!
\qmlattachedproperty flags QtQuick2::Drag::supportedActions
This property holds return values of Drag.drop() supported by the drag source.
@@ -465,6 +505,42 @@ void QQuickDragAttached::setProposedAction(Qt::DropAction action)
}
}
+/*!
+ \qmlattachedproperty enumeration QtQuick2::Drag::dragType
+ \since QtQuick 2.2
+
+ This property indicates whether to automatically start drags, do nothing, or
+ to use backwards compatible internal drags. The default is to use backwards
+ compatible internal drags.
+
+ A drag can also be started manually using \l startDrag.
+
+ \list
+ \li Drag.None - do not start drags automatically
+ \li Drag.Automatic - start drags automatically
+ \li Drag.Internal (default) - start backwards compatible drags automatically
+ \endlist
+
+ When using \l Drag.Automatic you should also define \l mimeData and bind the
+ \active property to the active property of \l MouseArea.drag.
+
+ */
+
+QQuickDrag::DragType QQuickDragAttached::dragType() const
+{
+ Q_D(const QQuickDragAttached);
+ return d->dragType;
+}
+
+void QQuickDragAttached::setDragType(QQuickDrag::DragType dragType)
+{
+ Q_D(QQuickDragAttached);
+ if (d->dragType != dragType) {
+ d->dragType = dragType;
+ emit dragTypeChanged();
+ }
+}
+
void QQuickDragAttachedPrivate::start(Qt::DropActions supportedActions)
{
Q_Q(QQuickDragAttached);
@@ -496,7 +572,8 @@ void QQuickDragAttachedPrivate::start(Qt::DropActions supportedActions)
/*!
\qmlattachedmethod void QtQuick2::Drag::start(flags supportedActions)
- Starts sending drag events.
+ Starts sending drag events. Used for starting old-style internal drags. \l startDrag is the
+ new-style, preferred method of starting drags.
The optional \a supportedActions argument can be used to override the \l supportedActions
property for the started sequence.
@@ -616,6 +693,223 @@ void QQuickDragAttached::cancel()
emit activeChanged();
}
+/*!
+ \qmlsignal QtQuick2::DropArea::onDragStarted()
+
+ This handler is called when a drag is started with the \l startDrag method
+ or when it is started automatically using the \l dragType property.
+ */
+
+/*!
+ \qmlsignal QtQuick2::DropArea::onDragFinished(DropAction action)
+
+ This handler is called when a drag finishes and the drag was started with the
+ \l startDrag method or started automatically using the \l dragType property.
+ */
+
+Qt::DropAction QQuickDragAttachedPrivate::startDrag(Qt::DropActions supportedActions)
+{
+ Q_Q(QQuickDragAttached);
+
+ QDrag *drag = new QDrag(q);
+ QMimeData *mimeData = new QMimeData();
+
+ Q_FOREACH (const QString &key, externalMimeData.keys()) {
+ mimeData->setData(key, externalMimeData[key].toString().toUtf8());
+ }
+
+ drag->setMimeData(mimeData);
+
+ // TODO: how to handle drag image?
+ // drag->setPixmap(iconPixmap);
+
+ emit q->dragStarted();
+
+ Qt::DropAction dropAction = drag->exec(supportedActions);
+
+ delete drag;
+
+ deliverLeaveEvent();
+
+ if (target) {
+ target = 0;
+ emit q->targetChanged();
+ }
+
+ emit q->dragFinished(dropAction);
+
+ active = false;
+ emit q->activeChanged();
+
+ return dropAction;
+}
+
+
+/*!
+ \qmlattachedmethod void QtQuick2::Drag::startDrag(flags supportedActions)
+
+ Starts sending drag events.
+
+ The optional \a supportedActions argument can be used to override the \l supportedActions
+ property for the started sequence.
+*/
+
+void QQuickDragAttached::startDrag(QQmlV4Function *args)
+{
+ Q_D(QQuickDragAttached);
+
+ if (d->inEvent) {
+ qmlInfo(this) << "startDrag() cannot be called from within a drag event handler";
+ return;
+ }
+
+ if (!d->active) {
+ qmlInfo(this) << "startDrag() drag must be active";
+ return;
+ }
+
+ Qt::DropActions supportedActions = d->supportedActions;
+
+ // check arguments for supportedActions
+ if (args->length() >= 1) {
+ QV4::Value v = (*args)[0];
+ if (v.isInt32()) {
+ supportedActions = Qt::DropActions(v.integerValue());
+ }
+ }
+
+ Qt::DropAction dropAction = d->startDrag(supportedActions);
+
+ args->setReturnValue(QV4::Value::fromInt32(dropAction));
+}
+
+QQuickDrag::QQuickDrag(QObject *parent)
+: QObject(parent), _target(0), _axis(XAndYAxis), _xmin(-FLT_MAX),
+_xmax(FLT_MAX), _ymin(-FLT_MAX), _ymax(FLT_MAX), _active(false), _filterChildren(false)
+{
+}
+
+QQuickDrag::~QQuickDrag()
+{
+}
+
+QQuickItem *QQuickDrag::target() const
+{
+ return _target;
+}
+
+void QQuickDrag::setTarget(QQuickItem *t)
+{
+ if (_target == t)
+ return;
+ _target = t;
+ emit targetChanged();
+}
+
+void QQuickDrag::resetTarget()
+{
+ if (_target == 0)
+ return;
+ _target = 0;
+ emit targetChanged();
+}
+
+QQuickDrag::Axis QQuickDrag::axis() const
+{
+ return _axis;
+}
+
+void QQuickDrag::setAxis(QQuickDrag::Axis a)
+{
+ if (_axis == a)
+ return;
+ _axis = a;
+ emit axisChanged();
+}
+
+qreal QQuickDrag::xmin() const
+{
+ return _xmin;
+}
+
+void QQuickDrag::setXmin(qreal m)
+{
+ if (_xmin == m)
+ return;
+ _xmin = m;
+ emit minimumXChanged();
+}
+
+qreal QQuickDrag::xmax() const
+{
+ return _xmax;
+}
+
+void QQuickDrag::setXmax(qreal m)
+{
+ if (_xmax == m)
+ return;
+ _xmax = m;
+ emit maximumXChanged();
+}
+
+qreal QQuickDrag::ymin() const
+{
+ return _ymin;
+}
+
+void QQuickDrag::setYmin(qreal m)
+{
+ if (_ymin == m)
+ return;
+ _ymin = m;
+ emit minimumYChanged();
+}
+
+qreal QQuickDrag::ymax() const
+{
+ return _ymax;
+}
+
+void QQuickDrag::setYmax(qreal m)
+{
+ if (_ymax == m)
+ return;
+ _ymax = m;
+ emit maximumYChanged();
+}
+
+bool QQuickDrag::active() const
+{
+ return _active;
+}
+
+void QQuickDrag::setActive(bool drag)
+{
+ if (_active == drag)
+ return;
+ _active = drag;
+ emit activeChanged();
+}
+
+bool QQuickDrag::filterChildren() const
+{
+ return _filterChildren;
+}
+
+void QQuickDrag::setFilterChildren(bool filter)
+{
+ if (_filterChildren == filter)
+ return;
+ _filterChildren = filter;
+ emit filterChildrenChanged();
+}
+
+QQuickDragAttached *QQuickDrag::qmlAttachedProperties(QObject *obj)
+{
+ return new QQuickDragAttached(obj);
+}
+
QT_END_NAMESPACE
#endif // QT_NO_DRAGANDDROP
diff --git a/src/quick/items/qquickdrag_p.h b/src/quick/items/qquickdrag_p.h
index 3680fd5754..098fcc61b9 100644
--- a/src/quick/items/qquickdrag_p.h
+++ b/src/quick/items/qquickdrag_p.h
@@ -143,18 +143,90 @@ private:
};
class QQmlV4Function;
+class QQuickDragAttached;
+class Q_AUTOTEST_EXPORT QQuickDrag : public QObject
+{
+ Q_OBJECT
+
+ Q_ENUMS(Axis DragType)
+ Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged RESET resetTarget)
+ Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged)
+ Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged)
+ Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged)
+ Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged)
+ Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged)
+ Q_PROPERTY(bool active READ active NOTIFY activeChanged)
+ Q_PROPERTY(bool filterChildren READ filterChildren WRITE setFilterChildren NOTIFY filterChildrenChanged)
+ //### consider drag and drop
+
+public:
+ QQuickDrag(QObject *parent=0);
+ ~QQuickDrag();
+
+ enum DragType { None, Automatic, Internal };
+
+ QQuickItem *target() const;
+ void setTarget(QQuickItem *target);
+ void resetTarget();
+
+ enum Axis { XAxis=0x01, YAxis=0x02, XAndYAxis=0x03, XandYAxis=XAndYAxis };
+ Axis axis() const;
+ void setAxis(Axis);
+
+ qreal xmin() const;
+ void setXmin(qreal);
+ qreal xmax() const;
+ void setXmax(qreal);
+ qreal ymin() const;
+ void setYmin(qreal);
+ qreal ymax() const;
+ void setYmax(qreal);
+
+ bool active() const;
+ void setActive(bool);
+
+ bool filterChildren() const;
+ void setFilterChildren(bool);
+
+ static QQuickDragAttached *qmlAttachedProperties(QObject *obj);
+
+Q_SIGNALS:
+ void targetChanged();
+ void axisChanged();
+ void minimumXChanged();
+ void maximumXChanged();
+ void minimumYChanged();
+ void maximumYChanged();
+ void activeChanged();
+ void filterChildrenChanged();
+
+private:
+ QQuickItem *_target;
+ Axis _axis;
+ qreal _xmin;
+ qreal _xmax;
+ qreal _ymin;
+ qreal _ymax;
+ bool _active : 1;
+ bool _filterChildren: 1;
+ Q_DISABLE_COPY(QQuickDrag)
+};
class QQuickDragAttachedPrivate;
class QQuickDragAttached : public QObject
{
Q_OBJECT
+ Q_DECLARE_PRIVATE(QQuickDragAttached)
+
Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
Q_PROPERTY(QObject *source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource)
Q_PROPERTY(QObject *target READ target NOTIFY targetChanged)
Q_PROPERTY(QPointF hotSpot READ hotSpot WRITE setHotSpot NOTIFY hotSpotChanged)
Q_PROPERTY(QStringList keys READ keys WRITE setKeys NOTIFY keysChanged)
+ Q_PROPERTY(QVariantMap mimeData READ mimeData WRITE setMimeData NOTIFY mimeDataChanged)
Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions WRITE setSupportedActions NOTIFY supportedActionsChanged)
Q_PROPERTY(Qt::DropAction proposedAction READ proposedAction WRITE setProposedAction NOTIFY proposedActionChanged)
+ Q_PROPERTY(QQuickDrag::DragType dragType READ dragType WRITE setDragType NOTIFY dragTypeChanged)
public:
QQuickDragAttached(QObject *parent);
~QQuickDragAttached();
@@ -174,36 +246,47 @@ public:
QStringList keys() const;
void setKeys(const QStringList &keys);
+ QVariantMap mimeData() const;
+ void setMimeData(const QVariantMap &mimeData);
+
Qt::DropActions supportedActions() const;
void setSupportedActions(Qt::DropActions actions);
Qt::DropAction proposedAction() const;
void setProposedAction(Qt::DropAction action);
+ QQuickDrag::DragType dragType() const;
+ void setDragType(QQuickDrag::DragType dragType);
+
Q_INVOKABLE int drop();
bool event(QEvent *event);
public Q_SLOTS:
void start(QQmlV4Function *);
+ void startDrag(QQmlV4Function *);
void cancel();
Q_SIGNALS:
+ void dragStarted();
+ void dragFinished(Qt::DropAction dropAction);
+
void activeChanged();
void sourceChanged();
void targetChanged();
void hotSpotChanged();
void keysChanged();
+ void mimeDataChanged();
void supportedActionsChanged();
void proposedActionChanged();
-
-private:
- Q_DECLARE_PRIVATE(QQuickDragAttached)
+ void dragTypeChanged();
};
-
QT_END_NAMESPACE
+QML_DECLARE_TYPE(QQuickDrag)
+QML_DECLARE_TYPEINFO(QQuickDrag, QML_HAS_ATTACHED_PROPERTIES)
+
#endif // QT_NO_DRAGANDDROP
#endif
diff --git a/src/quick/items/qquickdroparea.cpp b/src/quick/items/qquickdroparea.cpp
index f453c42e5b..09dc7eeebb 100644
--- a/src/quick/items/qquickdroparea.cpp
+++ b/src/quick/items/qquickdroparea.cpp
@@ -77,11 +77,12 @@ public:
QPointF dragPosition;
QQuickDropAreaDrag *drag;
QPointer<QObject> source;
- QPointer<QMimeData> mimeData;
+ bool containsDrag;
};
QQuickDropAreaPrivate::QQuickDropAreaPrivate()
: drag(0)
+ , containsDrag(false)
{
}
@@ -133,7 +134,7 @@ QQuickDropArea::~QQuickDropArea()
bool QQuickDropArea::containsDrag() const
{
Q_D(const QQuickDropArea);
- return d->mimeData;
+ return d->containsDrag;
}
/*!
@@ -217,7 +218,7 @@ qreal QQuickDropAreaDrag::y() const
void QQuickDropArea::dragMoveEvent(QDragMoveEvent *event)
{
Q_D(QQuickDropArea);
- if (!d->mimeData)
+ if (!d->containsDrag)
return;
d->dragPosition = event->pos();
@@ -259,28 +260,27 @@ void QQuickDropArea::dragEnterEvent(QDragEnterEvent *event)
{
Q_D(QQuickDropArea);
const QMimeData *mimeData = event->mimeData();
- if (!d->effectiveEnable || d->mimeData || !mimeData || !d->hasMatchingKey(d->getKeys(mimeData)))
+ if (!d->effectiveEnable || d->containsDrag || !mimeData || !d->hasMatchingKey(d->getKeys(mimeData)))
return;
d->dragPosition = event->pos();
event->accept();
+
QQuickDropEvent dragTargetEvent(d, event);
emit entered(&dragTargetEvent);
- if (event->isAccepted()) {
- d->mimeData = const_cast<QMimeData *>(mimeData);
- if (QQuickDragMimeData *dragMime = qobject_cast<QQuickDragMimeData *>(d->mimeData))
- d->source = dragMime->source();
- else
- d->source = event->source();
- d->dragPosition = event->pos();
- if (d->drag) {
- emit d->drag->positionChanged();
- emit d->drag->sourceChanged();
- }
- emit containsDragChanged();
+ d->containsDrag = true;
+ if (QQuickDragMimeData *dragMime = qobject_cast<QQuickDragMimeData *>(const_cast<QMimeData *>(mimeData)))
+ d->source = dragMime->source();
+ else
+ d->source = event->source();
+ d->dragPosition = event->pos();
+ if (d->drag) {
+ emit d->drag->positionChanged();
+ emit d->drag->sourceChanged();
}
+ emit containsDragChanged();
}
/*!
@@ -292,12 +292,12 @@ void QQuickDropArea::dragEnterEvent(QDragEnterEvent *event)
void QQuickDropArea::dragLeaveEvent(QDragLeaveEvent *)
{
Q_D(QQuickDropArea);
- if (!d->mimeData)
+ if (!d->containsDrag)
return;
emit exited();
- d->mimeData = 0;
+ d->containsDrag = false;
d->source = 0;
emit containsDragChanged();
if (d->drag)
@@ -314,13 +314,13 @@ void QQuickDropArea::dragLeaveEvent(QDragLeaveEvent *)
void QQuickDropArea::dropEvent(QDropEvent *event)
{
Q_D(QQuickDropArea);
- if (!d->mimeData)
+ if (!d->containsDrag)
return;
QQuickDropEvent dragTargetEvent(d, event);
emit dropped(&dragTargetEvent);
- d->mimeData = 0;
+ d->containsDrag = false;
d->source = 0;
emit containsDragChanged();
if (d->drag)
@@ -337,6 +337,16 @@ void QQuickDropArea::dropEvent(QDropEvent *event)
The position of the drag event can be obtained from the \l x and \l y
properties, and the \l keys property identifies the drag keys of the event
\l source.
+
+ The existence of specific drag types can be determined using the \l hasColor,
+ \l hasHtml, \l hasText, and \l hasUrls properties.
+
+ The list of all supplied formats can be determined using the \l formats property.
+
+ Specific drag types can be obtained using the \l colorData, \l html, \l text,
+ and \l urls properties.
+
+ A string version of any available mimeType can be obtained using \l getDataAsString.
*/
/*!
@@ -357,14 +367,6 @@ void QQuickDropArea::dropEvent(QDropEvent *event)
This property holds the source of a drag event.
*/
-QObject *QQuickDropEvent::source()
-{
- if (const QQuickDragMimeData *dragMime = qobject_cast<const QQuickDragMimeData *>(event->mimeData()))
- return dragMime->source();
- else
- return event->source();
-}
-
/*!
\qmlproperty stringlist QtQuick2::DragEvent::keys
@@ -372,11 +374,6 @@ QObject *QQuickDropEvent::source()
drag event.
*/
-QStringList QQuickDropEvent::keys() const
-{
- return d->getKeys(event->mimeData());
-}
-
/*!
\qmlproperty enumeration QtQuick2::DragEvent::action
@@ -400,6 +397,14 @@ QStringList QQuickDropEvent::keys() const
*/
/*!
+ \qmlproperty flags QtQuick2::DragEvent::proposedAction
+ \since QtQuick 2.2
+
+ This property holds the set of \l {action}{actions} proposed by the
+ drag source.
+*/
+
+/*!
\qmlproperty bool QtQuick2::DragEvent::accepted
This property holds whether the drag event was accepted by a handler.
@@ -416,6 +421,157 @@ QStringList QQuickDropEvent::keys() const
If an \a action is specified it will overwrite the value of the \l action property.
*/
+/*!
+ \qmlmethod QtQuick2::DragEvent::acceptProposedAction()
+ \since QtQuick 2.2
+
+ Accepts the drag event with the \l proposedAction.
+*/
+
+/*!
+ \qmlproperty bool QtQuick2::DragEvent::hasColor
+ \since QtQuick 2.2
+
+ This property holds whether the drag event contains a color item.
+*/
+
+/*!
+ \qmlproperty bool QtQuick2::DragEvent::hasHtml
+ \since QtQuick 2.2
+
+ This property holds whether the drag event contains a html item.
+*/
+
+/*!
+ \qmlproperty bool QtQuick2::DragEvent::hasText
+ \since QtQuick 2.2
+
+ This property holds whether the drag event contains a text item.
+*/
+
+/*!
+ \qmlproperty bool QtQuick2::DragEvent::hasUrls
+ \since QtQuick 2.2
+
+ This property holds whether the drag event contains one or more url items.
+*/
+
+/*!
+ \qmlproperty color QtQuick2::DragEvent::colorData
+ \since QtQuick 2.2
+
+ This property holds color data, if any.
+*/
+
+/*!
+ \qmlproperty string QtQuick2::DragEvent::html
+ \since QtQuick 2.2
+
+ This property holds html data, if any.
+*/
+
+/*!
+ \qmlproperty string QtQuick2::DragEvent::text
+ \since QtQuick 2.2
+
+ This property holds text data, if any.
+*/
+
+/*!
+ \qmlproperty urllist QtQuick2::DragEvent::urls
+ \since QtQuick 2.2
+
+ This property holds a list of urls, if any.
+*/
+
+/*!
+ \qmlproperty stringlist QtQuick2::DragEvent::formats
+ \since QtQuick 2.2
+
+ This property holds a list of mime type formats contained in the drag data.
+*/
+
+/*!
+ \qmlmethod string QtQuick2::DragEvent::getDataAsString(string format)
+ \since QtQuick 2.2
+
+ Returns the data for the given \a format converted to a string. \a format should be one contained in the \l formats property.
+*/
+
+QObject *QQuickDropEvent::source()
+{
+ if (const QQuickDragMimeData *dragMime = qobject_cast<const QQuickDragMimeData *>(event->mimeData()))
+ return dragMime->source();
+ else
+ return event->source();
+}
+
+QStringList QQuickDropEvent::keys() const
+{
+ return d->getKeys(event->mimeData());
+}
+
+bool QQuickDropEvent::hasColor() const
+{
+ return event->mimeData()->hasColor();
+}
+
+bool QQuickDropEvent::hasHtml() const
+{
+ return event->mimeData()->hasHtml();
+}
+
+bool QQuickDropEvent::hasText() const
+{
+ return event->mimeData()->hasText();
+}
+
+bool QQuickDropEvent::hasUrls() const
+{
+ return event->mimeData()->hasUrls();
+}
+
+QVariant QQuickDropEvent::colorData() const
+{
+ return event->mimeData()->colorData();
+}
+
+QString QQuickDropEvent::html() const
+{
+ return event->mimeData()->html();
+}
+
+QString QQuickDropEvent::text() const
+{
+ return event->mimeData()->text();
+}
+
+QList<QUrl> QQuickDropEvent::urls() const
+{
+ return event->mimeData()->urls();
+}
+
+QStringList QQuickDropEvent::formats() const
+{
+ return event->mimeData()->formats();
+}
+
+void QQuickDropEvent::getDataAsString(QQmlV4Function *args)
+{
+ if (args->length() != 0) {
+ QV4::Value v = (*args)[0];
+ QString format = v.toQString();
+ QString rv = QString::fromUtf8(event->mimeData()->data(format));
+ QV4::ExecutionEngine *v4 = QV8Engine::getV4(args->engine());
+ args->setReturnValue(QV4::Value::fromString(v4, rv));
+ }
+}
+
+void QQuickDropEvent::acceptProposedAction(QQmlV4Function *)
+{
+ event->acceptProposedAction();
+}
+
void QQuickDropEvent::accept(QQmlV4Function *args)
{
Qt::DropAction action = event->dropAction();
@@ -425,6 +581,7 @@ void QQuickDropEvent::accept(QQmlV4Function *args)
if (v.isInt32())
action = Qt::DropAction(v.integerValue());
}
+
// get action from arguments.
event->setDropAction(action);
event->accept();
diff --git a/src/quick/items/qquickdroparea_p.h b/src/quick/items/qquickdroparea_p.h
index 3bdbe7f72e..6ba876ef34 100644
--- a/src/quick/items/qquickdroparea_p.h
+++ b/src/quick/items/qquickdroparea_p.h
@@ -62,8 +62,18 @@ class QQuickDropEvent : public QObject
Q_PROPERTY(QObject *source READ source)
Q_PROPERTY(QStringList keys READ keys)
Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions)
+ Q_PROPERTY(Qt::DropActions proposedAction READ proposedAction)
Q_PROPERTY(Qt::DropAction action READ action WRITE setAction RESET resetAction)
Q_PROPERTY(bool accepted READ accepted WRITE setAccepted)
+ Q_PROPERTY(bool hasColor READ hasColor)
+ Q_PROPERTY(bool hasHtml READ hasHtml)
+ Q_PROPERTY(bool hasText READ hasText)
+ Q_PROPERTY(bool hasUrls READ hasUrls)
+ Q_PROPERTY(QVariant colorData READ colorData)
+ Q_PROPERTY(QString html READ html)
+ Q_PROPERTY(QString text READ text)
+ Q_PROPERTY(QList<QUrl> urls READ urls)
+ Q_PROPERTY(QStringList formats READ formats)
public:
QQuickDropEvent(QQuickDropAreaPrivate *d, QDropEvent *event) : d(d), event(event) {}
@@ -73,6 +83,7 @@ public:
QObject *source();
Qt::DropActions supportedActions() const { return event->possibleActions(); }
+ Qt::DropActions proposedAction() const { return event->proposedAction(); }
Qt::DropAction action() const { return event->dropAction(); }
void setAction(Qt::DropAction action) { event->setDropAction(action); }
void resetAction() { event->setDropAction(event->proposedAction()); }
@@ -82,6 +93,18 @@ public:
bool accepted() const { return event->isAccepted(); }
void setAccepted(bool accepted) { event->setAccepted(accepted); }
+ bool hasColor() const;
+ bool hasHtml() const;
+ bool hasText() const;
+ bool hasUrls() const;
+ QVariant colorData() const;
+ QString html() const;
+ QString text() const;
+ QList<QUrl> urls() const;
+ QStringList formats() const;
+
+ Q_INVOKABLE void getDataAsString(QQmlV4Function *);
+ Q_INVOKABLE void acceptProposedAction(QQmlV4Function *);
Q_INVOKABLE void accept(QQmlV4Function *);
private:
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp
index 1970a03bee..8a73a5d73d 100644
--- a/src/quick/items/qquickmousearea.cpp
+++ b/src/quick/items/qquickmousearea.cpp
@@ -61,137 +61,6 @@ DEFINE_BOOL_CONFIG_OPTION(qmlVisualTouchDebugging, QML_VISUAL_TOUCH_DEBUGGING)
static const int PressAndHoldDelay = 800;
-#ifndef QT_NO_DRAGANDDROP
-
-QQuickDrag::QQuickDrag(QObject *parent)
-: QObject(parent), _target(0), _axis(XAndYAxis), _xmin(-FLT_MAX),
-_xmax(FLT_MAX), _ymin(-FLT_MAX), _ymax(FLT_MAX), _active(false), _filterChildren(false)
-{
-}
-
-QQuickDrag::~QQuickDrag()
-{
-}
-
-QQuickItem *QQuickDrag::target() const
-{
- return _target;
-}
-
-void QQuickDrag::setTarget(QQuickItem *t)
-{
- if (_target == t)
- return;
- _target = t;
- emit targetChanged();
-}
-
-void QQuickDrag::resetTarget()
-{
- if (_target == 0)
- return;
- _target = 0;
- emit targetChanged();
-}
-
-QQuickDrag::Axis QQuickDrag::axis() const
-{
- return _axis;
-}
-
-void QQuickDrag::setAxis(QQuickDrag::Axis a)
-{
- if (_axis == a)
- return;
- _axis = a;
- emit axisChanged();
-}
-
-qreal QQuickDrag::xmin() const
-{
- return _xmin;
-}
-
-void QQuickDrag::setXmin(qreal m)
-{
- if (_xmin == m)
- return;
- _xmin = m;
- emit minimumXChanged();
-}
-
-qreal QQuickDrag::xmax() const
-{
- return _xmax;
-}
-
-void QQuickDrag::setXmax(qreal m)
-{
- if (_xmax == m)
- return;
- _xmax = m;
- emit maximumXChanged();
-}
-
-qreal QQuickDrag::ymin() const
-{
- return _ymin;
-}
-
-void QQuickDrag::setYmin(qreal m)
-{
- if (_ymin == m)
- return;
- _ymin = m;
- emit minimumYChanged();
-}
-
-qreal QQuickDrag::ymax() const
-{
- return _ymax;
-}
-
-void QQuickDrag::setYmax(qreal m)
-{
- if (_ymax == m)
- return;
- _ymax = m;
- emit maximumYChanged();
-}
-
-bool QQuickDrag::active() const
-{
- return _active;
-}
-
-void QQuickDrag::setActive(bool drag)
-{
- if (_active == drag)
- return;
- _active = drag;
- emit activeChanged();
-}
-
-bool QQuickDrag::filterChildren() const
-{
- return _filterChildren;
-}
-
-void QQuickDrag::setFilterChildren(bool filter)
-{
- if (_filterChildren == filter)
- return;
- _filterChildren = filter;
- emit filterChildrenChanged();
-}
-
-QQuickDragAttached *QQuickDrag::qmlAttachedProperties(QObject *obj)
-{
- return new QQuickDragAttached(obj);
-}
-
-#endif // QT_NO_DRAGANDDROP
-
QQuickMouseAreaPrivate::QQuickMouseAreaPrivate()
: enabled(true), hovered(false), longPress(false),
moved(false), stealMouse(false), doubleClick(false), preventStealing(false),
diff --git a/src/quick/items/qquickmousearea_p.h b/src/quick/items/qquickmousearea_p.h
index fa32f32b65..ffe75ad843 100644
--- a/src/quick/items/qquickmousearea_p.h
+++ b/src/quick/items/qquickmousearea_p.h
@@ -49,78 +49,7 @@
QT_BEGIN_NAMESPACE
class QQuickMouseEvent;
-
-#ifndef QT_NO_DRAGANDDROP
-
-class QQuickDragAttached;
-class Q_AUTOTEST_EXPORT QQuickDrag : public QObject
-{
- Q_OBJECT
-
- Q_ENUMS(Axis)
- Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged RESET resetTarget)
- Q_PROPERTY(Axis axis READ axis WRITE setAxis NOTIFY axisChanged)
- Q_PROPERTY(qreal minimumX READ xmin WRITE setXmin NOTIFY minimumXChanged)
- Q_PROPERTY(qreal maximumX READ xmax WRITE setXmax NOTIFY maximumXChanged)
- Q_PROPERTY(qreal minimumY READ ymin WRITE setYmin NOTIFY minimumYChanged)
- Q_PROPERTY(qreal maximumY READ ymax WRITE setYmax NOTIFY maximumYChanged)
- Q_PROPERTY(bool active READ active NOTIFY activeChanged)
- Q_PROPERTY(bool filterChildren READ filterChildren WRITE setFilterChildren NOTIFY filterChildrenChanged)
- //### consider drag and drop
-
-public:
- QQuickDrag(QObject *parent=0);
- ~QQuickDrag();
-
- QQuickItem *target() const;
- void setTarget(QQuickItem *target);
- void resetTarget();
-
- enum Axis { XAxis=0x01, YAxis=0x02, XAndYAxis=0x03, XandYAxis=XAndYAxis };
- Axis axis() const;
- void setAxis(Axis);
-
- qreal xmin() const;
- void setXmin(qreal);
- qreal xmax() const;
- void setXmax(qreal);
- qreal ymin() const;
- void setYmin(qreal);
- qreal ymax() const;
- void setYmax(qreal);
-
- bool active() const;
- void setActive(bool);
-
- bool filterChildren() const;
- void setFilterChildren(bool);
-
- static QQuickDragAttached *qmlAttachedProperties(QObject *obj);
-
-Q_SIGNALS:
- void targetChanged();
- void axisChanged();
- void minimumXChanged();
- void maximumXChanged();
- void minimumYChanged();
- void maximumYChanged();
- void activeChanged();
- void filterChildrenChanged();
-
-private:
- QQuickItem *_target;
- Axis _axis;
- qreal _xmin;
- qreal _xmax;
- qreal _ymin;
- qreal _ymax;
- bool _active : 1;
- bool _filterChildren: 1;
- Q_DISABLE_COPY(QQuickDrag)
-};
-
-#endif // QT_NO_DRAGANDDROP
-
+class QQuickDrag;
class QQuickMouseAreaPrivate;
class QQuickWheelEvent;
// used in Qt Location
@@ -244,10 +173,6 @@ private:
QT_END_NAMESPACE
-#ifndef QT_NO_DRAGANDDROP
-QML_DECLARE_TYPE(QQuickDrag)
-QML_DECLARE_TYPEINFO(QQuickDrag, QML_HAS_ATTACHED_PROPERTIES)
-#endif
QML_DECLARE_TYPE(QQuickMouseArea)
#endif // QQUICKMOUSEAREA_P_H
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
index 6bdd8dc221..c195994de4 100644
--- a/src/quick/items/qquicktextinput.cpp
+++ b/src/quick/items/qquicktextinput.cpp
@@ -48,6 +48,7 @@
#include <QtCore/qcoreapplication.h>
+#include <QtCore/qmimedata.h>
#include <QtQml/qqmlinfo.h>
#include <QtGui/qevent.h>
#include <QTextBoundaryFinder>
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index 21e1a009b0..41c7cd9618 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -46,6 +46,8 @@
#include "qquickitem_p.h"
#include "qquickevents_p_p.h"
+#include <private/qquickdrag_p.h>
+
#include <QtQuick/private/qsgrenderer_p.h>
#include <QtQuick/private/qsgtexture_p.h>
#include <QtQuick/private/qsgflashnode_p.h>
@@ -364,6 +366,9 @@ QQuickWindowPrivate::QQuickWindowPrivate()
#ifndef QT_NO_CURSOR
, cursorItem(0)
#endif
+#ifndef QT_NO_DRAGANDDROP
+ , dragGrabber(0)
+#endif
, touchMouseId(-1)
, touchMousePressTimestamp(0)
, dirtyItemList(0)
@@ -380,6 +385,9 @@ QQuickWindowPrivate::QQuickWindowPrivate()
, renderTargetId(0)
, incubationController(0)
{
+#ifndef QT_NO_DRAGANDDROP
+ dragGrabber = new QQuickDragGrabber;
+#endif
}
QQuickWindowPrivate::~QQuickWindowPrivate()
@@ -984,7 +992,9 @@ QQuickWindow::~QQuickWindow()
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
delete d->incubationController; d->incubationController = 0;
-
+#ifndef QT_NO_DRAGANDDROP
+ delete d->dragGrabber; d->dragGrabber = 0;
+#endif
delete d->contentItem; d->contentItem = 0;
}
@@ -1202,7 +1212,7 @@ bool QQuickWindow::event(QEvent *e)
case QEvent::DragLeave:
case QEvent::DragMove:
case QEvent::Drop:
- d->deliverDragEvent(&d->dragGrabber, e);
+ d->deliverDragEvent(d->dragGrabber, e);
break;
#endif
case QEvent::WindowDeactivate:
diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h
index aa7d7c5128..ad861754d7 100644
--- a/src/quick/items/qquickwindow_p.h
+++ b/src/quick/items/qquickwindow_p.h
@@ -57,7 +57,6 @@
#include "qquickwindow.h"
#include <QtQuick/private/qsgcontext_p.h>
-#include <private/qquickdrag_p.h>
#include <QtCore/qthread.h>
#include <QtCore/qmutex.h>
@@ -73,6 +72,7 @@ QT_BEGIN_NAMESPACE
//Make it easy to identify and customize the root item if needed
class QSGRenderLoop;
+class QQuickDragGrabber;
class QQuickRootItem : public QQuickItem
{
@@ -116,7 +116,7 @@ public:
QQuickItem *cursorItem;
#endif
#ifndef QT_NO_DRAGANDDROP
- QQuickDragGrabber dragGrabber;
+ QQuickDragGrabber *dragGrabber;
#endif
int touchMouseId;
bool checkIfDoubleClicked(ulong newPressEventTimestamp);