[Marble-commits] KDE/kdeedu/marble/src/lib/routing

Dennis Nienhüser earthwings at gentoo.org
Thu Mar 11 23:08:39 CET 2010


SVN commit 1102147 by nienhueser:

Input selection from the map can be canceled both by hitting Escape or clicking on the button once again. Less confusing tooltips. Clicking on the green flag only activates the respective placemark, but not the underlying placemark model (can still be done by hitting enter in the search field)

 M  +12 -7     RoutingInputWidget.cpp  
 M  +5 -2      RoutingInputWidget.h  
 M  +21 -0     RoutingLayer.cpp  
 M  +6 -1      RoutingLayer.h  
 M  +24 -9     RoutingWidget.cpp  
 M  +5 -2      RoutingWidget.h  


--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingInputWidget.cpp #1102146:1102147
@@ -67,7 +67,7 @@
         m_stateIcon(":/data/bitmaps/routing_via.png")
 {
     m_stateButton = new QPushButton(parent);
-    m_stateButton->setToolTip("Activate this destination");
+    m_stateButton->setToolTip("Center Map here");
     m_stateButton->setIcon(m_stateIcon);
     m_stateButton->setEnabled(false);
     m_stateButton->setFlat(true);
@@ -77,13 +77,13 @@
     m_removeButton = new QPushButton(parent);
     /** @todo: Use an icon instead */
     m_removeButton->setText("X");
-    m_removeButton->setToolTip("Remove this destination");
+    m_removeButton->setToolTip("Remove this input field");
     m_removeButton->setFlat(true);
     m_removeButton->setMaximumWidth(12);
 
     m_pickButton = new QPushButton(parent);
     m_pickButton->setIcon(QIcon(":/data/bitmaps/routing_select.png"));
-    m_pickButton->setToolTip("Choose destination from the map");
+    m_pickButton->setToolTip("Choose position from the map");
     m_pickButton->setCheckable(true);
     m_pickButton->setFlat(true);
     m_pickButton->setMaximumWidth(22);
@@ -108,8 +108,8 @@
 
     connect(d->m_stateButton, SIGNAL(clicked()),
             this, SLOT(requestActivity()));
-    connect(d->m_pickButton, SIGNAL(clicked()),
-            this, SLOT(requestMapPosition()));
+    connect(d->m_pickButton, SIGNAL(clicked(bool)),
+            this, SLOT(setMapInputModeEnabled(bool)));
     connect(d->m_removeButton, SIGNAL(clicked()),
             this, SLOT(requestRemoval()));
 
@@ -203,9 +203,9 @@
     return !d->m_lineEdit->text().isEmpty();
 }
 
-void RoutingInputWidget::requestMapPosition()
+void RoutingInputWidget::setMapInputModeEnabled(bool enabled)
 {
-   emit mapInputRequest(this);
+   emit mapInputModeEnabled(this, enabled);
 }
 
 void RoutingInputWidget::updateProgress()
@@ -231,6 +231,11 @@
     }
 }
 
+void RoutingInputWidget::abortMapInputRequest()
+{
+    d->m_pickButton->setChecked(false);
+}
+
 } // namespace Marble
 
 #include "RoutingInputWidget.moc"
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingInputWidget.h #1102146:1102147
@@ -89,6 +89,9 @@
       */
     void setTargetPosition(const GeoDataCoordinates &position);
 
+    /** Cancel a started input request from the map */
+    void abortMapInputRequest();
+
 Q_SIGNALS:
     /** All runners are finished */
     void searchFinished(RoutingInputWidget*);
@@ -100,7 +103,7 @@
     void activityRequest(RoutingInputWidget*);
 
     /** User requests position input from the map */
-    void mapInputRequest(RoutingInputWidget*);
+    void mapInputModeEnabled(RoutingInputWidget*, bool enabled);
 
     /** hasTargetPosition changed because of selecting a placemark or changing the search term */
     void targetValidityChanged(bool targetValid);
@@ -116,7 +119,7 @@
     void requestRemoval();
 
     /** Handle click on the map input button */
-    void requestMapPosition();
+    void setMapInputModeEnabled(bool enabled);
 
     /** Progress animation update */
     void updateProgress();
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingLayer.cpp #1102146:1102147
@@ -32,6 +32,7 @@
 #include <QtGui/QPixmap>
 #include <QtGui/QIcon>
 #include <QtGui/QMouseEvent>
+#include <QtGui/QKeyEvent>
 #include <QtGui/QAbstractProxyModel>
 #include <QtGui/QItemSelectionModel>
 
@@ -111,6 +112,9 @@
     /** Dragging trip points, route polygon hovering */
     inline bool handleMouseMove(QMouseEvent* e);
 
+    /** Escape to stop selecting points */
+    inline bool handleKeyEvent(QKeyEvent *e);
+
     /** True if the given point (screen coordinates) is among the route instruction points */
     inline bool isInfoPoint(const QPoint &point);
 };
@@ -345,6 +349,18 @@
     return false;
 }
 
+bool RoutingLayerPrivate::handleKeyEvent(QKeyEvent *e)
+{
+    if (m_pointSelection && e->key() == Qt::Key_Escape)
+    {
+        m_pointSelection = false;
+        emit q->pointSelectionAborted();
+        return true;
+    }
+
+    return false;
+}
+
 bool RoutingLayerPrivate::isInfoPoint(const QPoint &point)
 {
     foreach(const QRegion &region, m_infoRegions) {
@@ -395,6 +411,11 @@
 {
     Q_UNUSED(obj)
 
+    if (event->type() == QEvent::KeyPress ) {
+        QKeyEvent* e = static_cast<QKeyEvent*>(event);
+        return d->handleKeyEvent(e);
+    }
+
     if (event->type() == QEvent::MouseButtonPress) {
         QMouseEvent* e = static_cast<QMouseEvent*>(event);
         return d->handleMouseButtonPress(e);
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingLayer.h #1102146:1102147
@@ -102,8 +102,13 @@
     /**
       * A point was selected by a mouse click after setPointSelectionEnabled(true) was called
       */
-    void pointSelected(const GeoDataCoordinates &coordinates);
+    void pointSelected(const GeoDataCoordinates &coordinates);   
 
+    /**
+      * Selection of points was aborted by the user without selecting a point
+      */
+    void pointSelectionAborted();
+
 protected:
     /** Overriding QWidget, used to make the layer interactive */
     bool eventFilter(QObject *obj, QEvent *event);
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingWidget.cpp #1102146:1102147
@@ -144,6 +144,8 @@
             this, SLOT(activatePlacemark(QModelIndex)));
     connect(d->m_routingLayer, SIGNAL(pointSelected(GeoDataCoordinates)),
             this, SLOT(retrieveSelectedPoint(GeoDataCoordinates)));
+    connect(d->m_routingLayer, SIGNAL(pointSelectionAborted()),
+            this, SLOT(pointSelectionCanceled()));
     connect(d->m_routingManager, SIGNAL(stateChanged(RoutingManager::State,GeoDataLineString)),
             this, SLOT(updateRouteState(RoutingManager::State,GeoDataLineString)));
 
@@ -242,10 +244,8 @@
     }
 }
 
-void RoutingWidget::activateInputWidget(RoutingInputWidget* widget)
+void RoutingWidget::centerOnInputWidget(RoutingInputWidget* widget)
 {
-    d->setActiveInput(widget);
-
     if (widget->hasTargetPosition()) {
         d->m_widget->centerOn(widget->targetPosition());
     }
@@ -274,9 +274,9 @@
         connect(input, SIGNAL(removalRequest(RoutingInputWidget*)),
                 this, SLOT(removeInputWidget(RoutingInputWidget*)));
         connect(input, SIGNAL(activityRequest(RoutingInputWidget*)),
-                this, SLOT(activateInputWidget(RoutingInputWidget*)));
-        connect(input, SIGNAL(mapInputRequest(RoutingInputWidget*)),
-                this, SLOT(requestMapPosition(RoutingInputWidget*)));
+                this, SLOT(centerOnInputWidget(RoutingInputWidget*)));
+        connect(input, SIGNAL(mapInputModeEnabled(RoutingInputWidget*, bool)),
+                this, SLOT(requestMapPosition(RoutingInputWidget*, bool)));
         connect(input, SIGNAL(targetValidityChanged(bool)),
                 this, SLOT(adjustSearchButton()));
 
@@ -314,10 +314,18 @@
     d->m_routingLayer->setRouteDirty(state == RoutingManager::Downloading);
 }
 
-void RoutingWidget::requestMapPosition(RoutingInputWidget* widget)
+void RoutingWidget::requestMapPosition(RoutingInputWidget* widget, bool enabled)
 {
-    d->m_inputRequest = widget;
-    d->m_routingLayer->setPointSelectionEnabled(true);
+    pointSelectionCanceled();
+
+    if (enabled) {
+        d->m_inputRequest = widget;
+        d->m_routingLayer->setPointSelectionEnabled(true);
+        d->m_widget->setFocus(Qt::OtherFocusReason);
+    }
+    else {
+        d->m_routingLayer->setPointSelectionEnabled(false);
+    }
 }
 
 void RoutingWidget::retrieveSelectedPoint(const GeoDataCoordinates &coordinates)
@@ -335,6 +343,13 @@
     d->adjustSearchButton();
 }
 
+void RoutingWidget::pointSelectionCanceled()
+{
+    if (d->m_inputRequest) {
+        d->m_inputRequest->abortMapInputRequest();
+    }
+}
+
 } // namespace Marble
 
 #include "RoutingWidget.moc"
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingWidget.h #1102146:1102147
@@ -67,7 +67,7 @@
     void handleSearchResult(RoutingInputWidget* widget);
 
     /** Switch to the placemark model of an input field */
-    void activateInputWidget(RoutingInputWidget* widget);
+    void centerOnInputWidget(RoutingInputWidget* widget);
 
     /** A placemark was selected in the map, synchronize list view */
     void activatePlacemark(const QModelIndex &index );
@@ -82,7 +82,7 @@
     void updateRouteState(RoutingManager::State state, const GeoDataLineString &route);
 
     /** An input field requests a position input from the map */
-    void requestMapPosition(RoutingInputWidget* widget);
+    void requestMapPosition(RoutingInputWidget* widget, bool enabled);
 
     /** Position in the map selected by the user after a previous slotMapInputRequested */
     void retrieveSelectedPoint(const GeoDataCoordinates &coordinates);
@@ -90,6 +90,9 @@
     /** Update the text of the Search / GetDirections button */
     void adjustSearchButton();
 
+    /** The user canceled point selection from the map */
+    void pointSelectionCanceled();
+
 private:
     RoutingWidgetPrivate* const d;
 };


More information about the Marble-commits mailing list