bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / qt5 / QtSvpGraphics.cxx
blob8ae869a1c247baa2c053351cf89ce2337801a69e
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 <QtData.hxx>
17 #include <QtFrame.hxx>
18 #include <QtGraphics_Controls.hxx>
19 #include <QtSvpGraphics.hxx>
20 #include <QtSvpSurface.hxx>
21 #include <QtTools.hxx>
23 #include <QtGui/QScreen>
24 #include <QtGui/QWindow>
25 #include <QtWidgets/QWidget>
27 QtSvpGraphics::QtSvpGraphics(QtFrame* pFrame)
28 : m_pFrame(pFrame)
30 if (!QtData::noNativeControls())
31 m_pWidgetDraw.reset(new QtGraphics_Controls(*this));
32 if (m_pFrame)
33 setDevicePixelRatioF(m_pFrame->devicePixelRatioF());
36 QtSvpGraphics::~QtSvpGraphics() {}
38 void QtSvpGraphics::updateQWidget() const
40 if (!m_pFrame)
41 return;
42 QWidget* pQWidget = m_pFrame->GetQWidget();
43 if (pQWidget)
44 pQWidget->update(pQWidget->rect());
47 #if ENABLE_CAIRO_CANVAS
49 bool QtSvpGraphics::SupportsCairo() const { return true; }
51 cairo::SurfaceSharedPtr
52 QtSvpGraphics::CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const
54 return std::make_shared<cairo::QtSvpSurface>(rSurface);
57 cairo::SurfaceSharedPtr QtSvpGraphics::CreateSurface(const OutputDevice& /*rRefDevice*/, int x,
58 int y, int width, int height) const
60 return std::make_shared<cairo::QtSvpSurface>(this, x, y, width, height);
63 #endif
65 static void QImage2BitmapBuffer(QImage& rImg, BitmapBuffer& rBuf)
67 assert(rImg.width());
68 assert(rImg.height());
70 rBuf.mnWidth = rImg.width();
71 rBuf.mnHeight = rImg.height();
72 rBuf.mnBitCount = getFormatBits(rImg.format());
73 rBuf.mpBits = rImg.bits();
74 rBuf.mnScanlineSize = rImg.bytesPerLine();
77 void QtSvpGraphics::handleDamage(const tools::Rectangle& rDamagedRegion)
79 assert(m_pWidgetDraw);
80 assert(dynamic_cast<QtGraphics_Controls*>(m_pWidgetDraw.get()));
81 assert(!rDamagedRegion.IsEmpty());
83 QImage* pImage = static_cast<QtGraphics_Controls*>(m_pWidgetDraw.get())->getImage();
84 assert(pImage);
85 if (pImage->width() == 0 || pImage->height() == 0)
86 return;
88 BitmapBuffer aBuffer;
89 QImage2BitmapBuffer(*pImage, aBuffer);
90 SalTwoRect aTR(0, 0, pImage->width(), pImage->height(), rDamagedRegion.Left(),
91 rDamagedRegion.Top(), rDamagedRegion.GetWidth(), rDamagedRegion.GetHeight());
93 getSvpBackend()->drawBitmapBuffer(aTR, &aBuffer, CAIRO_OPERATOR_OVER);
96 void QtSvpGraphics::GetResolution(sal_Int32& rDPIX, sal_Int32& rDPIY)
98 char* pForceDpi;
99 if ((pForceDpi = getenv("SAL_FORCEDPI")))
101 OString sForceDPI(pForceDpi);
102 rDPIX = rDPIY = sForceDPI.toInt32();
103 return;
106 if (!m_pFrame)
107 return;
109 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
110 QScreen* pScreen = m_pFrame->GetQWidget()->screen();
111 #else
112 if (!m_pFrame->GetQWidget()->window()->windowHandle())
113 return;
115 QScreen* pScreen = m_pFrame->GetQWidget()->window()->windowHandle()->screen();
116 #endif
117 rDPIX = pScreen->logicalDotsPerInchX() * pScreen->devicePixelRatio() + 0.5;
118 rDPIY = pScreen->logicalDotsPerInchY() * pScreen->devicePixelRatio() + 0.5;
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */