1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <Qt5Graphics.hxx>
21 
22 #include <Qt5Font.hxx>
23 #include <Qt5Frame.hxx>
24 #include <Qt5Graphics_Controls.hxx>
25 #include <Qt5Painter.hxx>
26 
27 #include <QtGui/QImage>
28 #include <QtGui/QPainter>
29 #include <QtWidgets/QPushButton>
30 #include <QtWidgets/QWidget>
31 
Qt5Graphics(Qt5Frame * pFrame,QImage * pQImage)32 Qt5Graphics::Qt5Graphics( Qt5Frame *pFrame, QImage *pQImage )
33     : m_pFrame( pFrame )
34     , m_pQImage( pQImage )
35     , m_aLineColor( 0x00, 0x00, 0x00 )
36     , m_aFillColor( 0xFF, 0xFF, 0XFF )
37     , m_eCompositionMode( QPainter::CompositionMode_SourceOver )
38     , m_pFontCollection( nullptr )
39     , m_pTextStyle{ nullptr, }
40     , m_aTextColor( 0x00, 0x00, 0x00 )
41 {
42     ResetClipRegion();
43     if (!Qt5Data::noNativeControls())
44         m_pWidgetDraw.reset(new Qt5Graphics_Controls());
45 }
46 
~Qt5Graphics()47 Qt5Graphics::~Qt5Graphics() { ReleaseFonts(); }
48 
ChangeQImage(QImage * pQImage)49 void Qt5Graphics::ChangeQImage(QImage* pQImage)
50 {
51     m_pQImage = pQImage;
52     ResetClipRegion();
53 }
54 
GetImpl() const55 SalGraphicsImpl* Qt5Graphics::GetImpl() const { return nullptr; }
56 
GetGraphicsData() const57 SystemGraphicsData Qt5Graphics::GetGraphicsData() const { return SystemGraphicsData(); }
58 
supportsOperation(OutDevSupportType eType) const59 bool Qt5Graphics::supportsOperation(OutDevSupportType eType) const
60 {
61     switch (eType)
62     {
63         case OutDevSupportType::B2DDraw:
64         case OutDevSupportType::TransparentRect:
65             return true;
66         default:
67             return false;
68     }
69 }
70 
71 #if ENABLE_CAIRO_CANVAS
72 
SupportsCairo() const73 bool Qt5Graphics::SupportsCairo() const { return false; }
74 
75 cairo::SurfaceSharedPtr
CreateSurface(const cairo::CairoSurfaceSharedPtr &) const76 Qt5Graphics::CreateSurface(const cairo::CairoSurfaceSharedPtr& /*rSurface*/) const
77 {
78     return nullptr;
79 }
80 
CreateSurface(const OutputDevice &,int,int,int,int) const81 cairo::SurfaceSharedPtr Qt5Graphics::CreateSurface(const OutputDevice& /*rRefDevice*/, int /*x*/,
82                                                    int /*y*/, int /*width*/, int /*height*/) const
83 {
84     return nullptr;
85 }
86 
CreateBitmapSurface(const OutputDevice &,const BitmapSystemData &,const Size &) const87 cairo::SurfaceSharedPtr Qt5Graphics::CreateBitmapSurface(const OutputDevice& /*rRefDevice*/,
88                                                          const BitmapSystemData& /*rData*/,
89                                                          const Size& /*rSize*/) const
90 {
91     return nullptr;
92 }
93 
GetNativeSurfaceHandle(cairo::SurfaceSharedPtr &,const basegfx::B2ISize &) const94 css::uno::Any Qt5Graphics::GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& /*rSurface*/,
95                                                   const basegfx::B2ISize& /*rSize*/) const
96 {
97     return css::uno::Any();
98 }
99 
GetSysFontData(int) const100 SystemFontData Qt5Graphics::GetSysFontData(int /*nFallbacklevel*/) const
101 {
102     return SystemFontData();
103 }
104 
105 #endif
106 
handleDamage(const tools::Rectangle & rDamagedRegion)107 void Qt5Graphics::handleDamage(const tools::Rectangle& rDamagedRegion)
108 {
109     assert(m_pWidgetDraw);
110     assert(dynamic_cast<Qt5Graphics_Controls*>(m_pWidgetDraw.get()));
111     assert(!rDamagedRegion.IsEmpty());
112 
113     QImage* pImage = static_cast<Qt5Graphics_Controls*>(m_pWidgetDraw.get())->getImage();
114     Qt5Painter aPainter(*this);
115     aPainter.drawImage(QPoint(rDamagedRegion.getX(), rDamagedRegion.getY()), *pImage);
116     aPainter.update(toQRect(rDamagedRegion));
117 }
118 
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
120