• 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
  • crosshairs
CrosshairsPlugin.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 2008 Torsten Rahn <tackat@kde.org>
9 // Copyright 2010 Cezar Mocan <mocancezar@gmail.com>
10 //
11 
12 #include "CrosshairsPlugin.h"
13 #include "ui_CrosshairsConfigWidget.h"
14 
15 #include "GeoPainter.h"
16 #include "MarbleDebug.h"
17 #include "MarbleDirs.h"
18 #include "ViewportParams.h"
19 
20 #include <QRect>
21 #include <QColor>
22 #include <QPixmap>
23 #include <QPushButton>
24 #include <QSvgRenderer>
25 
26 
27 namespace Marble
28 {
29 
30 CrosshairsPlugin::CrosshairsPlugin()
31  : RenderPlugin( 0 ),
32  m_svgobj( 0 )
33 {
34 }
35 
36 CrosshairsPlugin::CrosshairsPlugin( const MarbleModel *marbleModel )
37  : RenderPlugin( marbleModel ),
38  m_isInitialized( false ),
39  m_svgobj( 0 ),
40  m_themeIndex( 0 ),
41  m_configDialog( 0 ),
42  m_uiConfigWidget( 0 )
43 {
44 }
45 
46 CrosshairsPlugin::~CrosshairsPlugin ()
47 {
48  delete m_svgobj;
49 }
50 
51 
52 QStringList CrosshairsPlugin::backendTypes() const
53 {
54  return QStringList( "crosshairs" );
55 }
56 
57 QString CrosshairsPlugin::renderPolicy() const
58 {
59  return QString( "ALWAYS" );
60 }
61 
62 QStringList CrosshairsPlugin::renderPosition() const
63 {
64  return QStringList( "FLOAT_ITEM" ); // although this is not a float item we choose the position of one
65 }
66 
67 RenderPlugin::RenderType CrosshairsPlugin::renderType() const
68 {
69  return RenderPlugin::TopLevelRenderType;
70 }
71 
72 QString CrosshairsPlugin::name() const
73 {
74  return tr( "Crosshairs" );
75 }
76 
77 QString CrosshairsPlugin::guiString() const
78 {
79  return tr( "Cross&hairs" );
80 }
81 
82 QString CrosshairsPlugin::nameId() const
83 {
84  return QString( "crosshairs" );
85 }
86 
87 QString CrosshairsPlugin::version() const
88 {
89  return "1.0";
90 }
91 
92 QString CrosshairsPlugin::description() const
93 {
94  return tr( "A plugin that shows crosshairs." );
95 }
96 
97 QString CrosshairsPlugin::copyrightYears() const
98 {
99  return "2009, 2010";
100 }
101 
102 QList<PluginAuthor> CrosshairsPlugin::pluginAuthors() const
103 {
104  return QList<PluginAuthor>()
105  << PluginAuthor( "Cezar Mocan", "cezarmocan@gmail.com" )
106  << PluginAuthor( "Torsten Rahn", "tackat@kde.org" );
107 }
108 
109 QIcon CrosshairsPlugin::icon () const
110 {
111  return QIcon( ":/icons/crosshairs.png" );
112 }
113 
114 void CrosshairsPlugin::initialize ()
115 {
116  readSettings();
117  m_isInitialized = true;
118 }
119 
120 bool CrosshairsPlugin::isInitialized () const
121 {
122  return m_isInitialized;
123 }
124 
125 QDialog *CrosshairsPlugin::configDialog()
126 {
127  if ( !m_configDialog ) {
128  m_configDialog = new QDialog();
129  m_uiConfigWidget = new Ui::CrosshairsConfigWidget;
130  m_uiConfigWidget->setupUi( m_configDialog );
131  readSettings();
132  connect( m_uiConfigWidget->m_buttonBox, SIGNAL(accepted()),
133  SLOT(writeSettings()) );
134  connect( m_uiConfigWidget->m_buttonBox, SIGNAL(rejected()),
135  SLOT(readSettings()) );
136  QPushButton *applyButton = m_uiConfigWidget->m_buttonBox->button( QDialogButtonBox::Apply );
137  connect( applyButton, SIGNAL(clicked()),
138  this, SLOT(writeSettings()) );
139  }
140 
141  return m_configDialog;
142 }
143 
144 QHash<QString,QVariant> CrosshairsPlugin::settings() const
145 {
146  QHash<QString, QVariant> result = RenderPlugin::settings();
147 
148  result.insert( "theme", m_themeIndex );
149 
150  return result;
151 }
152 
153 void CrosshairsPlugin::setSettings( const QHash<QString,QVariant> &settings )
154 {
155  RenderPlugin::setSettings( settings );
156 
157  m_themeIndex = settings.value( "theme", 0 ).toInt();
158 
159  readSettings();
160 }
161 
162 
163 void CrosshairsPlugin::readSettings()
164 {
165  if ( m_uiConfigWidget && m_themeIndex >= 0 && m_themeIndex < m_uiConfigWidget->m_themeList->count() ) {
166  m_uiConfigWidget->m_themeList->setCurrentRow( m_themeIndex );
167  }
168 
169  QString theme = ":/crosshairs-pointed.svg";
170  switch( m_themeIndex ) {
171  case 1:
172  theme = ":/crosshairs-gun1.svg";
173  break;
174  case 2:
175  theme = ":/crosshairs-gun2.svg";
176  break;
177  case 3:
178  theme = ":/crosshairs-circled.svg";
179  break;
180  case 4:
181  theme = ":/crosshairs-german.svg";
182  break;
183  }
184 
185  delete m_svgobj;
186  CrosshairsPlugin * me = const_cast<CrosshairsPlugin*>( this );
187  m_svgobj = new QSvgRenderer( theme, me );
188  m_crosshairs = QPixmap();
189 }
190 
191 void CrosshairsPlugin::writeSettings()
192 {
193  if ( m_uiConfigWidget ) {
194  m_themeIndex = m_uiConfigWidget->m_themeList->currentRow();
195  }
196  readSettings();
197  emit settingsChanged( nameId() );
198 }
199 
200 bool CrosshairsPlugin::render( GeoPainter *painter, ViewportParams *viewport,
201  const QString& renderPos,
202  GeoSceneLayer * layer )
203 {
204  Q_UNUSED( renderPos )
205  Q_UNUSED( layer )
206 
207  const int width = 21;
208  const int height = 21;
209 
210  if ( m_crosshairs.isNull() ) {
211  painter->setRenderHint( QPainter::Antialiasing, true );
212  m_crosshairs = QPixmap( QSize( width, height ) );
213  m_crosshairs.fill( Qt::transparent );
214  QPainter mapPainter( &m_crosshairs );
215  m_svgobj->render( &mapPainter );
216  }
217 
218  GeoDataCoordinates const focusPoint = viewport->focusPoint();
219  GeoDataCoordinates const centerPoint = GeoDataCoordinates( viewport->centerLongitude(), viewport->centerLatitude() );
220  if ( focusPoint == centerPoint ) {
221  // Focus point is in the middle of the screen. Special casing this avoids jittering.
222  int centerX = viewport->size().width() / 2;
223  int centerY = viewport->size().height() / 2;
224  painter->drawPixmap( QPoint ( centerX - width / 2, centerY - height / 2 ), m_crosshairs );
225  } else {
226  qreal centerX = 0.0;
227  qreal centerY = 0.0;
228  viewport->screenCoordinates( focusPoint, centerX, centerY );
229  painter->drawPixmap( QPoint ( centerX - width / 2, centerY - height / 2 ), m_crosshairs );
230  }
231 
232  return true;
233 }
234 
235 }
236 
237 Q_EXPORT_PLUGIN2( CrosshairsPlugin, Marble::CrosshairsPlugin )
238 
239 #include "CrosshairsPlugin.moc"
QPainter
Marble::RenderPlugin::TopLevelRenderType
Definition: RenderPlugin.h:61
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::ViewportParams::size
QSize size() const
Definition: ViewportParams.cpp:260
Marble::CrosshairsPlugin::render
bool render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer=0)
Renders the content provided by the layer on the viewport.
Definition: CrosshairsPlugin.cpp:200
Marble::CrosshairsPlugin
The class that specifies the Marble layer interface of a plugin.
Definition: CrosshairsPlugin.h:39
QDialog
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::PluginAuthor
Definition: PluginInterface.h:28
Marble::CrosshairsPlugin::description
QString description() const
Returns a user description of the plugin.
Definition: CrosshairsPlugin.cpp:92
Marble::CrosshairsPlugin::renderPolicy
QString renderPolicy() const
Return how the plugin settings should be used.
Definition: CrosshairsPlugin.cpp:57
MarbleDebug.h
Marble::CrosshairsPlugin::renderPosition
QStringList renderPosition() const
Preferred level in the layer stack for the rendering.
Definition: CrosshairsPlugin.cpp:62
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
Marble::CrosshairsPlugin::~CrosshairsPlugin
~CrosshairsPlugin()
Definition: CrosshairsPlugin.cpp:46
Marble::CrosshairsPlugin::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: CrosshairsPlugin.cpp:52
Marble::ViewportParams::focusPoint
GeoDataCoordinates focusPoint() const
Definition: ViewportParams.cpp:413
Marble::RenderPlugin::settingsChanged
void settingsChanged(QString nameId)
This signal is emitted if the settings of the RenderPlugin changed.
MarbleDirs.h
CrosshairsPlugin.h
Marble::CrosshairsPlugin::pluginAuthors
QList< PluginAuthor > pluginAuthors() const
Definition: CrosshairsPlugin.cpp:102
Marble::ViewportParams::screenCoordinates
bool screenCoordinates(const qreal lon, const qreal lat, qreal &x, qreal &y) const
Get the screen coordinates corresponding to geographical coordinates in the map.
Definition: ViewportParams.cpp:357
GeoPainter.h
Marble::CrosshairsPlugin::isInitialized
bool isInitialized() const
Definition: CrosshairsPlugin.cpp:120
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::CrosshairsPlugin::renderType
virtual RenderType renderType() const
Render type of the plugin.
Definition: CrosshairsPlugin.cpp:67
Q_EXPORT_PLUGIN2
#define Q_EXPORT_PLUGIN2(a, b)
Definition: marble_export.h:34
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::ViewportParams::centerLatitude
qreal centerLatitude() const
Definition: ViewportParams.cpp:294
Marble::CrosshairsPlugin::setSettings
void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
Definition: CrosshairsPlugin.cpp:153
Marble::CrosshairsPlugin::guiString
QString guiString() const
String that should be displayed in GUI.
Definition: CrosshairsPlugin.cpp:77
Marble::CrosshairsPlugin::initialize
void initialize()
Definition: CrosshairsPlugin.cpp:114
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:96
Marble::CrosshairsPlugin::icon
QIcon icon() const
Returns an icon for the plugin.
Definition: CrosshairsPlugin.cpp:109
Marble::CrosshairsPlugin::settings
QHash< QString, QVariant > settings() const
Settings of the plugin.
Definition: CrosshairsPlugin.cpp:144
Marble::CrosshairsPlugin::configDialog
QDialog * configDialog()
Returns a pointer to the configuration dialog of the plugin.
Definition: CrosshairsPlugin.cpp:125
Marble::ViewportParams::centerLongitude
qreal centerLongitude() const
Definition: ViewportParams.cpp:289
Marble::CrosshairsPlugin::nameId
QString nameId() const
Returns the unique name of the plugin.
Definition: CrosshairsPlugin.cpp:82
Marble::CrosshairsPlugin::copyrightYears
QString copyrightYears() const
Definition: CrosshairsPlugin.cpp:97
Marble::RenderPlugin::settings
virtual QHash< QString, QVariant > settings() const
Settings of the plugin.
Definition: RenderPlugin.cpp:183
Marble::RenderPlugin::RenderType
RenderType
A Type of plugin.
Definition: RenderPlugin.h:59
Marble::CrosshairsPlugin::version
QString version() const
Definition: CrosshairsPlugin.cpp:87
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::RenderPlugin::setSettings
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
Definition: RenderPlugin.cpp:193
Marble::CrosshairsPlugin::name
QString name() const
Returns the user-visible name of the plugin.
Definition: CrosshairsPlugin.cpp:72
Marble::CrosshairsPlugin::CrosshairsPlugin
CrosshairsPlugin()
Definition: CrosshairsPlugin.cpp:30
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