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
This commit is contained in:
csoler 2013-09-25 20:13:57 +00:00
parent 027b9ba017
commit 1d0c7b2e2f
4 changed files with 38 additions and 3 deletions

View File

@ -136,8 +136,6 @@ GraphWidget::GraphWidget(QWidget *)
setResizeAnchor(AnchorViewCenter); setResizeAnchor(AnchorViewCenter);
_friction_factor = 1.0f ; _friction_factor = 1.0f ;
scale(qreal(0.8), qreal(0.8)); 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) void GraphWidget::wheelEvent(QWheelEvent *event)
{ {
scaleView(pow((double)2, -event->delta() / 240.0)); scaleView(pow((double)2, -event->delta() / 240.0));

View File

@ -83,6 +83,7 @@ public:
void setEdgeLength(uint32_t l) ; void setEdgeLength(uint32_t l) ;
uint32_t edgeLength() const { return _edge_length ; } uint32_t edgeLength() const { return _edge_length ; }
void forceRedraw() ;
protected: protected:
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
void timerEvent(QTimerEvent *event); void timerEvent(QTimerEvent *event);
@ -102,6 +103,7 @@ private:
uint32_t _edge_length ; uint32_t _edge_length ;
float _friction_factor ; float _friction_factor ;
NodeId _current_node ;
}; };
#endif #endif

View File

@ -62,6 +62,8 @@
#define IMAGE_TRUSTED ":/images/rs-2.png" #define IMAGE_TRUSTED ":/images/rs-2.png"
#define IMAGE_MAKEFRIEND ":/images/user/add_user16.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) 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) : 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) } ; 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<Edge*>::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->setPen(Qt::NoPen);
painter->setBrush(Qt::darkGray); painter->setBrush(Qt::darkGray);
@ -318,6 +339,9 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
void Node::mousePressEvent(QGraphicsSceneMouseEvent *event) void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
_selected_node = this ;
graph->forceRedraw() ;
update(); update();
QGraphicsItem::mousePressEvent(event); QGraphicsItem::mousePressEvent(event);
} }
@ -354,6 +378,10 @@ void Node::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
_selected_node = NULL ;
graph->forceRedraw() ;
update(); update();
QGraphicsItem::mouseReleaseEvent(event); QGraphicsItem::mouseReleaseEvent(event);
} }

View File

@ -106,6 +106,8 @@ private:
bool mDeterminedBB ; bool mDeterminedBB ;
int mBBWidth ; int mBBWidth ;
static Node *_selected_node ;
std::string _ssl_id ; std::string _ssl_id ;
std::string _gpg_id ; std::string _gpg_id ;