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