diff options
author | David Faure <faure@kde.org> | 2011-05-19 11:47:37 (GMT) |
---|---|---|
committer | Qt Commercial Integration <QtCommercial@digia.com> | 2012-01-31 10:24:39 (GMT) |
commit | a47ff02e918aa0c6e3cb7e8087e6071728e69586 (patch) | |
tree | 84be8bf13cb7872da3d2644bd1e1bae77b4ec8d7 /src | |
parent | bed275599ff44809372af99b9b6cbe492f5fdec8 (diff) | |
download | Qt-a47ff02e918aa0c6e3cb7e8087e6071728e69586.zip Qt-a47ff02e918aa0c6e3cb7e8087e6071728e69586.tar.gz Qt-a47ff02e918aa0c6e3cb7e8087e6071728e69586.tar.bz2 |
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 <denis.dzyubenko@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qdnd_x11.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/gui/kernel/qdnd_x11.cpp b/src/gui/kernel/qdnd_x11.cpp index 750ddf8..0c683b4 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<QImage>(o->data->imageData()); + QBuffer buf(&result); + buf.open(QBuffer::WriteOnly); + image.save(&buf, mimeType.mid(mimeType.indexOf(QLatin1Char('/')) + 1).toLatin1().toUpper()); + } return result; } |