2
* evopedia: An offline Wikipedia reader.
4
* Copyright (C) 2010-2011 evopedia developers
6
* This program 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.
11
* This program 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.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include "mapwindow.h"
22
#include "ui_mapwindow.h"
25
#include <QtGui/QX11Info>
27
#include <X11/Xatom.h>
30
#include <QtWidgets/QMessageBox>
33
MapWindow::MapWindow(QWidget *parent) :
35
#if defined(USE_MOBILITY)
36
posSource(QGeoPositionInfoSource::createDefaultSource(this)),
41
ui->mapWidget->setFocus();
42
#if defined(USE_MOBILITY)
44
connect(posSource, SIGNAL(positionUpdated(QGeoPositionInfo)), SLOT(positionUpdated(QGeoPositionInfo)));
46
ui->actionGo_to_GPS_Position->setEnabled(false);
47
ui->actionUse_GPS->setEnabled(false);
48
ui->actionFollow_GPS->setEnabled(false);
51
#if defined(Q_OS_SYMBIAN)
52
QAction *closeAction = new QAction(tr("Back"), ui->menuMenu);
53
connect(closeAction, SIGNAL(triggered()), SLOT(close()));
54
ui->menuMenu->addAction(closeAction);
57
connect(ui->actionShow_Articles, SIGNAL(toggled(bool)), ui->mapWidget, SLOT(overlaysEnable(bool)));
58
connect(ui->actionZoom_In, SIGNAL(triggered()), ui->mapWidget, SLOT(zoomIn()));
59
connect(ui->actionZoom_Out, SIGNAL(triggered()), ui->mapWidget, SLOT(zoomOut()));
61
QTimer::singleShot(0, this, SLOT(delayedInit()));
64
MapWindow::~MapWindow()
70
void MapWindow::grabZoomKeys(bool grab)
73
qWarning("Can't grab keys unless we have a window id");
77
unsigned long val = (grab) ? 1 : 0;
78
Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
80
qWarning("Unable to obtain _HILDON_ZOOM_KEY_ATOM. This example will only work "
81
"on a Maemo 5 device!");
85
XChangeProperty (QX11Info::display(),
91
reinterpret_cast<unsigned char *>(&val),
97
void MapWindow::setPosition(qreal lat, qreal lon, int zoom)
99
ui->mapWidget->setPosition(lat, lon, zoom);
102
void MapWindow::getPosition(qreal &lat, qreal &lng, int &zoom)
104
ui->mapWidget->getPosition(lat, lng, zoom);
107
#if defined(USE_MOBILITY)
108
void MapWindow::positionUpdated(const QGeoPositionInfo &posInfo)
110
const QGeoCoordinate coordinate = posInfo.coordinate();
111
if (ui->actionFollow_GPS->isChecked() && coordinate.isValid()) {
112
setPosition(coordinate.latitude(), coordinate.longitude());
117
void MapWindow::on_actionUse_GPS_toggled(bool value)
119
#if defined(USE_MOBILITY)
120
if (posSource == 0) {
121
QMessageBox::critical(this, tr("Error"), tr("No position info source available."));
126
posSource->startUpdates();
128
posSource->stopUpdates();
129
ui->actionFollow_GPS->setEnabled(value);
130
ui->actionGo_to_GPS_Position->setEnabled(value);
136
void MapWindow::on_actionGo_to_GPS_Position_triggered()
138
#if defined(USE_MOBILITY)
139
if (posSource == 0) return;
140
const QGeoCoordinate coordinate = posSource->lastKnownPosition().coordinate();
141
if (coordinate.isValid())
142
setPosition(coordinate.latitude(), coordinate.longitude());
146
void MapWindow::on_actionFollow_GPS_toggled(bool value)
149
on_actionGo_to_GPS_Position_triggered();