Support dropping of geo coordinates/geouris on the mapview & focus on them

Reviewers: rahn, nienhueser, #marble

Reviewed By: nienhueser, #marble

Differential Revision: https://phabricator.kde.org/D2070
parent 40e71f93
......@@ -36,6 +36,7 @@
#include <QShortcut>
#include <QMenu>
#include <QToolBar>
#include <QMimeData>
#ifdef MARBLE_DBUS
#include <QDBusConnection>
......@@ -121,6 +122,8 @@ ControlView::ControlView( QWidget *parent )
connect( bookmarkSyncManager, SIGNAL(mergeConflict(MergeItem*)), this, SLOT(showConflictDialog(MergeItem*)) );
connect( bookmarkSyncManager, SIGNAL(syncComplete()), m_conflictDialog, SLOT(stopAutoResolve()) );
connect( m_conflictDialog, SIGNAL(resolveConflict(MergeItem*)), bookmarkSyncManager, SLOT(resolveConflict(MergeItem*)) );
setAcceptDrops(true);
}
ControlView::~ControlView()
......@@ -251,10 +254,11 @@ void ControlView::printMapScreenShot( QPointer<QPrintDialog> printDialog)
#endif
}
void ControlView::openGeoUri( const QString& geoUriString )
bool ControlView::openGeoUri( const QString& geoUriString )
{
GeoUriParser uriParser( geoUriString );
if ( uriParser.parse() ) {
const bool success = uriParser.parse();
if ( success ) {
if ( uriParser.planet().id() != marbleModel()->planet()->id() ) {
MapThemeManager *manager = mapThemeManager();
foreach( const QString& planetName, manager->mapThemeIds()) {
......@@ -270,6 +274,7 @@ void ControlView::openGeoUri( const QString& geoUriString )
m_marbleWidget->setDistance( uriParser.coordinates().altitude() * METER2KM );
}
}
return success;
}
QActionGroup *ControlView::createViewSizeActionGroup( QObject* parent )
......@@ -903,6 +908,78 @@ void ControlView::closeEvent( QCloseEvent *event )
}
}
void ControlView::dragEnterEvent(QDragEnterEvent *event)
{
bool success = false;
const QMimeData *mimeData = event->mimeData();
GeoUriParser uriParser;
// prefer urls
if (mimeData->hasUrls()) {
// be generous and take the first usable url
foreach(const QUrl& url, mimeData->urls()) {
uriParser.setGeoUri(url.url());
success = uriParser.parse();
if (success) {
break;
}
}
}
// fall back to own string parsing
if (!success && mimeData->hasText()) {
const QString text = mimeData->text();
// first try human readable coordinates
GeoDataCoordinates::fromString(text, success);
// next geo uri
if (!success) {
uriParser.setGeoUri(text);
success = uriParser.parse();
}
}
if (success) {
event->acceptProposedAction();
}
}
void ControlView::dropEvent(QDropEvent *event)
{
bool success = false;
const QMimeData *mimeData = event->mimeData();
// prefer urls
if (mimeData->hasUrls()) {
// be generous and take the first usable url
foreach(const QUrl& url, mimeData->urls()) {
success = openGeoUri(url.url());
if (success) {
break;
}
}
}
// fall back to own string parsing
if (!success && mimeData->hasText()) {
const QString text = mimeData->text();
// first try human readable coordinates
const GeoDataCoordinates coordinates = GeoDataCoordinates::fromString(text, success);
if (success) {
const qreal longitude = coordinates.longitude(GeoDataCoordinates::Degree);
const qreal latitude = coordinates.latitude(GeoDataCoordinates::Degree);
m_marbleWidget->centerOn(longitude, latitude);
} else {
success = openGeoUri(text);
}
}
if (success) {
event->acceptProposedAction();
}
}
}
#include "moc_ControlView.cpp"
......@@ -101,9 +101,10 @@ class ControlView : public QWidget
/**
* Opens the passed Geo URI
* @return true if uri could be parsed and opened
* @see Marble::GeoUriParser for details
*/
void openGeoUri( const QString& geoUriString );
bool openGeoUri( const QString& geoUriString );
static QActionGroup* createViewSizeActionGroup( QObject* parent );
......@@ -133,6 +134,15 @@ Q_SIGNALS:
protected:
void closeEvent( QCloseEvent *event );
/**
* @brief Reimplementation of the dragEnterEvent() function in QWidget.
*/
void dragEnterEvent(QDragEnterEvent *event);
/**
* @brief Reimplementation of the dropEvent() function in QWidget.
*/
void dropEvent(QDropEvent *event);
private Q_SLOTS:
void showSearch();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment