mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-22 20:59:45 -04:00
first networkview implementation. Totally unfinished
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3738 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a1f9d2a607
commit
0fcc298801
7 changed files with 263 additions and 238 deletions
|
@ -143,28 +143,28 @@ GraphWidget::GraphWidget(QWidget *)
|
|||
|
||||
void GraphWidget::clearGraph()
|
||||
{
|
||||
QGraphicsScene *oldscene = scene();
|
||||
|
||||
QGraphicsScene *scene = new QGraphicsScene(this);
|
||||
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||
scene->setSceneRect(-200, -200, 1000, 1000);
|
||||
setScene(scene);
|
||||
// QGraphicsScene *scene = new QGraphicsScene(this);
|
||||
// scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||
// setScene(scene);
|
||||
|
||||
// scene->addItem(centerNode);
|
||||
// centerNode->setPos(0, 0);
|
||||
|
||||
if (oldscene != NULL)
|
||||
{
|
||||
delete oldscene;
|
||||
}
|
||||
// if (oldscene != NULL)
|
||||
// {
|
||||
// delete oldscene;
|
||||
// }
|
||||
|
||||
scene()->clear();
|
||||
scene()->setSceneRect(-200, -200, 1000, 1000);
|
||||
_edges.clear();
|
||||
_nodes.clear();
|
||||
}
|
||||
|
||||
GraphWidget::NodeId GraphWidget::addNode(const std::string& node_string,uint32_t flags)
|
||||
GraphWidget::NodeId GraphWidget::addNode(const std::string& node_short_string,const std::string& node_complete_string,NodeType type,AuthType auth)
|
||||
{
|
||||
Node *node = new Node(node_string,flags,this);
|
||||
Node *node = new Node(node_short_string,type,auth,this);
|
||||
node->setToolTip(QString::fromStdString(node_complete_string)) ;
|
||||
_nodes.push_back(node) ;
|
||||
scene()->addItem(node);
|
||||
node->setPos(-50+rand()%1000/53.0f, -50+rand()%1000/53.0f);
|
||||
|
@ -179,7 +179,10 @@ GraphWidget::EdgeId GraphWidget::addEdge(NodeId n1,NodeId n2)
|
|||
void GraphWidget::itemMoved()
|
||||
{
|
||||
if (!timerId)
|
||||
{
|
||||
std::cout << "starting timer" << std::endl;
|
||||
timerId = startTimer(1000 / 25);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphWidget::keyPressEvent(QKeyEvent *event)
|
||||
|
@ -306,17 +309,28 @@ void GraphWidget::timerEvent(QTimerEvent *event)
|
|||
}
|
||||
|
||||
bool itemsMoved = false;
|
||||
foreach (Node *node, _nodes) {
|
||||
if (node->advance())
|
||||
foreach (Node *node, _nodes)
|
||||
if(node->advance())
|
||||
itemsMoved = true;
|
||||
}
|
||||
|
||||
if (!itemsMoved) {
|
||||
killTimer(timerId);
|
||||
std::cerr << "Killing timr" << std::endl ;
|
||||
timerId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void GraphWidget::setEdgeLength(uint32_t l)
|
||||
{
|
||||
_edge_length = l ;
|
||||
|
||||
if(!timerId)
|
||||
{
|
||||
std::cout << "starting timer" << std::endl;
|
||||
timerId = startTimer(1000 / 25);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphWidget::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
scaleView(pow((double)2, -event->delta() / 240.0));
|
||||
|
|
|
@ -58,17 +58,26 @@ public:
|
|||
typedef int EdgeId ;
|
||||
|
||||
typedef enum {
|
||||
ELASTIC_NODE_FLAG_OWN = 0x0001,
|
||||
ELASTIC_NODE_FLAG_FRIEND = 0x0002,
|
||||
ELASTIC_NODE_FLAG_AUTHED = 0x0004,
|
||||
ELASTIC_NODE_FLAG_MARGINALAUTH = 0x0008
|
||||
} NodeFlags ;
|
||||
ELASTIC_NODE_TYPE_OWN = 0x0000,
|
||||
ELASTIC_NODE_TYPE_FRIEND = 0x0001,
|
||||
ELASTIC_NODE_TYPE_F_OF_F = 0x0002,
|
||||
ELASTIC_NODE_TYPE_UNKNOWN = 0x0003
|
||||
} NodeType ;
|
||||
|
||||
virtual void itemMoved();
|
||||
NodeId addNode(const std::string& NodeText,uint32_t flags) ;
|
||||
typedef enum {
|
||||
ELASTIC_NODE_AUTH_FULL = 0x0000,
|
||||
ELASTIC_NODE_AUTH_MARGINAL = 0x0001,
|
||||
ELASTIC_NODE_AUTH_UNKNOWN = 0x0002
|
||||
} AuthType ;
|
||||
|
||||
NodeId addNode(const std::string& NodeShortText,const std::string& nodeCompleteText,NodeType type,AuthType auth) ;
|
||||
EdgeId addEdge(NodeId n1,NodeId n2) ;
|
||||
|
||||
void clearGraph() ;
|
||||
virtual void itemMoved();
|
||||
|
||||
void setEdgeLength(uint32_t l) ;
|
||||
uint32_t edgeLength() const { return _edge_length ; }
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
@ -85,6 +94,8 @@ private:
|
|||
|
||||
std::vector<Node *> _nodes ;
|
||||
std::vector<Node *> _edges ;
|
||||
|
||||
uint32_t _edge_length ;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -51,8 +51,8 @@
|
|||
#include "node.h"
|
||||
#include "graphwidget.h"
|
||||
|
||||
Node::Node(const std::string& node_string,uint32_t flags,GraphWidget *graphWidget)
|
||||
: graph(graphWidget),_desc_string(node_string),_flags(flags)
|
||||
Node::Node(const std::string& node_string,GraphWidget::NodeType type,GraphWidget::AuthType auth,GraphWidget *graphWidget)
|
||||
: graph(graphWidget),_desc_string(node_string),_type(type),_auth(auth)
|
||||
{
|
||||
setFlag(ItemIsMovable);
|
||||
#if QT_VERSION >= 0x040600
|
||||
|
@ -147,7 +147,7 @@ void Node::calculateForces(const double *map,int width,int height,int W,int H,fl
|
|||
pos = mapFromItem(edge->sourceNode(), 0, 0);
|
||||
|
||||
float dist = sqrtf(pos.x()*pos.x() + pos.y()*pos.y()) ;
|
||||
float val = dist - NODE_DISTANCE ;
|
||||
float val = dist - graph->edgeLength() ;
|
||||
|
||||
xforce += 0.01*pos.x() * val / weight;
|
||||
yforce += 0.01*pos.y() * val / weight;
|
||||
|
@ -183,11 +183,10 @@ void Node::calculateForces(const double *map,int width,int height,int W,int H,fl
|
|||
|
||||
bool Node::advance()
|
||||
{
|
||||
if (newPos == pos())
|
||||
return false;
|
||||
float f = std::max(fabs(newPos.x() - pos().x()), fabs(newPos.y() - pos().y())) ;
|
||||
|
||||
setPos(newPos);
|
||||
return true;
|
||||
return f > 0.05;
|
||||
}
|
||||
|
||||
QRectF Node::boundingRect() const
|
||||
|
@ -217,44 +216,26 @@ QPainterPath Node::shape() const
|
|||
|
||||
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
|
||||
{
|
||||
static QColor type_color[4] = { QColor(Qt::yellow), QColor(Qt::green), QColor(Qt::cyan), QColor(Qt::black) } ;
|
||||
static QColor auth_color[3] = { QColor(Qt::darkYellow), QColor(Qt::darkGreen), QColor(Qt::darkBlue) } ;
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(Qt::darkGray);
|
||||
painter->drawEllipse(-7, -7, 20, 20);
|
||||
|
||||
QColor col0, col1;
|
||||
if (_flags & GraphWidget::ELASTIC_NODE_FLAG_OWN)
|
||||
{
|
||||
col0 = QColor(Qt::yellow);
|
||||
col1 = QColor(Qt::darkYellow);
|
||||
}
|
||||
else if (_flags & GraphWidget::ELASTIC_NODE_FLAG_FRIEND)
|
||||
{
|
||||
col0 = QColor(Qt::green);
|
||||
col1 = QColor(Qt::darkGreen);
|
||||
}
|
||||
else if (_flags & GraphWidget::ELASTIC_NODE_FLAG_AUTHED)
|
||||
{
|
||||
col0 = QColor(Qt::cyan);
|
||||
col1 = QColor(Qt::darkBlue);
|
||||
}
|
||||
else if (_flags & GraphWidget::ELASTIC_NODE_FLAG_MARGINALAUTH)
|
||||
{
|
||||
col0 = QColor(Qt::magenta);
|
||||
col1 = QColor(Qt::darkMagenta);
|
||||
}
|
||||
else
|
||||
{
|
||||
col0 = QColor(Qt::red);
|
||||
col1 = QColor(Qt::darkRed);
|
||||
}
|
||||
QColor col0(type_color[_type]) ;
|
||||
QColor col1(auth_color[_auth]) ;
|
||||
|
||||
QRadialGradient gradient(-3, -3, 10);
|
||||
if (option->state & QStyle::State_Sunken) {
|
||||
if (option->state & QStyle::State_Sunken)
|
||||
{
|
||||
gradient.setCenter(3, 3);
|
||||
gradient.setFocalPoint(3, 3);
|
||||
gradient.setColorAt(1, col0.light(120));
|
||||
gradient.setColorAt(0, col1.light(120));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
gradient.setColorAt(0, col0);
|
||||
gradient.setColorAt(1, col1);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ QT_END_NAMESPACE
|
|||
class Node : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
Node(const std::string& node_string,uint32_t flags,GraphWidget *graphWidget);
|
||||
Node(const std::string& node_string,GraphWidget::NodeType type,GraphWidget::AuthType auth,GraphWidget *graphWidget);
|
||||
|
||||
void addEdge(Edge *edge);
|
||||
QList<Edge *> edges() const;
|
||||
|
@ -82,7 +82,8 @@ private:
|
|||
qreal _speedx,_speedy;
|
||||
int _steps ;
|
||||
std::string _desc_string ;
|
||||
uint32_t _flags ;
|
||||
GraphWidget::NodeType _type ;
|
||||
GraphWidget::AuthType _auth ;
|
||||
bool mDeterminedBB ;
|
||||
int mBBWidth ;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue