tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrellipseprimitive2d.cxx
blob2beb18dbebb4a4d26586404ff111b60d0f27a482
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sdr/primitive2d/sdrellipseprimitive2d.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <basegfx/polygon/b2dpolygontools.hxx>
23 #include <basegfx/polygon/b2dpolypolygon.hxx>
24 #include <sdr/primitive2d/sdrdecompositiontools.hxx>
25 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
26 #include <basegfx/matrix/b2dhommatrixtools.hxx>
27 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
28 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
29 #include <utility>
32 using namespace com::sun::star;
35 namespace drawinglayer::primitive2d
37 Primitive2DReference SdrEllipsePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
39 Primitive2DContainer aRetval;
41 // create unit outline polygon
42 // Do use createPolygonFromUnitCircle, but let create from first quadrant to mimic old geometry creation.
43 // This is needed to have the same look when stroke is used since the polygon start point defines the
44 // stroke start, too.
45 basegfx::B2DPolygon aUnitOutline(basegfx::utils::createPolygonFromUnitCircle(1));
47 // scale and move UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
48 const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
49 basegfx::utils::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
51 // apply to the geometry
52 aUnitOutline.transform(aUnitCorrectionMatrix);
54 // add fill
55 if(!getSdrLFSTAttribute().getFill().isDefault())
57 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
59 aTransformed.transform(getTransform());
60 aRetval.push_back(
61 createPolyPolygonFillPrimitive(
62 aTransformed,
63 getSdrLFSTAttribute().getFill(),
64 getSdrLFSTAttribute().getFillFloatTransGradient()));
67 // add line
68 if(getSdrLFSTAttribute().getLine().isDefault())
70 // create invisible line for HitTest/BoundRect
71 aRetval.push_back(
72 createHiddenGeometryPrimitives2D(
73 false,
74 basegfx::B2DPolyPolygon(aUnitOutline),
75 getTransform()));
77 else
79 basegfx::B2DPolygon aTransformed(aUnitOutline);
81 aTransformed.transform(getTransform());
82 aRetval.push_back(
83 createPolygonLinePrimitive(
84 aTransformed,
85 getSdrLFSTAttribute().getLine(),
86 attribute::SdrLineStartEndAttribute()));
89 // add text
90 if(!getSdrLFSTAttribute().getText().isDefault())
92 aRetval.push_back(
93 createTextPrimitive(
94 basegfx::B2DPolyPolygon(aUnitOutline),
95 getTransform(),
96 getSdrLFSTAttribute().getText(),
97 getSdrLFSTAttribute().getLine(),
98 false,
99 false));
102 // add shadow
103 if(!getSdrLFSTAttribute().getShadow().isDefault())
105 aRetval = createEmbeddedShadowPrimitive(
106 std::move(aRetval),
107 getSdrLFSTAttribute().getShadow());
110 return new GroupPrimitive2D(std::move(aRetval));
113 SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
114 basegfx::B2DHomMatrix aTransform,
115 const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute)
116 : maTransform(std::move(aTransform)),
117 maSdrLFSTAttribute(rSdrLFSTAttribute)
121 bool SdrEllipsePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
123 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
125 const SdrEllipsePrimitive2D& rCompare = static_cast<const SdrEllipsePrimitive2D&>(rPrimitive);
127 return (getTransform() == rCompare.getTransform()
128 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute());
131 return false;
134 // provide unique ID
135 sal_uInt32 SdrEllipsePrimitive2D::getPrimitive2DID() const
137 return PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D;
142 Primitive2DReference SdrEllipseSegmentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
144 Primitive2DContainer aRetval;
146 // create unit outline polygon
147 basegfx::B2DPolygon aUnitOutline(basegfx::utils::createPolygonFromUnitEllipseSegment(mfStartAngle, mfEndAngle));
149 if(mbCloseSegment)
151 if(mbCloseUsingCenter)
153 // for compatibility, insert the center point at polygon start to get the same
154 // line stroking pattern as the old painting mechanisms.
155 aUnitOutline.insert(0, basegfx::B2DPoint(0.0, 0.0));
158 aUnitOutline.setClosed(true);
161 // move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
162 const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
163 basegfx::utils::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
165 // apply to the geometry
166 aUnitOutline.transform(aUnitCorrectionMatrix);
168 // add fill
169 if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline.isClosed())
171 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
173 aTransformed.transform(getTransform());
174 aRetval.push_back(
175 createPolyPolygonFillPrimitive(
176 aTransformed,
177 getSdrLFSTAttribute().getFill(),
178 getSdrLFSTAttribute().getFillFloatTransGradient()));
181 // add line
182 if(getSdrLFSTAttribute().getLine().isDefault())
184 // create invisible line for HitTest/BoundRect
185 aRetval.push_back(
186 createHiddenGeometryPrimitives2D(
187 false,
188 basegfx::B2DPolyPolygon(aUnitOutline),
189 getTransform()));
191 else
193 basegfx::B2DPolygon aTransformed(aUnitOutline);
195 aTransformed.transform(getTransform());
196 aRetval.push_back(
197 createPolygonLinePrimitive(
198 aTransformed,
199 getSdrLFSTAttribute().getLine(),
200 getSdrLFSTAttribute().getLineStartEnd()));
203 // add text
204 if(!getSdrLFSTAttribute().getText().isDefault())
206 aRetval.push_back(
207 createTextPrimitive(
208 basegfx::B2DPolyPolygon(aUnitOutline),
209 getTransform(),
210 getSdrLFSTAttribute().getText(),
211 getSdrLFSTAttribute().getLine(),
212 false,
213 false));
216 // add shadow
217 if(!getSdrLFSTAttribute().getShadow().isDefault())
219 aRetval = createEmbeddedShadowPrimitive(
220 std::move(aRetval),
221 getSdrLFSTAttribute().getShadow());
224 return new GroupPrimitive2D(std::move(aRetval));
227 SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
228 const basegfx::B2DHomMatrix& rTransform,
229 const attribute::SdrLineFillEffectsTextAttribute& rSdrLFSTAttribute,
230 double fStartAngle,
231 double fEndAngle,
232 bool bCloseSegment,
233 bool bCloseUsingCenter)
234 : SdrEllipsePrimitive2D(rTransform, rSdrLFSTAttribute),
235 mfStartAngle(fStartAngle),
236 mfEndAngle(fEndAngle),
237 mbCloseSegment(bCloseSegment),
238 mbCloseUsingCenter(bCloseUsingCenter)
242 bool SdrEllipseSegmentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
244 if(SdrEllipsePrimitive2D::operator==(rPrimitive))
246 const SdrEllipseSegmentPrimitive2D& rCompare = static_cast<const SdrEllipseSegmentPrimitive2D&>(rPrimitive);
248 if( mfStartAngle == rCompare.mfStartAngle
249 && mfEndAngle == rCompare.mfEndAngle
250 && mbCloseSegment == rCompare.mbCloseSegment
251 && mbCloseUsingCenter == rCompare.mbCloseUsingCenter)
253 return true;
257 return false;
260 // provide unique ID
261 sal_uInt32 SdrEllipseSegmentPrimitive2D::getPrimitive2DID() const
263 return PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D;
266 } // end of namespace
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */