bump product version to 6.4.0.3
[LibreOffice.git] / vcl / qt5 / Qt5SvpGraphics.cxx
blobfc58bbcfcc159b25e7b828e7fcdbafc1b6a9dc7c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
11 #include <sal/log.hxx>
12 #include <salbmp.hxx>
14 #include <config_cairo_canvas.h>
16 #include <Qt5Data.hxx>
17 #include <Qt5Frame.hxx>
18 #include <Qt5Graphics_Controls.hxx>
19 #include <Qt5SvpGraphics.hxx>
20 #include <Qt5SvpSurface.hxx>
21 #include <Qt5Tools.hxx>
23 #include <QtGui/QScreen>
24 #include <QtGui/QWindow>
25 #include <QtWidgets/QWidget>
27 Qt5SvpGraphics::Qt5SvpGraphics(Qt5Frame* pFrame)
28 : SvpSalGraphics()
29 , m_pFrame(pFrame)
31 if (!Qt5Data::noNativeControls())
32 m_pWidgetDraw.reset(new Qt5Graphics_Controls());
35 Qt5SvpGraphics::~Qt5SvpGraphics() {}
37 void Qt5SvpGraphics::updateQWidget() const
39 if (!m_pFrame)
40 return;
41 QWidget* pQWidget = m_pFrame->GetQWidget();
42 if (pQWidget)
43 pQWidget->update(pQWidget->rect());
46 #if ENABLE_CAIRO_CANVAS
48 bool Qt5SvpGraphics::SupportsCairo() const { return true; }
50 cairo::SurfaceSharedPtr
51 Qt5SvpGraphics::CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const
53 return cairo::SurfaceSharedPtr(new cairo::Qt5SvpSurface(rSurface));
56 cairo::SurfaceSharedPtr Qt5SvpGraphics::CreateSurface(const OutputDevice& /*rRefDevice*/, int x,
57 int y, int width, int height) const
59 return cairo::SurfaceSharedPtr(new cairo::Qt5SvpSurface(this, x, y, width, height));
62 #endif
64 static void QImage2BitmapBuffer(QImage& rImg, BitmapBuffer& rBuf)
66 assert(rImg.width());
67 assert(rImg.height());
69 rBuf.mnWidth = rImg.width();
70 rBuf.mnHeight = rImg.height();
71 rBuf.mnBitCount = getFormatBits(rImg.format());
72 rBuf.mpBits = rImg.bits();
73 rBuf.mnScanlineSize = rImg.bytesPerLine();
76 void Qt5SvpGraphics::handleDamage(const tools::Rectangle& rDamagedRegion)
78 assert(m_pWidgetDraw);
79 assert(dynamic_cast<Qt5Graphics_Controls*>(m_pWidgetDraw.get()));
80 assert(!rDamagedRegion.IsEmpty());
82 QImage* pImage = static_cast<Qt5Graphics_Controls*>(m_pWidgetDraw.get())->getImage();
83 assert(pImage);
85 BitmapBuffer aBuffer;
86 QImage2BitmapBuffer(*pImage, aBuffer);
87 SalTwoRect aTR(0, 0, pImage->width(), pImage->height(), rDamagedRegion.getX(),
88 rDamagedRegion.getY(), rDamagedRegion.GetWidth(), rDamagedRegion.GetHeight());
89 drawBitmap(aTR, &aBuffer, CAIRO_OPERATOR_OVER);
92 void Qt5SvpGraphics::GetResolution(sal_Int32& rDPIX, sal_Int32& rDPIY)
94 char* pForceDpi;
95 if ((pForceDpi = getenv("SAL_FORCEDPI")))
97 OString sForceDPI(pForceDpi);
98 rDPIX = rDPIY = sForceDPI.toInt32();
99 return;
102 if (!m_pFrame || !m_pFrame->GetQWidget()->window()->windowHandle())
103 return;
105 QScreen* pScreen = m_pFrame->GetQWidget()->window()->windowHandle()->screen();
106 rDPIX = pScreen->logicalDotsPerInchX() * pScreen->devicePixelRatio() + 0.5;
107 rDPIY = pScreen->logicalDotsPerInchY() * pScreen->devicePixelRatio() + 0.5;
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */