[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r3446: Add a TorMapWidgetInputHandler subclass of MarbleWidgetInput (in vidalia/branches/marble/src/vidalia: . network)



Author: edmanm
Date: 2009-01-17 01:58:02 -0500 (Sat, 17 Jan 2009)
New Revision: 3446

Added:
   vidalia/branches/marble/src/vidalia/network/tormapwidgetinputhandler.cpp
   vidalia/branches/marble/src/vidalia/network/tormapwidgetinputhandler.h
Modified:
   vidalia/branches/marble/src/vidalia/CMakeLists.txt
   vidalia/branches/marble/src/vidalia/network/tormapwidget.cpp
Log:
Add a TorMapWidgetInputHandler subclass of MarbleWidgetInputHandler and
replace the default Marble input handler with it. Currently supports mouse
wheel and double-click zooming, mouse panning and placemark identification.
Need to add a replacement for MarbleWidgetPopupMenu that will get called from
the new input handler.


Modified: vidalia/branches/marble/src/vidalia/CMakeLists.txt
===================================================================
--- vidalia/branches/marble/src/vidalia/CMakeLists.txt	2009-01-17 01:47:07 UTC (rev 3445)
+++ vidalia/branches/marble/src/vidalia/CMakeLists.txt	2009-01-17 06:58:02 UTC (rev 3446)
@@ -169,6 +169,7 @@
   network/routerlistwidget.cpp
   network/streamitem.cpp
   network/tormapwidget.cpp
+  network/tormapwidgetinputhandler.cpp
 )
 qt4_wrap_cpp(vidalia_SRCS
   network/circuitlistwidget.h
@@ -177,6 +178,7 @@
   network/routerdescriptorview.h
   network/routerlistwidget.h
   network/tormapwidget.h
+  network/tormapwidgetinputhandler.h
 )
 
 ## Choose the correct tray icon implementation for the current platform

Modified: vidalia/branches/marble/src/vidalia/network/tormapwidget.cpp
===================================================================
--- vidalia/branches/marble/src/vidalia/network/tormapwidget.cpp	2009-01-17 01:47:07 UTC (rev 3445)
+++ vidalia/branches/marble/src/vidalia/network/tormapwidget.cpp	2009-01-17 06:58:02 UTC (rev 3446)
@@ -15,11 +15,11 @@
 */
 
 #include <QStringList>
-#include <cmath>
+#include <vidalia.h>
+
+#include "tormapwidgetinputhandler.h"
 #include "tormapwidget.h"
 
-#include <vidalia.h>
-
 using namespace Marble;
 
 /** QPens to use for drawing different map elements */
@@ -34,6 +34,9 @@
   setMapThemeId("earth/srtm/srtm.dgml");
   setShowScaleBar(false);
   setShowCrosshairs(false);
+
+  setCursor(Qt::OpenHandCursor);
+  setInputHandler(new TorMapWidgetInputHandler());
 }
 
 /** Destructor */

Added: vidalia/branches/marble/src/vidalia/network/tormapwidgetinputhandler.cpp
===================================================================
--- vidalia/branches/marble/src/vidalia/network/tormapwidgetinputhandler.cpp	                        (rev 0)
+++ vidalia/branches/marble/src/vidalia/network/tormapwidgetinputhandler.cpp	2009-01-17 06:58:02 UTC (rev 3446)
@@ -0,0 +1,135 @@
+/*
+**  This file is part of Vidalia, and is subject to the license terms in the
+**  LICENSE file, found in the top level directory of this distribution. If you
+**  did not receive the LICENSE file with this file, you may obtain it from the
+**  Vidalia source package distributed by the Vidalia Project at
+**  http://www.vidalia-project.net/. No part of Vidalia, including this file,
+**  may be copied, modified, propagated, or distributed except according to the
+**  terms described in the LICENSE file.
+*/
+
+#include <QTimer>
+#include <QMouseEvent>
+#include <QWheelEvent>
+#include <QPersistentModelIndex>
+
+#include <MarbleWidget.h>
+#include <MarbleMap.h>
+#include <MarbleModel.h>
+#include <ViewParams.h>
+#include <ViewPortParams.h>
+
+#include "tormapwidgetinputhandler.h"
+
+using namespace Marble;
+
+
+/** Amount to zoom in or out when responding to mouse double clicks. This
+ * value was taken from MarbleMap.cpp.
+ */
+#define MAP_ZOOM_STEP   40
+
+/** Number of units the mouse must be clicked and dragged before it will
+ * force a map rotation and repaint.
+*/
+#define MIN_DRAG_THRESHOLD 3
+
+
+TorMapWidgetInputHandler::TorMapWidgetInputHandler()
+  : MarbleWidgetInputHandler()
+{
+}
+
+bool
+TorMapWidgetInputHandler::eventFilter(QObject *obj, QEvent *e)
+{
+  Q_UNUSED(obj);
+  
+  QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(e);
+
+  switch (e->type()) {
+    case QEvent::MouseButtonPress:
+      _mousePressedX = mouseEvent->x();
+      _mousePressedY = mouseEvent->y();
+      _mousePressedLon = m_widget->centerLongitude();
+      _mousePressedLat = m_widget->centerLatitude();
+
+      if (! pointHasFeatures(mouseEvent->pos()))
+        m_widget->setCursor(Qt::ClosedHandCursor);
+      break;
+
+    case QEvent::MouseButtonRelease:
+      if (! pointHasFeatures(mouseEvent->pos()))
+        m_widget->setCursor(Qt::OpenHandCursor);
+      else
+        m_widget->setCursor(Qt::PointingHandCursor);
+      break;
+
+    case QEvent::MouseMove:
+      if (mouseEvent->buttons() & Qt::LeftButton) {
+        // Pan the map if the left button is pressed while dragging
+        int dx = mouseEvent->x() - _mousePressedX;
+        int dy = mouseEvent->y() - _mousePressedY;
+
+        if (abs(dx) <= MIN_DRAG_THRESHOLD && abs(dy) <= MIN_DRAG_THRESHOLD)
+          return true;
+        m_widget->setCursor(Qt::ClosedHandCursor);
+
+        qreal dir = 1;
+        if (m_widget->projection() == Spherical) {
+          if (m_widget->map()->viewParams()->viewport()->polarity() > 0) {
+            if (mouseEvent->y() < (-m_widget->northPoleY() + m_widget->height()/2))
+              dir = -1;
+          } else {
+            if (mouseEvent->y() > (+m_widget->northPoleY() + m_widget->height()/2))
+              dir = -1;
+          }
+        }
+
+        qreal radius = (qreal)(m_widget->radius());
+        qreal lon = (qreal)(_mousePressedLon) - 90.0 * dir * dx / radius;
+        qreal lat = (qreal)(_mousePressedLat) + 90.0 * dy / radius;
+        m_widget->centerOn(lon, lat, false);
+
+        return true;
+      } else {
+        // Change the mouse cursor if we're hovering over a relay placemark
+        if (pointHasFeatures(mouseEvent->pos()) > 0)
+          m_widget->setCursor(Qt::PointingHandCursor);
+        else
+          m_widget->setCursor(Qt::OpenHandCursor);
+      }
+      break;
+
+    case QEvent::MouseButtonDblClick:
+      // Adjust the zoom level on the map
+      if (mouseEvent->button() == Qt::LeftButton) {
+        m_widget->zoomViewBy(MAP_ZOOM_STEP);
+        return true;
+      } else if (mouseEvent->button() == Qt::RightButton) {
+        m_widget->zoomViewBy(-MAP_ZOOM_STEP);
+        return true;
+      }
+      break;
+
+    case QEvent::Wheel:
+      // Adjust the zoom level on the map
+      m_widget->setViewContext(Marble::Animation);
+
+      QWheelEvent *wheelEvent = static_cast<QWheelEvent*>(e);
+      m_widget->zoomViewBy((int)(wheelEvent->delta() / 3));
+      m_mouseWheelTimer->start(400);
+      return true;
+
+    default:
+      break;;
+  }
+  return MarbleWidgetInputHandler::eventFilter(obj, e);
+}
+
+bool
+TorMapWidgetInputHandler::pointHasFeatures(const QPoint &point) const
+{
+  return (m_widget->model()->whichFeatureAt(point).size() > 0);
+}
+


Property changes on: vidalia/branches/marble/src/vidalia/network/tormapwidgetinputhandler.cpp
___________________________________________________________________
Name: svn:eol-style
   + native

Added: vidalia/branches/marble/src/vidalia/network/tormapwidgetinputhandler.h
===================================================================
--- vidalia/branches/marble/src/vidalia/network/tormapwidgetinputhandler.h	                        (rev 0)
+++ vidalia/branches/marble/src/vidalia/network/tormapwidgetinputhandler.h	2009-01-17 06:58:02 UTC (rev 3446)
@@ -0,0 +1,46 @@
+/*
+**  This file is part of Vidalia, and is subject to the license terms in the
+**  LICENSE file, found in the top level directory of this distribution. If you
+**  did not receive the LICENSE file with this file, you may obtain it from the
+**  Vidalia source package distributed by the Vidalia Project at
+**  http://www.vidalia-project.net/. No part of Vidalia, including this file,
+**  may be copied, modified, propagated, or distributed except according to the
+**  terms described in the LICENSE file.
+*/
+
+#ifndef _TORMAPWIDGETINPUTHANDLER_H
+#define _TORMAPWIDGETINPUTHANDLER_H
+
+#include <QEvent>
+#include <QObject>
+#include <QPoint>
+
+#include <MarbleWidgetInputHandler.h>
+
+
+class TorMapWidgetInputHandler : public Marble::MarbleWidgetInputHandler
+{
+  Q_OBJECT
+
+public:
+  /** Default constructor.
+   */
+  TorMapWidgetInputHandler();
+
+protected:
+  /** Filter and handles event <b>e</b> that was sent to widget <b>obj</b>.
+   * <b>obj</b> is always a MarbleWidget object.
+   */
+  virtual bool eventFilter(QObject *obj, QEvent *e);
+
+private:
+  bool pointHasFeatures(const QPoint &point) const;
+
+  int   _mousePressedX;
+  int   _mousePressedY;
+  qreal _mousePressedLon;
+  qreal _mousePressedLat;
+};
+
+#endif
+


Property changes on: vidalia/branches/marble/src/vidalia/network/tormapwidgetinputhandler.h
___________________________________________________________________
Name: svn:keywords
   + tormapwidgetinputhandler.cpp
Name: svn:eol-style
   + native