Initial import of version 0.3
[gpsdata] / src / gpscompasswindow.cpp
1 /*
2  *  GPSData for Maemo.
3  *  Copyright (C) 2011 Roman Moravcik
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <QtGui>
21
22 #include "gpscompasswindow.h"
23
24 GpsCompassWindow::GpsCompassWindow(QWidget *parent) : QMainWindow(parent)
25 {
26     m_screenLocked = false;
27
28     createUi();
29
30     connect(parent, SIGNAL(screenLocked(bool)), this, SLOT(onScreenLocked(bool)));
31 }
32
33 GpsCompassWindow::~GpsCompassWindow()
34 {
35     delete m_compass;
36 }
37
38 void GpsCompassWindow::createUi()
39 {
40 #if defined(Q_OS_SYMBIAN)
41     setAttribute(Qt::WA_DeleteOnClose);
42 #elif defined(Q_WS_MAEMO_5)
43     setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
44     setAttribute(Qt::WA_Maemo5StackedWindow);
45
46     /* Workaround to show compass widget maximized */
47     showMaximized();
48 #endif
49
50     setWindowTitle(tr("GPS compass"));
51
52     m_compass = new Compass(Compass::Gps);
53     setCentralWidget(m_compass);
54
55 #ifdef Q_OS_SYMBIAN
56     QAction* backSoftkey = new QAction(tr("Back"), this);
57     backSoftkey->setSoftKeyRole(QAction::NegativeSoftKey);
58     connect(backSoftkey, SIGNAL(triggered()), this, SLOT(close()));
59     addAction(backSoftkey);
60 #endif
61 }
62
63 void GpsCompassWindow::onScreenLocked(bool locked)
64 {
65     m_screenLocked = locked;
66 }
67
68 void GpsCompassWindow::onPositionUpdated(const QGeoPositionInfo &position)
69 {
70     if (m_screenLocked)
71         return;
72
73     if (position.hasAttribute(QGeoPositionInfo::Direction)) {
74         m_compass->updateWidget(position.attribute(QGeoPositionInfo::Direction), true,
75                                 position.attribute(QGeoPositionInfo::GroundSpeed));
76     } else {
77         m_compass->updateWidget(0, false, 0);
78     }
79 }
80
81 void GpsCompassWindow::setPositionInfoSource(QGeoPositionInfoSource *positionInfoSource)
82 {
83     m_position = positionInfoSource;
84     if (m_position) {
85         connect(m_position, SIGNAL(positionUpdated(const QGeoPositionInfo &)), this,
86                 SLOT(onPositionUpdated(const QGeoPositionInfo &)));
87
88         m_position->requestUpdate();
89     }
90 }