File indexing completed on 2024-05-05 03:50:53
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2008 Torsten Rahn <tackat@kde.org> 0004 // 0005 0006 #include "TestPlugin.h" 0007 0008 #include <QColor> 0009 #include <QPixmap> 0010 #include <QIcon> 0011 #include <QRadialGradient> 0012 #include "MarbleDirs.h" 0013 #include "GeoPainter.h" 0014 #include "GeoDataCoordinates.h" 0015 #include "GeoDataLineString.h" 0016 #include "GeoDataLinearRing.h" 0017 0018 namespace Marble 0019 { 0020 0021 TestPlugin::TestPlugin() 0022 : RenderPlugin(nullptr) 0023 { 0024 setEnabled(true); 0025 setVisible(true); 0026 } 0027 0028 TestPlugin::TestPlugin(const MarbleModel *marbleModel) 0029 : RenderPlugin(marbleModel) 0030 { 0031 setEnabled(true); 0032 setVisible(true); 0033 } 0034 0035 0036 QStringList TestPlugin::backendTypes() const 0037 { 0038 return QStringList(QStringLiteral("test")); 0039 } 0040 0041 QString TestPlugin::renderPolicy() const 0042 { 0043 return QStringLiteral("ALWAYS"); 0044 } 0045 0046 QStringList TestPlugin::renderPosition() const 0047 { 0048 return QStringList(QStringLiteral("ALWAYS_ON_TOP")); 0049 } 0050 0051 QString TestPlugin::name() const 0052 { 0053 return tr( "Test Plugin" ); 0054 } 0055 0056 QString TestPlugin::guiString() const 0057 { 0058 return tr( "&Test Plugin" ); 0059 } 0060 0061 QString TestPlugin::nameId() const 0062 { 0063 return QStringLiteral("test-plugin"); 0064 } 0065 0066 QString TestPlugin::version() const 0067 { 0068 return QStringLiteral("1.0"); 0069 } 0070 0071 QString TestPlugin::description() const 0072 { 0073 return tr( "This is a simple test plugin." ); 0074 } 0075 0076 QString TestPlugin::copyrightYears() const 0077 { 0078 return QStringLiteral("2008"); 0079 } 0080 0081 QVector<PluginAuthor> TestPlugin::pluginAuthors() const 0082 { 0083 return QVector<PluginAuthor>() 0084 << PluginAuthor(QStringLiteral("Torsten Rahn"), QStringLiteral("tackat@kde.org")); 0085 } 0086 0087 QIcon TestPlugin::icon () const 0088 { 0089 return QIcon(); 0090 } 0091 0092 0093 void TestPlugin::initialize () 0094 { 0095 } 0096 0097 bool TestPlugin::isInitialized () const 0098 { 0099 return true; 0100 } 0101 0102 bool TestPlugin::render( GeoPainter *painter, ViewportParams *viewport, const QString& renderPos, GeoSceneLayer * layer ) 0103 { 0104 Q_UNUSED(viewport); 0105 Q_UNUSED(renderPos); 0106 Q_UNUSED(layer); 0107 0108 // Example: draw a straight line 0109 0110 GeoDataCoordinates northpole1( 0.0, 90.0, 0.0, GeoDataCoordinates::Degree ); 0111 GeoDataCoordinates northpole2( 0.0, 90.0, 3000000.0, GeoDataCoordinates::Degree ); 0112 0113 painter->setPen( QColor( 255, 255, 255, 255 ) ); 0114 0115 GeoDataLineString poleLineString; 0116 poleLineString << northpole1 << northpole2; 0117 painter->drawPolyline(poleLineString); 0118 0119 // Example: draw a straight line string ("polyline") 0120 0121 GeoDataCoordinates madrid( -3.7, 40.4, 0.0, GeoDataCoordinates::Degree ); 0122 GeoDataCoordinates flensburg( 9.4, 54.8, 0.0, GeoDataCoordinates::Degree ); 0123 GeoDataCoordinates linkoeping( 15.6, 58.4, 0.0, GeoDataCoordinates::Degree ); 0124 GeoDataCoordinates istanbul( 28.0, 41.0, 0.0, GeoDataCoordinates::Degree ); 0125 GeoDataCoordinates moscow( 37.6, 55.75, 0.0, GeoDataCoordinates::Degree ); 0126 GeoDataCoordinates brasilia( -47.9, -15.75, 0.0, GeoDataCoordinates::Degree ); 0127 GeoDataCoordinates orbit( 105.6, 0.0, 3000000.0, GeoDataCoordinates::Degree ); 0128 GeoDataCoordinates easteregg( 10.0, 70.0, 0.0, GeoDataCoordinates::Degree ); 0129 GeoDataCoordinates easteregg2( 179.0, -40.0, 0.0, GeoDataCoordinates::Degree ); 0130 0131 painter->setPen( QColor( 200, 200, 200, 255 ) ); 0132 0133 GeoDataLineString lineString; 0134 lineString << madrid << flensburg << linkoeping << istanbul << moscow; 0135 0136 painter->drawPolyline( lineString ); 0137 0138 // Example: draw plain filled circles with text on earth and in earth orbit 0139 0140 painter->setPen( QColor( 99, 198, 99, 255 ) ); 0141 painter->setBrush( QColor( 99, 198, 99, 80 ) ); 0142 painter->drawEllipse( flensburg, 30, 30 ); 0143 0144 painter->drawText( flensburg, "Torsten" ); 0145 0146 painter->setPen( QColor( 198, 99, 99, 255 ) ); 0147 painter->setBrush( QColor( 198, 99, 99, 80 ) ); 0148 painter->drawEllipse( linkoeping, 30, 30 ); 0149 0150 painter->drawText( linkoeping, "Inge" ); 0151 0152 painter->drawEllipse( easteregg, 20, 10, true ); 0153 0154 painter->drawText( easteregg, "Easter Egg" ); 0155 0156 painter->drawEllipse( easteregg2, 20, 20, true ); 0157 0158 0159 painter->setPen( QColor( 99, 99, 198, 255 ) ); 0160 painter->setBrush( QColor( 99, 99, 198, 80 ) ); 0161 painter->drawEllipse( orbit, 20, 20 ); 0162 0163 painter->drawText( orbit, "Claudiu" ); 0164 0165 // Example: draw plain pixmaps 0166 0167 painter->drawPixmap(istanbul, QPixmap(MarbleDirs::path(QStringLiteral("bitmaps/earth_apollo.jpg")))); 0168 0169 painter->drawImage(brasilia, QImage(MarbleDirs::path(QStringLiteral("bitmaps/earth_apollo.jpg"))); 0170 0171 // Example: draw a plain rectangle and a rounded rectangle 0172 0173 painter->setPen( QColor( 99, 198, 198, 255 ) ); 0174 QBrush brush( QColor( 99, 198, 198, 80 ) ); 0175 painter->setBrush( brush ); 0176 0177 painter->drawRect( madrid, 30, 30 ); 0178 0179 painter->setPen( QColor( 198, 99, 198, 255 ) ); 0180 brush.setColor( QColor( 198, 99, 198, 180 ) ); 0181 brush.setStyle( Qt::DiagCrossPattern ); 0182 painter->setBrush( brush ); 0183 0184 painter->drawRoundedRect(moscow, 40, 40); 0185 0186 // Example: draw earth orbit 0187 0188 GeoDataCoordinates m1(-180.0, 0.0, 3000000.0, GeoDataCoordinates::Degree ); 0189 GeoDataCoordinates m2(-90.0, 0.0, 3000000.0, GeoDataCoordinates::Degree ); 0190 GeoDataCoordinates m3(0.0, 0.0, 3000000.0, GeoDataCoordinates::Degree ); 0191 GeoDataCoordinates m4(+90.0, 0.0, 3000000.0, GeoDataCoordinates::Degree ); 0192 GeoDataCoordinates m5(+180.0, 0.0, 3000000.0, GeoDataCoordinates::Degree ); 0193 0194 GeoDataLineString ring( Tessellate ); 0195 0196 ring << m1 << m2 << m3 << m4 << m5; 0197 0198 painter->drawPolyline( ring ); 0199 0200 // Example: draw a triangle with lines that follow the coordinate grid 0201 0202 painter->setPen( QColor( 198, 99, 99, 255 ) ); 0203 brush.setColor( QColor( 198, 99, 99, 180 ) ); 0204 brush.setStyle( Qt::FDiagPattern ); 0205 painter->setBrush( brush ); 0206 0207 GeoDataCoordinates t1(0.0, 90.0, 0.0, GeoDataCoordinates::Degree ); 0208 GeoDataCoordinates t2(-12.5, 45.0, 0.0, GeoDataCoordinates::Degree ); 0209 GeoDataCoordinates t3(-77.5, 45.0, 0.0, GeoDataCoordinates::Degree ); 0210 0211 GeoDataLinearRing triangle( Tessellate | RespectLatitudeCircle ); 0212 0213 triangle << t1 << t2 << t3; 0214 0215 painter->drawPolygon( triangle, Qt::OddEvenFill ); 0216 0217 // Example: draw a triangle with lines that follow the great circles 0218 0219 GeoDataLinearRing triangle2( Tessellate ); 0220 0221 GeoDataCoordinates t4(0.0, 90.0, 0.0, GeoDataCoordinates::Degree ); 0222 GeoDataCoordinates t5(-102.5, 45.0, 0.0, GeoDataCoordinates::Degree ); 0223 GeoDataCoordinates t6(-167.5, 45.0, 0.0, GeoDataCoordinates::Degree ); 0224 0225 triangle2 << t4 << t5 << t6; 0226 0227 painter->drawPolygon( triangle2, Qt::OddEvenFill ); 0228 0229 // Example: draw a triangle with straight lines 0230 0231 GeoDataLinearRing triangle3; 0232 0233 GeoDataCoordinates t7(0.0, 90.0, 0.0, GeoDataCoordinates::Degree ); 0234 GeoDataCoordinates t8(102.5, 35.0, 0.0, GeoDataCoordinates::Degree ); 0235 GeoDataCoordinates t9(167.5, 45.0, 0.0, GeoDataCoordinates::Degree ); 0236 0237 triangle3 << t7 << t8 << t9; 0238 0239 painter->drawPolygon( triangle3, Qt::OddEvenFill ); 0240 0241 0242 // Example: draw a polygon across the dateline 0243 0244 GeoDataLinearRing dateLinePolygon( Tessellate | RespectLatitudeCircle ); 0245 0246 GeoDataCoordinates t10(+170.0, 40.0, 0.0, GeoDataCoordinates::Degree ); 0247 GeoDataCoordinates t11(-170.0, 40.0, 0.0, GeoDataCoordinates::Degree ); 0248 GeoDataCoordinates t12(-170.0, 35.0, 0.0, GeoDataCoordinates::Degree ); 0249 GeoDataCoordinates t13(+175.0, 35.0, 0.0, GeoDataCoordinates::Degree ); 0250 GeoDataCoordinates t14(+175.0, 25.0, 0.0, GeoDataCoordinates::Degree ); 0251 GeoDataCoordinates t15(-170.0, 25.0, 0.0, GeoDataCoordinates::Degree ); 0252 GeoDataCoordinates t16(-170.0, 15.0, 0.0, GeoDataCoordinates::Degree ); 0253 GeoDataCoordinates t17(+170.0, 20.0, 0.0, GeoDataCoordinates::Degree ); 0254 0255 dateLinePolygon << t10 << t11 << t12 << t13 << t14 << t15 << t16 << t17; 0256 0257 painter->drawPolygon( dateLinePolygon, Qt::OddEvenFill ); 0258 0259 // Example: draw a rectangle with lines that follow the coordinate grid 0260 0261 GeoDataCoordinates rectCenter( -45.0, 20.0, 0.0, GeoDataCoordinates::Degree ); 0262 painter->drawRect( rectCenter, 20.0, 20.0, true ); 0263 0264 0265 // Example: draw annotations 0266 0267 GeoDataCoordinates sotm(4.89, 52.37, 0.0, GeoDataCoordinates::Degree ); 0268 0269 painter->setPen( QColor( 198, 99, 99, 255 ) ); 0270 brush.setColor( QColor( 255, 255, 255, 200 ) ); 0271 brush.setStyle( Qt::SolidPattern ); 0272 painter->setBrush( brush ); 0273 0274 painter->drawAnnotation ( sotm, "State of the Map,\n 10-12 July 2009,\n OSM conference", QSize(140,100), 10, 30, 15, 15 ); 0275 0276 GeoDataCoordinates akademy2009( -15.43, 28.1, 0.0, GeoDataCoordinates::Degree ); 0277 0278 painter->setPen( QColor( 99, 99, 0 ) ); 0279 0280 QRadialGradient radialGrad(QPointF(100, 100), 100); 0281 radialGrad.setColorAt(0, QColor( 198, 198, 198, 200 ) ); 0282 radialGrad.setColorAt(0.5, QColor( 199, 198, 99, 200 ) ); 0283 radialGrad.setColorAt( 1, Qt::white ); 0284 radialGrad.setSpread( QGradient::ReflectSpread ); 0285 0286 QBrush gradientBrush( radialGrad ); 0287 painter->setBrush( gradientBrush ); 0288 0289 painter->drawAnnotation ( akademy2009, "Akademy 2009,\n 3-11 July 2009,\n KDE conference" ); 0290 0291 return true; 0292 } 0293 0294 } 0295 0296 #include "moc_TestPlugin.cpp"