aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickdrag.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/qquickdrag.cpp')
-rw-r--r--src/quick/items/qquickdrag.cpp86
1 files changed, 67 insertions, 19 deletions
diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp
index bdca024b1d..47064ad433 100644
--- a/src/quick/items/qquickdrag.cpp
+++ b/src/quick/items/qquickdrag.cpp
@@ -9,7 +9,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/qquickpixmap_p.h>
#include <private/qv4scopedvalue_p.h>
#include <QtCore/qbuffer.h>
#include <QtCore/qmimedata.h>
@@ -55,7 +55,7 @@ using namespace Qt::StringLiterals;
\l {supportedActions}{drop action} chosen by the recipient of the event,
otherwise it will return Qt.IgnoreAction.
- \sa {Qt Quick Examples - Drag and Drop}, {Qt Quick Examples - externaldraganddrop}
+ \sa {Qt Quick Examples - Drag and Drop}
*/
void QQuickDragAttachedPrivate::itemGeometryChanged(QQuickItem *, QQuickGeometryChange change,
@@ -354,7 +354,7 @@ void QQuickDragAttached::setImageSource(const QUrl &url)
if (url.isEmpty()) {
d->pixmapLoader.clear();
} else {
- d->pixmapLoader.load(qmlEngine(parent()), url);
+ d->loadPixmap();
}
Q_EMIT imageSourceChanged();
@@ -362,6 +362,48 @@ void QQuickDragAttached::setImageSource(const QUrl &url)
}
/*!
+ \qmlattachedproperty size QtQuick::Drag::imageSourceSize
+ \since 6.8
+
+ This property holds the size of the image that 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.
+
+ This property sets the maximum number of pixels stored for the loaded
+ image so that large images do not use more memory than necessary.
+ See \l {QtQuick::Image::sourceSize}{Image.sourceSize} for more details.
+
+ The example below shows an SVG image rendered at one size, and re-renders
+ it at a different size for the drag image:
+
+ \snippet qml/externalDragScaledImage.qml 0
+
+ \sa imageSource, Item::grabToImage()
+*/
+
+QSize QQuickDragAttached::imageSourceSize() const
+{
+ Q_D(const QQuickDragAttached);
+ int width = d->imageSourceSize.width();
+ int height = d->imageSourceSize.height();
+ return QSize(width != -1 ? width : d->pixmapLoader.width(),
+ height != -1 ? height : d->pixmapLoader.height());
+}
+
+void QQuickDragAttached::setImageSourceSize(const QSize &size)
+{
+ Q_D(QQuickDragAttached);
+ if (d->imageSourceSize != size) {
+ d->imageSourceSize = size;
+
+ if (!d->imageSource.isEmpty())
+ d->loadPixmap();
+
+ Q_EMIT imageSourceSizeChanged();
+ }
+}
+
+/*!
\qmlattachedproperty stringlist QtQuick::Drag::keys
This property holds a list of keys that can be used by a DropArea to filter drag events.
@@ -477,11 +519,9 @@ void QQuickDragAttached::setProposedAction(Qt::DropAction action)
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
+ \value Drag.None do not start drags automatically
+ \value Drag.Automatic start drags automatically
+ \value Drag.Internal (default) start backwards compatible drags automatically
When using \c Drag.Automatic you should also define \l mimeData and bind the
\l active property to the active property of MouseArea : \l {MouseArea::drag.active}
@@ -540,7 +580,7 @@ void QQuickDragAttachedPrivate::start(Qt::DropActions supportedActions)
property for the started sequence.
*/
-void QQuickDragAttached::start(QQmlV4Function *args)
+void QQuickDragAttached::start(QQmlV4FunctionPtr args)
{
Q_D(QQuickDragAttached);
if (d->inEvent) {
@@ -576,12 +616,10 @@ void QQuickDragAttached::start(QQmlV4Function *args)
The returned drop action may be one of:
- \list
- \li Qt.CopyAction Copy the data to the target
- \li Qt.MoveAction Move the data from the source to the target
- \li Qt.LinkAction Create a link from the source to the target.
- \li Qt.IgnoreAction Ignore the action (do nothing with the data).
- \endlist
+ \value Qt.CopyAction Copy the data to the target
+ \value Qt.MoveAction Move the data from the source to the target
+ \value Qt.LinkAction Create a link from the source to the target.
+ \value Qt.IgnoreAction Ignore the action (do nothing with the data).
*/
int QQuickDragAttached::drop()
@@ -705,11 +743,10 @@ QMimeData *QQuickDragAttachedPrivate::createMimeData() const
else
qmlWarning(q) << "Don't know how to encode text as " << mimeType;
} else {
- mimeData->setData(mimeType, text.toUtf8().constData());
+ mimeData->setData(mimeType, text.toUtf8());
}
} else {
- qmlWarning(q) << "Mime data contains a string, but mime type " << mimeType
- << " is not a supported text type";
+ mimeData->setData(mimeType, text.toUtf8());
}
break;
}
@@ -765,6 +802,17 @@ QMimeData *QQuickDragAttachedPrivate::createMimeData() const
return mimeData;
}
+void QQuickDragAttachedPrivate::loadPixmap()
+{
+ Q_Q(QQuickDragAttached);
+
+ QUrl loadUrl = imageSource;
+ const QQmlContext *context = qmlContext(q->parent());
+ if (context)
+ loadUrl = context->resolvedUrl(imageSource);
+ pixmapLoader.load(context ? context->engine() : nullptr, loadUrl, QRect(), q->imageSourceSize());
+}
+
Qt::DropAction QQuickDragAttachedPrivate::startDrag(Qt::DropActions supportedActions)
{
Q_Q(QQuickDragAttached);
@@ -808,7 +856,7 @@ Qt::DropAction QQuickDragAttachedPrivate::startDrag(Qt::DropActions supportedAct
property for the started sequence.
*/
-void QQuickDragAttached::startDrag(QQmlV4Function *args)
+void QQuickDragAttached::startDrag(QQmlV4FunctionPtr args)
{
Q_D(QQuickDragAttached);