gui: network_view: add coloring edges for searched and selected nodes

didn't bother to check
edges repaints every now and again
commented out nevertheles
This commit is contained in:
chelovechishko 2022-04-16 02:51:57 +09:00
parent 0d7174225f
commit 7d8f23259c
5 changed files with 40 additions and 6 deletions

View File

@ -96,6 +96,12 @@ QRectF Edge::boundingRect() const
.adjusted(-extra, -extra, extra, extra);
}
void Edge::setEdgeColor(QColor color)
{
edgeColor = color;
update(boundingRect());
}
void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
if (!source || !dest)
@ -103,7 +109,7 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
// Draw the line itself
QLineF line(sourcePoint, destPoint);
painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter->setPen(QPen(edgeColor, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter->drawLine(line);
return ;

View File

@ -40,6 +40,7 @@ public:
void setDestNode(Node *node);
void adjust();
void setEdgeColor(QColor color);
enum { Type = UserType + 2 };
int type() const { return Type; }
@ -54,6 +55,7 @@ private:
QPointF sourcePoint;
QPointF destPoint;
qreal arrowSize;
QColor edgeColor = Qt::black;
};
#endif

View File

@ -251,23 +251,48 @@ static QColor lightdark(const QColor& col,int l,int d)
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) } ;
// QColor default_edge = Qt::black;
// QColor searched_node_edge = Qt::magenta;
// QColor selected_node_edge = Qt::green;
QColor col0 ;
// selected_node = clicked on with left mouse button
if(_selected_node == NULL)
{
col0 = type_color[_type] ;
/* if (sought_for) // this node
{
// repaint edge
for (QList<Edge*>::const_iterator it(edgeList.begin()); it != edgeList.end(); ++it)
(*it)->setEdgeColor(searched_node_edge);
}
else
{
for (QList<Edge*>::const_iterator it(edgeList.begin()); it != edgeList.end(); ++it)
(*it)->setEdgeColor(default_edge);
} */
}
else if(_selected_node == this)
{
// for (QList<Edge*>::const_iterator it(edgeList.begin()); it != edgeList.end(); ++it)
// (*it)->setEdgeColor(selected_node_edge);
col0 = type_color[0] ;
}
// selected_node = some_other_node
else
{
bool found = false ;
for(QList<Edge*>::const_iterator it(edgeList.begin());it!=edgeList.end();++it)
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] ;

View File

@ -65,7 +65,7 @@ public:
QRectF boundingRect() const;
QPainterPath shape() const;
void setNodeDrawSize(int nds){mNodeDrawSize = nds;}
void setNodeDrawSize(int nds, bool repaint_edges) {mNodeDrawSize = nds; sought_for=repaint_edges;}
int getNodeDrawSize(){return mNodeDrawSize;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@ -95,6 +95,7 @@ private:
bool mDeterminedBB ;
int mBBWidth ;
int mNodeDrawSize;
bool sought_for = false;
static Node *_selected_node ;

View File

@ -297,7 +297,7 @@ void GraphWidget::setNameSearch(QString s)
if (s.length() == 0){
for(uint32_t i=0;i<_nodes.size();++i)
_nodes[i]->setNodeDrawSize(12 * f);
_nodes[i]->setNodeDrawSize(12 * f, false);
forceRedraw();
return;
}
@ -309,10 +309,10 @@ void GraphWidget::setNameSearch(QString s)
if (ns.find(qs) != std::string::npos) {
//std::cout << "found!" << '\n';
ni->setNodeDrawSize(22 * f);
ni->setNodeDrawSize(22 * f, true);
//std::cout << ni->getNodeDrawSize() << '\n';
} else {
ni->setNodeDrawSize(12 * f);
ni->setNodeDrawSize(12 * f, false);
}
}