From c319214f919e3345f673391253f92c6bc0e2a285 Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 19 May 2011 13:47:37 +0200 Subject: Fix in-process drag-n-drop of image data, image/* was not available. If we give the exact initial QMimeData to the dropEvent, we only get application/x-qt-image as available mimeType. We need to go through QDropData to call xdndObtainData, which can still do some in-process optimization, but there we can do the "saving QImage to the requested format" conversion. Task-number: QTBUG-4110 Merge-request: 860 Reviewed-by: Denis Dzyubenko --- src/gui/kernel/qdnd_x11.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/gui/kernel/qdnd_x11.cpp b/src/gui/kernel/qdnd_x11.cpp index 1c59d41..ecb9a70 100644 --- a/src/gui/kernel/qdnd_x11.cpp +++ b/src/gui/kernel/qdnd_x11.cpp @@ -1166,12 +1166,20 @@ void QX11Data::xdndHandleDrop(QWidget *, const XEvent * xe, bool passive) // some XEMBEDding, so try to find the real QMimeData used // based on the timestamp for this drop. QMimeData *dropData = 0; - int at = findXdndDropTransactionByTime(qt_xdnd_target_current_time); - if (at != -1) + const int at = findXdndDropTransactionByTime(qt_xdnd_target_current_time); + if (at != -1) { dropData = QDragManager::dragPrivate(X11->dndDropTransactions.at(at).object)->data; + // Can't use the source QMimeData if we need the image conversion code from xdndObtainData + if (dropData && dropData->hasImage()) + dropData = 0; + } // if we can't find it, then use the data in the drag manager - if (!dropData) - dropData = (manager->object) ? manager->dragPrivate()->data : manager->dropData; + if (!dropData) { + if (manager->object && !manager->dragPrivate()->data->hasImage()) + dropData = manager->dragPrivate()->data; + else + dropData = manager->dropData; + } // Drop coming from another app? Update keyboard modifiers. if (!qt_xdnd_dragging) { @@ -1855,8 +1863,16 @@ static QVariant xdndObtainData(const char *format, QVariant::Type requestedType) && (!(w->windowType() == Qt::Desktop) || w->acceptDrops())) { QDragPrivate * o = QDragManager::self()->dragPrivate(); - if (o->data->hasFormat(QLatin1String(format))) - result = o->data->data(QLatin1String(format)); + const QString mimeType = QString::fromLatin1(format); + if (o->data->hasFormat(mimeType)) { + result = o->data->data(mimeType); + } else if (mimeType.startsWith(QLatin1String("image/")) && o->data->hasImage()) { + // ### duplicated from QInternalMimeData::renderDataHelper + QImage image = qvariant_cast(o->data->imageData()); + QBuffer buf(&result); + buf.open(QBuffer::WriteOnly); + image.save(&buf, mimeType.mid(mimeType.indexOf(QLatin1Char('/')) + 1).toLatin1().toUpper()); + } return result; } -- cgit v0.12