• 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
  • 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_widgetItem( 0 )
30 {
31 }
32 
33 Speedometer::Speedometer( const MarbleModel *marbleModel )
34  : AbstractFloatItem( marbleModel, QPointF( 10.5, 110 ), QSizeF( 135.0, 80.0 ) ),
35  m_widgetItem( 0 )
36 {
37  setVisible( false );
38 
39  const bool smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
40  if ( smallScreen ) {
41  setPosition( QPointF( 10.5, 10.5 ) );
42  }
43 }
44 
45 Speedometer::~Speedometer()
46 {
47 }
48 
49 QStringList Speedometer::backendTypes() const
50 {
51  return QStringList( "speedometer" );
52 }
53 
54 QString Speedometer::name() const
55 {
56  return tr( "Speedometer" );
57 }
58 
59 QString Speedometer::guiString() const
60 {
61  return tr( "&Speedometer" );
62 }
63 
64 QString Speedometer::nameId() const
65 {
66  return QString( "speedometer" );
67 }
68 
69 QString Speedometer::version() const
70 {
71  return "1.0";
72 }
73 
74 QString Speedometer::description() const
75 {
76  return tr( "Display the current cruising speed." );
77 }
78 
79 QString Speedometer::copyrightYears() const
80 {
81  return "2011";
82 }
83 
84 QList<PluginAuthor> Speedometer::pluginAuthors() const
85 {
86  return QList<PluginAuthor>()
87  << PluginAuthor( "Bernhard Beschow", "bbeschow@cs.tu-berlin.de" );
88 }
89 
90 QIcon Speedometer::icon () const
91 {
92  return QIcon(":/icons/speedometer.png");
93 }
94 
95 void Speedometer::initialize ()
96 {
97  if ( !m_widgetItem ) {
98  QWidget *widget = new QWidget;
99  m_widget.setupUi( widget );
100  m_widgetItem = new WidgetGraphicsItem( this );
101  m_widgetItem->setWidget( widget );
102 
103  MarbleGraphicsGridLayout *layout = new MarbleGraphicsGridLayout( 1, 1 );
104  layout->addItem( m_widgetItem, 0, 0 );
105  setLayout( layout );
106  setPadding( 0 );
107 
108  m_locale = MarbleGlobal::getInstance()->locale();
109  connect( marbleModel()->positionTracking(), SIGNAL(gpsLocation(GeoDataCoordinates,qreal)),
110  this, SLOT(updateLocation(GeoDataCoordinates,qreal)) );
111  }
112 }
113 
114 bool Speedometer::isInitialized () const
115 {
116  return m_widgetItem;
117 }
118 
119 void Speedometer::updateLocation( GeoDataCoordinates coordinates, qreal speed )
120 {
121  Q_UNUSED( coordinates );
122 
123  speed *= METER2KM / SEC2HOUR;
124  QString speedUnit;
125 
126  switch ( m_locale->measurementSystem() ) {
127  case QLocale::ImperialSystem:
128  //miles per hour
129  speedUnit = tr("mph");
130  speed *= KM2MI;
131  break;
132 
133  case QLocale::MetricSystem:
134  //kilometers per hour
135  speedUnit = tr("km/h");
136  break;
137  }
138 
139  m_widget.speed->display( speed );
140  m_widget.speedUnit->setText( speedUnit );
141 
142  update();
143  emit repaintNeeded();
144 }
145 
146 }
147 
148 Q_EXPORT_PLUGIN2( Speedometer, Marble::Speedometer )
149 
150 #include "Speedometer.moc"
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::Speedometer::nameId
QString nameId() const
Returns the unique name of the plugin.
Definition: Speedometer.cpp:64
Marble::WidgetGraphicsItem::setWidget
void setWidget(QWidget *widget)
Definition: WidgetGraphicsItem.cpp:48
Marble::MarbleLocale::measurementSystem
QLocale::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:74
Marble::Speedometer::icon
QIcon icon() const
Returns an icon for the plugin.
Definition: Speedometer.cpp:90
Marble::Speedometer
The class that displays Position Tracking info.
Definition: Speedometer.h:37
MarbleModel.h
This file contains the headers for MarbleModel.
QWidget
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
Marble::Speedometer::name
QString name() const
Returns the user-visible name of the plugin.
Definition: Speedometer.cpp:54
Marble::Speedometer::~Speedometer
~Speedometer()
Definition: Speedometer.cpp:45
Marble::Speedometer::version
QString version() const
Definition: Speedometer.cpp:69
Marble::AbstractFloatItem
The abstract class for float item plugins.
Definition: AbstractFloatItem.h:48
Marble::Speedometer::copyrightYears
QString copyrightYears() const
Definition: Speedometer.cpp:79
Marble::MarbleGraphicsGridLayout
Definition: MarbleGraphicsGridLayout.h:27
Marble::MarbleGlobal::locale
MarbleLocale * locale() const
Definition: MarbleGlobal.cpp:43
MarbleLocale.h
MarbleGlobal.h
Marble::WidgetGraphicsItem
Definition: WidgetGraphicsItem.h:28
WidgetGraphicsItem.h
Marble::METER2KM
const qreal METER2KM
Definition: MarbleGlobal.h:205
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:49
Q_EXPORT_PLUGIN2
#define Q_EXPORT_PLUGIN2(a, b)
Definition: marble_export.h:34
Marble::KM2MI
const qreal KM2MI
Definition: MarbleGlobal.h:189
MarbleGraphicsGridLayout.h
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::MarbleGlobal::SmallScreen
Definition: MarbleGlobal.h:268
Marble::MarbleGlobal::getInstance
static MarbleGlobal * getInstance()
Definition: MarbleGlobal.cpp:37
Marble::MarbleModel
The data model (not based on QAbstractModel) for a MarbleWidget.
Definition: MarbleModel.h:96
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:217
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:59
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::Speedometer::pluginAuthors
QList< PluginAuthor > pluginAuthors() const
Definition: Speedometer.cpp:84
PositionTracking.h
Marble::RenderPlugin::marbleModel
const MarbleModel * marbleModel() const
Access to the MarbleModel.
Definition: RenderPlugin.cpp:81
Marble::FrameGraphicsItem::setPadding
void setPadding(qreal width)
Set the padding of the item.
Definition: FrameGraphicsItem.cpp:130
Marble::Speedometer::initialize
void initialize()
Definition: Speedometer.cpp:95
Marble::Speedometer::isInitialized
bool isInitialized() const
Definition: Speedometer.cpp:114
Marble::AbstractFloatItem::setVisible
void setVisible(bool visible)
Set visibility of the float item.
Definition: AbstractFloatItem.cpp:128
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:52 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