00001 /**************************************************************** 00002 * Vidalia is distributed under the following license: 00003 * 00004 * Copyright (C) 2006, Matt Edman, Justin Hipple 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 ****************************************************************/ 00021 00022 /** 00023 * \file tormapwidget.h 00024 * \version $Id: tormapwidget.h 1262 2006-10-03 07:16:16Z edmanm $ 00025 * \brief Displays Tor servers and circuits on a map of the world 00026 */ 00027 00028 #ifndef _TORMAPWIDGET_H 00029 #define _TORMAPWIDGET_H 00030 00031 #include <QHash> 00032 #include <QPair> 00033 #include <QPainter> 00034 #include <QPainterPath> 00035 00036 #include "zimageview.h" 00037 00038 00039 class TorMapWidget : public ZImageView 00040 { 00041 Q_OBJECT 00042 00043 public: 00044 /** Default constructor. */ 00045 TorMapWidget(QWidget *parent = 0); 00046 /** Destructor. */ 00047 ~TorMapWidget(); 00048 00049 /** Plots the given router on the map using the given coordinates. */ 00050 void addRouter(QString id, float latitude, float longitude); 00051 /** Plots the given circuit on the map. */ 00052 void addCircuit(quint64 circid, QStringList path); 00053 /** Selects and hightlights a router on the map. */ 00054 void selectRouter(QString id); 00055 /** Selects and highlights a circuit on the map. */ 00056 void selectCircuit(quint64 circid); 00057 /** Returns the minimum size of the widget */ 00058 QSize minimumSizeHint() const; 00059 00060 public slots: 00061 /** Removes a circuit from the map. */ 00062 void removeCircuit(quint64 circid); 00063 /** Deselects all the highlighted circuits and routers */ 00064 void deselectAll(); 00065 /** Clears the known routers and removes all the data from the map */ 00066 void clear(); 00067 /** Zooms to fit all currently displayed circuits on the map. */ 00068 void zoomToFit(); 00069 00070 protected: 00071 /** Paints the current circuits and streams on the image. */ 00072 virtual void paintImage(QPainter *painter); 00073 00074 private: 00075 /** Converts world space coordinates into map space coordinates */ 00076 QPointF toMapSpace(float latitude, float longitude); 00077 /** Linearly interpolates using the values in the projection table */ 00078 float lerp(float input, float *table); 00079 /** Computes a bounding box around all currently displayed circuit paths on 00080 * the map. */ 00081 QRectF circuitBoundingBox(); 00082 00083 /** Stores map locations for tor routers */ 00084 QHash<QString, QPair<QPointF,bool>* > _routers; 00085 /** Stores circuit information */ 00086 QHash<quint64, QPair<QPainterPath *,bool>* > _circuits; 00087 }; 00088 00089 #endif 00090