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>
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
)
30 if (!QtData::noNativeControls())
31 m_pWidgetDraw
.reset(new QtGraphics_Controls(*this));
33 setDevicePixelRatioF(m_pFrame
->devicePixelRatioF());
36 QtSvpGraphics::~QtSvpGraphics() {}
38 void QtSvpGraphics::updateQWidget() const
42 QWidget
* pQWidget
= m_pFrame
->GetQWidget();
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
);
65 static void QImage2BitmapBuffer(QImage
& rImg
, BitmapBuffer
& rBuf
)
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();
85 if (pImage
->width() == 0 || pImage
->height() == 0)
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
)
99 if ((pForceDpi
= getenv("SAL_FORCEDPI")))
101 OString
sForceDPI(pForceDpi
);
102 rDPIX
= rDPIY
= sForceDPI
.toInt32();
109 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
110 QScreen
* pScreen
= m_pFrame
->GetQWidget()->screen();
112 if (!m_pFrame
->GetQWidget()->window()->windowHandle())
115 QScreen
* pScreen
= m_pFrame
->GetQWidget()->window()->windowHandle()->screen();
117 rDPIX
= pScreen
->logicalDotsPerInchX() * pScreen
->devicePixelRatio() + 0.5;
118 rDPIY
= pScreen
->logicalDotsPerInchY() * pScreen
->devicePixelRatio() + 0.5;
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */