1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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>
13 #include <o3tl/string_view.hxx>
15 #include <config_cairo_canvas.h>
18 #include <QtFrame.hxx>
19 #include <QtGraphics_Controls.hxx>
20 #include <QtSvpGraphics.hxx>
21 #include <QtSvpSurface.hxx>
22 #include <QtTools.hxx>
24 #include <QtWidgets/QWidget>
26 QtSvpGraphics::QtSvpGraphics(QtFrame
* pFrame
)
29 if (!QtData::noNativeControls())
30 m_pWidgetDraw
.reset(new QtGraphics_Controls(*this));
32 setDevicePixelRatioF(m_pFrame
->devicePixelRatioF());
35 QtSvpGraphics::~QtSvpGraphics() {}
37 void QtSvpGraphics::updateQWidget() const
41 QWidget
* pQWidget
= m_pFrame
->GetQWidget();
43 pQWidget
->update(pQWidget
->rect());
46 #if ENABLE_CAIRO_CANVAS
48 bool QtSvpGraphics::SupportsCairo() const { return true; }
50 cairo::SurfaceSharedPtr
51 QtSvpGraphics::CreateSurface(const cairo::CairoSurfaceSharedPtr
& rSurface
) const
53 return std::make_shared
<cairo::QtSvpSurface
>(rSurface
);
56 cairo::SurfaceSharedPtr
QtSvpGraphics::CreateSurface(const OutputDevice
& /*rRefDevice*/, int x
,
57 int y
, int width
, int height
) const
59 return std::make_shared
<cairo::QtSvpSurface
>(this, x
, y
, width
, height
);
64 static void QImage2BitmapBuffer(QImage
& rImg
, BitmapBuffer
& rBuf
)
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 QtSvpGraphics::handleDamage(const tools::Rectangle
& rDamagedRegion
)
78 assert(m_pWidgetDraw
);
79 assert(dynamic_cast<QtGraphics_Controls
*>(m_pWidgetDraw
.get()));
80 assert(!rDamagedRegion
.IsEmpty());
82 QImage
* pImage
= static_cast<QtGraphics_Controls
*>(m_pWidgetDraw
.get())->getImage();
84 if (pImage
->width() == 0 || pImage
->height() == 0)
88 QImage2BitmapBuffer(*pImage
, aBuffer
);
89 SalTwoRect
aTR(0, 0, pImage
->width(), pImage
->height(), rDamagedRegion
.Left(),
90 rDamagedRegion
.Top(), rDamagedRegion
.GetWidth(), rDamagedRegion
.GetHeight());
92 getSvpBackend()->drawBitmapBuffer(aTR
, &aBuffer
, CAIRO_OPERATOR_OVER
);
95 void QtSvpGraphics::GetResolution(sal_Int32
& rDPIX
, sal_Int32
& rDPIY
)
97 QtGraphicsBase::ImplGetResolution(m_pFrame
, rDPIX
, rDPIY
);
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */