00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If you 00004 ** did not receive the LICENSE file with this file, you may obtain it from the 00005 ** Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.vidalia-project.net/. No part of Vidalia, including this file, 00007 ** may be copied, modified, propagated, or distributed except according to the 00008 ** terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file TorMapImageView.h 00013 ** \version $Id: TorMapImageView.h 3735 2009-04-28 20:28:01Z edmanm $ 00014 ** \brief Displays Tor servers and circuits on a map of the world 00015 */ 00016 00017 #ifndef _TORMAPIMAGEVIEW_H 00018 #define _TORMAPIMAGEVIEW_H 00019 00020 #include "ZImageView.h" 00021 #include "GeoIp.h" 00022 00023 #include "RouterDescriptor.h" 00024 #include "Circuit.h" 00025 00026 #include <QHash> 00027 #include <QPair> 00028 #include <QPainter> 00029 #include <QPainterPath> 00030 00031 00032 class TorMapImageView : public ZImageView 00033 { 00034 Q_OBJECT 00035 00036 public: 00037 /** Default constructor. */ 00038 TorMapImageView(QWidget *parent = 0); 00039 /** Destructor. */ 00040 ~TorMapImageView(); 00041 00042 /** Plots the given router on the map using the given coordinates. */ 00043 void addRouter(const RouterDescriptor &desc, const GeoIp &geoip); 00044 /** Plots the given circuit on the map. */ 00045 void addCircuit(const CircuitId &circid, const QStringList &path); 00046 /** Selects and hightlights a router on the map. */ 00047 void selectRouter(const QString &id); 00048 /** Selects and highlights a circuit on the map. */ 00049 void selectCircuit(const CircuitId &circid); 00050 /** Returns the minimum size of the widget */ 00051 QSize minimumSizeHint() const; 00052 00053 public slots: 00054 /** Removes a circuit from the map. */ 00055 void removeCircuit(const CircuitId &circid); 00056 /** Deselects all the highlighted circuits and routers */ 00057 void deselectAll(); 00058 /** Clears the known routers and removes all the data from the map */ 00059 void clear(); 00060 /** Zooms to fit all currently displayed circuits on the map. */ 00061 void zoomToFit(); 00062 /** Zoom to a particular router on the map. */ 00063 void zoomToRouter(const QString &id); 00064 /** Zoom to the circuit on the map with the given <b>circid</b>. */ 00065 void zoomToCircuit(const CircuitId &circid); 00066 00067 protected: 00068 /** Paints the current circuits and streams on the image. */ 00069 virtual void paintImage(QPainter *painter); 00070 00071 private: 00072 /** Converts world space coordinates into map space coordinates */ 00073 QPointF toMapSpace(float latitude, float longitude); 00074 /** Linearly interpolates using the values in the projection table */ 00075 float lerp(float input, float *table); 00076 /** Computes a bounding box around all currently displayed circuit paths on 00077 * the map. */ 00078 QRectF circuitBoundingBox(); 00079 00080 /** Stores map locations for tor routers */ 00081 QHash<QString, QPair<QPointF,bool>* > _routers; 00082 /** Stores circuit information */ 00083 QHash<CircuitId, QPair<QPainterPath *,bool>* > _circuits; 00084 }; 00085 00086 #endif 00087