Vidalia  0.2.21
TorMapImageView.h
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If you
4 ** did not receive the LICENSE file with this file, you may obtain it from the
5 ** Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file TorMapImageView.h
13 ** \brief Displays Tor servers and circuits on a map of the world
14 */
15 
16 #ifndef _TORMAPIMAGEVIEW_H
17 #define _TORMAPIMAGEVIEW_H
18 
19 #include "ZImageView.h"
20 #include "GeoIpRecord.h"
21 
22 #include "RouterDescriptor.h"
23 #include "Circuit.h"
24 
25 #include <QHash>
26 #include <QPair>
27 #include <QPainter>
28 #include <QPainterPath>
29 
30 
32 {
33  Q_OBJECT
34 
35 public:
36  /** Default constructor. */
37  TorMapImageView(QWidget *parent = 0);
38  /** Destructor. */
40 
41  /** Plots the given router on the map using the given coordinates. */
42  void addRouter(const RouterDescriptor &desc, const GeoIpRecord &geoip);
43  /** Plots the given circuit on the map. */
44  void addCircuit(const CircuitId &circid, const QStringList &path);
45  /** Selects and hightlights a router on the map. */
46  void selectRouter(const QString &id);
47  /** Selects and highlights a circuit on the map. */
48  void selectCircuit(const CircuitId &circid);
49  /** Returns the minimum size of the widget */
50  QSize minimumSizeHint() const;
51 
52 public slots:
53  /** Removes a circuit from the map. */
54  void removeCircuit(const CircuitId &circid);
55  /** Deselects all the highlighted circuits and routers */
56  void deselectAll();
57  /** Clears the known routers and removes all the data from the map */
58  void clear();
59  /** Zooms to fit all currently displayed circuits on the map. */
60  void zoomToFit();
61  /** Zoom to a particular router on the map. */
62  void zoomToRouter(const QString &id);
63  /** Zoom to the circuit on the map with the given <b>circid</b>. */
64  void zoomToCircuit(const CircuitId &circid);
65 
66 protected:
67  /** Paints the current circuits and streams on the image. */
68  virtual void paintImage(QPainter *painter);
69 
70 private:
71  /** Converts world space coordinates into map space coordinates */
72  QPointF toMapSpace(float latitude, float longitude);
73  /** Linearly interpolates using the values in the projection table */
74  float lerp(float input, float *table);
75  /** Computes a bounding box around all currently displayed circuit paths on
76  * the map. */
77  QRectF circuitBoundingBox();
78 
79  /** Stores map locations for tor routers */
80  QHash<QString, QPair<QPointF,bool>* > _routers;
81  /** Stores circuit information */
82  QHash<CircuitId, QPair<QPainterPath *,bool>* > _circuits;
83 };
84 
85 #endif
86