SVN checkout 11/12/2010
[monav:monav.git] / client / gpsdialog.cpp
1 /*
2 Copyright 2010  Christian Vetter veaac.fdirct@gmail.com
3
4 This file is part of MoNav.
5
6 MoNav is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MoNav is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with MoNav.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "gpsdialog.h"
21 #include "ui_gpsdialog.h"
22 #include "routinglogic.h"
23
24 GPSDialog::GPSDialog( QWidget *parent ) :
25                 QDialog( parent ),
26                 m_ui( new Ui::GPSDialog )
27 {
28         m_ui->setupUi(this);
29         // Windows Mobile Window Flags
30         setWindowFlags( windowFlags() & ( ~Qt::WindowOkButtonHint ) );
31 #ifdef Q_WS_MAEMO_5
32         setAttribute( Qt::WA_Maemo5StackedWindow );
33 #endif
34         gpsInfoUpdated();
35         connect( RoutingLogic::instance(), SIGNAL(gpsInfoChanged()), this, SLOT(gpsInfoUpdated()) );
36 }
37
38 void GPSDialog::gpsInfoUpdated()
39 {
40         const RoutingLogic::GPSInfo& gpsInfo = RoutingLogic::instance()->gpsInfo();
41         if ( gpsInfo.position.IsValid() ) {
42                 GPSCoordinate gps = gpsInfo.position.ToGPSCoordinate();
43                 m_ui->latitude->setText( QString::number( gps.latitude ) + QString::fromUtf8( "\302\260" ) + " +- " + QString::number( gpsInfo.horizontalAccuracy ) + "m" );
44                 m_ui->longitude->setText( QString::number( gps.longitude ) + QString::fromUtf8( "\302\260" ) + " +- " + QString::number( gpsInfo.horizontalAccuracy ) + "m" );
45         } else {
46                 m_ui->latitude->setText( tr( "N/A" ) );
47                 m_ui->longitude->setText( tr( "N/A" ) );
48         }
49         if ( gpsInfo.heading >= 0 )
50                 m_ui->heading->setText( QString::number( gpsInfo.heading ) + QString::fromUtf8( "\302\260" ) );
51         else
52                 m_ui->heading->setText( tr( "N/A" ) );
53         if ( gpsInfo.altitude >= 0 )
54                 m_ui->height->setText( QString::number( gpsInfo.altitude ) + " +- " + QString::number( gpsInfo.verticalAccuracy ) + "m" );
55         else
56                 m_ui->height->setText( tr( "N/A" ) );
57         if ( gpsInfo.groundSpeed >= 0 )
58                 m_ui->speed->setText( QString::number( gpsInfo.groundSpeed ) + "m/s" );
59         else
60                 m_ui->speed->setText( tr( "N/A" ) );
61         if ( gpsInfo.verticalSpeed >= 0 )
62                 m_ui->verticalSpeed->setText( QString::number( gpsInfo.verticalSpeed ) + "m/s" );
63         else
64                 m_ui->verticalSpeed->setText( tr( "N/A" ) );
65         if ( gpsInfo.timestamp.isValid() )
66                 m_ui->time->setText( gpsInfo.timestamp.toString() );
67         else
68                 m_ui->time->setText( tr( "N/A" ) );
69 }
70
71 GPSDialog::~GPSDialog()
72 {
73         delete m_ui;
74 }