nodeview: allow users to place a node on an edge to automatically connect it

between the two nodes

UI convenience. Edge highlights when the cursor is in range to perform this
action.
This commit is contained in:
itsmattkc
2020-02-16 12:40:12 +11:00
parent a987899e5c
commit ce889f68d5
6 changed files with 111 additions and 8 deletions
+18 -7
View File
@@ -30,7 +30,8 @@
NodeViewEdge::NodeViewEdge(QGraphicsItem *parent) :
QGraphicsLineItem(parent),
edge_(nullptr),
connected_(false)
connected_(false),
highlighted_(false)
{
// Ensures this UI object is drawn behind other objects
setZValue(-1);
@@ -101,19 +102,29 @@ void NodeViewEdge::Adjust()
void NodeViewEdge::SetConnected(bool c)
{
connected_ = c;
update();
}
void NodeViewEdge::SetHighlighted(bool e)
{
highlighted_ = e;
update();
}
void NodeViewEdge::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QPalette::ColorGroup color_mode;
QPalette::ColorGroup color_group = QPalette::Active;
QPalette::ColorRole color_role = QPalette::Text;
if (connected_) {
color_mode = QPalette::Active;
} else {
color_mode = QPalette::Disabled;
if (highlighted_) {
color_role = QPalette::Highlight;
}
setPen(QPen(widget->palette().color(color_mode, QPalette::Text), edge_width_));
if (!connected_) {
color_group = QPalette::Disabled;
}
setPen(QPen(widget->palette().color(color_group, color_role), edge_width_));
QGraphicsLineItem::paint(painter, option, widget);
}