• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • plugins
  • render
  • atmosphere
AtmospherePlugin.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2006-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 // Copyright 2008-2010 Jens-Michael Hoffmann <jmho@c-xx.com>
11 // Copyright 2008-2009 Patrick Spendrin <ps_ml@gmx.de>
12 // Copyright 2010-2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
13 // Copyright 2012 Mohammed Nafees <nafees.technocool@gmail.com>
14 // Copyright 2012 Kovalevskyy Illya <illya.kovalevskyy@gmail.com>
15 //
16 
17 #include "AtmospherePlugin.h"
18 #include "Planet.h"
19 
20 #include "GeoPainter.h"
21 #include "ViewportParams.h"
22 #include "MarbleModel.h"
23 
24 namespace Marble
25 {
26 
27 AtmospherePlugin::AtmospherePlugin() :
28  RenderPlugin( 0 ),
29  m_renderRadius(-1)
30 {
31 }
32 
33 AtmospherePlugin::AtmospherePlugin( const MarbleModel *marbleModel ) :
34  RenderPlugin( marbleModel ),
35  m_renderRadius(-1)
36 {
37  connect( marbleModel, SIGNAL(themeChanged(QString)),
38  this, SLOT(updateTheme()) );
39 }
40 
41 QStringList AtmospherePlugin::backendTypes() const
42 {
43  return QStringList( "atmosphere" );
44 }
45 
46 QString AtmospherePlugin::renderPolicy() const
47 {
48  return QString( "SPECIFIED_ALWAYS" );
49 }
50 
51 QStringList AtmospherePlugin::renderPosition() const
52 {
53  return QStringList() << "SURFACE";
54 }
55 
56 RenderPlugin::RenderType AtmospherePlugin::renderType() const
57 {
58  return RenderPlugin::ThemeRenderType;
59 }
60 
61 QString AtmospherePlugin::name() const
62 {
63  return tr( "Atmosphere" );
64 }
65 
66 QString AtmospherePlugin::guiString() const
67 {
68  return tr( "&Atmosphere" );
69 }
70 
71 QString AtmospherePlugin::nameId() const
72 {
73  return "atmosphere";
74 }
75 
76 QString AtmospherePlugin::version() const
77 {
78  return "1.0";
79 }
80 
81 QString AtmospherePlugin::description() const
82 {
83  return tr( "Shows the atmosphere around the earth." );
84 }
85 
86 QIcon AtmospherePlugin::icon() const
87 {
88  return QIcon(":/icons/atmosphere.png");
89 }
90 
91 QString AtmospherePlugin::copyrightYears() const
92 {
93  return "2006-2012";
94 }
95 
96 QList<PluginAuthor> AtmospherePlugin::pluginAuthors() const
97 {
98  return QList<PluginAuthor>()
99  << PluginAuthor( "Torsten Rahn", "tackat@kde.org" )
100  << PluginAuthor( "Inge Wallin", "ingwa@kde.org" )
101  << PluginAuthor( "Jens-Michael Hoffmann", "jmho@c-xx.com" )
102  << PluginAuthor( "Patrick Spendrin", "ps_ml@gmx.de" )
103  << PluginAuthor( "Bernhard Beschow", "bbeschow@cs.tu-berlin.de" )
104  << PluginAuthor( "Mohammed Nafees", "nafees.technocool@gmail.com" );
105 }
106 
107 qreal AtmospherePlugin::zValue() const
108 {
109  return -100.0;
110 }
111 
112 void AtmospherePlugin::initialize()
113 {
114  /* nothing to do */
115 }
116 
117 bool AtmospherePlugin::isInitialized() const
118 {
119  return true;
120 }
121 
122 void AtmospherePlugin::updateTheme()
123 {
124  bool hasAtmosphere = marbleModel()->planet()->hasAtmosphere();
125  setEnabled( hasAtmosphere );
126  setVisible( hasAtmosphere );
127 }
128 
129 bool AtmospherePlugin::render( GeoPainter *painter,
130  ViewportParams *viewParams,
131  const QString &renderPos,
132  GeoSceneLayer *layer )
133 {
134  Q_UNUSED(renderPos)
135  Q_UNUSED(layer)
136 
137  if ( !visible() || !marbleModel()->planet()->hasAtmosphere() )
138  return true;
139 
140  // Only draw an atmosphere if projection is spherical
141  if ( viewParams->projection() != Spherical )
142  return true;
143 
144  // No use to draw atmosphere if it's not visible in the area.
145  if ( viewParams->mapCoversViewport() )
146  return true;
147 
148  // Gradient should be recalculated only if planet color or size changed
149  if(viewParams->radius() != m_renderRadius || marbleModel()->planet()->atmosphereColor() != m_renderColor) {
150  m_renderRadius = viewParams->radius();
151  m_renderColor = marbleModel()->planet()->atmosphereColor();
152  repaintPixmap(viewParams);
153  }
154  int imageHalfWidth = viewParams->width() / 2;
155  int imageHalfHeight = viewParams->height() / 2;
156  painter->drawPixmap(imageHalfWidth - (int) ( (qreal) ( viewParams->radius() ) * 1.05 ),
157  imageHalfHeight - (int) ( (qreal) ( viewParams->radius() ) * 1.05 ),
158  m_renderPixmap);
159  return true;
160 }
161 
162 void AtmospherePlugin::repaintPixmap(const ViewportParams *viewParams)
163 {
164  int imageHalfWidth = 1.05 * viewParams->radius();
165  int imageHalfHeight = 1.05 * viewParams->radius();
166 
167  int diameter = (int) ( 2.1 * (qreal) ( viewParams->radius()));
168  m_renderPixmap = QPixmap(diameter, diameter);
169  m_renderPixmap.fill(QColor(Qt::transparent));
170 
171  QPainter renderPainter(&m_renderPixmap);
172 
173  QColor color = marbleModel()->planet()->atmosphereColor();
174 
175  // Recalculate the atmosphere effect and paint it to canvasImage.
176  QRadialGradient grad( QPointF( imageHalfWidth, imageHalfHeight ),
177  1.05 * viewParams->radius() );
178  grad.setColorAt( 0.91, color );
179  grad.setColorAt( 1.00, QColor(color.red(), color.green(), color.blue(), 0) );
180 
181  QBrush brush(grad);
182  renderPainter.setBrush(brush);
183  renderPainter.setPen(Qt::NoPen);
184  renderPainter.setRenderHint(QPainter::Antialiasing, false);
185 
186  // Let's paint elipse we want in this::render(..) on pixmap from point (0;0)
187  renderPainter.drawEllipse(0, 0, diameter, diameter);
188 }
189 
190 }
191 
192 Q_EXPORT_PLUGIN2( AtmospherePlugin, Marble::AtmospherePlugin )
193 
194 #include "AtmospherePlugin.moc"
QPainter
Marble::RenderPlugin::visible
bool visible() const
is visible
Marble::AtmospherePlugin::pluginAuthors
QList< PluginAuthor > pluginAuthors() const
Definition: AtmospherePlugin.cpp:96
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
MarbleModel.h
This file contains the headers for MarbleModel.
Marble::AtmospherePlugin::name
QString name() const
Returns the user-visible name of the plugin.
Definition: AtmospherePlugin.cpp:61
Marble::AtmospherePlugin::icon
QIcon icon() const
Returns an icon for the plugin.
Definition: AtmospherePlugin.cpp:86
Marble::AtmospherePlugin::zValue
qreal zValue() const
Returns the z value of the layer (default: 0.0).
Definition: AtmospherePlugin.cpp:107
Marble::PluginAuthor
Definition: PluginInterface.h:28
Marble::ViewportParams::projection
Projection projection() const
Definition: ViewportParams.cpp:129
Planet.h
Marble::MarbleModel::planet
const Planet * planet() const
Returns the planet object for the current map.
Definition: MarbleModel.cpp:574
Marble::ViewportParams::height
int height() const
Definition: ViewportParams.cpp:255
Marble::AtmospherePlugin::render
bool render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer=0)
Renders the content provided by the layer on the viewport.
Definition: AtmospherePlugin.cpp:129
Marble::AtmospherePlugin::nameId
QString nameId() const
Returns the unique name of the plugin.
Definition: AtmospherePlugin.cpp:71
Marble::AtmospherePlugin::renderPosition
QStringList renderPosition() const
Preferred level in the layer stack for the rendering.
Definition: AtmospherePlugin.cpp:51
Marble::AtmospherePlugin::updateTheme
void updateTheme()
Definition: AtmospherePlugin.cpp:122
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
Marble::Planet::hasAtmosphere
bool hasAtmosphere() const
Definition: Planet.cpp:402
Marble::ViewportParams::width
int width() const
Definition: ViewportParams.cpp:250
Marble::AtmospherePlugin
Definition: AtmospherePlugin.h:20
Marble::ViewportParams::mapCoversViewport
bool mapCoversViewport() const
Definition: ViewportParams.cpp:398
Marble::AtmospherePlugin::renderPolicy
QString renderPolicy() const
Return how the plugin settings should be used.
Definition: AtmospherePlugin.cpp:46
Marble::RenderPlugin::setVisible
void setVisible(bool visible)
settting visible
Definition: RenderPlugin.cpp:149
Marble::AtmospherePlugin::backendTypes
QStringList backendTypes() const
Returns the name(s) of the backend that the plugin can render This method should return the name of t...
Definition: AtmospherePlugin.cpp:41
Marble::AtmospherePlugin::isInitialized
bool isInitialized() const
Definition: AtmospherePlugin.cpp:117
GeoPainter.h
Marble::AtmospherePlugin::guiString
QString guiString() const
String that should be displayed in GUI.
Definition: AtmospherePlugin.cpp:66
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::AtmospherePlugin::copyrightYears
QString copyrightYears() const
Definition: AtmospherePlugin.cpp:91
Q_EXPORT_PLUGIN2
#define Q_EXPORT_PLUGIN2(a, b)
Definition: marble_export.h:34
Marble::AtmospherePlugin::AtmospherePlugin
AtmospherePlugin()
Definition: AtmospherePlugin.cpp:27
AtmospherePlugin.h
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::AtmospherePlugin::initialize
void initialize()
Definition: AtmospherePlugin.cpp:112
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:96
Marble::RenderPlugin::setEnabled
void setEnabled(bool enabled)
settting enabled
Definition: RenderPlugin.cpp:137
Marble::AtmospherePlugin::version
QString version() const
Definition: AtmospherePlugin.cpp:76
Marble::ViewportParams::radius
int radius() const
Definition: ViewportParams.cpp:195
Marble::Planet::atmosphereColor
QColor atmosphereColor() const
Definition: Planet.cpp:412
Marble::AtmospherePlugin::renderType
virtual RenderType renderType() const
Render type of the plugin.
Definition: AtmospherePlugin.cpp:56
Marble::AtmospherePlugin::repaintPixmap
void repaintPixmap(const ViewportParams *viewParams)
Definition: AtmospherePlugin.cpp:162
Marble::RenderPlugin::ThemeRenderType
Definition: RenderPlugin.h:64
Marble::Spherical
Spherical projection.
Definition: MarbleGlobal.h:45
Marble::RenderPlugin::marbleModel
const MarbleModel * marbleModel() const
Access to the MarbleModel.
Definition: RenderPlugin.cpp:81
Marble::RenderPlugin::RenderType
RenderType
A Type of plugin.
Definition: RenderPlugin.h:59
Marble::GeoPainter::drawPixmap
void drawPixmap(const GeoDataCoordinates &centerPosition, const QPixmap &pixmap)
Draws a pixmap at the given position. The pixmap is placed with its center located at the given cente...
Definition: GeoPainter.cpp:452
Marble::RenderPlugin
The abstract class that creates a renderable item.
Definition: RenderPlugin.h:43
Marble::AtmospherePlugin::description
QString description() const
Returns a user description of the plugin.
Definition: AtmospherePlugin.cpp:81
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:49 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal