2010-06-09 12:19:24 +03:00
|
|
|
/*
|
2011-02-18 10:53:32 +02:00
|
|
|
* Copyright 2010-2011 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de>
|
2010-06-09 12:19:24 +03:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mainwidget.h"
|
|
|
|
|
2010-06-11 00:52:34 +03:00
|
|
|
#include "downloadwidget.h"
|
2011-02-18 11:21:53 +02:00
|
|
|
#include "fileselector.h"
|
2010-06-09 12:19:24 +03:00
|
|
|
#include "mapwidget.h"
|
|
|
|
#include "markerlist.h"
|
2010-11-04 22:01:35 +02:00
|
|
|
#include "searchwidget.h"
|
2010-06-09 12:19:24 +03:00
|
|
|
|
2010-06-22 00:38:54 +03:00
|
|
|
#include "batterylayer.h"
|
2010-06-22 23:31:29 +03:00
|
|
|
#include "gpslayer.h"
|
2010-06-22 00:38:54 +03:00
|
|
|
#include "gpxlayer.h"
|
|
|
|
#include "markerlayer.h"
|
2010-11-03 22:39:06 +02:00
|
|
|
#include "monavlayer.h"
|
2010-10-30 22:35:33 +03:00
|
|
|
#include "poilayer.h"
|
2010-06-22 00:38:54 +03:00
|
|
|
#include "timelayer.h"
|
|
|
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
#include <QtGui/QApplication>
|
2010-06-09 12:19:24 +03:00
|
|
|
#include <QtGui/QLayout>
|
|
|
|
|
|
|
|
MainWidget::MainWidget(QWidget *parent)
|
|
|
|
: QWidget(parent),
|
|
|
|
m_stack(new QStackedWidget(this)),
|
|
|
|
m_map(new MapWidget(this)),
|
2010-06-11 00:52:34 +03:00
|
|
|
m_markerList(new MarkerList(this)),
|
2010-07-29 23:24:38 +03:00
|
|
|
m_dlWidget(new DownloadWidget(this)),
|
2011-02-18 11:21:53 +02:00
|
|
|
m_fileSelector(new FileSelector(this)),
|
2010-11-04 22:01:35 +02:00
|
|
|
m_search(new SearchWidget(this))
|
2010-06-09 12:19:24 +03:00
|
|
|
{
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
layout->addWidget(m_stack);
|
|
|
|
|
2010-06-22 00:38:54 +03:00
|
|
|
AbstractLayer *l = new TimeLayer(m_map);
|
|
|
|
l->setVisible(false);
|
2010-10-01 16:01:08 +03:00
|
|
|
m_map->addLayer(l, 4, "Time");
|
2010-06-22 00:38:54 +03:00
|
|
|
|
|
|
|
l = new BatteryLayer(m_map);
|
|
|
|
l->setVisible(false);
|
2010-10-01 16:01:08 +03:00
|
|
|
m_map->addLayer(l, 4, "Battery");
|
2010-06-22 00:38:54 +03:00
|
|
|
|
|
|
|
l = new MarkerLayer(m_map);
|
|
|
|
connect(l, SIGNAL(markerAdded(QString)), m_markerList, SLOT(addMarker(QString)));
|
|
|
|
connect(m_markerList, SIGNAL(centerOnMarker(int)), l, SLOT(centerOnMarker(int)));
|
|
|
|
connect(m_markerList, SIGNAL(removeMarker(int)), l, SLOT(removeMarker(int)));
|
|
|
|
connect(m_markerList, SIGNAL(markerRenamed(int, QString)), l, SLOT(renameMarker(int, QString)));
|
|
|
|
l->load(QDir::homePath()+"/Maps/marker.list");
|
2010-10-01 16:01:08 +03:00
|
|
|
m_map->addLayer(l, 3, "Marker");
|
2010-06-22 23:31:29 +03:00
|
|
|
|
2010-11-03 22:39:06 +02:00
|
|
|
l = new MonavLayer(m_map);
|
|
|
|
m_map->addLayer(l, 2, "MoNav Routing");
|
|
|
|
|
2010-06-22 23:31:29 +03:00
|
|
|
l = new GpsLayer(m_map);
|
2010-10-01 16:01:08 +03:00
|
|
|
m_map->addLayer(l, 1, "GPS-Position");
|
2010-06-22 00:38:54 +03:00
|
|
|
|
2010-09-08 15:31:52 +03:00
|
|
|
connect(m_map, SIGNAL(close()), this, SIGNAL(close()));
|
2010-06-11 00:52:34 +03:00
|
|
|
connect(m_map, SIGNAL(showMarkerList()), this, SLOT(showList()));
|
|
|
|
connect(m_map, SIGNAL(downloadArea(int, QRectF)), this, SLOT(downloadArea(int, QRectF)));
|
2011-02-18 11:21:53 +02:00
|
|
|
connect(m_map, SIGNAL(loadFile()), this, SLOT(showFileSelector()));
|
2010-11-04 22:01:35 +02:00
|
|
|
connect(m_map, SIGNAL(search()), this, SLOT(search()));
|
2010-06-09 12:19:24 +03:00
|
|
|
m_stack->insertWidget(0, m_map);
|
2010-06-11 00:52:34 +03:00
|
|
|
|
2010-06-09 12:19:24 +03:00
|
|
|
connect(m_markerList, SIGNAL(back()), this, SLOT(showMap()));
|
2010-06-22 00:38:54 +03:00
|
|
|
connect(m_markerList, SIGNAL(centerOnMarker(int)), this, SLOT(showMap()));
|
2010-06-09 12:19:24 +03:00
|
|
|
m_stack->insertWidget(1, m_markerList);
|
|
|
|
|
2010-06-11 00:52:34 +03:00
|
|
|
connect(m_dlWidget, SIGNAL(back()), this, SLOT(showMap()));
|
2011-02-18 10:53:32 +02:00
|
|
|
connect(m_dlWidget, SIGNAL(loadFile(QString, QString)), this, SLOT(loadFile(QString, QString)));
|
2010-06-11 00:52:34 +03:00
|
|
|
m_stack->insertWidget(2, m_dlWidget);
|
|
|
|
|
2010-11-04 22:01:35 +02:00
|
|
|
connect(m_search, SIGNAL(back()), this, SLOT(showMap()));
|
|
|
|
connect(m_search, SIGNAL(centerOn(qreal, qreal)), this, SLOT(showMap(qreal, qreal)));
|
|
|
|
m_stack->insertWidget(3, m_search);
|
2010-07-29 23:24:38 +03:00
|
|
|
|
2011-02-19 14:13:21 +02:00
|
|
|
m_fileSelector->setTitle("Open POI / Track file");
|
2011-02-18 11:21:53 +02:00
|
|
|
m_fileSelector->setFileTypes(QStringList() << "*.gpx" << "*.osm");
|
|
|
|
connect(m_fileSelector, SIGNAL(cancel()), this, SLOT(showMap()));
|
|
|
|
connect(m_fileSelector, SIGNAL(fileSelected(QString)), this, SLOT(loadFile(QString)));
|
|
|
|
m_stack->insertWidget(4, m_fileSelector);
|
|
|
|
|
2010-06-09 12:19:24 +03:00
|
|
|
resize(320, 240);
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWidget::~MainWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-02-18 11:21:53 +02:00
|
|
|
void MainWidget::loadFile(const QString &fileName)
|
|
|
|
{
|
|
|
|
loadFile(fileName, "");
|
|
|
|
}
|
|
|
|
|
2011-02-18 10:53:32 +02:00
|
|
|
void MainWidget::loadFile(const QString &fileName, const QString &title)
|
2010-09-08 15:31:52 +03:00
|
|
|
{
|
|
|
|
if (fileName.endsWith(".gpx")) {
|
|
|
|
AbstractLayer *l = new GpxLayer(m_map);
|
|
|
|
l->load(fileName);
|
2011-02-18 10:53:32 +02:00
|
|
|
QString t = title.isEmpty() ? "GPS-Track" : title;
|
|
|
|
m_map->addLayer(l, 2, t);
|
2010-10-30 22:35:33 +03:00
|
|
|
} else if (fileName.endsWith(".osm")) {
|
|
|
|
AbstractLayer *l = new PoiLayer(m_map);
|
|
|
|
l->load(fileName);
|
2011-02-18 10:53:32 +02:00
|
|
|
QString t = title.isEmpty() ? "Points Of Interest" : title;
|
|
|
|
m_map->addLayer(l, 3, t);
|
2010-09-08 15:31:52 +03:00
|
|
|
}
|
2011-02-18 11:21:53 +02:00
|
|
|
showMap();
|
2010-09-08 15:31:52 +03:00
|
|
|
}
|
|
|
|
|
2010-06-09 12:19:24 +03:00
|
|
|
void MainWidget::showList()
|
|
|
|
{
|
|
|
|
m_stack->setCurrentIndex(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWidget::markerAdded(const QString &name)
|
|
|
|
{
|
|
|
|
m_markerList->addMarker(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWidget::showMap()
|
|
|
|
{
|
|
|
|
m_stack->setCurrentIndex(0);
|
2011-02-18 11:21:53 +02:00
|
|
|
m_map->setFocus(Qt::OtherFocusReason);
|
2010-06-09 12:19:24 +03:00
|
|
|
}
|
|
|
|
|
2010-11-04 22:01:35 +02:00
|
|
|
void MainWidget::showMap(qreal lon, qreal lat)
|
|
|
|
{
|
|
|
|
m_map->centerOnGeoPos(lon, lat);
|
|
|
|
showMap();
|
|
|
|
}
|
|
|
|
|
2010-06-11 00:52:34 +03:00
|
|
|
void MainWidget::downloadArea(int level, const QRectF &rect)
|
|
|
|
{
|
|
|
|
m_dlWidget->setStartLevel(level);
|
|
|
|
m_dlWidget->setDownloadRect(rect);
|
|
|
|
m_stack->setCurrentIndex(2);
|
|
|
|
}
|
|
|
|
|
2010-11-04 22:01:35 +02:00
|
|
|
void MainWidget::search()
|
2010-07-29 23:24:38 +03:00
|
|
|
{
|
|
|
|
m_stack->setCurrentIndex(3);
|
|
|
|
}
|
|
|
|
|
2011-02-18 11:21:53 +02:00
|
|
|
void MainWidget::showFileSelector()
|
|
|
|
{
|
|
|
|
m_stack->setCurrentIndex(4);
|
|
|
|
}
|
|
|
|
|