• 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
  • annotate
AreaAnnotation.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 2009 Andrew Manson <g.real.ate@gmail.com>
9 // Copyright 2013 Thibaut Gridel <tgridel@free.fr>
10 //
11 #include "AreaAnnotation.h"
12 
13 #include "GeoDataPlacemark.h"
14 #include "GeoDataTypes.h"
15 #include "GeoPainter.h"
16 #include "ViewportParams.h"
17 
18 
19 namespace Marble
20 {
21 
22 
23 
24 AreaAnnotation::AreaAnnotation( GeoDataPlacemark *placemark )
25  :SceneGraphicsItem( placemark ),
26  m_movedPoint( -1 ),
27  m_viewport( 0 )
28 {
29 }
30 
31 void AreaAnnotation::paint(GeoPainter *painter, const ViewportParams *viewport )
32 {
33  m_viewport = viewport;
34  QList<QRegion> regionList;
35 
36  painter->save();
37  painter->setBrush( Oxygen::aluminumGray4 );
38  if( placemark()->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType ) {
39  GeoDataPolygon *polygon = static_cast<GeoDataPolygon*>( placemark()->geometry() );
40  GeoDataLinearRing &ring = polygon->outerBoundary();
41  for( int i=0; i< ring.size(); ++i ) {
42  painter->drawEllipse( ring.at(i) , 10, 10 );
43  regionList.append( painter->regionFromEllipse( ring.at(i), 10, 10 ));
44  }
45  regionList.append( painter->regionFromPolygon( ring, Qt::OddEvenFill ) );
46  }
47  painter->restore();
48  setRegions( regionList );
49 }
50 
51 bool AreaAnnotation::mousePressEvent( QMouseEvent *event )
52 {
53  QList<QRegion> regionList = regions();
54  // react to all ellipse point markers and skip the polygon
55  for( int i=0; i< regionList.size()-1; ++i ) {
56  if( regionList.at(i).contains( event->pos()) ) {
57  m_movedPoint = i;
58  return true;
59  }
60  }
61  return false;
62 }
63 
64 bool AreaAnnotation::mouseMoveEvent( QMouseEvent *event )
65 {
66  if( !m_viewport
67  || m_movedPoint < 0 ) {
68  return false;
69  }
70  if( placemark()->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType ) {
71  GeoDataPolygon *polygon = static_cast<GeoDataPolygon*>( placemark()->geometry() );
72  GeoDataLinearRing &ring = polygon->outerBoundary();
73  qreal lon, lat;
74  m_viewport->geoCoordinates( event->pos().x(),
75  event->pos().y(),
76  lon, lat,
77  GeoDataCoordinates::Radian );
78  ring[m_movedPoint] = GeoDataCoordinates( lon, lat );
79  return true;
80  }
81  return false;
82 }
83 
84 bool AreaAnnotation::mouseReleaseEvent( QMouseEvent *event )
85 {
86  Q_UNUSED(event);
87  m_movedPoint = -1;
88  return true;
89 }
90 
91 }
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataCoordinates::Radian
Definition: GeoDataCoordinates.h:65
Marble::GeoDataLinearRing
A LinearRing that allows to store a closed, contiguous set of line segments.
Definition: GeoDataLinearRing.h:68
Marble::GeoDataTypes::GeoDataPolygonType
const char * GeoDataPolygonType
Definition: GeoDataTypes.cpp:65
Marble::ViewportParams::geoCoordinates
bool geoCoordinates(const int x, const int y, qreal &lon, qreal &lat, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Degree) const
Get the earth coordinates corresponding to a pixel in the map.
Definition: ViewportParams.cpp:391
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::AreaAnnotation::paint
virtual void paint(GeoPainter *painter, const ViewportParams *viewport)
Paints the item using the given GeoPainter.
Definition: AreaAnnotation.cpp:31
Marble::GeoDataLineString::size
int size() const
Returns the number of nodes in a LineString.
Definition: GeoDataLineString.cpp:134
Marble::AreaAnnotation::mouseReleaseEvent
virtual bool mouseReleaseEvent(QMouseEvent *event)
Definition: AreaAnnotation.cpp:84
Marble::SceneGraphicsItem::setRegions
void setRegions(const QList< QRegion > &regions)
Definition: SceneGraphicsItem.cpp:76
AreaAnnotation.h
Marble::GeoPainter::drawEllipse
void drawEllipse(const GeoDataCoordinates &centerPosition, qreal width, qreal height, bool isGeoProjected=false)
Draws an ellipse at the given position. The ellipse is placed with its center located at the given ce...
Definition: GeoPainter.cpp:289
Marble::GeoPainter::regionFromEllipse
QRegion regionFromEllipse(const GeoDataCoordinates &centerPosition, qreal width, qreal height, bool isGeoProjected=false, qreal strokeWidth=3) const
Creates a region for an ellipse at a given position.
Definition: GeoPainter.cpp:356
Marble::GeoDataPlacemark::geometry
GeoDataGeometry * geometry() const
The geometry of the GeoDataPlacemark is to be rendered to the marble map along with the icon at the c...
Definition: GeoDataPlacemark.cpp:63
Marble::AreaAnnotation::AreaAnnotation
AreaAnnotation(GeoDataPlacemark *placemark)
Definition: AreaAnnotation.cpp:24
Marble::Oxygen::aluminumGray4
QColor const aluminumGray4
Definition: MarbleColors.h:92
Marble::SceneGraphicsItem
Definition: SceneGraphicsItem.h:28
Marble::AreaAnnotation::mouseMoveEvent
virtual bool mouseMoveEvent(QMouseEvent *event)
Definition: AreaAnnotation.cpp:64
Marble::GeoDataPolygon
A polygon that can have "holes".
Definition: GeoDataPolygon.h:81
GeoPainter.h
GeoDataPlacemark.h
Marble::GeoDataPolygon::outerBoundary
GeoDataLinearRing & outerBoundary()
Returns the outer boundary that is represented as a LinearRing.
Definition: GeoDataPolygon.cpp:85
Marble::GeoDataLineString::at
GeoDataCoordinates & at(int pos)
Returns a reference to the coordinates of a node at a given position. This method detaches the return...
Definition: GeoDataLineString.cpp:139
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::SceneGraphicsItem::placemark
GeoDataPlacemark * placemark()
Definition: SceneGraphicsItem.cpp:36
Marble::SceneGraphicsItem::regions
QList< QRegion > regions() const
Definition: SceneGraphicsItem.cpp:31
Marble::GeoPainter::regionFromPolygon
QRegion regionFromPolygon(const GeoDataLinearRing &linearRing, Qt::FillRule fillRule, qreal strokeWidth=3) const
Creates a region for a given linear ring (a "polygon without holes").
Definition: GeoPainter.cpp:585
GeoDataTypes.h
Marble::GeoDataPlacemark
a class representing a point of interest on the map
Definition: GeoDataPlacemark.h:54
Marble::AreaAnnotation::mousePressEvent
virtual bool mousePressEvent(QMouseEvent *event)
Definition: AreaAnnotation.cpp:51
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