[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r3436: Initial replacement of ZImageView with MarbleWidget. No plac (vidalia/branches/marble/src/vidalia/network)
Author: edmanm
Date: 2009-01-15 20:11:32 -0500 (Thu, 15 Jan 2009)
New Revision: 3436
Modified:
vidalia/branches/marble/src/vidalia/network/tormapwidget.cpp
vidalia/branches/marble/src/vidalia/network/tormapwidget.h
Log:
Initial replacement of ZImageView with MarbleWidget. No placemarks or circuits
yet, and the zoom is funky. Need to replacement the default input handler.
Modified: vidalia/branches/marble/src/vidalia/network/tormapwidget.cpp
===================================================================
--- vidalia/branches/marble/src/vidalia/network/tormapwidget.cpp 2009-01-16 01:08:33 UTC (rev 3435)
+++ vidalia/branches/marble/src/vidalia/network/tormapwidget.cpp 2009-01-16 01:11:32 UTC (rev 3436)
@@ -18,68 +18,34 @@
#include <cmath>
#include "tormapwidget.h"
-#define IMG_WORLD_MAP ":/images/map/world-map.png"
+using namespace Marble;
/** QPens to use for drawing different map elements */
#define PEN_ROUTER QPen(QColor("#ff030d"), 1.0)
#define PEN_CIRCUIT QPen(Qt::yellow, 0.5)
#define PEN_SELECTED QPen(Qt::green, 2.0)
-/** Size of the map image */
-#define IMG_WIDTH 1000
-#define IMG_HEIGHT 507
-/** Border between the edge of the image and the actual map */
-#define MAP_TOP 2
-#define MAP_BOTTOM 2
-#define MAP_RIGHT 5
-#define MAP_LEFT 5
-#define MAP_WIDTH (IMG_WIDTH-MAP_LEFT-MAP_RIGHT)
-#define MAP_HEIGHT (IMG_HEIGHT-MAP_TOP-MAP_BOTTOM)
-
-/** Map offset from zero longitude */
-#define MAP_ORIGIN -10
-
-/** Minimum allowable size for this widget */
-#define MIN_SIZE QSize(512,256)
-
-/** Robinson projection table */
-/** Length of the parallel of latitude */
-static float plen[] = {
- 1.0000, 0.9986, 0.9954, 0.9900,
- 0.9822, 0.9730, 0.9600, 0.9427,
- 0.9216, 0.8962, 0.8679, 0.8350,
- 0.7986, 0.7597, 0.7186, 0.6732,
- 0.6213, 0.5722, 0.5322
- };
-
-/** Distance of corresponding parallel from equator */
-static float pdfe[] = {
- 0.0000, 0.0620, 0.1240, 0.1860,
- 0.2480, 0.3100, 0.3720, 0.4340,
- 0.4958, 0.5571, 0.6176, 0.6769,
- 0.7346, 0.7903, 0.8435, 0.8936,
- 0.9394, 0.9761, 1.0000
- };
-
/** Default constructor */
TorMapWidget::TorMapWidget(QWidget *parent)
-: ZImageView(parent)
+ : MarbleWidget(parent)
{
- QImage map(IMG_WORLD_MAP);
- setImage(map);
+ setMapThemeId("earth/srtm/srtm.dgml");
}
/** Destructor */
TorMapWidget::~TorMapWidget()
{
+#if 0
clear();
+#endif
}
/** Adds a router to the map. */
void
TorMapWidget::addRouter(const QString &id, float latitude, float longitude)
{
+#if 0
QPointF routerCoord = toMapSpace(latitude, longitude);
/* Add data the hash of known routers, and plot the point on the map */
@@ -87,12 +53,14 @@
_routers.value(id)->first = routerCoord;
else
_routers.insert(id, new QPair<QPointF,bool>(routerCoord, false));
+#endif
}
/** Adds a circuit to the map using the given ordered list of router IDs. */
void
TorMapWidget::addCircuit(const CircuitId &circid, const QStringList &path)
{
+#if 0
QPainterPath *circPainterPath = new QPainterPath;
/* Build the new circuit */
@@ -124,29 +92,34 @@
/* This is a new path, so just add it to our list */
_circuits.insert(circid, new QPair<QPainterPath*,bool>(circPainterPath,false));
}
+#endif
}
/** Removes a circuit from the map. */
void
TorMapWidget::removeCircuit(const CircuitId &circid)
{
+#if 0
QPair<QPainterPath*,bool> *circ = _circuits.take(circid);
QPainterPath *circpath = circ->first;
if (circpath) {
delete circpath;
}
delete circ;
+#endif
}
/** Selects and highlights the router on the map. */
void
TorMapWidget::selectRouter(const QString &id)
{
+#if 0
if (_routers.contains(id)) {
QPair<QPointF, bool> *routerPair = _routers.value(id);
routerPair->second = true;
}
repaint();
+#endif
}
/** Selects and highlights the circuit with the id <b>circid</b>
@@ -154,17 +127,20 @@
void
TorMapWidget::selectCircuit(const CircuitId &circid)
{
+#if 0
if (_circuits.contains(circid)) {
QPair<QPainterPath*, bool> *circuitPair = _circuits.value(circid);
circuitPair->second = true;
}
repaint();
+#endif
}
/** Deselects any highlighted routers or circuits */
void
TorMapWidget::deselectAll()
{
+#if 0
/* Deselect all router points */
foreach (QString router, _routers.keys()) {
QPair<QPointF,bool> *routerPair = _routers.value(router);
@@ -175,12 +151,14 @@
QPair<QPainterPath*,bool> *circuitPair = _circuits.value(circid);
circuitPair->second = false;
}
+#endif
}
/** Clears the list of routers and removes all the data on the map */
void
TorMapWidget::clear()
{
+#if 0
/* Clear out all the router points and free their memory */
foreach (QString router, _routers.keys()) {
delete _routers.take(router);
@@ -191,77 +169,16 @@
delete circuitPair->first;
delete circuitPair;
}
+#endif
}
-
-/** Draws the routers and paths onto the map image. */
-void
-TorMapWidget::paintImage(QPainter *painter)
-{
- painter->setRenderHint(QPainter::Antialiasing);
-
- /* Draw the router points */
- foreach(QString router, _routers.keys()) {
- QPair<QPointF,bool> *routerPair = _routers.value(router);
- painter->setPen((routerPair->second ? PEN_SELECTED : PEN_ROUTER));
- painter->drawPoint(routerPair->first);
- }
- /* Draw the circuit paths */
- foreach(CircuitId circid, _circuits.keys()) {
- QPair<QPainterPath*,bool> *circuitPair = _circuits.value(circid);
- painter->setPen((circuitPair->second ? PEN_SELECTED : PEN_CIRCUIT));
- painter->drawPath(*(circuitPair->first));
- }
-}
-
-/** Converts world space coordinates into map space coordinates */
-QPointF
-TorMapWidget::toMapSpace(float latitude, float longitude)
-{
- float width = MAP_WIDTH;
- float height = MAP_HEIGHT;
- float deg = width / 360.0;
- longitude += MAP_ORIGIN;
-
- float lat;
- float lon;
-
- lat = floor(longitude * (deg * lerp(abs(int(latitude)), plen))
- + width/2 + MAP_LEFT);
-
- if (latitude < 0) {
- lon = floor((height/2) + (lerp(abs(int(latitude)), pdfe) * (height/2))
- + MAP_TOP);
- } else {
- lon = floor((height/2) - (lerp(abs(int(latitude)), pdfe) * (height/2))
- + MAP_TOP);
- }
-
- return QPointF(lat, lon);
-}
-
-/** Linearly interpolates using the values in the Robinson projection table */
-float
-TorMapWidget::lerp(float input, float *table)
-{
- int x = int(floor(input / 5));
-
- return ((table[x+1] - table[x]) /
- (((x+1)*5) - (x*5))) * (input - x*5) + table[x];
-}
-
-/** Returns the minimum size of the widget */
-QSize
-TorMapWidget::minimumSizeHint() const
-{
- return MIN_SIZE;
-}
-
+
/** Zooms to fit all currently displayed circuits on the map. If there are no
* circuits on the map, the viewport will be returned to its default position
* (zoomed all the way out and centered). */
void
TorMapWidget::zoomToFit()
{
+#if 0
QRectF rect = circuitBoundingBox();
if (rect.isNull()) {
@@ -275,12 +192,14 @@
zoom(rect.center().toPoint(), zoomLevel+0.2);
}
+#endif
}
/** Zoom to the circuit on the map with the given <b>circid</b>. */
void
TorMapWidget::zoomToCircuit(const CircuitId &circid)
{
+#if 0
if (_circuits.contains(circid)) {
QPair<QPainterPath*,bool> *pair = _circuits.value(circid);
QRectF rect = ((QPainterPath *)pair->first)->boundingRect();
@@ -291,12 +210,14 @@
zoom(rect.center().toPoint(), zoomLevel+0.2);
}
}
+#endif
}
/** Zooms in on the router with the given <b>id</b>. */
void
TorMapWidget::zoomToRouter(const QString &id)
{
+#if 0
QPair<QPointF,bool> *routerPair;
if (_routers.contains(id)) {
@@ -305,21 +226,6 @@
routerPair->second = true; /* Set the router point to "selected" */
zoom(routerPair->first.toPoint(), 1.0);
}
+#endif
}
-/** Computes a bounding box around all currently displayed circuit paths on
- * the map. */
-QRectF
-TorMapWidget::circuitBoundingBox()
-{
- QRectF rect;
-
- /* Compute the union of bounding rectangles for all circuit paths */
- foreach (CircuitId circid, _circuits.keys()) {
- QPair<QPainterPath*,bool> *pair = _circuits.value(circid);
- QPainterPath *circuit = pair->first;
- rect = rect.unite(circuit->boundingRect());
- }
- return rect;
-}
-
Modified: vidalia/branches/marble/src/vidalia/network/tormapwidget.h
===================================================================
--- vidalia/branches/marble/src/vidalia/network/tormapwidget.h 2009-01-16 01:08:33 UTC (rev 3435)
+++ vidalia/branches/marble/src/vidalia/network/tormapwidget.h 2009-01-16 01:11:32 UTC (rev 3436)
@@ -24,10 +24,10 @@
#include <circuit.h>
#include <stream.h>
-#include "zimageview.h"
+#include <MarbleWidget.h>
-class TorMapWidget : public ZImageView
+class TorMapWidget : public Marble::MarbleWidget
{
Q_OBJECT
@@ -46,7 +46,7 @@
/** Selects and highlights a circuit on the map. */
void selectCircuit(const CircuitId &circid);
/** Returns the minimum size of the widget */
- QSize minimumSizeHint() const;
+ //QSize minimumSizeHint() const;
public slots:
/** Removes a circuit from the map. */
@@ -64,16 +64,16 @@
protected:
/** Paints the current circuits and streams on the image. */
- virtual void paintImage(QPainter *painter);
+ // virtual void paintImage(QPainter *painter);
private:
/** Converts world space coordinates into map space coordinates */
- QPointF toMapSpace(float latitude, float longitude);
+ //QPointF toMapSpace(float latitude, float longitude);
/** Linearly interpolates using the values in the projection table */
- float lerp(float input, float *table);
+ //float lerp(float input, float *table);
/** Computes a bounding box around all currently displayed circuit paths on
* the map. */
- QRectF circuitBoundingBox();
+ //QRectF circuitBoundingBox();
/** Stores map locations for tor routers */
QHash<QString, QPair<QPointF,bool>* > _routers;