• 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
  • speedometer
Speedometer.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 2011 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
9 //
10 
11 #include "Speedometer.h"
12 
13 #include "MarbleGlobal.h"
14 #include "MarbleDebug.h"
15 #include "MarbleLocale.h"
16 #include "MarbleModel.h"
17 #include "PositionTracking.h"
18 #include "WidgetGraphicsItem.h"
19 #include "MarbleGraphicsGridLayout.h"
20 #include "ViewportParams.h"
21 
22 #include <QLCDNumber>
23 
24 namespace Marble
25 {
26 
27 Speedometer::Speedometer()
28  : AbstractFloatItem( 0 ),
29  m_locale( 0 ),
30  m_widgetItem( 0 )
31 {
32 }
33 
34 Speedometer::Speedometer( const MarbleModel *marbleModel )
35  : AbstractFloatItem( marbleModel, QPointF( 10.5, 110 ), QSizeF( 135.0, 80.0 ) ),
36  m_locale( 0 ),
37  m_widgetItem( 0 )
38 {
39  setVisible( false );
40 
41  const bool smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
42  if ( smallScreen ) {
43  setPosition( QPointF( 10.5, 10.5 ) );
44  }
45 }
46 
47 Speedometer::~Speedometer()
48 {
49 }
50 
51 QStringList Speedometer::backendTypes() const
52 {
53  return QStringList( "speedometer" );
54 }
55 
56 QString Speedometer::name() const
57 {
58  return tr( "Speedometer" );
59 }
60 
61 QString Speedometer::guiString() const
62 {
63  return tr( "&Speedometer" );
64 }
65 
66 QString Speedometer::nameId() const
67 {
68  return QString( "speedometer" );
69 }
70 
71 QString Speedometer::version() const
72 {
73  return "1.0";
74 }
75 
76 QString Speedometer::description() const
77 {
78  return tr( "Display the current cruising speed." );
79 }
80 
81 QString Speedometer::copyrightYears() const
82 {
83  return "2011";
84 }
85 
86 QList<PluginAuthor> Speedometer::pluginAuthors() const
87 {
88  return QList<PluginAuthor>()
89  << PluginAuthor( "Bernhard Beschow", "bbeschow@cs.tu-berlin.de" );
90 }
91 
92 QIcon Speedometer::icon () const
93 {
94  return QIcon(":/icons/speedometer.png");
95 }
96 
97 void Speedometer::initialize ()
98 {
99  if ( !m_widgetItem ) {
100  QWidget *widget = new QWidget;
101  m_widget.setupUi( widget );
102  m_widgetItem = new WidgetGraphicsItem( this );
103  m_widgetItem->setWidget( widget );
104 
105  MarbleGraphicsGridLayout *layout = new MarbleGraphicsGridLayout( 1, 1 );
106  layout->addItem( m_widgetItem, 0, 0 );
107  setLayout( layout );
108  setPadding( 0 );
109 
110  m_locale = MarbleGlobal::getInstance()->locale();
111  connect( marbleModel()->positionTracking(), SIGNAL(gpsLocation(GeoDataCoordinates,qreal)),
112  this, SLOT(updateLocation(GeoDataCoordinates,qreal)) );
113  }
114 }
115 
116 bool Speedometer::isInitialized () const
117 {
118  return m_widgetItem;
119 }
120 
121 void Speedometer::updateLocation( GeoDataCoordinates coordinates, qreal speed )
122 {
123  Q_UNUSED( coordinates );
124 
125  speed *= METER2KM / SEC2HOUR;
126  QString speedUnit;
127 
128  switch ( m_locale->measurementSystem() ) {
129  case MarbleLocale::ImperialSystem:
130  //miles per hour
131  speedUnit = tr("mph");
132  speed *= KM2MI;
133  break;
134 
135  case MarbleLocale::MetricSystem:
136  //kilometers per hour
137  speedUnit = tr("km/h");
138  break;
139 
140  case MarbleLocale::NauticalSystem:
141  // nm per hour (kt)
142  speedUnit = tr("kt");
143  speed *= KM2NM;
144  break;
145  }
146 
147  m_widget.speed->display( speed );
148  m_widget.speedUnit->setText( speedUnit );
149 
150  update();
151  emit repaintNeeded();
152 }
153 
154 }
155 
156 Q_EXPORT_PLUGIN2( Speedometer, Marble::Speedometer )
157 
158 #include "Speedometer.moc"
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
QWidget
Marble::Speedometer::nameId
QString nameId() const
Returns the unique name of the plugin.
Definition: Speedometer.cpp:66
Marble::WidgetGraphicsItem::setWidget
void setWidget(QWidget *widget)
Definition: WidgetGraphicsItem.cpp:48
Marble::MarbleLocale::NauticalSystem
Definition: MarbleLocale.h:40
Marble::MarbleLocale::measurementSystem
MarbleLocale::MeasurementSystem measurementSystem() const
Definition: MarbleLocale.cpp:45
Marble::RenderPlugin::repaintNeeded
void repaintNeeded(QRegion dirtyRegion=QRegion())
This signal is emitted if an update of the view is needed.
Marble::Speedometer::description
QString description() const
Returns a user description of the plugin.
Definition: Speedometer.cpp:76
Marble::Speedometer::icon
QIcon icon() const
Returns an icon for the plugin.
Definition: Speedometer.cpp:92
Marble::Speedometer
The class that displays Position Tracking info.
Definition: Speedometer.h:37
MarbleModel.h
This file contains the headers for MarbleModel.
Marble::PluginAuthor
Definition: PluginInterface.h:28
Marble::Speedometer::Speedometer
Speedometer()
Definition: Speedometer.cpp:27
Marble::MarbleGraphicsItem::setLayout
void setLayout(AbstractMarbleGraphicsLayout *layout)
Set the layout of the graphics item.
Definition: MarbleGraphicsItem.cpp:146
Marble::MarbleGraphicsGridLayout::addItem
void addItem(ScreenGraphicsItem *item, int row, int column)
Definition: MarbleGraphicsGridLayout.cpp:74
MarbleDebug.h
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
QPointF
Marble::Speedometer::name
QString name() const
Returns the user-visible name of the plugin.
Definition: Speedometer.cpp:56
Marble::Speedometer::~Speedometer
~Speedometer()
Definition: Speedometer.cpp:47
Marble::Speedometer::version
QString version() const
Definition: Speedometer.cpp:71
Marble::AbstractFloatItem
The abstract class for float item plugins.
Definition: AbstractFloatItem.h:45
Marble::Speedometer::copyrightYears
QString copyrightYears() const
Definition: Speedometer.cpp:81
Marble::MarbleGraphicsGridLayout
Definition: MarbleGraphicsGridLayout.h:27
Marble::MarbleGlobal::locale
MarbleLocale * locale() const
Definition: MarbleGlobal.cpp:43
QString
QList
MarbleLocale.h
MarbleGlobal.h
Marble::WidgetGraphicsItem
Definition: WidgetGraphicsItem.h:28
WidgetGraphicsItem.h
Marble::METER2KM
const qreal METER2KM
Definition: MarbleGlobal.h:224
QStringList
Marble::Speedometer::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: Speedometer.cpp:51
Q_EXPORT_PLUGIN2
#define Q_EXPORT_PLUGIN2(a, b)
Definition: marble_export.h:34
Marble::KM2MI
const qreal KM2MI
Definition: MarbleGlobal.h:203
MarbleGraphicsGridLayout.h
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::MarbleGlobal::SmallScreen
Definition: MarbleGlobal.h:287
Marble::MarbleGlobal::getInstance
static MarbleGlobal * getInstance()
Definition: MarbleGlobal.cpp:37
Marble::MarbleLocale::MetricSystem
Definition: MarbleLocale.h:38
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:97
QSizeF
Marble::ScreenGraphicsItem::setPosition
void setPosition(const QPointF &position)
Set the position of the ScreenGraphicsItem.
Definition: ScreenGraphicsItem.cpp:44
Marble::SEC2HOUR
const qreal SEC2HOUR
Definition: MarbleGlobal.h:236
Marble::MarbleGlobal::profiles
Profiles profiles() const
Definition: MarbleGlobal.cpp:48
Speedometer.h
Marble::Speedometer::guiString
QString guiString() const
String that should be displayed in GUI.
Definition: Speedometer.cpp:61
Marble::MarbleGraphicsItem::update
void update()
Marks the item and all parent items as invalid.
Definition: MarbleGraphicsItem.cpp:167
Marble::MarbleGraphicsItem::layout
AbstractMarbleGraphicsLayout * layout() const
Returns the layout of the MarbleGraphicsItem.
Definition: MarbleGraphicsItem.cpp:141
Marble::MarbleLocale::ImperialSystem
Definition: MarbleLocale.h:39
Marble::Speedometer::pluginAuthors
QList< PluginAuthor > pluginAuthors() const
Definition: Speedometer.cpp:86
Marble::KM2NM
const qreal KM2NM
Definition: MarbleGlobal.h:207
PositionTracking.h
Marble::RenderPlugin::marbleModel
const MarbleModel * marbleModel() const
Access to the MarbleModel.
Definition: RenderPlugin.cpp:83
Marble::FrameGraphicsItem::setPadding
void setPadding(qreal width)
Set the padding of the item.
Definition: FrameGraphicsItem.cpp:126
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Marble::Speedometer::initialize
void initialize()
Definition: Speedometer.cpp:97
Marble::Speedometer::isInitialized
bool isInitialized() const
Definition: Speedometer.cpp:116
QIcon
Marble::AbstractFloatItem::setVisible
void setVisible(bool visible)
Set visibility of the float item.
Definition: AbstractFloatItem.cpp:130
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:42 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