aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickdrag.cpp
diff options
context:
space:
mode:
authorAlberto Mardegan <mardy@users.sourceforge.net>2016-04-11 23:10:29 +0300
committerAlberto Mardegan <mardy@users.sourceforge.net>2016-05-07 19:08:56 +0000
commit4b982c744f538a24e21a2af146c45f93d27dd1cb (patch)
treec2c117720d27be3f1a3cc9cf546832364f2af116 /src/quick/items/qquickdrag.cpp
parent69b7ba225007d68e113ee425ad58ce7e186a92c2 (diff)
Add imageSource property to attached Drag property
This property holds a URL which is loaded into a QPixmap via QQuickPixmap, and subsequently set on the QDrag object. This is especially important for drag and drop to external applications, where of course a QQuickItem cannot be dragged; however, combined with QQuickItem::grabToImage(), this change allows setting a QQuickItem's contents as the drag pixmap. [ChangeLog][QtQuick][Drag] Added imageSource property to attached Drag object: this allows drag sources to specify the pixmap to be drawn next to the mouse cursor when starting a drag and drop operation. Task-number: QTBUG-37366 Change-Id: Ibcf1d888c525e50976a116ec743ce6fca4c31525 Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'src/quick/items/qquickdrag.cpp')
-rw-r--r--src/quick/items/qquickdrag.cpp46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp
index 4aa54b71df..76e13bc985 100644
--- a/src/quick/items/qquickdrag.cpp
+++ b/src/quick/items/qquickdrag.cpp
@@ -45,6 +45,7 @@
#include <private/qquickitem_p.h>
#include <QtQuick/private/qquickevents_p_p.h>
#include <private/qquickitemchangelistener_p.h>
+#include <private/qquickpixmapcache_p.h>
#include <private/qv8engine_p.h>
#include <private/qv4scopedvalue_p.h>
#include <QtCore/qmimedata.h>
@@ -110,6 +111,8 @@ public:
bool eventQueued : 1;
bool overrideActions : 1;
QPointF hotSpot;
+ QUrl imageSource;
+ QQuickPixmap pixmapLoader;
QStringList keys;
QVariantMap externalMimeData;
QQuickDrag::DragType dragType;
@@ -408,6 +411,43 @@ void QQuickDragAttached::setHotSpot(const QPointF &hotSpot)
}
/*!
+ \qmlattachedproperty QUrl QtQuick::Drag::imageSource
+ \since 5.8
+
+ This property holds the URL of the image which will be used to represent
+ the data during the drag and drop operation. Changing this property after
+ the drag operation has started will have no effect.
+
+ The example below uses an item's contents as a drag image:
+
+ \snippet qml/externaldrag.qml 0
+
+ \sa Item::grabToImage()
+*/
+
+QUrl QQuickDragAttached::imageSource() const
+{
+ Q_D(const QQuickDragAttached);
+ return d->imageSource;
+}
+
+void QQuickDragAttached::setImageSource(const QUrl &url)
+{
+ Q_D(QQuickDragAttached);
+ if (d->imageSource != url) {
+ d->imageSource = url;
+
+ if (url.isEmpty()) {
+ d->pixmapLoader.clear();
+ } else {
+ d->pixmapLoader.load(qmlEngine(this), url);
+ }
+
+ Q_EMIT imageSourceChanged();
+ }
+}
+
+/*!
\qmlattachedproperty stringlist QtQuick::Drag::keys
This property holds a list of keys that can be used by a DropArea to filter drag events.
@@ -726,9 +766,9 @@ Qt::DropAction QQuickDragAttachedPrivate::startDrag(Qt::DropActions supportedAct
mimeData->setData(it.key(), it.value().toString().toUtf8());
drag->setMimeData(mimeData);
-
- // TODO: how to handle drag image?
- // drag->setPixmap(iconPixmap);
+ if (pixmapLoader.isReady()) {
+ drag->setPixmap(QPixmap::fromImage(pixmapLoader.image()));
+ }
emit q->dragStarted();