2013-05-17 11:14:10 +00:00
|
|
|
#include "globe.h"
|
2013-05-18 00:58:49 +00:00
|
|
|
#include "kmessagewidget.h"
|
2013-05-17 16:28:02 +00:00
|
|
|
#include "../dive.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
2013-05-17 11:14:10 +00:00
|
|
|
#include <marble/AbstractFloatItem.h>
|
2013-05-17 16:28:02 +00:00
|
|
|
#include <marble/GeoDataPlacemark.h>
|
|
|
|
#include <marble/GeoDataDocument.h>
|
|
|
|
#include <marble/MarbleModel.h>
|
2013-05-25 15:28:35 +00:00
|
|
|
#include <marble/MarbleDirs.h>
|
2013-05-18 16:44:54 +00:00
|
|
|
#if INCOMPLETE_MARBLE
|
|
|
|
#include "marble/GeoDataTreeModel.h"
|
|
|
|
#else
|
2013-05-17 16:28:02 +00:00
|
|
|
#include <marble/GeoDataTreeModel.h>
|
2013-05-18 16:44:54 +00:00
|
|
|
#endif
|
2013-05-17 19:12:55 +00:00
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QMessageBox>
|
2013-05-17 11:14:10 +00:00
|
|
|
|
2013-05-17 16:28:02 +00:00
|
|
|
GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0)
|
2013-05-17 11:14:10 +00:00
|
|
|
{
|
2013-05-25 15:28:35 +00:00
|
|
|
// this will find the Google maps when running from your build directory
|
|
|
|
// TODO: all the magic to find the install path (and actually install/bundle these files)
|
|
|
|
MarbleDirs::setMarbleDataPath(QDir("./marbledata").absolutePath());
|
2013-05-24 19:15:49 +00:00
|
|
|
messageWidget = new KMessageWidget(this);
|
|
|
|
messageWidget->setCloseButtonVisible(false);
|
|
|
|
messageWidget->setHidden(true);
|
2013-05-18 01:52:04 +00:00
|
|
|
|
2013-05-24 14:07:59 +00:00
|
|
|
setMapThemeId("earth/googlesat/googlesat.dgml");
|
2013-05-18 01:52:04 +00:00
|
|
|
//setMapThemeId("earth/openstreetmap/openstreetmap.dgml");
|
2013-05-23 04:25:05 +00:00
|
|
|
setProjection(Marble::Spherical);
|
2013-05-17 11:14:10 +00:00
|
|
|
|
2013-05-17 17:09:10 +00:00
|
|
|
setAnimationsEnabled(true);
|
2013-05-23 04:25:05 +00:00
|
|
|
setShowClouds(false);
|
|
|
|
setShowBorders(false);
|
|
|
|
setShowPlaces(true);
|
|
|
|
setShowCrosshairs(false);
|
|
|
|
setShowGrid(false);
|
2013-05-17 11:14:10 +00:00
|
|
|
setShowOverviewMap(false);
|
2013-05-18 01:52:04 +00:00
|
|
|
setShowScaleBar(true);
|
2013-05-24 19:21:16 +00:00
|
|
|
setShowCompass(false);
|
2013-05-17 11:14:10 +00:00
|
|
|
}
|
2013-05-17 16:28:02 +00:00
|
|
|
|
|
|
|
void GlobeGPS::reload()
|
|
|
|
{
|
2013-05-23 04:25:05 +00:00
|
|
|
if (loadedDives) {
|
2013-05-17 16:28:02 +00:00
|
|
|
model()->treeModel()->removeDocument(loadedDives);
|
|
|
|
delete loadedDives;
|
|
|
|
}
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2013-05-23 04:25:05 +00:00
|
|
|
if (editingDiveCoords) {
|
2013-05-17 19:12:55 +00:00
|
|
|
editingDiveCoords = 0;
|
2013-05-27 17:43:21 +00:00
|
|
|
if (messageWidget->isVisible())
|
|
|
|
messageWidget->animatedHide();
|
2013-05-17 19:12:55 +00:00
|
|
|
}
|
2013-05-17 16:28:02 +00:00
|
|
|
|
|
|
|
loadedDives = new GeoDataDocument;
|
|
|
|
|
2013-05-18 01:56:21 +00:00
|
|
|
diveLocations.clear();
|
2013-05-17 16:28:02 +00:00
|
|
|
int idx = 0;
|
|
|
|
struct dive *dive;
|
|
|
|
for_each_dive(idx, dive) {
|
|
|
|
if (dive_has_gps_location(dive)) {
|
2013-05-17 17:09:10 +00:00
|
|
|
// don't add dive locations twice.
|
2013-05-23 04:25:05 +00:00
|
|
|
if (diveLocations.contains(QString(dive->location)))
|
2013-05-17 17:09:10 +00:00
|
|
|
continue;
|
|
|
|
|
2013-05-23 04:25:05 +00:00
|
|
|
diveLocations.append(QString(dive->location));
|
|
|
|
GeoDataPlacemark *place = new GeoDataPlacemark(dive->location);
|
|
|
|
place->setCoordinate(dive->longitude.udeg / 1000000.0,dive->latitude.udeg / 1000000.0 , 0, GeoDataCoordinates::Degree);
|
|
|
|
loadedDives->append(place);
|
2013-05-17 16:28:02 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-23 04:25:05 +00:00
|
|
|
model()->treeModel()->addDocument(loadedDives);
|
2013-05-17 16:28:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlobeGPS::centerOn(dive* dive)
|
|
|
|
{
|
2013-05-18 00:58:49 +00:00
|
|
|
// dive has changed, if we had the 'editingDive', hide it.
|
2013-05-23 04:25:05 +00:00
|
|
|
if (messageWidget->isVisible() && (!dive || dive_has_gps_location(dive))) {
|
2013-05-18 00:58:49 +00:00
|
|
|
messageWidget->animatedHide();
|
|
|
|
}
|
|
|
|
|
|
|
|
editingDiveCoords = 0;
|
|
|
|
|
2013-05-17 19:12:55 +00:00
|
|
|
qreal longitude = dive->longitude.udeg / 1000000.0;
|
|
|
|
qreal latitude = dive->latitude.udeg / 1000000.0;
|
|
|
|
|
2013-05-23 04:25:05 +00:00
|
|
|
if (!longitude || !latitude) {
|
2013-05-17 19:12:55 +00:00
|
|
|
prepareForGetDiveCoordinates(dive);
|
|
|
|
return;
|
|
|
|
}
|
2013-05-27 17:27:14 +00:00
|
|
|
|
|
|
|
// set the zoom as seen from n kilometer above. 3km / 10,000ft seems pleasant
|
|
|
|
// do not change it it was already modified by user
|
|
|
|
if (!zoom())
|
|
|
|
zoomView(zoomFromDistance(3));
|
|
|
|
|
2013-05-17 19:12:55 +00:00
|
|
|
centerOn(longitude,latitude, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlobeGPS::prepareForGetDiveCoordinates(dive* dive)
|
|
|
|
{
|
2013-05-22 14:28:25 +00:00
|
|
|
if (!messageWidget->isVisible()) {
|
|
|
|
messageWidget->setMessageType(KMessageWidget::Warning);
|
2013-05-22 16:00:07 +00:00
|
|
|
messageWidget->setText(QObject::tr("No location data - move the map and double-click to set the dive location"));
|
2013-05-22 14:28:25 +00:00
|
|
|
messageWidget->setWordWrap(true);
|
|
|
|
messageWidget->animatedShow();
|
|
|
|
}
|
2013-05-17 19:12:55 +00:00
|
|
|
editingDiveCoords = dive;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
|
|
|
|
{
|
|
|
|
// convert to degrees if in radian.
|
2013-05-23 04:25:05 +00:00
|
|
|
if (unit == GeoDataCoordinates::Radian) {
|
2013-05-17 19:12:55 +00:00
|
|
|
lon = lon * 180 / M_PI;
|
|
|
|
lat = lat * 180 / M_PI;
|
|
|
|
}
|
2013-05-23 04:25:05 +00:00
|
|
|
if (!editingDiveCoords) {
|
2013-05-17 19:12:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-25 11:14:16 +00:00
|
|
|
editingDiveCoords->latitude.udeg = lrint(lat * 1000000.0);
|
|
|
|
editingDiveCoords->longitude.udeg = lrint(lon * 1000000.0);
|
2013-05-17 19:12:55 +00:00
|
|
|
centerOn(lon, lat, true);
|
|
|
|
reload();
|
|
|
|
editingDiveCoords = 0;
|
2013-05-18 00:58:49 +00:00
|
|
|
messageWidget->animatedHide();
|
2013-05-17 16:28:02 +00:00
|
|
|
}
|
2013-05-17 19:12:55 +00:00
|
|
|
|
|
|
|
void GlobeGPS::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
qreal lat, lon;
|
2013-05-24 23:06:51 +00:00
|
|
|
if (editingDiveCoords && geoCoordinates(event->pos().x(), event->pos().y(), lon, lat, GeoDataCoordinates::Degree)) {
|
|
|
|
changeDiveGeoPosition(lon, lat, GeoDataCoordinates::Degree);
|
2013-05-17 19:12:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-24 19:15:49 +00:00
|
|
|
void GlobeGPS::resizeEvent(QResizeEvent* event)
|
2013-05-18 00:58:49 +00:00
|
|
|
{
|
2013-05-24 19:15:49 +00:00
|
|
|
int size = event->size().width();
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2013-05-24 19:15:49 +00:00
|
|
|
MarbleWidget::resizeEvent(event);
|
2013-05-18 00:58:49 +00:00
|
|
|
|
2013-05-24 19:15:49 +00:00
|
|
|
if (size > 600)
|
|
|
|
messageWidget->setGeometry((size - 600) / 2, 5, 600, 0);
|
|
|
|
else
|
|
|
|
messageWidget->setGeometry(5, 5, size - 10, 0);
|
|
|
|
|
|
|
|
messageWidget->setMaximumHeight(500);
|
|
|
|
}
|