1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <sal/config.h>
11 #include <sal/log.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
)
31 if (!Qt5Data::noNativeControls())
32 m_pWidgetDraw
.reset(new Qt5Graphics_Controls(*this));
34 setDevicePixelRatioF(m_pFrame
->devicePixelRatioF());
37 Qt5SvpGraphics::~Qt5SvpGraphics() {}
39 void Qt5SvpGraphics::updateQWidget() const
43 QWidget
* pQWidget
= m_pFrame
->GetQWidget();
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
);
66 static void QImage2BitmapBuffer(QImage
& rImg
, BitmapBuffer
& rBuf
)
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();
86 if (pImage
->width() == 0 || pImage
->height() == 0)
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
)
99 if ((pForceDpi
= getenv("SAL_FORCEDPI")))
101 OString
sForceDPI(pForceDpi
);
102 rDPIX
= rDPIY
= sForceDPI
.toInt32();
106 if (!m_pFrame
|| !m_pFrame
->GetQWidget()->window()->windowHandle())
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: */