diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-12-02 15:06:19 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-12-02 09:44:55 -0800 |
commit | d26f109fba9d5f6f3a78b907334affacce4ffaeb (patch) | |
tree | 18a184fa64db42e850784e2c9ca2fdc81a0b763d /qt-ui/globe.cpp | |
parent | bbc022ba181b446011427235ae19a50d743c7cc7 (diff) | |
download | subsurface-d26f109fba9d5f6f3a78b907334affacce4ffaeb.tar.gz |
Fixes Setting the dive-location via the map.
This patch adds a context menu to set the dive location
via the globe, being the dive with a coordinate or not.
It also fixes setting the dive location on edit mode.
Fixes: #315
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/globe.cpp')
-rw-r--r-- | qt-ui/globe.cpp | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/qt-ui/globe.cpp b/qt-ui/globe.cpp index 8b3f140b7..c149bda74 100644 --- a/qt-ui/globe.cpp +++ b/qt-ui/globe.cpp @@ -24,7 +24,7 @@ #include <QMouseEvent> #include <QMessageBox> -GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0) +GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0), editingDiveLocation(false) { // check if Google Sat Maps are installed // if not, check if they are in a known location @@ -72,7 +72,6 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0) setMinimumHeight(0); setMinimumWidth(0); - editingDiveCoords = 0; fixZoomTimer = new QTimer(); connect(fixZoomTimer, SIGNAL(timeout()), this, SLOT(fixZoom())); fixZoomTimer->setSingleShot(true); @@ -82,19 +81,29 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0) bool GlobeGPS::eventFilter(QObject *obj, QEvent *ev) { // This disables Zooming when a double click occours on the scene. - if (ev->type() == QEvent::MouseButtonDblClick && !editingDiveCoords) + if (ev->type() == QEvent::MouseButtonDblClick && !editingDiveLocation) return true; // This disables the Marble's Context Menu // we need to move this to our 'contextMenuEvent' // if we plan to do a different one in the future. - if (ev->type() == QEvent::ContextMenu) + if (ev->type() == QEvent::ContextMenu){ + contextMenuEvent(static_cast<QContextMenuEvent*>(ev)); return true; + } if (ev->type() == QEvent::MouseButtonPress){ QMouseEvent *e = static_cast<QMouseEvent*>(ev); if(e->button() == Qt::RightButton) return true; } - return QObject::eventFilter(obj,ev ); + return QObject::eventFilter(obj,ev ); +} + +void GlobeGPS::contextMenuEvent(QContextMenuEvent* ev) +{ + QMenu m; + QAction *a = m.addAction(tr("Edit Selected Dive Locations"), this, SLOT(prepareForGetDiveCoordinates())); + a->setData(QVariant::fromValue<void*>(&m)); + m.exec(ev->globalPos()); } void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit) @@ -185,11 +194,9 @@ void GlobeGPS::repopulateLabels() void GlobeGPS::reload() { - editingDiveCoords = 0; - + editingDiveLocation = false; if (messageWidget->isVisible()) messageWidget->animatedHide(); - repopulateLabels(); } @@ -202,13 +209,11 @@ void GlobeGPS::centerOn(dive* dive) if (!dive) return; - editingDiveCoords = 0; - qreal longitude = dive->longitude.udeg / 1000000.0; qreal latitude = dive->latitude.udeg / 1000000.0; if (!longitude || !latitude) { - prepareForGetDiveCoordinates(dive); + prepareForGetDiveCoordinates(); return; } @@ -231,37 +236,27 @@ void GlobeGPS::fixZoom() zoomView(currentZoomLevel, Marble::Linear); } - -void GlobeGPS::prepareForGetDiveCoordinates(dive* dive) +void GlobeGPS::prepareForGetDiveCoordinates() { if (!messageWidget->isVisible()) { messageWidget->setMessageType(KMessageWidget::Warning); messageWidget->setText(QObject::tr("No location data - move the map and double-click to set the dive location")); messageWidget->setWordWrap(true); messageWidget->animatedShow(); + editingDiveLocation = true; } - editingDiveCoords = dive; -} - -void GlobeGPS::diveEditMode() -{ - if (messageWidget->isVisible()) - messageWidget->animatedHide(); - messageWidget->setMessageType(KMessageWidget::Warning); - messageWidget->setText(QObject::tr("Editing dive - move the map and double-click to set the dive location")); - messageWidget->setWordWrap(true); - messageWidget->animatedShow(); } void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::Unit unit) { + if (mainWindow()->dive_list()->selectionModel()->selection().isEmpty()) + return; + // convert to degrees if in radian. if (unit == GeoDataCoordinates::Radian) { lon = lon * 180 / M_PI; lat = lat * 180 / M_PI; } - if (!editingDiveCoords) - return; /* change everything on the selection. */ int i; @@ -273,7 +268,7 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U dive->longitude.udeg = lrint(lon * 1000000.0); } centerOn(lon, lat, true); - editingDiveCoords = 0; + editingDiveLocation = false; mark_divelist_changed(TRUE); messageWidget->animatedHide(); mainWindow()->refreshDisplay(); @@ -282,13 +277,13 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U void GlobeGPS::mousePressEvent(QMouseEvent* event) { qreal lat, lon; + bool clickOnGlobe = geoCoordinates(event->pos().x(), event->pos().y(), lon, lat, GeoDataCoordinates::Degree); + // there could be two scenarios that got us here; let's check if we are editing a dive - if (mainWindow()->information()->isEditing() && - geoCoordinates(event->pos().x(), event->pos().y(), lon, lat, GeoDataCoordinates::Degree)) { + if (mainWindow()->information()->isEditing() && clickOnGlobe) { mainWindow()->information()->updateCoordinatesText(lat, lon); repopulateLabels(); - } else if (editingDiveCoords && - geoCoordinates(event->pos().x(), event->pos().y(), lon, lat, GeoDataCoordinates::Degree)) { + } else if (clickOnGlobe) { changeDiveGeoPosition(lon, lat, GeoDataCoordinates::Degree); } } |