• 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
  • plugins
  • render
  • aprs
AprsObject.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 2010 Wes Hardaker <marble@ws6z.com>
9 //
10 
11 #include "AprsObject.h"
12 
13 #include <QPixmap>
14 
15 #include "MarbleDebug.h"
16 #include "MarbleDirs.h"
17 #include "GeoDataLineString.h"
18 #include "GeoPainter.h"
19 #include "GeoAprsCoordinates.h"
20 
21 using namespace Marble;
22 
23 AprsObject::AprsObject( const GeoAprsCoordinates &at, const QString &name )
24  : m_myName( name ),
25  m_seenFrom( at.seenFrom() ),
26  m_havePixmap ( false ),
27  m_pixmapFilename( ),
28  m_pixmap( 0 )
29 {
30  m_history.push_back( at );
31 }
32 
33 AprsObject::~AprsObject()
34 {
35  delete m_pixmap;
36 }
37 
38 GeoAprsCoordinates
39 AprsObject::location() const
40 {
41  return m_history.last();
42 }
43 
44 void
45 AprsObject::setLocation( const GeoAprsCoordinates &location )
46 {
47  // Not ideal but it's unlikely they'll jump to the *exact* same spot again
48  if ( !m_history.contains( location ) ) {
49  m_history.push_back( location );
50  mDebug() << " moved: " << m_myName.toLocal8Bit().data();
51  } else {
52  int index = m_history.indexOf( location );
53  QTime now;
54  m_history[index].setTimestamp( now );
55  m_history[index].addSeenFrom( location.seenFrom() );
56  }
57 
58  m_seenFrom = ( m_seenFrom | location.seenFrom() );
59 }
60 
61 void
62 AprsObject::setPixmapId( QString &pixmap )
63 {
64  QString pixmapFilename = MarbleDirs::path( pixmap );
65  if ( QFile( pixmapFilename ).exists() ) {
66  m_havePixmap = true;
67  m_pixmapFilename = pixmapFilename;
68  // We can't load the pixmap here since it's used in a different thread
69  }
70  else {
71  m_havePixmap = false;
72  }
73 }
74 
75 QColor
76 AprsObject::calculatePaintColor( int from, const QTime &time, int fadeTime )
77 {
78  QColor color;
79  if ( from & GeoAprsCoordinates::Directly ) {
80  color = Oxygen::emeraldGreen4; // oxygen green if direct
81  } else if ( (from & ( GeoAprsCoordinates::FromTCPIP | GeoAprsCoordinates::FromTTY ) ) == ( GeoAprsCoordinates::FromTCPIP | GeoAprsCoordinates::FromTTY ) ) {
82  color = Oxygen::burgundyPurple4; // oxygen purple if both
83  } else if ( from & GeoAprsCoordinates::FromTCPIP ) {
84  color = Oxygen::brickRed4; // oxygen red if net
85  } else if ( from & GeoAprsCoordinates::FromTTY ) {
86  color = Oxygen::seaBlue4; // oxygen blue if TNC TTY relay
87  } else if ( from & ( GeoAprsCoordinates::FromFile ) ) {
88  color = Oxygen::sunYellow3; // oxygen yellow if file only
89  } else {
90  mDebug() << "**************************************** unknown from: "
91  << from;
92  color = Oxygen::aluminumGray5; // shouldn't happen but a user
93  // could mess up I suppose we
94  // should at least draw it in
95  // something.
96  }
97 
98  if ( fadeTime > 0 && time.elapsed() > fadeTime ) { // 5 min ( 600000 ms )
99  color.setAlpha( 160 );
100  }
101 
102  return color;
103 }
104 
105 void
106 AprsObject::render( GeoPainter *painter, ViewportParams *viewport,
107  int fadeTime, int hideTime )
108 {
109  Q_UNUSED( viewport );
110 
111  if ( hideTime > 0 && m_history.last().timestamp().elapsed() > hideTime )
112  return;
113 
114  QColor baseColor = calculatePaintColor( m_seenFrom,
115  m_history.last().timestamp(),
116  fadeTime );
117 
118  if ( m_history.count() > 1 ) {
119 
120  QList<GeoAprsCoordinates>::iterator spot = m_history.begin();
121  QList<GeoAprsCoordinates>::iterator endSpot = m_history.end();
122 
123  GeoDataLineString lineString;
124  lineString.setTessellate( true );
125  lineString << *spot; // *spot exists because m_history.count() > 1
126 
127  for( ++spot; spot != endSpot; ++spot ) {
128 
129  if ( hideTime > 0 && ( *spot ).timestamp().elapsed() > hideTime )
130  break;
131 
132  lineString << *spot;
133 
134  // draw the new circle in whatever is appropriate for that point
135  const QColor penColor = calculatePaintColor( spot->seenFrom(), spot->timestamp(), fadeTime );
136  painter->setPen( penColor );
137  painter->drawRect( *spot, 5, 5 );
138  }
139 
140  // draw the line in the base color
141  painter->setPen( baseColor );
142  painter->drawPolyline( lineString );
143  }
144 
145 
146  // Always draw the symbol then the text last so it's on top
147  if ( m_havePixmap ) {
148  if ( ! m_pixmap )
149  m_pixmap = new QPixmap ( m_pixmapFilename );
150  if ( m_pixmap && ! m_pixmap->isNull() )
151  painter->drawPixmap( m_history.last(), *m_pixmap );
152  else
153  painter->drawRect( m_history.last(), 6, 6 );
154  }
155  else
156  painter->drawRect( m_history.last(), 6, 6 );
157 
158  painter->setPen( baseColor );
159  painter->drawText( m_history.last(), m_myName );
160 }
Marble::GeoDataLineString::setTessellate
void setTessellate(bool tessellate)
Sets the tessellation property for the LineString.
Definition: GeoDataLineString.cpp:320
Marble::MarbleDirs::path
static QString path(const QString &relativePath)
Definition: MarbleDirs.cpp:59
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::GeoAprsCoordinates::Directly
Definition: GeoAprsCoordinates.h:28
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
Marble::AprsObject::~AprsObject
~AprsObject()
Definition: AprsObject.cpp:33
GeoAprsCoordinates.h
QTime
MarbleDebug.h
QFile
QTime::elapsed
int elapsed() const
Marble::GeoAprsCoordinates::FromTTY
Definition: GeoAprsCoordinates.h:25
Marble::GeoPainter::drawRect
void drawRect(const GeoDataCoordinates &centerPosition, qreal width, qreal height, bool isGeoProjected=false)
Draws a rectangle at the given position. The rectangle is placed with its center located at the given...
Definition: GeoPainter.cpp:700
AprsObject.h
QPainter::setPen
void setPen(const QColor &color)
Marble::AprsObject::setPixmapId
void setPixmapId(QString &pixmap)
Definition: AprsObject.cpp:62
MarbleDirs.h
GeoDataLineString.h
Marble::GeoAprsCoordinates::FromFile
Definition: GeoAprsCoordinates.h:27
Marble::AprsObject::calculatePaintColor
static QColor calculatePaintColor(int from, const QTime &time, int fadetime=10 *60 *1000)
Definition: AprsObject.cpp:76
Marble::AprsObject::setLocation
void setLocation(const GeoAprsCoordinates &location)
Definition: AprsObject.cpp:45
Marble::Oxygen::seaBlue4
QColor const seaBlue4
Definition: MarbleColors.h:62
Marble::AprsObject::render
void render(GeoPainter *painter, ViewportParams *viewport, int fadeTime=10 *60, int hideTime=30 *60)
Definition: AprsObject.cpp:106
Marble::GeoAprsCoordinates::seenFrom
int seenFrom() const
Definition: GeoAprsCoordinates.cpp:34
Marble::AprsObject::AprsObject
AprsObject(const GeoAprsCoordinates &at, const QString &name)
Definition: AprsObject.cpp:23
Marble::GeoAprsCoordinates::FromTCPIP
Definition: GeoAprsCoordinates.h:26
QString
QColor
GeoPainter.h
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
QList::iterator
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
QPixmap
QString::toLocal8Bit
QByteArray toLocal8Bit() const
QPixmap::isNull
bool isNull() const
Marble::AprsObject::location
GeoAprsCoordinates location() const
Definition: AprsObject.cpp:39
Marble::Oxygen::brickRed4
QColor const brickRed4
Definition: MarbleColors.h:32
Marble::GeoPainter::drawText
void drawText(const GeoDataCoordinates &position, const QString &text)
Draws the given text at a given geographic position. The text is drawn starting at the given position...
Definition: GeoPainter.cpp:264
Marble::Oxygen::aluminumGray5
QColor const aluminumGray5
Definition: MarbleColors.h:91
Marble::GeoAprsCoordinates
Definition: GeoAprsCoordinates.h:19
Marble::Oxygen::burgundyPurple4
QColor const burgundyPurple4
Definition: MarbleColors.h:44
Marble::Oxygen::emeraldGreen4
QColor const emeraldGreen4
Definition: MarbleColors.h:68
QByteArray::data
char * data()
Marble::Oxygen::sunYellow3
QColor const sunYellow3
Definition: MarbleColors.h:81
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:38 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