1 /*
2  *    Copyright 2012, 2013 Thomas Schöps
3  *    Copyright 2012-2017 Kai Pastor
4  *
5  *    This file is part of OpenOrienteering.
6  *
7  *    OpenOrienteering is free software: you can redistribute it and/or modify
8  *    it under the terms of the GNU General Public License as published by
9  *    the Free Software Foundation, either version 3 of the License, or
10  *    (at your option) any later version.
11  *
12  *    OpenOrienteering is distributed in the hope that it will be useful,
13  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *    GNU General Public License for more details.
16  *
17  *    You should have received a copy of the GNU General Public License
18  *    along with OpenOrienteering.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #ifndef OPENORIENTEERING_RENDERABLE_IMPLENTATION_H
23 #define OPENORIENTEERING_RENDERABLE_IMPLENTATION_H
24 
25 #include <Qt>
26 #include <QtGlobal>
27 #include <QPainterPath>
28 #include <QPointF>
29 #include <QRectF>
30 
31 #include "renderable.h"
32 
33 class QPainter;
34 class QPointF;
35 
36 namespace OpenOrienteering {
37 
38 class AreaSymbol;
39 class LineSymbol;
40 class MapColor;
41 class MapCoordF;
42 class PathPartVector;
43 class PointSymbol;
44 class TextObject;
45 class TextSymbol;
46 class VirtualPath;
47 
48 
49 /** Renderable for displaying a filled dot. */
50 class DotRenderable : public Renderable
51 {
52 public:
53 	DotRenderable(const PointSymbol* symbol, MapCoordF coord);
54 	void render(QPainter& painter, const RenderConfig& config) const override;
55 	PainterConfig getPainterConfig(const QPainterPath* clip_path = nullptr) const override;
56 };
57 
58 /** Renderable for displaying a circle. */
59 class CircleRenderable : public Renderable
60 {
61 public:
62 	CircleRenderable(const PointSymbol* symbol, MapCoordF coord);
63 	void render(QPainter& painter, const RenderConfig& config) const override;
64 	PainterConfig getPainterConfig(const QPainterPath* clip_path = nullptr) const override;
65 
66 protected:
67 	const qreal line_width;
68 	QRectF rect;
69 };
70 
71 /** Renderable for displaying a line. */
72 class LineRenderable : public Renderable
73 {
74 public:
75 	LineRenderable(const LineSymbol* symbol, const VirtualPath& virtual_path, bool closed);
76 	LineRenderable(const LineSymbol* symbol, QPointF first, QPointF second);
77 	void render(QPainter& painter, const RenderConfig& config) const override;
78 	PainterConfig getPainterConfig(const QPainterPath* clip_path = nullptr) const override;
79 
80 protected:
81 	void extentIncludeCap(quint32 i, qreal half_line_width, bool end_cap, const LineSymbol* symbol, const VirtualPath& path);
82 
83 	void extentIncludeJoin(quint32 i, qreal half_line_width, const LineSymbol* symbol, const VirtualPath& path);
84 
85 	const qreal line_width;
86 	QPainterPath path;
87 	Qt::PenCapStyle cap_style;
88 	Qt::PenJoinStyle join_style;
89 };
90 
91 /** Renderable for displaying an area. */
92 class AreaRenderable : public Renderable
93 {
94 public:
95 	AreaRenderable(const AreaSymbol* symbol, const PathPartVector& path_parts);
96 	AreaRenderable(const AreaSymbol* symbol, const VirtualPath& path);
97 	void render(QPainter& painter, const RenderConfig& config) const override;
98 	PainterConfig getPainterConfig(const QPainterPath* clip_path = nullptr) const override;
99 
100 	inline const QPainterPath* painterPath() const;
101 
102 protected:
103 	void addSubpath(const VirtualPath& virtual_path);
104 
105 	QPainterPath path;
106 };
107 
108 /** Renderable for displaying text. */
109 class TextRenderable : public Renderable
110 {
111 public:
112 	TextRenderable(const TextSymbol* symbol, const TextObject* text_object, const MapColor* color, double anchor_x, double anchor_y);
113 	PainterConfig getPainterConfig(const QPainterPath* clip_path = nullptr) const override;
114 	void render(QPainter& painter, const RenderConfig& config) const override;
115 
116 protected:
117 	void renderCommon(QPainter& painter, const RenderConfig& config) const;
118 
119 	QPainterPath path;
120 	qreal anchor_x;
121 	qreal anchor_y;
122 	qreal rotation;
123 	qreal scale_factor;
124 };
125 
126 /** Renderable for displaying framing line for text. */
127 class TextFramingRenderable : public TextRenderable
128 {
129 public:
130 	TextFramingRenderable(const TextSymbol* symbol, const TextObject* text_object, const MapColor* color, double anchor_x, double anchor_y);
131 	PainterConfig getPainterConfig(const QPainterPath* clip_path = nullptr) const override;
132 	void render(QPainter& painter, const RenderConfig& config) const override;
133 
134 protected:
135 	qreal framing_line_width;
136 };
137 
138 
139 
140 // ### AreaRenderable inline code ###
141 
painterPath()142 const QPainterPath* AreaRenderable::painterPath() const
143 {
144 	return &path;
145 }
146 
147 
148 }  // namespace OpenOrienteering
149 
150 #endif
151