1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2008 Torsten Rahn <tackat@kde.org>
4 //
5 
6 #include "TestPlugin.h"
7 
8 #include <QColor>
9 #include <QPixmap>
10 #include <QIcon>
11 #include <QRadialGradient>
12 #include "MarbleDirs.h"
13 #include "GeoPainter.h"
14 #include "GeoDataCoordinates.h"
15 #include "GeoDataLineString.h"
16 #include "GeoDataLinearRing.h"
17 
18 namespace Marble
19 {
20 
TestPlugin()21 TestPlugin::TestPlugin()
22     : RenderPlugin(nullptr)
23 {
24     setEnabled(true);
25     setVisible(true);
26 }
27 
TestPlugin(const MarbleModel * marbleModel)28 TestPlugin::TestPlugin(const MarbleModel *marbleModel)
29     : RenderPlugin(marbleModel)
30 {
31     setEnabled(true);
32     setVisible(true);
33 }
34 
35 
backendTypes() const36 QStringList TestPlugin::backendTypes() const
37 {
38     return QStringList(QStringLiteral("test"));
39 }
40 
renderPolicy() const41 QString TestPlugin::renderPolicy() const
42 {
43     return QStringLiteral("ALWAYS");
44 }
45 
renderPosition() const46 QStringList TestPlugin::renderPosition() const
47 {
48     return QStringList(QStringLiteral("ALWAYS_ON_TOP"));
49 }
50 
name() const51 QString TestPlugin::name() const
52 {
53     return tr( "Test Plugin" );
54 }
55 
guiString() const56 QString TestPlugin::guiString() const
57 {
58     return tr( "&Test Plugin" );
59 }
60 
nameId() const61 QString TestPlugin::nameId() const
62 {
63     return QStringLiteral("test-plugin");
64 }
65 
version() const66 QString TestPlugin::version() const
67 {
68     return QStringLiteral("1.0");
69 }
70 
description() const71 QString TestPlugin::description() const
72 {
73     return tr( "This is a simple test plugin." );
74 }
75 
copyrightYears() const76 QString TestPlugin::copyrightYears() const
77 {
78     return QStringLiteral("2008");
79 }
80 
pluginAuthors() const81 QVector<PluginAuthor> TestPlugin::pluginAuthors() const
82 {
83     return QVector<PluginAuthor>()
84             << PluginAuthor(QStringLiteral("Torsten Rahn"), QStringLiteral("tackat@kde.org"));
85 }
86 
icon() const87 QIcon TestPlugin::icon () const
88 {
89     return QIcon();
90 }
91 
92 
initialize()93 void TestPlugin::initialize ()
94 {
95 }
96 
isInitialized() const97 bool TestPlugin::isInitialized () const
98 {
99     return true;
100 }
101 
render(GeoPainter * painter,ViewportParams * viewport,const QString & renderPos,GeoSceneLayer * layer)102 bool TestPlugin::render( GeoPainter *painter, ViewportParams *viewport, const QString& renderPos, GeoSceneLayer * layer )
103 {
104     Q_UNUSED(viewport);
105     Q_UNUSED(renderPos);
106     Q_UNUSED(layer);
107 
108     // Example: draw a straight line
109 
110     GeoDataCoordinates northpole1( 0.0, 90.0, 0.0, GeoDataCoordinates::Degree );
111     GeoDataCoordinates northpole2( 0.0, 90.0, 3000000.0, GeoDataCoordinates::Degree );
112 
113     painter->setPen( QColor( 255, 255, 255, 255 ) );
114 
115     GeoDataLineString poleLineString;
116     poleLineString << northpole1 << northpole2;
117     painter->drawPolyline(poleLineString);
118 
119     // Example: draw a straight line string ("polyline")
120 
121     GeoDataCoordinates madrid( -3.7, 40.4, 0.0, GeoDataCoordinates::Degree );
122     GeoDataCoordinates flensburg( 9.4, 54.8, 0.0, GeoDataCoordinates::Degree );
123     GeoDataCoordinates linkoeping( 15.6, 58.4, 0.0, GeoDataCoordinates::Degree );
124     GeoDataCoordinates istanbul( 28.0, 41.0, 0.0, GeoDataCoordinates::Degree );
125     GeoDataCoordinates moscow( 37.6, 55.75, 0.0, GeoDataCoordinates::Degree );
126     GeoDataCoordinates brasilia( -47.9, -15.75, 0.0, GeoDataCoordinates::Degree );
127     GeoDataCoordinates orbit( 105.6, 0.0, 3000000.0, GeoDataCoordinates::Degree );
128     GeoDataCoordinates easteregg( 10.0, 70.0, 0.0, GeoDataCoordinates::Degree );
129     GeoDataCoordinates easteregg2( 179.0, -40.0, 0.0, GeoDataCoordinates::Degree );
130 
131     painter->setPen( QColor( 200, 200, 200, 255 ) );
132 
133     GeoDataLineString lineString;
134     lineString << madrid << flensburg << linkoeping << istanbul << moscow;
135 
136     painter->drawPolyline( lineString );
137 
138     // Example: draw plain filled circles with text on earth and in earth orbit
139 
140     painter->setPen( QColor( 99, 198, 99, 255 ) );
141     painter->setBrush( QColor( 99, 198, 99, 80 ) );
142     painter->drawEllipse( flensburg, 30, 30 );
143 
144     painter->drawText( flensburg, "Torsten" );
145 
146     painter->setPen( QColor( 198, 99, 99, 255 ) );
147     painter->setBrush( QColor( 198, 99, 99, 80 ) );
148     painter->drawEllipse( linkoeping, 30, 30 );
149 
150     painter->drawText( linkoeping, "Inge" );
151 
152     painter->drawEllipse( easteregg, 20, 10, true );
153 
154     painter->drawText( easteregg, "Easter Egg" );
155 
156     painter->drawEllipse( easteregg2, 20, 20, true );
157 
158 
159     painter->setPen( QColor( 99, 99, 198, 255 ) );
160     painter->setBrush( QColor( 99, 99, 198, 80 ) );
161     painter->drawEllipse( orbit, 20, 20 );
162 
163     painter->drawText( orbit, "Claudiu" );
164 
165     // Example: draw plain pixmaps
166 
167     painter->drawPixmap(istanbul, QPixmap(MarbleDirs::path(QStringLiteral("bitmaps/earth_apollo.jpg"))));
168 
169     painter->drawImage(brasilia, QImage(MarbleDirs::path(QStringLiteral("bitmaps/earth_apollo.jpg")));
170 
171     // Example: draw a plain rectangle and a rounded rectangle
172 
173     painter->setPen( QColor( 99, 198, 198, 255 ) );
174     QBrush brush( QColor( 99, 198, 198, 80 ) );
175     painter->setBrush( brush );
176 
177     painter->drawRect( madrid, 30, 30 );
178 
179     painter->setPen( QColor( 198, 99, 198, 255 ) );
180     brush.setColor( QColor( 198, 99, 198, 180 ) );
181     brush.setStyle( Qt::DiagCrossPattern );
182     painter->setBrush( brush );
183 
184     painter->drawRoundedRect(moscow, 40, 40);
185 
186     // Example: draw earth orbit
187 
188     GeoDataCoordinates m1(-180.0, 0.0, 3000000.0, GeoDataCoordinates::Degree );
189     GeoDataCoordinates m2(-90.0, 0.0, 3000000.0, GeoDataCoordinates::Degree );
190     GeoDataCoordinates m3(0.0, 0.0, 3000000.0, GeoDataCoordinates::Degree );
191     GeoDataCoordinates m4(+90.0, 0.0, 3000000.0, GeoDataCoordinates::Degree );
192     GeoDataCoordinates m5(+180.0, 0.0, 3000000.0, GeoDataCoordinates::Degree );
193 
194     GeoDataLineString ring( Tessellate );
195 
196     ring << m1 << m2 << m3 << m4 << m5;
197 
198     painter->drawPolyline( ring );
199 
200     // Example: draw a triangle with lines that follow the coordinate grid
201 
202     painter->setPen( QColor( 198, 99, 99, 255 ) );
203     brush.setColor( QColor( 198, 99, 99, 180 ) );
204     brush.setStyle( Qt::FDiagPattern );
205     painter->setBrush( brush );
206 
207     GeoDataCoordinates t1(0.0, 90.0, 0.0, GeoDataCoordinates::Degree );
208     GeoDataCoordinates t2(-12.5, 45.0, 0.0, GeoDataCoordinates::Degree );
209     GeoDataCoordinates t3(-77.5, 45.0, 0.0, GeoDataCoordinates::Degree );
210 
211     GeoDataLinearRing triangle( Tessellate | RespectLatitudeCircle );
212 
213     triangle << t1 << t2 << t3;
214 
215     painter->drawPolygon( triangle, Qt::OddEvenFill );
216 
217     // Example: draw a triangle with lines that follow the great circles
218 
219     GeoDataLinearRing triangle2( Tessellate );
220 
221     GeoDataCoordinates t4(0.0, 90.0, 0.0, GeoDataCoordinates::Degree );
222     GeoDataCoordinates t5(-102.5, 45.0, 0.0, GeoDataCoordinates::Degree );
223     GeoDataCoordinates t6(-167.5, 45.0, 0.0, GeoDataCoordinates::Degree );
224 
225     triangle2 << t4 << t5 << t6;
226 
227     painter->drawPolygon( triangle2, Qt::OddEvenFill );
228 
229     // Example: draw a triangle with straight lines
230 
231     GeoDataLinearRing triangle3;
232 
233     GeoDataCoordinates t7(0.0, 90.0, 0.0, GeoDataCoordinates::Degree );
234     GeoDataCoordinates t8(102.5, 35.0, 0.0, GeoDataCoordinates::Degree );
235     GeoDataCoordinates t9(167.5, 45.0, 0.0, GeoDataCoordinates::Degree );
236 
237     triangle3 << t7 << t8 << t9;
238 
239     painter->drawPolygon( triangle3, Qt::OddEvenFill );
240 
241 
242     // Example: draw a polygon across the dateline
243 
244     GeoDataLinearRing dateLinePolygon( Tessellate | RespectLatitudeCircle );
245 
246     GeoDataCoordinates t10(+170.0, 40.0, 0.0, GeoDataCoordinates::Degree );
247     GeoDataCoordinates t11(-170.0, 40.0, 0.0, GeoDataCoordinates::Degree );
248     GeoDataCoordinates t12(-170.0, 35.0, 0.0, GeoDataCoordinates::Degree );
249     GeoDataCoordinates t13(+175.0, 35.0, 0.0, GeoDataCoordinates::Degree );
250     GeoDataCoordinates t14(+175.0, 25.0, 0.0, GeoDataCoordinates::Degree );
251     GeoDataCoordinates t15(-170.0, 25.0, 0.0, GeoDataCoordinates::Degree );
252     GeoDataCoordinates t16(-170.0, 15.0, 0.0, GeoDataCoordinates::Degree );
253     GeoDataCoordinates t17(+170.0, 20.0, 0.0, GeoDataCoordinates::Degree );
254 
255     dateLinePolygon << t10 << t11 << t12 << t13 << t14 << t15 << t16 << t17;
256 
257     painter->drawPolygon( dateLinePolygon, Qt::OddEvenFill );
258 
259     // Example: draw a rectangle with lines that follow the coordinate grid
260 
261     GeoDataCoordinates rectCenter( -45.0, 20.0, 0.0, GeoDataCoordinates::Degree );
262     painter->drawRect( rectCenter, 20.0, 20.0, true );
263 
264 
265     // Example: draw annotations
266 
267     GeoDataCoordinates sotm(4.89, 52.37, 0.0, GeoDataCoordinates::Degree );
268 
269     painter->setPen( QColor( 198, 99, 99, 255 ) );
270     brush.setColor( QColor( 255, 255, 255, 200 ) );
271     brush.setStyle( Qt::SolidPattern );
272     painter->setBrush( brush );
273 
274     painter->drawAnnotation (  sotm, "State of the Map,\n  10-12 July 2009,\n OSM conference", QSize(140,100), 10, 30, 15, 15 );
275 
276     GeoDataCoordinates akademy2009( -15.43, 28.1, 0.0, GeoDataCoordinates::Degree );
277 
278     painter->setPen( QColor( 99, 99, 0 ) );
279 
280     QRadialGradient radialGrad(QPointF(100, 100), 100);
281     radialGrad.setColorAt(0, QColor( 198, 198, 198, 200 ) );
282     radialGrad.setColorAt(0.5, QColor( 199, 198, 99, 200  ) );
283     radialGrad.setColorAt( 1, Qt::white );
284     radialGrad.setSpread( QGradient::ReflectSpread );
285 
286     QBrush gradientBrush( radialGrad );
287     painter->setBrush( gradientBrush );
288 
289     painter->drawAnnotation (  akademy2009, "Akademy 2009,\n  3-11 July 2009,\n KDE conference" );
290 
291     return true;
292 }
293 
294 }
295 
296 #include "moc_TestPlugin.cpp"
297