From 30bf6b73178a6cf793cddb9c646560808f5faba7 Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Thu, 5 Jul 2018 18:06:54 +0200 Subject: Qt5 implement scaled image draws If the source and target rects don't match, LO expect the image to be scaled. Change-Id: I337acfa56600eba92c10aed7a70749ad08c03e90 --- vcl/inc/qt5/Qt5Graphics.hxx | 2 ++ vcl/qt5/Qt5Graphics_GDI.cxx | 43 ++++++++++++++++++------------------------- 2 files changed, 20 insertions(+), 25 deletions(-) (limited to 'vcl') diff --git a/vcl/inc/qt5/Qt5Graphics.hxx b/vcl/inc/qt5/Qt5Graphics.hxx index 0e9de46818a6..b1ba6ce85d98 100644 --- a/vcl/inc/qt5/Qt5Graphics.hxx +++ b/vcl/inc/qt5/Qt5Graphics.hxx @@ -53,6 +53,8 @@ class Qt5Graphics : public SalGraphics Qt5Graphics(Qt5Frame* pFrame, QImage* pQImage); + void drawScaledImage(const SalTwoRect& rPosAry, const QImage& rImage); + public: Qt5Graphics(Qt5Frame* pFrame) : Qt5Graphics(pFrame, nullptr) diff --git a/vcl/qt5/Qt5Graphics_GDI.cxx b/vcl/qt5/Qt5Graphics_GDI.cxx index 971b85f705fe..08c620c11796 100644 --- a/vcl/qt5/Qt5Graphics_GDI.cxx +++ b/vcl/qt5/Qt5Graphics_GDI.cxx @@ -356,6 +356,15 @@ bool Qt5Graphics::drawPolyLine(const basegfx::B2DPolygon& rPolyLine, double fTra bool Qt5Graphics::drawGradient(const tools::PolyPolygon&, const Gradient&) { return false; } +void Qt5Graphics::drawScaledImage(const SalTwoRect& rPosAry, const QImage& rImage) +{ + Qt5Painter aPainter(*this); + QRect aSrcRect(rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight); + QRect aDestRect(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight); + aPainter.drawImage(aDestRect, rImage, aSrcRect); + aPainter.update(aDestRect); +} + void Qt5Graphics::copyArea(long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth, long nSrcHeight, bool /*bWindowInvalidate*/) { @@ -372,25 +381,21 @@ void Qt5Graphics::copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics) || rPosAry.mnDestHeight <= 0) return; - assert(rPosAry.mnSrcWidth == rPosAry.mnDestWidth); - assert(rPosAry.mnSrcHeight == rPosAry.mnDestHeight); - - QImage aImage, *pImage = &aImage; + QImage aImage, *pImage; + SalTwoRect aPosAry = rPosAry; if (!pSrcGraphics || this == pSrcGraphics) { - if (rPosAry.mnDestX == rPosAry.mnSrcX && rPosAry.mnDestY == rPosAry.mnSrcY) - return; + pImage = static_cast(this)->m_pQImage; aImage = pImage->copy(rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight); + pImage = &aImage; + aPosAry.mnSrcX = 0; + aPosAry.mnSrcY = 0; } else pImage = static_cast(pSrcGraphics)->m_pQImage; - Qt5Painter aPainter(*this); - aPainter.drawImage( - QPoint(rPosAry.mnDestX, rPosAry.mnDestY), *pImage, - QRect(rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight)); - aPainter.update(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight); + drawScaledImage(aPosAry, *pImage); } void Qt5Graphics::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap) @@ -399,10 +404,6 @@ void Qt5Graphics::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBit || rPosAry.mnDestHeight <= 0) return; - assert(rPosAry.mnSrcWidth == rPosAry.mnDestWidth); - assert(rPosAry.mnSrcHeight == rPosAry.mnDestHeight); - - Qt5Painter aPainter(*this); Qt5Bitmap aRGBABitmap; if (rSalBitmap.GetBitCount() == 4) aRGBABitmap.Create(rSalBitmap, 32); @@ -411,10 +412,7 @@ void Qt5Graphics::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBit : aRGBABitmap.GetQImage(); assert(pImage); - aPainter.drawImage( - QPoint(rPosAry.mnDestX, rPosAry.mnDestY), *pImage, - QRect(rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight)); - aPainter.update(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight); + drawScaledImage(rPosAry, *pImage); } void Qt5Graphics::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& /*rSalBitmap*/, @@ -523,12 +521,7 @@ bool Qt5Graphics::drawAlphaBitmap(const SalTwoRect& rPosAry, const SalBitmap& rS QImage aImage; if (!getAlphaImage(rSourceBitmap, rAlphaBitmap, aImage)) return false; - - Qt5Painter aPainter(*this); - aPainter.drawImage( - QPoint(rPosAry.mnDestX, rPosAry.mnDestY), aImage, - QRect(rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight)); - aPainter.update(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, rPosAry.mnDestHeight); + drawScaledImage(rPosAry, aImage); return true; } -- cgit v1.2.3