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

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • geodata
  • graphicsitem
GeoLineStringGraphicsItem.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 //
10 
11 #include "GeoLineStringGraphicsItem.h"
12 
13 #include "GeoDataLineString.h"
14 #include "GeoDataLineStyle.h"
15 #include "GeoPainter.h"
16 #include "ViewportParams.h"
17 #include "GeoDataStyle.h"
18 
19 namespace Marble
20 {
21 
22 GeoLineStringGraphicsItem::GeoLineStringGraphicsItem( const GeoDataFeature *feature, const GeoDataLineString* lineString )
23  : GeoGraphicsItem( feature ),
24  m_lineString( lineString )
25 {
26 }
27 
28 void GeoLineStringGraphicsItem::setLineString( const GeoDataLineString* lineString )
29 {
30  m_lineString = lineString;
31 }
32 
33 const GeoDataLatLonAltBox& GeoLineStringGraphicsItem::latLonAltBox() const
34 {
35  return m_lineString->latLonAltBox();
36 }
37 
38 void GeoLineStringGraphicsItem::paint( GeoPainter* painter, const ViewportParams* viewport )
39 {
40  LabelPositionFlags labelPositionFlags = NoLabel;
41 
42  painter->save();
43 
44  if ( !style() ) {
45  painter->setPen( QPen() );
46  }
47  else {
48  QPen currentPen = painter->pen();
49 
50  if ( currentPen.color() != style()->lineStyle().paintedColor() )
51  currentPen.setColor( style()->lineStyle().paintedColor() );
52 
53  if ( currentPen.widthF() != style()->lineStyle().width() ||
54  style()->lineStyle().physicalWidth() != 0.0 ) {
55  if ( float( viewport->radius() ) / EARTH_RADIUS * style()->lineStyle().physicalWidth() < style()->lineStyle().width() )
56  currentPen.setWidthF( style()->lineStyle().width() );
57  else
58  currentPen.setWidthF( float( viewport->radius() ) / EARTH_RADIUS * style()->lineStyle().physicalWidth() );
59  }
60  else if ( style()->lineStyle().width() != 0.0 ) {
61  currentPen.setWidthF( style()->lineStyle().width() );
62  }
63 
64  if ( currentPen.capStyle() != style()->lineStyle().capStyle() )
65  currentPen.setCapStyle( style()->lineStyle().capStyle() );
66 
67  if ( currentPen.style() != style()->lineStyle().penStyle() )
68  currentPen.setStyle( style()->lineStyle().penStyle() );
69 
70  if ( style()->lineStyle().penStyle() == Qt::CustomDashLine )
71  currentPen.setDashPattern( style()->lineStyle().dashPattern() );
72 
73  if ( painter->mapQuality() != Marble::HighQuality
74  && painter->mapQuality() != Marble::PrintQuality ) {
75  QColor penColor = currentPen.color();
76  penColor.setAlpha( 255 );
77  currentPen.setColor( penColor );
78  }
79 
80  if ( painter->pen() != currentPen )
81  painter->setPen( currentPen );
82 
83  if ( style()->lineStyle().background() ) {
84  QBrush brush = painter->background();
85  brush.setColor( style()->polyStyle().paintedColor() );
86  painter->setBackground( brush );
87 
88  painter->setBackgroundMode( Qt::OpaqueMode );
89  }
90 
91  // label styles
92  painter->setFont( style()->labelStyle().font() );
93  switch ( style()->labelStyle().alignment() ) {
94  case GeoDataLabelStyle::Corner:
95  labelPositionFlags |= LineStart;
96  break;
97  case GeoDataLabelStyle::Center:
98  labelPositionFlags |= LineCenter;
99  break;
100  }
101  }
102 
103  painter->drawPolyline( *m_lineString, feature()->name(), labelPositionFlags );
104 
105  painter->restore();
106 }
107 
108 }
Marble::GeoDataLineStyle::capStyle
Qt::PenCapStyle capStyle() const
Return the current pen cap style.
Definition: GeoDataLineStyle.cpp:115
Marble::GeoLineStringGraphicsItem::m_lineString
const GeoDataLineString * m_lineString
Definition: GeoLineStringGraphicsItem.h:35
QPen::style
Qt::PenStyle style() const
QPainter::setBackgroundMode
void setBackgroundMode(Qt::BGMode mode)
QPen::setStyle
void setStyle(Qt::PenStyle style)
Marble::GeoGraphicsItem::style
const GeoDataStyle * style() const
Returns the style of item.
Definition: GeoGraphicsItem.cpp:82
QPainter::background
const QBrush & background() const
Marble::GeoLineStringGraphicsItem::setLineString
void setLineString(const GeoDataLineString *lineString)
Definition: GeoLineStringGraphicsItem.cpp:28
QPainter::setBackground
void setBackground(const QBrush &brush)
Marble::GeoDataLineStyle::penStyle
Qt::PenStyle penStyle() const
Return the current pen cap style.
Definition: GeoDataLineStyle.cpp:125
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::GeoLineStringGraphicsItem::paint
virtual void paint(GeoPainter *painter, const ViewportParams *viewport)
Paints the item using the given GeoPainter.
Definition: GeoLineStringGraphicsItem.cpp:38
GeoDataStyle.h
QPainter::save
void save()
Marble::GeoGraphicsItem
Definition: GeoGraphicsItem.h:30
Marble::GeoGraphicsItem::feature
const GeoDataFeature * feature() const
Returns the placemark for that item.
Definition: GeoGraphicsItem.cpp:62
QColor::setAlpha
void setAlpha(int alpha)
Marble::GeoPainter::drawPolyline
void drawPolyline(const GeoDataLineString &lineString, const QString &labelText=QString(), LabelPositionFlags labelPositionFlags=LineCenter)
Draws a given line string (a "polyline").
Definition: GeoPainter.cpp:474
QBrush
Marble::PrintQuality
Print quality.
Definition: MarbleGlobal.h:87
GeoDataLineStyle.h
Marble::GeoDataStyle::lineStyle
GeoDataLineStyle & lineStyle()
Return the label style of this style.
Definition: GeoDataStyle.cpp:143
Marble::GeoDataLineStyle::width
float width() const
Return the current width of the line.
Definition: GeoDataLineStyle.cpp:100
QPen::setCapStyle
void setCapStyle(Qt::PenCapStyle style)
QPen::color
QColor color() const
QPainter::setFont
void setFont(const QFont &font)
QPen::setDashPattern
void setDashPattern(const QVector< qreal > &pattern)
Marble::EARTH_RADIUS
const qreal EARTH_RADIUS
Definition: MarbleGlobal.h:257
QPainter::setPen
void setPen(const QColor &color)
Marble::LineCenter
Definition: MarbleGlobal.h:113
GeoDataLineString.h
QPen::setWidthF
void setWidthF(qreal width)
Marble::NoLabel
Definition: MarbleGlobal.h:111
Marble::LineStart
Definition: MarbleGlobal.h:112
QColor
GeoPainter.h
QPen::setColor
void setColor(const QColor &color)
GeoLineStringGraphicsItem.h
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::GeoDataLabelStyle::Center
Definition: GeoDataLabelStyle.h:39
ViewportParams.h
This file contains the headers for ViewportParams.
QPainter::restore
void restore()
Marble::ViewportParams::radius
int radius() const
Definition: ViewportParams.cpp:195
Marble::HighQuality
High quality (e.g. antialiasing for lines)
Definition: MarbleGlobal.h:86
Marble::GeoDataLabelStyle::Corner
Definition: GeoDataLabelStyle.h:39
QPen::capStyle
Qt::PenCapStyle capStyle() const
Marble::GeoDataFeature
A base class for all geodata features.
Definition: GeoDataFeature.h:57
Marble::GeoLineStringGraphicsItem::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Returns the bounding box covered by the item.
Definition: GeoLineStringGraphicsItem.cpp:33
QPen::widthF
qreal widthF() const
QPen
Marble::GeoLineStringGraphicsItem::GeoLineStringGraphicsItem
GeoLineStringGraphicsItem(const GeoDataFeature *feature, const GeoDataLineString *lineString)
Definition: GeoLineStringGraphicsItem.cpp:22
Marble::GeoPainter::mapQuality
MapQuality mapQuality() const
Returns the map quality.
Definition: GeoPainter.cpp:191
Marble::GeoDataLineStyle::physicalWidth
float physicalWidth() const
Return the current physical width of the line.
Definition: GeoDataLineStyle.cpp:105
QBrush::setColor
void setColor(const QColor &color)
QPainter::pen
const QPen & pen() const
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
Marble::GeoDataLineString::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Returns the smallest latLonAltBox that contains the LineString.
Definition: GeoDataLineString.cpp:580
Marble::GeoDataColorStyle::paintedColor
QColor paintedColor() const
Returns the color that should be painted: Either color() or a randomized version of it...
Definition: GeoDataColorStyle.cpp:103
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 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
  • 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