From 1d0c7b2e2f9728d20adb77d543266a04de5d74b1 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 25 Sep 2013 20:13:57 +0000 Subject: [PATCH] highlight peers in network graph according to friendship distance from selected node git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6765 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/gui/elastic/graphwidget.cpp | 7 +++-- retroshare-gui/src/gui/elastic/graphwidget.h | 2 ++ retroshare-gui/src/gui/elastic/node.cpp | 30 ++++++++++++++++++- retroshare-gui/src/gui/elastic/node.h | 2 ++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/retroshare-gui/src/gui/elastic/graphwidget.cpp b/retroshare-gui/src/gui/elastic/graphwidget.cpp index a824fd204..294fae1c7 100644 --- a/retroshare-gui/src/gui/elastic/graphwidget.cpp +++ b/retroshare-gui/src/gui/elastic/graphwidget.cpp @@ -136,8 +136,6 @@ GraphWidget::GraphWidget(QWidget *) setResizeAnchor(AnchorViewCenter); _friction_factor = 1.0f ; - - scale(qreal(0.8), qreal(0.8)); } @@ -384,6 +382,11 @@ void GraphWidget::setEdgeLength(uint32_t l) } } +void GraphWidget::forceRedraw() +{ + for(uint32_t i=0;i<_nodes.size();++i) + _nodes[i]->update(_nodes[i]->boundingRect()) ; +} void GraphWidget::wheelEvent(QWheelEvent *event) { scaleView(pow((double)2, -event->delta() / 240.0)); diff --git a/retroshare-gui/src/gui/elastic/graphwidget.h b/retroshare-gui/src/gui/elastic/graphwidget.h index 4d90f97df..d7115f9e5 100644 --- a/retroshare-gui/src/gui/elastic/graphwidget.h +++ b/retroshare-gui/src/gui/elastic/graphwidget.h @@ -83,6 +83,7 @@ public: void setEdgeLength(uint32_t l) ; uint32_t edgeLength() const { return _edge_length ; } + void forceRedraw() ; protected: void keyPressEvent(QKeyEvent *event); void timerEvent(QTimerEvent *event); @@ -102,6 +103,7 @@ private: uint32_t _edge_length ; float _friction_factor ; + NodeId _current_node ; }; #endif diff --git a/retroshare-gui/src/gui/elastic/node.cpp b/retroshare-gui/src/gui/elastic/node.cpp index d929d1d13..42f33e466 100644 --- a/retroshare-gui/src/gui/elastic/node.cpp +++ b/retroshare-gui/src/gui/elastic/node.cpp @@ -62,6 +62,8 @@ #define IMAGE_TRUSTED ":/images/rs-2.png" #define IMAGE_MAKEFRIEND ":/images/user/add_user16.png" +Node *Node::_selected_node = NULL ; + Node::Node(const std::string& node_string,GraphWidget::NodeType type,GraphWidget::AuthType auth,GraphWidget *graphWidget,const std::string& ssl_id,const std::string& gpg_id) : graph(graphWidget),_desc_string(node_string),_type(type),_auth(auth),_ssl_id(ssl_id),_gpg_id(gpg_id) { @@ -259,7 +261,26 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid { static QColor type_color[4] = { QColor(Qt::yellow), QColor(Qt::green), QColor(Qt::cyan), QColor(Qt::black) } ; - QColor col0(type_color[_type]) ; + QColor col0 ; + + if(_selected_node == NULL) + col0 = type_color[_type] ; + else if(_selected_node == this) + col0 = type_color[0] ; + else + { + bool found = false ; + for(QList::const_iterator it(edgeList.begin());it!=edgeList.end();++it) + if( (*it)->sourceNode() == _selected_node || (*it)->destNode() == _selected_node) + { + col0 = type_color[1] ; + found = true ; + break ; + } + + if(!found) + col0= type_color[2] ; + } painter->setPen(Qt::NoPen); painter->setBrush(Qt::darkGray); @@ -318,6 +339,9 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value) void Node::mousePressEvent(QGraphicsSceneMouseEvent *event) { + _selected_node = this ; + graph->forceRedraw() ; + update(); QGraphicsItem::mousePressEvent(event); } @@ -354,6 +378,10 @@ void Node::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + _selected_node = NULL ; + graph->forceRedraw() ; + update(); QGraphicsItem::mouseReleaseEvent(event); } + diff --git a/retroshare-gui/src/gui/elastic/node.h b/retroshare-gui/src/gui/elastic/node.h index 7987769bf..982743eff 100644 --- a/retroshare-gui/src/gui/elastic/node.h +++ b/retroshare-gui/src/gui/elastic/node.h @@ -106,6 +106,8 @@ private: bool mDeterminedBB ; int mBBWidth ; + static Node *_selected_node ; + std::string _ssl_id ; std::string _gpg_id ;