Vidalia 0.3.1
TorMapWidgetPopupMenu.cpp
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 TorMapWidgetPopupMenu.cpp
13** \brief Popup menu displayed when the user mouse clicks on a map placemark
14*/
15
17#include "Vidalia.h"
18
19#include <MarbleModel.h>
20#include <MarblePlacemarkModel.h>
21
22#include <QChar>
23#include <QVector>
24#include <QModelIndex>
25
26using namespace Marble;
27
28
30 : QObject(widget),
31 _widget(widget)
32{
33 _leftClickMenu = new QMenu(widget);
34 connect(_leftClickMenu, SIGNAL(triggered(QAction*)),
35 this, SLOT(relaySelected(QAction*)));
36}
37
38void
39TorMapWidgetPopupMenu::featureClicked(const QPoint &pos, Qt::MouseButton btn)
40{
41 switch (btn) {
42 case Qt::LeftButton:
44 break;
45
46 case Qt::RightButton:
47 break;
48
49 default:
50 break;
51 }
52}
53
54void
56{
57 QVector<QModelIndex>::const_iterator it;
58 QVector<QModelIndex> features = _widget->model()->whichFeatureAt(pos);
59 QString name, id;
60 int numRelays = 0;
61
62 _leftClickMenu->clear();
63 for (it = features.constBegin(); it != features.constEnd(); ++it) {
64 QChar role = (*it).data(MarblePlacemarkModel::GeoTypeRole).toChar();
65 if (role == '1') {
66 /* Normal Tor Relay */
67 name = (*it).data().toString();
68 id = (*it).data(MarblePlacemarkModel::DescriptionRole).toString();
69
70 QAction *action = _leftClickMenu->addAction(name);
71 action->setData(id);
72 numRelays++;
73 }
74 }
75
76 if (numRelays == 1)
77 emit displayRouterInfo(id);
78 else if (numRelays > 1)
79 _leftClickMenu->popup(_widget->mapToGlobal(pos));
80}
81
82void
84{
85 QString id = action->data().toString();
86 if (! id.isEmpty())
87 emit displayRouterInfo(id);
88}
89
stop errmsg connect(const QHostAddress &address, quint16 port)
virtual void featureLeftClicked(const QPoint &pos)
void displayRouterInfo(const QString &id)
void featureClicked(const QPoint &pos, Qt::MouseButton button)
void relaySelected(QAction *action)
TorMapWidgetPopupMenu(TorMapWidget *widget)