diff --git a/include/wx/qt/dataobj2.h b/include/wx/qt/dataobj2.h index d340432f6f..26536b2750 100644 --- a/include/wx/qt/dataobj2.h +++ b/include/wx/qt/dataobj2.h @@ -8,28 +8,15 @@ #ifndef _WX_QT_DATAOBJ2_H_ #define _WX_QT_DATAOBJ2_H_ -#include - -class QByteArray; - class WXDLLIMPEXP_CORE wxBitmapDataObject : public wxBitmapDataObjectBase { public: wxBitmapDataObject(); wxBitmapDataObject(const wxBitmap& bitmap); - ~wxBitmapDataObject(); - - void SetBitmap(const wxBitmap& bitmap) wxOVERRIDE; - size_t GetDataSize() const wxOVERRIDE; - bool GetDataHere(void *buf) const wxOVERRIDE; - bool SetData(const wxDataFormat& format, size_t len, const void *buf) wxOVERRIDE; - protected: - void DoConvertToPng(); private: - wxScopedPtr m_imageBytes; }; diff --git a/src/qt/clipbrd.cpp b/src/qt/clipbrd.cpp index 3cd5149c4d..e0eaf877d3 100644 --- a/src/qt/clipbrd.cpp +++ b/src/qt/clipbrd.cpp @@ -14,14 +14,14 @@ #include #include +#include +#include #include "wx/clipbrd.h" #include "wx/scopedarray.h" #include "wx/scopeguard.h" #include "wx/qt/private/converter.h" -#include - // ---------------------------------------------------------------------------- // wxClipboard ctor/dtor // ---------------------------------------------------------------------------- @@ -89,6 +89,14 @@ bool wxClipboard::IsOpened() const bool wxClipboard::AddData( wxDataObject *data ) { + wxBitmapDataObjectBase* bitmap = dynamic_cast(data); + if (bitmap != NULL) + { + QtClipboard->setPixmap(*bitmap->GetBitmap().GetHandle()); + delete data; + return true; + } + QMimeData *MimeData = new QMimeData; const size_t count = data->GetFormatCount(); wxDataFormatArray formats(count); @@ -134,6 +142,17 @@ bool wxClipboard::GetData( wxDataObject& data ) { wxCHECK_MSG( m_open, false, wxT("clipboard not open") ); + wxBitmapDataObjectBase* bitmap = dynamic_cast(&data); + if (bitmap != NULL) + { + QPixmap pix = QtClipboard->pixmap(); + if (pix.isNull()) + return false; + + bitmap->SetBitmap(wxBitmap(pix)); + return true; + } + const QMimeData *MimeData = QtClipboard->mimeData( (QClipboard::Mode)Mode() ); const size_t count = data.GetFormatCount(wxDataObject::Set); wxDataFormatArray formats(count); @@ -170,6 +189,10 @@ void wxClipboard::Clear() bool wxClipboard::IsSupported( const wxDataFormat& format ) { const QMimeData *data = QtClipboard->mimeData( (QClipboard::Mode)Mode() ); + if (format.GetType() == wxDF_BITMAP) + { + return data->hasImage(); + } return data->hasFormat(wxQtConvertString(format.GetMimeType())); } diff --git a/src/qt/dataobj.cpp b/src/qt/dataobj.cpp index acb4ee0005..d29c7be8b1 100644 --- a/src/qt/dataobj.cpp +++ b/src/qt/dataobj.cpp @@ -12,9 +12,6 @@ #pragma hdrstop #endif -#include -#include - #include "wx/dataobj.h" #include "wx/scopedarray.h" @@ -26,7 +23,7 @@ wxString DataFormatIdToMimeType(wxDataFormatId formatId) switch ( formatId ) { case wxDF_TEXT: return "text/plain"; - case wxDF_BITMAP: return "PNG"; + case wxDF_BITMAP: return "image/bmp"; case wxDF_TIFF: return "image/tiff"; case wxDF_WAVE: return "audio/x-wav"; case wxDF_UNICODETEXT: return "text/plain"; @@ -156,54 +153,12 @@ bool wxDataObject::IsSupportedFormat(const wxDataFormat& format, //############################################################################ wxBitmapDataObject::wxBitmapDataObject() - : m_imageBytes(new QByteArray()) { } wxBitmapDataObject::wxBitmapDataObject( const wxBitmap &bitmap ) - : wxBitmapDataObjectBase( bitmap ), - m_imageBytes(new QByteArray()) + : wxBitmapDataObjectBase( bitmap ) { - DoConvertToPng(); -} - -wxBitmapDataObject::~wxBitmapDataObject() -{ -} - -void wxBitmapDataObject::SetBitmap(const wxBitmap &bitmap) -{ - wxBitmapDataObjectBase::SetBitmap(bitmap); - - DoConvertToPng(); -} - -size_t wxBitmapDataObject::GetDataSize() const -{ - return m_imageBytes->size(); -} - -bool wxBitmapDataObject::GetDataHere(void *buf) const -{ - memcpy(buf, m_imageBytes->constData(), GetDataSize()); - return true; -} - -bool wxBitmapDataObject::SetData(const wxDataFormat &WXUNUSED(format), size_t len, const void *buf) -{ - m_imageBytes->resize(len); - memcpy(m_imageBytes->data(), buf, len); - QPixmap pix; - pix.loadFromData(*m_imageBytes); - m_bitmap = wxBitmap(pix); - return true; -} - -void wxBitmapDataObject::DoConvertToPng() -{ - QBuffer buffer(m_imageBytes.get()); - buffer.open(QIODevice::WriteOnly); - m_bitmap.GetHandle()->save(&buffer, "PNG"); } //#############################################################################