Add support for PNG to QWindowsMimeImage::convertFromMime().
GIMP asks for image data in PNG format when doing a "paste" which was previously handled only in convertToMime(). Add handling to convertFromMime() and register format. Task-number: QTBUG-46848 Change-Id: Ib11de27d301c8632869c7276e421e48e4f34e1d0 Reviewed-by: aavit <eirik.aavitsland@theqtcompany.com>
This commit is contained in:
parent
3719744b39
commit
4018cd3529
@ -995,6 +995,7 @@ QVector<FORMATETC> QWindowsMimeImage::formatsForMime(const QString &mimeType, co
|
||||
if (!image.isNull() && image.hasAlphaChannel())
|
||||
formatetcs += setCf(CF_DIBV5);
|
||||
formatetcs += setCf(CF_DIB);
|
||||
formatetcs += setCf(CF_PNG); // QTBUG-86848, Paste into GIMP queries for PNG.
|
||||
}
|
||||
return formatetcs;
|
||||
}
|
||||
@ -1025,13 +1026,15 @@ bool QWindowsMimeImage::canConvertFromMime(const FORMATETC &formatetc, const QMi
|
||||
return false;
|
||||
// QTBUG-11463, deny CF_DIB support for images with alpha to prevent loss of
|
||||
// transparency in conversion.
|
||||
return cf == CF_DIBV5 || (cf == CF_DIB && !image.hasAlphaChannel());
|
||||
return cf == CF_DIBV5
|
||||
|| (cf == CF_DIB && !image.hasAlphaChannel())
|
||||
|| cf == int(CF_PNG);
|
||||
}
|
||||
|
||||
bool QWindowsMimeImage::convertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData, STGMEDIUM * pmedium) const
|
||||
{
|
||||
int cf = getCf(formatetc);
|
||||
if ((cf == CF_DIB || cf == CF_DIBV5) && mimeData->hasImage()) {
|
||||
if ((cf == CF_DIB || cf == CF_DIBV5 || cf == int(CF_PNG)) && mimeData->hasImage()) {
|
||||
QImage img = qvariant_cast<QImage>(mimeData->imageData());
|
||||
if (img.isNull())
|
||||
return false;
|
||||
@ -1042,6 +1045,12 @@ bool QWindowsMimeImage::convertFromMime(const FORMATETC &formatetc, const QMimeD
|
||||
const QByteArray ba = writeDib(img);
|
||||
if (!ba.isEmpty())
|
||||
return setData(ba, pmedium);
|
||||
} else if (cf == int(CF_PNG)) {
|
||||
QBuffer buffer(&ba);
|
||||
const bool written = buffer.open(QIODevice::WriteOnly) && img.save(&buffer, "PNG");
|
||||
buffer.close();
|
||||
if (written)
|
||||
return setData(ba, pmedium);
|
||||
} else {
|
||||
QDataStream s(&ba, QIODevice::WriteOnly);
|
||||
s.setByteOrder(QDataStream::LittleEndian);// Intel byte order ####
|
||||
|
Loading…
Reference in New Issue
Block a user