nss: upgrade to release 3.73
[LibreOffice.git] / vcl / qt5 / Qt5SvpGraphics.cxx
blob8885b9cb533c55197629b13ed934467bd63e61bf
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(*this));
33 if (m_pFrame)
34 setDevicePixelRatioF(m_pFrame->devicePixelRatioF());
37 Qt5SvpGraphics::~Qt5SvpGraphics() {}
39 void Qt5SvpGraphics::updateQWidget() const
41 if (!m_pFrame)
42 return;
43 QWidget* pQWidget = m_pFrame->GetQWidget();
44 if (pQWidget)
45 pQWidget->update(pQWidget->rect());
48 #if ENABLE_CAIRO_CANVAS
50 bool Qt5SvpGraphics::SupportsCairo() const { return true; }
52 cairo::SurfaceSharedPtr
53 Qt5SvpGraphics::CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const
55 return std::make_shared<cairo::Qt5SvpSurface>(rSurface);
58 cairo::SurfaceSharedPtr Qt5SvpGraphics::CreateSurface(const OutputDevice& /*rRefDevice*/, int x,
59 int y, int width, int height) const
61 return std::make_shared<cairo::Qt5SvpSurface>(this, x, y, width, height);
64 #endif
66 static void QImage2BitmapBuffer(QImage& rImg, BitmapBuffer& rBuf)
68 assert(rImg.width());
69 assert(rImg.height());
71 rBuf.mnWidth = rImg.width();
72 rBuf.mnHeight = rImg.height();
73 rBuf.mnBitCount = getFormatBits(rImg.format());
74 rBuf.mpBits = rImg.bits();
75 rBuf.mnScanlineSize = rImg.bytesPerLine();
78 void Qt5SvpGraphics::handleDamage(const tools::Rectangle& rDamagedRegion)
80 assert(m_pWidgetDraw);
81 assert(dynamic_cast<Qt5Graphics_Controls*>(m_pWidgetDraw.get()));
82 assert(!rDamagedRegion.IsEmpty());
84 QImage* pImage = static_cast<Qt5Graphics_Controls*>(m_pWidgetDraw.get())->getImage();
85 assert(pImage);
86 if (pImage->width() == 0 || pImage->height() == 0)
87 return;
89 BitmapBuffer aBuffer;
90 QImage2BitmapBuffer(*pImage, aBuffer);
91 SalTwoRect aTR(0, 0, pImage->width(), pImage->height(), rDamagedRegion.getX(),
92 rDamagedRegion.getY(), rDamagedRegion.GetWidth(), rDamagedRegion.GetHeight());
93 drawBitmap(aTR, &aBuffer, CAIRO_OPERATOR_OVER);
96 void Qt5SvpGraphics::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 || !m_pFrame->GetQWidget()->window()->windowHandle())
107 return;
109 QScreen* pScreen = m_pFrame->GetQWidget()->window()->windowHandle()->screen();
110 rDPIX = pScreen->logicalDotsPerInchX() * pScreen->devicePixelRatio() + 0.5;
111 rDPIY = pScreen->logicalDotsPerInchY() * pScreen->devicePixelRatio() + 0.5;
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */