nodeview: implemented ability to select and delete node edges

This commit is contained in:
itsmattkc
2020-04-29 17:25:41 +10:00
parent 3f77c2ce91
commit 4ac5513e3f
5 changed files with 82 additions and 33 deletions
+28 -16
View File
@@ -23,6 +23,7 @@
#include <QApplication>
#include <QDebug>
#include <QGraphicsSceneMouseEvent>
#include <QStyleOptionGraphicsItem>
#include "common/clamp.h"
#include "common/lerp.h"
@@ -34,10 +35,12 @@ OLIVE_NAMESPACE_ENTER
NodeViewEdge::NodeViewEdge(QGraphicsItem *parent) :
QGraphicsPathItem(parent),
edge_(nullptr),
color_group_(QPalette::Active),
color_role_(QPalette::Text),
connected_(false),
highlighted_(false),
flow_dir_(NodeViewCommon::kLeftToRight)
{
setFlag(QGraphicsItem::ItemIsSelectable);
// Ensures this UI object is drawn behind other objects
setZValue(-1);
@@ -83,24 +86,16 @@ void NodeViewEdge::Adjust()
void NodeViewEdge::SetConnected(bool c)
{
if (c) {
color_group_ = QPalette::Active;
} else {
color_group_ = QPalette::Disabled;
}
connected_ = c;
UpdatePen();
update();
}
void NodeViewEdge::SetHighlighted(bool e)
{
if (e) {
color_role_ = QPalette::Highlight;
} else {
color_role_ = QPalette::Text;
}
highlighted_ = e;
UpdatePen();
update();
}
void NodeViewEdge::SetPoints(const QPointF &start, const QPointF &end, bool input_is_expanded)
@@ -137,9 +132,26 @@ void NodeViewEdge::SetFlowDirection(NodeViewCommon::FlowDirection dir)
Adjust();
}
void NodeViewEdge::UpdatePen()
void NodeViewEdge::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
setPen(QPen(qApp->palette().color(color_group_, color_role_), edge_width_));
QPalette::ColorGroup group;
QPalette::ColorRole role;
if (connected_) {
group = QPalette::Active;
} else {
group = QPalette::Disabled;
}
if (highlighted_ != bool(option->state & QStyle::State_Selected)) {
role = QPalette::Highlight;
} else {
role = QPalette::Text;
}
painter->setPen(QPen(qApp->palette().color(group, role), edge_width_));
painter->setBrush(Qt::NoBrush);
painter->drawPath(path());
}
OLIVE_NAMESPACE_EXIT