File indexing completed on 2025-01-05 03:59:24
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2006-2007 Torsten Rahn <tackat@kde.org> 0004 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org> 0005 // SPDX-FileCopyrightText: 2008-2010 Jens-Michael Hoffmann <jmho@c-xx.com> 0006 // SPDX-FileCopyrightText: 2008-2009 Patrick Spendrin <ps_ml@gmx.de> 0007 // SPDX-FileCopyrightText: 2010-2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de> 0008 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com> 0009 // SPDX-FileCopyrightText: 2012 Kovalevskyy Illya <illya.kovalevskyy@gmail.com> 0010 // 0011 0012 #include "AtmospherePlugin.h" 0013 0014 #include <QIcon> 0015 0016 #include <klocalizedstring.h> 0017 0018 #include "Planet.h" 0019 #include "GeoPainter.h" 0020 #include "ViewportParams.h" 0021 #include "MarbleModel.h" 0022 0023 namespace Marble 0024 { 0025 0026 AtmospherePlugin::AtmospherePlugin() : 0027 RenderPlugin( nullptr ), 0028 m_renderRadius(-1) 0029 { 0030 } 0031 0032 AtmospherePlugin::AtmospherePlugin( const MarbleModel *marbleModel ) : 0033 RenderPlugin( marbleModel ), 0034 m_renderRadius(-1) 0035 { 0036 connect( marbleModel, SIGNAL(themeChanged(QString)), 0037 this, SLOT(updateTheme()) ); 0038 } 0039 0040 QStringList AtmospherePlugin::backendTypes() const 0041 { 0042 return QStringList(QStringLiteral("atmosphere")); 0043 } 0044 0045 QString AtmospherePlugin::renderPolicy() const 0046 { 0047 return QStringLiteral("SPECIFIED_ALWAYS"); 0048 } 0049 0050 QStringList AtmospherePlugin::renderPosition() const 0051 { 0052 return QStringList(QStringLiteral("SURFACE")); 0053 } 0054 0055 RenderPlugin::RenderType AtmospherePlugin::renderType() const 0056 { 0057 return RenderPlugin::ThemeRenderType; 0058 } 0059 0060 QString AtmospherePlugin::name() const 0061 { 0062 return i18n( "Atmosphere" ); 0063 } 0064 0065 QString AtmospherePlugin::guiString() const 0066 { 0067 return i18n( "&Atmosphere" ); 0068 } 0069 0070 QString AtmospherePlugin::nameId() const 0071 { 0072 return QStringLiteral("atmosphere"); 0073 } 0074 0075 QString AtmospherePlugin::version() const 0076 { 0077 return QStringLiteral("1.0"); 0078 } 0079 0080 QString AtmospherePlugin::description() const 0081 { 0082 return i18n( "A plugin to show the atmosphere around the earth." ); 0083 } 0084 0085 QIcon AtmospherePlugin::icon() const 0086 { 0087 return QIcon::fromTheme(QStringLiteral("atmosphere")); 0088 } 0089 0090 QString AtmospherePlugin::copyrightYears() const 0091 { 0092 return QStringLiteral("2006-2012"); 0093 } 0094 0095 QVector<PluginAuthor> AtmospherePlugin::pluginAuthors() const 0096 { 0097 return QVector<PluginAuthor>() 0098 << PluginAuthor(QStringLiteral("Torsten Rahn"), QStringLiteral("tackat@kde.org")) 0099 << PluginAuthor(QStringLiteral("Inge Wallin"), QStringLiteral("ingwa@kde.org")) 0100 << PluginAuthor(QStringLiteral("Jens-Michael Hoffmann"), QStringLiteral("jmho@c-xx.com")) 0101 << PluginAuthor(QStringLiteral("Patrick Spendrin"), QStringLiteral("ps_ml@gmx.de")) 0102 << PluginAuthor(QStringLiteral("Bernhard Beschow"), QStringLiteral("bbeschow@cs.tu-berlin.de")) 0103 << PluginAuthor(QStringLiteral("Mohammed Nafees"), QStringLiteral("nafees.technocool@gmail.com")); 0104 } 0105 0106 qreal AtmospherePlugin::zValue() const 0107 { 0108 return -100.0; 0109 } 0110 0111 void AtmospherePlugin::initialize() 0112 { 0113 /* nothing to do */ 0114 } 0115 0116 bool AtmospherePlugin::isInitialized() const 0117 { 0118 return true; 0119 } 0120 0121 void AtmospherePlugin::updateTheme() 0122 { 0123 bool hasAtmosphere = marbleModel()->planet()->hasAtmosphere(); 0124 setEnabled( hasAtmosphere ); 0125 setVisible( hasAtmosphere ); 0126 } 0127 0128 bool AtmospherePlugin::render( GeoPainter *painter, 0129 ViewportParams *viewParams, 0130 const QString &renderPos, 0131 GeoSceneLayer *layer ) 0132 { 0133 Q_UNUSED(renderPos) 0134 Q_UNUSED(layer) 0135 0136 if ( !visible() || !marbleModel()->planet()->hasAtmosphere() ) 0137 return true; 0138 0139 // Only draw an atmosphere if projection is spherical 0140 if ( viewParams->projection() != Spherical && viewParams->projection() != VerticalPerspective ) 0141 return true; 0142 0143 // No use to draw atmosphere if it's not visible in the area. 0144 if ( viewParams->mapCoversViewport() ) 0145 return true; 0146 0147 // Gradient should be recalculated only if planet color or size changed 0148 if(viewParams->radius() != m_renderRadius || marbleModel()->planet()->atmosphereColor() != m_renderColor) { 0149 m_renderRadius = viewParams->radius(); 0150 m_renderColor = marbleModel()->planet()->atmosphereColor(); 0151 repaintPixmap(viewParams); 0152 } 0153 int imageHalfWidth = viewParams->width() / 2; 0154 int imageHalfHeight = viewParams->height() / 2; 0155 painter->drawPixmap(imageHalfWidth - (int) ( (qreal) ( viewParams->radius() ) * 1.05 ), 0156 imageHalfHeight - (int) ( (qreal) ( viewParams->radius() ) * 1.05 ), 0157 m_renderPixmap); 0158 return true; 0159 } 0160 0161 void AtmospherePlugin::repaintPixmap(const ViewportParams *viewParams) 0162 { 0163 int imageHalfWidth = 1.05 * viewParams->radius(); 0164 int imageHalfHeight = 1.05 * viewParams->radius(); 0165 0166 int diameter = (int) ( 2.1 * (qreal) ( viewParams->radius())); 0167 m_renderPixmap = QPixmap(diameter, diameter); 0168 m_renderPixmap.fill(QColor(Qt::transparent)); 0169 0170 QPainter renderPainter(&m_renderPixmap); 0171 0172 QColor color = marbleModel()->planet()->atmosphereColor(); 0173 0174 // Recalculate the atmosphere effect and paint it to canvasImage. 0175 QRadialGradient grad( QPointF( imageHalfWidth, imageHalfHeight ), 0176 1.05 * viewParams->radius() ); 0177 grad.setColorAt( 0.91, color ); 0178 grad.setColorAt( 1.00, QColor(color.red(), color.green(), color.blue(), 0) ); 0179 0180 QBrush brush(grad); 0181 renderPainter.setBrush(brush); 0182 renderPainter.setPen(Qt::NoPen); 0183 renderPainter.setRenderHint(QPainter::Antialiasing, false); 0184 0185 // Let's paint ellipse we want in this::render(..) on pixmap from point (0;0) 0186 renderPainter.drawEllipse(0, 0, diameter, diameter); 0187 } 0188 0189 } // namespace Marble 0190 0191 #include "moc_AtmospherePlugin.cpp"