1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 Jochen Becher
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #pragma once
27 
28 #include "shape.h"
29 #include "qmt/infrastructure/qmt_global.h"
30 
31 #include "shapevalue.h"
32 #include "shapevisitor.h"
33 
34 #include <QList>
35 
36 namespace qmt {
37 
38 class QMT_EXPORT LineShape : public IShape
39 {
40 public:
41     LineShape() = default;
42 
LineShape(const ShapePointF & pos1,const ShapePointF & pos2)43     LineShape(const ShapePointF &pos1, const ShapePointF &pos2)
44         : m_pos1(pos1),
45           m_pos2(pos2)
46     {
47     }
48 
pos1()49     ShapePointF pos1() const { return m_pos1; }
pos2()50     ShapePointF pos2() const { return m_pos2; }
51 
52     IShape *clone() const override;
53     void accept(ShapeVisitor *visitor) override;
54     void accept(ShapeConstVisitor *visitor) const override;
55 
56 private:
57     ShapePointF m_pos1;
58     ShapePointF m_pos2;
59 };
60 
61 class QMT_EXPORT RectShape : public IShape
62 {
63 public:
64     RectShape() = default;
65 
RectShape(const ShapePointF & pos,const ShapeSizeF & size)66     RectShape(const ShapePointF &pos, const ShapeSizeF &size)
67         : m_pos(pos),
68           m_size(size)
69     {
70     }
71 
pos()72     ShapePointF pos() const { return m_pos; }
size()73     ShapeSizeF size() const { return m_size; }
74 
75     IShape *clone() const override;
76     void accept(ShapeVisitor *visitor) override;
77     void accept(ShapeConstVisitor *visitor) const override;
78 
79 private:
80     ShapePointF m_pos;
81     ShapeSizeF m_size;
82 };
83 
84 class QMT_EXPORT RoundedRectShape : public IShape
85 {
86 public:
87     RoundedRectShape() = default;
88 
RoundedRectShape(const ShapePointF & pos,const ShapeSizeF & size,const ShapeValueF & radius)89     RoundedRectShape(const ShapePointF &pos, const ShapeSizeF &size, const ShapeValueF &radius)
90         : m_pos(pos),
91           m_size(size),
92           m_radius(radius)
93     {
94     }
95 
pos()96     ShapePointF pos() const { return m_pos; }
size()97     ShapeSizeF size() const { return m_size; }
radius()98     ShapeValueF radius() const { return m_radius; }
99 
100     IShape *clone() const override;
101     void accept(ShapeVisitor *visitor) override;
102     void accept(ShapeConstVisitor *visitor) const override;
103 
104 private:
105     ShapePointF m_pos;
106     ShapeSizeF m_size;
107     ShapeValueF m_radius;
108 };
109 
110 class QMT_EXPORT CircleShape : public IShape
111 {
112 public:
113     CircleShape() = default;
114 
CircleShape(const ShapePointF & center,const ShapeValueF & radius)115     CircleShape(const ShapePointF &center, const ShapeValueF &radius)
116         : m_center(center),
117           m_radius(radius)
118     {
119     }
120 
center()121     ShapePointF center() const { return m_center; }
radius()122     ShapeValueF radius() const { return m_radius; }
123 
124     IShape *clone() const override;
125     void accept(ShapeVisitor *visitor) override;
126     void accept(ShapeConstVisitor *visitor) const override;
127 
128 private:
129     ShapePointF m_center;
130     ShapeValueF m_radius;
131 };
132 
133 class QMT_EXPORT EllipseShape : public IShape
134 {
135 public:
136     EllipseShape() = default;
137 
EllipseShape(const ShapePointF & center,const ShapeSizeF & radius)138     EllipseShape(const ShapePointF &center, const ShapeSizeF &radius)
139         : m_center(center),
140           m_radius(radius)
141     {
142     }
143 
center()144     ShapePointF center() const { return m_center; }
radius()145     ShapeSizeF radius() const { return m_radius; }
146 
147     IShape *clone() const override;
148     void accept(ShapeVisitor *visitor) override;
149     void accept(ShapeConstVisitor *visitor) const override;
150 
151 private:
152     ShapePointF m_center;
153     ShapeSizeF m_radius;
154 };
155 
156 class QMT_EXPORT DiamondShape : public IShape
157 {
158 public:
159     DiamondShape() = default;
160 
DiamondShape(const ShapePointF & center,const ShapeSizeF & size,bool filled)161     DiamondShape(const ShapePointF &center, const ShapeSizeF &size, bool filled)
162         : m_center(center),
163           m_size(size),
164           m_filled(filled)
165     {
166     }
167 
center()168     ShapePointF center() const { return m_center; }
size()169     ShapeSizeF size() const { return m_size; }
filled()170     bool filled() const { return m_filled; }
171 
172     IShape *clone() const override;
173     void accept(ShapeVisitor *visitor) override;
174     void accept(ShapeConstVisitor *visitor) const override;
175 
176 private:
177     ShapePointF m_center;
178     ShapeSizeF m_size;
179     bool m_filled = false;
180 };
181 
182 class QMT_EXPORT TriangleShape : public IShape
183 {
184 public:
185     TriangleShape() = default;
186 
TriangleShape(const ShapePointF & center,const ShapeSizeF & size,bool filled)187     TriangleShape(const ShapePointF &center, const ShapeSizeF &size, bool filled)
188         : m_center(center),
189           m_size(size),
190           m_filled(filled)
191     {
192     }
193 
center()194     ShapePointF center() const { return m_center; }
size()195     ShapeSizeF size() const { return m_size; }
filled()196     bool filled() const { return m_filled; }
197 
198     IShape *clone() const override;
199     void accept(ShapeVisitor *visitor) override;
200     void accept(ShapeConstVisitor *visitor) const override;
201 
202 private:
203     ShapePointF m_center;
204     ShapeSizeF m_size;
205     bool m_filled = false;
206 };
207 
208 class QMT_EXPORT ArcShape : public IShape
209 {
210 public:
211     ArcShape() = default;
212 
ArcShape(const ShapePointF & center,const ShapeSizeF & radius,qreal startAngle,qreal spanAngle)213     ArcShape(const ShapePointF &center, const ShapeSizeF &radius, qreal startAngle, qreal spanAngle)
214         : m_center(center),
215           m_radius(radius),
216           m_startAngle(startAngle),
217           m_spanAngle(spanAngle)
218     {
219     }
220 
center()221     ShapePointF center() const { return m_center; }
radius()222     ShapeSizeF radius() const { return m_radius; }
startAngle()223     qreal startAngle() const { return m_startAngle; }
spanAngle()224     qreal spanAngle() const { return m_spanAngle; }
225 
226     IShape *clone() const override;
227     void accept(ShapeVisitor *visitor) override;
228     void accept(ShapeConstVisitor *visitor) const override;
229 
230 private:
231     ShapePointF m_center;
232     ShapeSizeF m_radius;
233     qreal m_startAngle = 0.0;
234     qreal m_spanAngle = 0.0;
235 };
236 
237 class QMT_EXPORT PathShape : public IShape
238 {
239 public:
240     enum ElementType {
241         TypeNone,
242         TypeMoveto,
243         TypeLineto,
244         TypeArcmoveto,
245         TypeArcto,
246         TypeClose
247     };
248 
249     class Element
250     {
251     public:
252         explicit Element(ElementType element = TypeNone)
m_elementType(element)253             : m_elementType(element)
254         {
255         }
256 
257         ElementType m_elementType = TypeNone;
258         ShapePointF m_position;
259         ShapeSizeF m_size;
260         qreal m_angle1 = 0.0;
261         qreal m_angle2 = 0.0;
262     };
263 
264     PathShape();
265     ~PathShape() override;
266 
elements()267     QList<Element> elements() const { return m_elements; }
268 
269     IShape *clone() const override;
270     void accept(ShapeVisitor *visitor) override;
271     void accept(ShapeConstVisitor *visitor) const override;
272 
273     void moveTo(const ShapePointF &pos);
274     void lineTo(const ShapePointF &pos);
275     void arcMoveTo(const ShapePointF &center, const ShapeSizeF &radius, qreal angle);
276     void arcTo(const ShapePointF &center, const ShapeSizeF &radius,
277                qreal startAngle, qreal sweepLength);
278     void close();
279 
280 private:
281     QList<Element> m_elements;
282 };
283 
284 } // namespace qmt
285