summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2011-05-19 11:47:37 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2011-05-19 11:47:37 (GMT)
commitc319214f919e3345f673391253f92c6bc0e2a285 (patch)
tree9b5f7513b4fe166e49864dc52d8cf6e1d15ca104
parent3b7b05ce8db881acfdcf193b3c8fb3d4919eb1c2 (diff)
downloadQt-c319214f919e3345f673391253f92c6bc0e2a285.zip
Qt-c319214f919e3345f673391253f92c6bc0e2a285.tar.gz
Qt-c319214f919e3345f673391253f92c6bc0e2a285.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>
-rw-r--r--src/gui/kernel/qdnd_x11.cpp28
1 files 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<QImage>(o->data->imageData());
+ QBuffer buf(&result);
+ buf.open(QBuffer::WriteOnly);
+ image.save(&buf, mimeType.mid(mimeType.indexOf(QLatin1Char('/')) + 1).toLatin1().toUpper());
+ }
return result;
}