Vidalia 0.2.10
|
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 TorMapWidgetPopupMenu.cpp 00013 ** \version $Id: TorMapWidgetPopupMenu.cpp 3735 2009-04-28 20:28:01Z edmanm $ 00014 ** \brief Popup menu displayed when the user mouse clicks on a map placemark 00015 */ 00016 00017 #include "TorMapWidgetPopupMenu.h" 00018 #include "Vidalia.h" 00019 00020 #include <MarbleModel.h> 00021 #include <MarblePlacemarkModel.h> 00022 00023 #include <QChar> 00024 #include <QVector> 00025 #include <QModelIndex> 00026 00027 using namespace Marble; 00028 00029 00030 TorMapWidgetPopupMenu::TorMapWidgetPopupMenu(TorMapWidget *widget) 00031 : QObject(widget), 00032 _widget(widget) 00033 { 00034 _leftClickMenu = new QMenu(widget); 00035 connect(_leftClickMenu, SIGNAL(triggered(QAction*)), 00036 this, SLOT(relaySelected(QAction*))); 00037 } 00038 00039 void 00040 TorMapWidgetPopupMenu::featureClicked(const QPoint &pos, Qt::MouseButton btn) 00041 { 00042 switch (btn) { 00043 case Qt::LeftButton: 00044 featureLeftClicked(pos); 00045 break; 00046 00047 case Qt::RightButton: 00048 break; 00049 00050 default: 00051 break; 00052 } 00053 } 00054 00055 void 00056 TorMapWidgetPopupMenu::featureLeftClicked(const QPoint &pos) 00057 { 00058 QVector<QModelIndex>::const_iterator it; 00059 QVector<QModelIndex> features = _widget->model()->whichFeatureAt(pos); 00060 QString name, id; 00061 int numRelays = 0; 00062 00063 _leftClickMenu->clear(); 00064 for (it = features.constBegin(); it != features.constEnd(); ++it) { 00065 QChar role = (*it).data(MarblePlacemarkModel::GeoTypeRole).toChar(); 00066 if (role == '1') { 00067 /* Normal Tor Relay */ 00068 name = (*it).data().toString(); 00069 id = (*it).data(MarblePlacemarkModel::DescriptionRole).toString(); 00070 00071 QAction *action = _leftClickMenu->addAction(name); 00072 action->setData(id); 00073 numRelays++; 00074 } 00075 } 00076 00077 if (numRelays == 1) 00078 emit displayRouterInfo(id); 00079 else if (numRelays > 1) 00080 _leftClickMenu->popup(_widget->mapToGlobal(pos)); 00081 } 00082 00083 void 00084 TorMapWidgetPopupMenu::relaySelected(QAction *action) 00085 { 00086 QString id = action->data().toString(); 00087 if (! id.isEmpty()) 00088 emit displayRouterInfo(id); 00089 } 00090