Root/
| 1 | /* |
| 2 | * Copyright 2010-2011 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include "mainwidget.h" |
| 21 | |
| 22 | #include "downloadwidget.h" |
| 23 | #include "fileselector.h" |
| 24 | #include "mapwidget.h" |
| 25 | #include "markerlist.h" |
| 26 | #include "searchwidget.h" |
| 27 | |
| 28 | #include "batterylayer.h" |
| 29 | #include "gpslayer.h" |
| 30 | #include "gpxlayer.h" |
| 31 | #include "markerlayer.h" |
| 32 | #include "monavlayer.h" |
| 33 | #include "poilayer.h" |
| 34 | #include "timelayer.h" |
| 35 | |
| 36 | #include <QtCore/QDir> |
| 37 | #include <QtGui/QApplication> |
| 38 | #include <QtGui/QLayout> |
| 39 | |
| 40 | MainWidget::MainWidget(QWidget *parent) |
| 41 | : QWidget(parent), |
| 42 | m_stack(new QStackedWidget(this)), |
| 43 | m_map(new MapWidget(this)), |
| 44 | m_markerList(new MarkerList(this)), |
| 45 | m_dlWidget(new DownloadWidget(this)), |
| 46 | m_fileSelector(new FileSelector(this)), |
| 47 | m_search(new SearchWidget(this)) |
| 48 | { |
| 49 | QHBoxLayout *layout = new QHBoxLayout(this); |
| 50 | layout->setContentsMargins(0, 0, 0, 0); |
| 51 | layout->addWidget(m_stack); |
| 52 | |
| 53 | AbstractLayer *l = new TimeLayer(m_map); |
| 54 | l->setVisible(false); |
| 55 | m_map->addLayer(l, 4, "Time"); |
| 56 | |
| 57 | l = new BatteryLayer(m_map); |
| 58 | l->setVisible(false); |
| 59 | m_map->addLayer(l, 4, "Battery"); |
| 60 | |
| 61 | l = new MarkerLayer(m_map); |
| 62 | connect(l, SIGNAL(markerAdded(QString)), m_markerList, SLOT(addMarker(QString))); |
| 63 | connect(m_markerList, SIGNAL(centerOnMarker(int)), l, SLOT(centerOnMarker(int))); |
| 64 | connect(m_markerList, SIGNAL(removeMarker(int)), l, SLOT(removeMarker(int))); |
| 65 | connect(m_markerList, SIGNAL(markerRenamed(int, QString)), l, SLOT(renameMarker(int, QString))); |
| 66 | l->load(QDir::homePath()+"/Maps/marker.list"); |
| 67 | m_map->addLayer(l, 3, "Marker"); |
| 68 | |
| 69 | l = new MonavLayer(m_map); |
| 70 | m_map->addLayer(l, 2, "MoNav Routing"); |
| 71 | |
| 72 | l = new GpsLayer(m_map); |
| 73 | m_map->addLayer(l, 1, "GPS-Position"); |
| 74 | |
| 75 | connect(m_map, SIGNAL(close()), this, SIGNAL(close())); |
| 76 | connect(m_map, SIGNAL(showMarkerList()), this, SLOT(showList())); |
| 77 | connect(m_map, SIGNAL(downloadArea(int, QRectF)), this, SLOT(downloadArea(int, QRectF))); |
| 78 | connect(m_map, SIGNAL(loadFile()), this, SLOT(showFileSelector())); |
| 79 | connect(m_map, SIGNAL(search()), this, SLOT(search())); |
| 80 | m_stack->insertWidget(0, m_map); |
| 81 | |
| 82 | connect(m_markerList, SIGNAL(back()), this, SLOT(showMap())); |
| 83 | connect(m_markerList, SIGNAL(centerOnMarker(int)), this, SLOT(showMap())); |
| 84 | m_stack->insertWidget(1, m_markerList); |
| 85 | |
| 86 | connect(m_dlWidget, SIGNAL(back()), this, SLOT(showMap())); |
| 87 | connect(m_dlWidget, SIGNAL(loadFile(QString, QString)), this, SLOT(loadFile(QString, QString))); |
| 88 | m_stack->insertWidget(2, m_dlWidget); |
| 89 | |
| 90 | connect(m_search, SIGNAL(back()), this, SLOT(showMap())); |
| 91 | connect(m_search, SIGNAL(centerOn(qreal, qreal)), this, SLOT(showMap(qreal, qreal))); |
| 92 | m_stack->insertWidget(3, m_search); |
| 93 | |
| 94 | m_fileSelector->setTitle("Open POI / Track file"); |
| 95 | m_fileSelector->setFileTypes(QStringList() << "*.gpx" << "*.osm"); |
| 96 | connect(m_fileSelector, SIGNAL(cancel()), this, SLOT(showMap())); |
| 97 | connect(m_fileSelector, SIGNAL(fileSelected(QString)), this, SLOT(loadFile(QString))); |
| 98 | m_stack->insertWidget(4, m_fileSelector); |
| 99 | |
| 100 | resize(320, 240); |
| 101 | } |
| 102 | |
| 103 | MainWidget::~MainWidget() |
| 104 | { |
| 105 | } |
| 106 | |
| 107 | void MainWidget::loadFile(const QString &fileName) |
| 108 | { |
| 109 | loadFile(fileName, ""); |
| 110 | } |
| 111 | |
| 112 | void MainWidget::loadFile(const QString &fileName, const QString &title) |
| 113 | { |
| 114 | if (fileName.endsWith(".gpx")) { |
| 115 | AbstractLayer *l = new GpxLayer(m_map); |
| 116 | l->load(fileName); |
| 117 | QString t = title.isEmpty() ? "GPS-Track" : title; |
| 118 | m_map->addLayer(l, 2, t); |
| 119 | } else if (fileName.endsWith(".osm")) { |
| 120 | AbstractLayer *l = new PoiLayer(m_map); |
| 121 | l->load(fileName); |
| 122 | QString t = title.isEmpty() ? fileName.section("/", -1) : title; |
| 123 | m_map->addLayer(l, 3, t); |
| 124 | } |
| 125 | showMap(); |
| 126 | } |
| 127 | |
| 128 | void MainWidget::showList() |
| 129 | { |
| 130 | m_stack->setCurrentIndex(1); |
| 131 | } |
| 132 | |
| 133 | void MainWidget::markerAdded(const QString &name) |
| 134 | { |
| 135 | m_markerList->addMarker(name); |
| 136 | } |
| 137 | |
| 138 | void MainWidget::showMap() |
| 139 | { |
| 140 | m_stack->setCurrentIndex(0); |
| 141 | m_map->setFocus(Qt::OtherFocusReason); |
| 142 | } |
| 143 | |
| 144 | void MainWidget::showMap(qreal lon, qreal lat) |
| 145 | { |
| 146 | m_map->centerOnGeoPos(lon, lat); |
| 147 | showMap(); |
| 148 | } |
| 149 | |
| 150 | void MainWidget::downloadArea(int level, const QRectF &rect) |
| 151 | { |
| 152 | m_dlWidget->setStartLevel(level); |
| 153 | m_dlWidget->setDownloadRect(rect); |
| 154 | m_stack->setCurrentIndex(2); |
| 155 | } |
| 156 | |
| 157 | void MainWidget::search() |
| 158 | { |
| 159 | m_stack->setCurrentIndex(3); |
| 160 | } |
| 161 | |
| 162 | void MainWidget::showFileSelector() |
| 163 | { |
| 164 | m_stack->setCurrentIndex(4); |
| 165 | } |
| 166 | |
| 167 |
Branches:
master
