Qt 4.8
Public Functions | Private Functions | Properties | List of all members
QWindowsMimeImage Class Reference
Inheritance diagram for QWindowsMimeImage:
QWindowsMime

Public Functions

bool canConvertFromMime (const FORMATETC &formatetc, const QMimeData *mimeData) const
 Returns true if the converter can convert from the mimeData to the format specified in formatetc. More...
 
bool canConvertToMime (const QString &mimeType, IDataObject *pDataObj) const
 Returns true if the converter can convert to the mimeType from the available formats in pDataObj. More...
 
bool convertFromMime (const FORMATETC &formatetc, const QMimeData *mimeData, STGMEDIUM *pmedium) const
 Convert the mimeData to the format specified in formatetc. More...
 
QVariant convertToMime (const QString &mime, IDataObject *pDataObj, QVariant::Type preferredType) const
 Returns a QVariant containing the converted data for mimeType from pDataObj. More...
 
QVector< FORMATETCformatsForMime (const QString &mimeType, const QMimeData *mimeData) const
 Returns a QVector of FORMATETC structures representing the different windows clipboard formats that can be provided for the mimeType from the mimeData. More...
 
QString mimeForFormat (const FORMATETC &formatetc) const
 Returns the mime type that will be created form the format specified in formatetc, or an empty string if this converter does not support formatetc. More...
 
 QWindowsMimeImage ()
 
- Public Functions inherited from QWindowsMime
 QWindowsMime ()
 Constructs a new conversion object, adding it to the globally accessed list of available converters. More...
 
virtual ~QWindowsMime ()
 Destroys a conversion object, removing it from the global list of available converters. More...
 

Private Functions

bool hasOriginalDIBV5 (IDataObject *pDataObj) const
 

Properties

UINT CF_PNG
 

Additional Inherited Members

- Static Public Functions inherited from QWindowsMime
static int registerMimeType (const QString &mime)
 Registers the MIME type mime, and returns an ID number identifying the format on Windows. More...
 

Detailed Description

Definition at line 882 of file qmime_win.cpp.

Constructors and Destructors

◆ QWindowsMimeImage()

QWindowsMimeImage::QWindowsMimeImage ( )

Definition at line 900 of file qmime_win.cpp.

901 {
902  CF_PNG = RegisterClipboardFormat(L"PNG");
903 }

Functions

◆ canConvertFromMime()

bool QWindowsMimeImage::canConvertFromMime ( const FORMATETC formatetc,
const QMimeData mimeData 
) const
virtual

Returns true if the converter can convert from the mimeData to the format specified in formatetc.

All subclasses must reimplement this pure virtual function.

Implements QWindowsMime.

Definition at line 934 of file qmime_win.cpp.

935 {
936  int cf = getCf(formatetc);
937  if (mimeData->hasImage()) {
938  if (cf == CF_DIB)
939  return true;
940  else if (cf == CF_DIBV5) {
941  //support DIBV5 conversion only if the image has alpha channel
942  QImage image = qvariant_cast<QImage>(mimeData->imageData());
943  if (!image.isNull() && image.hasAlphaChannel())
944  return true;
945  }
946  }
947  return false;
948 }
static int getCf(const FORMATETC &formatetc)
Definition: qmime_win.cpp:125
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QVariant imageData() const
Returns a QVariant storing a QImage if the object can return an image; otherwise returns a null varia...
Definition: qmimedata.cpp:442
bool hasImage() const
Returns true if the object can return an image; otherwise returns false.
Definition: qmimedata.cpp:471
#define CF_DIBV5
Definition: qmime_win.cpp:69
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ canConvertToMime()

bool QWindowsMimeImage::canConvertToMime ( const QString mimeType,
IDataObject *  pDataObj 
) const
virtual

Returns true if the converter can convert to the mimeType from the available formats in pDataObj.

All subclasses must reimplement this pure virtual function.

Implements QWindowsMime.

Definition at line 926 of file qmime_win.cpp.

927 {
928  if ((mimeType == QLatin1String("application/x-qt-image")) &&
929  (canGetData(CF_DIB, pDataObj) || canGetData(CF_PNG, pDataObj)))
930  return true;
931  return false;
932 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static bool canGetData(int cf, IDataObject *pDataObj)
Definition: qmime_win.cpp:191

◆ convertFromMime()

bool QWindowsMimeImage::convertFromMime ( const FORMATETC formatetc,
const QMimeData mimeData,
STGMEDIUM pmedium 
) const
virtual

Convert the mimeData to the format specified in formatetc.

The converted data should then be placed in pmedium structure.

Return true if the conversion was successful.

All subclasses must reimplement this pure virtual function.

Implements QWindowsMime.

Definition at line 950 of file qmime_win.cpp.

951 {
952  int cf = getCf(formatetc);
953  if ((cf == CF_DIB || cf == CF_DIBV5) && mimeData->hasImage()) {
954  QImage img = qvariant_cast<QImage>(mimeData->imageData());
955  if (img.isNull())
956  return false;
957  QByteArray ba;
959  s.setByteOrder(QDataStream::LittleEndian);// Intel byte order ####
960  if (cf == CF_DIB) {
961  if (img.format() > QImage::Format_ARGB32)
963  if (qt_write_dib(s, img))
964  return setData(ba, pmedium);
965  } else {
966  if (qt_write_dibv5(s, img))
967  return setData(ba, pmedium);
968  }
969  }
970  return false;
971 }
bool qt_write_dib(QDataStream &, QImage)
static int getCf(const FORMATETC &formatetc)
Definition: qmime_win.cpp:125
static bool qt_write_dibv5(QDataStream &s, QImage image)
Definition: qmime_win.cpp:1386
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
static bool setData(const QByteArray &data, STGMEDIUM *pmedium)
Definition: qmime_win.cpp:141
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QVariant imageData() const
Returns a QVariant storing a QImage if the object can return an image; otherwise returns a null varia...
Definition: qmimedata.cpp:442
bool hasImage() const
Returns true if the object can return an image; otherwise returns false.
Definition: qmimedata.cpp:471
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
#define CF_DIBV5
Definition: qmime_win.cpp:69
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71

◆ convertToMime()

QVariant QWindowsMimeImage::convertToMime ( const QString mimeType,
IDataObject *  pDataObj,
QVariant::Type  preferredType 
) const
virtual

Returns a QVariant containing the converted data for mimeType from pDataObj.

If possible the QVariant should be of the preferredType to avoid needless conversions.

All subclasses must reimplement this pure virtual function.

Implements QWindowsMime.

Definition at line 995 of file qmime_win.cpp.

996 {
997  Q_UNUSED(preferredType);
998  QVariant result;
999  if (mimeType != QLatin1String("application/x-qt-image"))
1000  return result;
1001  //Try to convert from a format which has more data
1002  //DIBV5, use only if its is not synthesized
1003  if (canGetData(CF_DIBV5, pDataObj) && hasOriginalDIBV5(pDataObj)) {
1004  QImage img;
1005  QByteArray data = getData(CF_DIBV5, pDataObj);
1006  QDataStream s(&data, QIODevice::ReadOnly);
1007  s.setByteOrder(QDataStream::LittleEndian);
1008  if (qt_read_dibv5(s, img)) { // #### supports only 32bit DIBV5
1009  return img;
1010  }
1011  }
1012  //PNG, MS Office place this (undocumented)
1013  if (canGetData(CF_PNG, pDataObj)) {
1014  QImage img;
1015  QByteArray data = getData(CF_PNG, pDataObj);
1016  if (img.loadFromData(data, "PNG")) {
1017  return img;
1018  }
1019  }
1020  //Fallback to DIB
1021  if (canGetData(CF_DIB, pDataObj)) {
1022  QImage img;
1023  QByteArray data = getData(CF_DIB, pDataObj);
1024  QDataStream s(&data, QIODevice::ReadOnly);
1025  s.setByteOrder(QDataStream::LittleEndian);// Intel byte order ####
1026  if (qt_read_dib(s, img)) { // ##### encaps "-14"
1027  return img;
1028  }
1029  }
1030  // Failed
1031  return result;
1032 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool hasOriginalDIBV5(IDataObject *pDataObj) const
Definition: qmime_win.cpp:973
bool qt_read_dib(QDataStream &, QImage &)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
#define CF_DIBV5
Definition: qmime_win.cpp:69
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QByteArray getData(int cf, IDataObject *pDataObj)
Definition: qmime_win.cpp:156
bool loadFromData(const uchar *buf, int len, const char *format=0)
Loads an image from the first len bytes of the given binary data.
Definition: qimage.cpp:5275
static bool canGetData(int cf, IDataObject *pDataObj)
Definition: qmime_win.cpp:191
static bool qt_read_dibv5(QDataStream &s, QImage &image)
Definition: qmime_win.cpp:1471

◆ formatsForMime()

QVector< FORMATETC > QWindowsMimeImage::formatsForMime ( const QString mimeType,
const QMimeData mimeData 
) const
virtual

Returns a QVector of FORMATETC structures representing the different windows clipboard formats that can be provided for the mimeType from the mimeData.

All subclasses must reimplement this pure virtual function.

Implements QWindowsMime.

Definition at line 905 of file qmime_win.cpp.

906 {
907  QVector<FORMATETC> formatetcs;
908  if (mimeData->hasImage() && mimeType == QLatin1String("application/x-qt-image")) {
909  //add DIBV5 if image has alpha channel
910  QImage image = qvariant_cast<QImage>(mimeData->imageData());
911  if (!image.isNull() && image.hasAlphaChannel())
912  formatetcs += setCf(CF_DIBV5);
913  formatetcs += setCf(CF_DIB);
914  }
915  return formatetcs;
916 }
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
static FORMATETC setCf(int cf)
Definition: qmime_win.cpp:130
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QVariant imageData() const
Returns a QVariant storing a QImage if the object can return an image; otherwise returns a null varia...
Definition: qmimedata.cpp:442
bool hasImage() const
Returns true if the object can return an image; otherwise returns false.
Definition: qmimedata.cpp:471
#define CF_DIBV5
Definition: qmime_win.cpp:69
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ hasOriginalDIBV5()

bool QWindowsMimeImage::hasOriginalDIBV5 ( IDataObject *  pDataObj) const
private

Definition at line 973 of file qmime_win.cpp.

974 {
975  bool isSynthesized = true;
976  IEnumFORMATETC *pEnum =NULL;
977  HRESULT res = pDataObj->EnumFormatEtc(1, &pEnum);
978  if (res == S_OK && pEnum) {
979  FORMATETC fc;
980  while ((res = pEnum->Next(1, &fc, 0)) == S_OK) {
981  if (fc.ptd)
982  CoTaskMemFree(fc.ptd);
983  if (fc.cfFormat == CF_DIB)
984  break;
985  else if (fc.cfFormat == CF_DIBV5) {
986  isSynthesized = false;
987  break;
988  }
989  }
990  pEnum->Release();
991  }
992  return !isSynthesized;
993 }
struct tagFORMATETC FORMATETC
Definition: qmime.h:66
long HRESULT
#define CF_DIBV5
Definition: qmime_win.cpp:69

◆ mimeForFormat()

QString QWindowsMimeImage::mimeForFormat ( const FORMATETC formatetc) const
virtual

Returns the mime type that will be created form the format specified in formatetc, or an empty string if this converter does not support formatetc.

All subclasses must reimplement this pure virtual function.

Implements QWindowsMime.

Definition at line 918 of file qmime_win.cpp.

919 {
920  int cf = getCf(formatetc);
921  if (cf == CF_DIB || cf == CF_DIBV5 || cf == int(CF_PNG))
922  return QLatin1String("application/x-qt-image");
923  return QString();
924 }
static int getCf(const FORMATETC &formatetc)
Definition: qmime_win.cpp:125
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define CF_DIBV5
Definition: qmime_win.cpp:69

Properties

◆ CF_PNG

UINT QWindowsMimeImage::CF_PNG
private

Definition at line 897 of file qmime_win.cpp.


The documentation for this class was generated from the following file: