diff --git a/src/qt/bitmap.cpp b/src/qt/bitmap.cpp index 485d9a30c5..3b86572e7a 100644 --- a/src/qt/bitmap.cpp +++ b/src/qt/bitmap.cpp @@ -124,7 +124,7 @@ static QImage ConvertImage( const wxImage &image ) class wxBitmapRefData: public wxGDIRefData { public: - wxBitmapRefData() { } + wxBitmapRefData() { m_mask = NULL; } wxBitmapRefData( int width, int height, int depth ) { @@ -132,15 +132,23 @@ class wxBitmapRefData: public wxGDIRefData m_qtPixmap = QBitmap( width, height ); else m_qtPixmap = QPixmap( width, height ); + m_mask = NULL; } wxBitmapRefData( QPixmap pix ) { m_qtPixmap = pix; + m_mask = NULL; } + virtual ~wxBitmapRefData() { delete m_mask; } + QPixmap m_qtPixmap; - wxMask m_mask; + wxMask *m_mask; + +private: + wxBitmapRefData(const wxBitmapRefData&other); + wxBitmapRefData& operator=(const wxBitmapRefData&other); }; //----------------------------------------------------------------------------- @@ -255,27 +263,26 @@ int wxBitmap::GetDepth() const #if wxUSE_IMAGE wxImage wxBitmap::ConvertToImage() const { - return ConvertImage(M_PIXDATA.toImage()); + QPixmap pixmap(M_PIXDATA); + if(M_MASK && M_MASK->GetHandle()) + pixmap.setMask(*M_MASK->GetHandle()); + return ConvertImage(pixmap.toImage()); } #endif // wxUSE_IMAGE wxMask *wxBitmap::GetMask() const { - return M_MASK.GetHandle() ? &M_MASK : NULL; + return M_MASK; } void wxBitmap::SetMask(wxMask *mask) { - if(mask && mask->GetHandle() ) - { - M_MASK = *mask; - M_PIXDATA.setMask( *mask->GetHandle() ); - } else - M_MASK = wxMask(); + AllocExclusive(); + delete M_MASK; + M_MASK = mask; } - wxBitmap wxBitmap::GetSubBitmap(const wxRect& rect) const { return wxBitmap(M_PIXDATA.copy(wxQtConvertRect(rect))); @@ -438,9 +445,8 @@ wxGDIRefData *wxBitmap::CloneGDIRefData(const wxGDIRefData *data) const { const wxBitmapRefData* oldRef = static_cast(data); wxBitmapRefData *d = new wxBitmapRefData; - d->m_qtPixmap = oldRef->m_qtPixmap.copy();// copy not needed - d->m_mask = oldRef->m_mask; - + d->m_qtPixmap = oldRef->m_qtPixmap; //.copy();// copy not needed + d->m_mask = oldRef->m_mask ? new wxMask(*oldRef->m_mask) : NULL; return d; } diff --git a/src/qt/dc.cpp b/src/qt/dc.cpp index 78e406e0d8..255ce0487a 100644 --- a/src/qt/dc.cpp +++ b/src/qt/dc.cpp @@ -649,20 +649,8 @@ void wxQtDCImpl::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, m_qtPainter->setBackground(savedBrush); m_qtPainter->setPen(savedPen); } else { - if ( !useMask && bmp.GetMask() ) - { - // Temporarly disable mask - QBitmap mask; - mask = pix.mask(); - pix.setMask( QBitmap() ); - - // Draw - m_qtPainter->drawPixmap(x, y, pix); - - // Restore saved mask - pix.setMask( mask ); - } - else + if(useMask && bmp.GetMask() && bmp.GetMask()->GetHandle()) + pix.setMask(*bmp.GetMask()->GetHandle()); m_qtPainter->drawPixmap(x, y, pix); } } diff --git a/src/qt/dcmemory.cpp b/src/qt/dcmemory.cpp index 2898270d7f..dfa743ee13 100644 --- a/src/qt/dcmemory.cpp +++ b/src/qt/dcmemory.cpp @@ -69,8 +69,12 @@ void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap ) m_selected = bitmap; if ( bitmap.IsOk() && !bitmap.GetHandle()->isNull() ) { + QPixmap pixmap(*bitmap.GetHandle()); + // apply mask before converting to image + if(bitmap.GetMask() && bitmap.GetMask()->GetHandle()) + pixmap.setMask(*bitmap.GetMask()->GetHandle()); // create the intermediate image for the pixmap: - m_qtImage = new QImage( bitmap.GetHandle()->toImage() ); + m_qtImage = new QImage( pixmap.toImage() ); // start drawing on the intermediary device: m_ok = m_qtPainter->begin( m_qtImage );