File indexing completed on 2024-04-28 03:50:24
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2011 Bernhard Beschow <bbeschow@cs.tu-berlin.de> 0004 // 0005 0006 #include "Speedometer.h" 0007 0008 #include <QIcon> 0009 0010 #include "MarbleGlobal.h" 0011 #include "MarbleDebug.h" 0012 #include "MarbleLocale.h" 0013 #include "MarbleModel.h" 0014 #include "PositionTracking.h" 0015 #include "WidgetGraphicsItem.h" 0016 #include "MarbleGraphicsGridLayout.h" 0017 #include "ViewportParams.h" 0018 0019 namespace Marble 0020 { 0021 0022 Speedometer::Speedometer() 0023 : AbstractFloatItem( nullptr ), 0024 m_locale( nullptr ), 0025 m_widgetItem( nullptr ) 0026 { 0027 } 0028 0029 Speedometer::Speedometer( const MarbleModel *marbleModel ) 0030 : AbstractFloatItem( marbleModel, QPointF( 10.5, 110 ), QSizeF( 135.0, 80.0 ) ), 0031 m_locale( nullptr ), 0032 m_widgetItem( nullptr ) 0033 { 0034 setVisible( false ); 0035 0036 const bool smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen; 0037 if ( smallScreen ) { 0038 setPosition( QPointF( 10.5, 10.5 ) ); 0039 } 0040 } 0041 0042 Speedometer::~Speedometer() 0043 { 0044 } 0045 0046 QStringList Speedometer::backendTypes() const 0047 { 0048 return QStringList(QStringLiteral("speedometer")); 0049 } 0050 0051 QString Speedometer::name() const 0052 { 0053 return tr( "Speedometer" ); 0054 } 0055 0056 QString Speedometer::guiString() const 0057 { 0058 return tr( "&Speedometer" ); 0059 } 0060 0061 QString Speedometer::nameId() const 0062 { 0063 return QStringLiteral("speedometer"); 0064 } 0065 0066 QString Speedometer::version() const 0067 { 0068 return QStringLiteral("1.0"); 0069 } 0070 0071 QString Speedometer::description() const 0072 { 0073 return tr( "Display the current cruising speed." ); 0074 } 0075 0076 QString Speedometer::copyrightYears() const 0077 { 0078 return QStringLiteral("2011"); 0079 } 0080 0081 QVector<PluginAuthor> Speedometer::pluginAuthors() const 0082 { 0083 return QVector<PluginAuthor>() 0084 << PluginAuthor(QStringLiteral("Bernhard Beschow"), QStringLiteral("bbeschow@cs.tu-berlin.de")); 0085 } 0086 0087 QIcon Speedometer::icon () const 0088 { 0089 return QIcon(QStringLiteral(":/icons/speedometer.png")); 0090 } 0091 0092 void Speedometer::initialize () 0093 { 0094 if ( !m_widgetItem ) { 0095 QWidget *widget = new QWidget; 0096 m_widget.setupUi( widget ); 0097 m_widgetItem = new WidgetGraphicsItem( this ); 0098 m_widgetItem->setWidget( widget ); 0099 0100 MarbleGraphicsGridLayout *layout = new MarbleGraphicsGridLayout( 1, 1 ); 0101 layout->addItem( m_widgetItem, 0, 0 ); 0102 setLayout( layout ); 0103 setPadding( 0 ); 0104 0105 m_locale = MarbleGlobal::getInstance()->locale(); 0106 connect( marbleModel()->positionTracking(), SIGNAL(gpsLocation(GeoDataCoordinates,qreal)), 0107 this, SLOT(updateLocation(GeoDataCoordinates,qreal)) ); 0108 } 0109 } 0110 0111 bool Speedometer::isInitialized () const 0112 { 0113 return m_widgetItem; 0114 } 0115 0116 void Speedometer::updateLocation( const GeoDataCoordinates& coordinates, qreal speed ) 0117 { 0118 Q_UNUSED( coordinates ); 0119 0120 speed *= METER2KM / SEC2HOUR; 0121 QString speedUnit; 0122 0123 switch ( m_locale->measurementSystem() ) { 0124 case MarbleLocale::ImperialSystem: 0125 //miles per hour 0126 speedUnit = tr("mph"); 0127 speed *= KM2MI; 0128 break; 0129 0130 case MarbleLocale::MetricSystem: 0131 //kilometers per hour 0132 speedUnit = tr("km/h"); 0133 break; 0134 0135 case MarbleLocale::NauticalSystem: 0136 // nm per hour (kt) 0137 speedUnit = tr("kt"); 0138 speed *= KM2NM; 0139 break; 0140 } 0141 0142 m_widget.speed->display( speed ); 0143 m_widget.speedUnit->setText( speedUnit ); 0144 0145 update(); 0146 emit repaintNeeded(); 0147 } 0148 0149 } 0150 0151 #include "moc_Speedometer.cpp"