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

[vidalia-svn] r3457: Add a custom menu for handling the user clicking on placemar (in vidalia/branches/marble/src/vidalia: . network)



Author: edmanm
Date: 2009-01-18 20:31:47 -0500 (Sun, 18 Jan 2009)
New Revision: 3457

Added:
   vidalia/branches/marble/src/vidalia/network/tormapwidgetpopupmenu.cpp
   vidalia/branches/marble/src/vidalia/network/tormapwidgetpopupmenu.h
Modified:
   vidalia/branches/marble/src/vidalia/CMakeLists.txt
   vidalia/branches/marble/src/vidalia/network/tormapwidget.cpp
   vidalia/branches/marble/src/vidalia/network/tormapwidget.h
Log:

Add a custom menu for handling the user clicking on placemarks. If the
location clicked contains only one relay placemark, emit a displayRouterInfo()
signal indicating which relay was clicked. If the location clicked has more
than one relay, display a popup menu to let the user select a particular relay
from among all those at that location.


Modified: vidalia/branches/marble/src/vidalia/CMakeLists.txt
===================================================================
--- vidalia/branches/marble/src/vidalia/CMakeLists.txt	2009-01-18 06:42:52 UTC (rev 3456)
+++ vidalia/branches/marble/src/vidalia/CMakeLists.txt	2009-01-19 01:31:47 UTC (rev 3457)
@@ -170,6 +170,7 @@
   network/streamitem.cpp
   network/tormapwidget.cpp
   network/tormapwidgetinputhandler.cpp
+  network/tormapwidgetpopupmenu.cpp
 )
 qt4_wrap_cpp(vidalia_SRCS
   network/circuitlistwidget.h
@@ -179,6 +180,7 @@
   network/routerlistwidget.h
   network/tormapwidget.h
   network/tormapwidgetinputhandler.h
+  network/tormapwidgetpopupmenu.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-18 06:42:52 UTC (rev 3456)
+++ vidalia/branches/marble/src/vidalia/network/tormapwidget.cpp	2009-01-19 01:31:47 UTC (rev 3457)
@@ -14,16 +14,11 @@
 ** \brief Displays Tor servers and circuits on a map of the world
 */
 
-#include <QPoint>
-#include <QVector>
-#include <QPersistentModelIndex>
 #include <QStringList>
 #include <vidalia.h>
 
-#include <MarbleModel.h>
-#include <MarblePlacemarkModel.h>
-
 #include "tormapwidgetinputhandler.h"
+#include "tormapwidgetpopupmenu.h"
 #include "tormapwidget.h"
 
 using namespace Marble;
@@ -41,9 +36,17 @@
   setShowScaleBar(false);
   setShowCrosshairs(false);
   setAnimationsEnabled(true);
+  setCursor(Qt::OpenHandCursor);
 
-  setCursor(Qt::OpenHandCursor);
-  setInputHandler(new TorMapWidgetInputHandler());
+  TorMapWidgetInputHandler *handler = new TorMapWidgetInputHandler();
+  TorMapWidgetPopupMenu *popupMenu  = new TorMapWidgetPopupMenu(this);
+
+  connect(handler, SIGNAL(featureClicked(QPoint,Qt::MouseButton)),
+          popupMenu, SLOT(featureClicked(QPoint,Qt::MouseButton)));
+  connect(popupMenu, SIGNAL(displayRouterInfo(QString)),
+          this, SIGNAL(displayRouterInfo(QString)));
+
+  setInputHandler(handler);
 }
 
 /** Destructor */

Modified: vidalia/branches/marble/src/vidalia/network/tormapwidget.h
===================================================================
--- vidalia/branches/marble/src/vidalia/network/tormapwidget.h	2009-01-18 06:42:52 UTC (rev 3456)
+++ vidalia/branches/marble/src/vidalia/network/tormapwidget.h	2009-01-19 01:31:47 UTC (rev 3457)
@@ -66,6 +66,11 @@
   /** Zoom to the circuit on the map with the given <b>circid</b>. */
   void zoomToCircuit(const CircuitId &circid);
 
+signals:
+  /** Emitted when the user selects a router placemark on the map. <b>id</b>
+   * contain's the selected router's fingerprint. */
+  void displayRouterInfo(const QString &id);
+
 protected:
   /** Paints the current circuits and streams on the image. */
   virtual void customPaint(Marble::GeoPainter *painter);

Added: vidalia/branches/marble/src/vidalia/network/tormapwidgetpopupmenu.cpp
===================================================================
--- vidalia/branches/marble/src/vidalia/network/tormapwidgetpopupmenu.cpp	                        (rev 0)
+++ vidalia/branches/marble/src/vidalia/network/tormapwidgetpopupmenu.cpp	2009-01-19 01:31:47 UTC (rev 3457)
@@ -0,0 +1,90 @@
+/*
+**  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.
+*/
+
+/*
+** \file tormapwidgetpopupmenu.cpp
+** \version $Id$
+** \brief Popup menu displayed when the user mouse clicks on a map placemark
+*/
+
+#include <QChar>
+#include <QVector>
+#include <QPersistentModelIndex>
+#include <vidalia.h>
+
+#include <MarbleModel.h>
+#include <MarblePlacemarkModel.h>
+
+#include "tormapwidgetpopupmenu.h"
+
+using namespace Marble;
+
+
+TorMapWidgetPopupMenu::TorMapWidgetPopupMenu(TorMapWidget *widget)
+  : QObject(widget),
+    _widget(widget)
+{
+  _leftClickMenu = new QMenu(widget);
+  connect(_leftClickMenu, SIGNAL(triggered(QAction*)),
+          this, SLOT(relaySelected(QAction*)));
+}
+
+void
+TorMapWidgetPopupMenu::featureClicked(const QPoint &pos, Qt::MouseButton btn)
+{
+  switch (btn) {
+    case Qt::LeftButton:
+      featureLeftClicked(pos);
+      break;
+
+    case Qt::RightButton:
+      break;
+
+    default:
+      break;
+  }
+}
+
+void
+TorMapWidgetPopupMenu::featureLeftClicked(const QPoint &pos)
+{
+  QVector<QPersistentModelIndex>::const_iterator it;
+  QVector<QPersistentModelIndex> features = _widget->model()->whichFeatureAt(pos);
+  QString name, id;
+  int numRelays = 0;
+
+  _leftClickMenu->clear();
+  for (it = features.constBegin(); it != features.constEnd(); ++it) {
+    QChar role = (*it).data(MarblePlacemarkModel::GeoTypeRole).toChar();
+    if (role == '1') {
+      /* Normal Tor Relay */
+      name = (*it).data().toString();
+      id   = (*it).data(MarblePlacemarkModel::DescriptionRole).toString();
+
+      QAction *action = _leftClickMenu->addAction(name);
+      action->setData(id);
+      numRelays++;
+    }
+  }
+
+  if (numRelays == 1)
+    emit displayRouterInfo(id);
+  else if (numRelays > 1)
+    _leftClickMenu->popup(_widget->mapToGlobal(pos));
+}
+
+void
+TorMapWidgetPopupMenu::relaySelected(QAction *action)
+{
+  QString id = action->data().toString();
+  if (! id.isEmpty())
+    emit displayRouterInfo(id);
+}
+


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

Added: vidalia/branches/marble/src/vidalia/network/tormapwidgetpopupmenu.h
===================================================================
--- vidalia/branches/marble/src/vidalia/network/tormapwidgetpopupmenu.h	                        (rev 0)
+++ vidalia/branches/marble/src/vidalia/network/tormapwidgetpopupmenu.h	2009-01-19 01:31:47 UTC (rev 3457)
@@ -0,0 +1,81 @@
+/*
+**  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.
+*/
+
+/*
+** \file tormapwidgetpopupmenu.h
+** \version $Id$
+** \brief Popup menu displayed when the user mouse clicks on a map placemark
+*/
+
+#ifndef _TORMAPWIDGETPOPUPMENU_H
+#define _TORMAPWIDGETPOPUPMENU_H
+
+#include <QObject>
+#include <QPoint>
+#include <QString>
+#include <QMenu>
+
+#include "tormapwidget.h"
+
+
+class TorMapWidgetPopupMenu : public QObject
+{
+  Q_OBJECT
+
+public:
+  /** Constructor. <b>widget</b> is the parent map widget on which the popup
+   * menu will be displayed.
+   */
+  TorMapWidgetPopupMenu(TorMapWidget *widget);
+
+public slots:
+  /** Called when the user clicks on one or more map features located at mouse
+   * position <b>pos</b>. <b>button</b> specifies the mouse button clicked.
+   * A popup menu will be displayed depending on which mouse button was
+   * clicked.
+   *
+   * \sa featureLeftClicked
+   */
+  void featureClicked(const QPoint &pos, Qt::MouseButton button);
+
+signals:
+  /** Emitted when the user selects the router placemark whose fingerprint
+   * is <b>id</b>.
+   */
+  void displayRouterInfo(const QString &id);
+
+protected:
+  /** Called when the user left-clicks on one or more placemarks at mouse
+   * position <b>pos</b>. If only one relay placemark exists at <b>pos</b>,
+   * then the displayRouterInfo() signal will be emitted. Otherwise, a
+   * popup menu will be displayed listing all placemarks at this location.
+   *
+   * \sa featureLeftClicked
+   */
+  virtual void featureLeftClicked(const QPoint &pos);
+
+private slots:
+  /** Called when the user selects a relay from the popup menu used to
+   * disambiguate a location with multiple relay placemarks.
+   */
+  void relaySelected(QAction *action);
+
+private:
+  /** The parent map widget on which the popup menu is displayed.
+   */
+  TorMapWidget *_widget;
+
+  /** Menu displayed when the user left-clicks on one or more placemarks.
+   */
+  QMenu *_leftClickMenu;
+};
+
+#endif
+


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