nodeview: added setting for curved/straight edges

This commit is contained in:
itsmattkc
2020-05-10 04:33:37 +10:00
parent ed82061b51
commit 9c30f13a2e
6 changed files with 70 additions and 16 deletions
-1
View File
@@ -83,7 +83,6 @@ void Config::SetDefaults()
config_map_["DropWithoutSequenceBehavior"] = TimelineWidget::kDWSAsk;
config_map_["Loop"] = false;
config_map_["NodeCatColor0"] = QVariant::fromValue(Color(0.75f, 0.75f, 0.75f));
config_map_["NodeCatColor1"] = QVariant::fromValue(Color(0.25f, 0.25f, 0.25f));
config_map_["NodeCatColor2"] = QVariant::fromValue(Color(0.75f, 0.75f, 0.25f));
+7
View File
@@ -452,6 +452,13 @@ void NodeView::ShowContextMenu(const QPoint &pos)
} else {
QAction* curved_action = m.addAction(tr("Smooth Edges"));
curved_action->setCheckable(true);
curved_action->setChecked(scene_.GetEdgesAreCurved());
connect(curved_action, &QAction::triggered, &scene_, &NodeViewScene::SetEdgesAreCurved);
m.addSeparator();
Menu* filter_menu = new Menu(tr("Filter"), &m);
filter_menu->addAction(tr("Show All"))->setData(NodeViewScene::kFilterShowAll);
+30 -14
View File
@@ -37,7 +37,8 @@ NodeViewEdge::NodeViewEdge(QGraphicsItem *parent) :
edge_(nullptr),
connected_(false),
highlighted_(false),
flow_dir_(NodeViewCommon::kLeftToRight)
flow_dir_(NodeViewCommon::kLeftToRight),
curved_(true)
{
setFlag(QGraphicsItem::ItemIsSelectable);
@@ -103,24 +104,32 @@ void NodeViewEdge::SetPoints(const QPointF &start, const QPointF &end, bool inpu
QPainterPath path;
path.moveTo(start);
double half_x = lerp(start.x(), end.x(), 0.5);
double half_y = lerp(start.y(), end.y(), 0.5);
if (curved_) {
QPointF cp1, cp2;
double half_x = lerp(start.x(), end.x(), 0.5);
double half_y = lerp(start.y(), end.y(), 0.5);
QPointF cp1, cp2;
if (NodeViewCommon::GetFlowOrientation(flow_dir_) == Qt::Horizontal) {
cp1 = QPointF(half_x, start.y());
} else {
cp1 = QPointF(start.x(), half_y);
}
if (NodeViewCommon::GetFlowOrientation(flow_dir_) == Qt::Horizontal || input_is_expanded) {
cp2 = QPointF(half_x, end.y());
} else {
cp2 = QPointF(end.x(), half_y);
}
path.cubicTo(cp1, cp2, end);
if (NodeViewCommon::GetFlowOrientation(flow_dir_) == Qt::Horizontal) {
cp1 = QPointF(half_x, start.y());
} else {
cp1 = QPointF(start.x(), half_y);
}
if (NodeViewCommon::GetFlowOrientation(flow_dir_) == Qt::Horizontal || input_is_expanded) {
cp2 = QPointF(half_x, end.y());
} else {
cp2 = QPointF(end.x(), half_y);
}
path.lineTo(end);
path.cubicTo(cp1, cp2, end);
}
setPath(path);
}
@@ -132,6 +141,13 @@ void NodeViewEdge::SetFlowDirection(NodeViewCommon::FlowDirection dir)
Adjust();
}
void NodeViewEdge::SetCurved(bool e)
{
curved_ = e;
update();
}
void NodeViewEdge::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
QPalette::ColorGroup group;
+7
View File
@@ -89,6 +89,11 @@ public:
*/
void SetFlowDirection(NodeViewCommon::FlowDirection dir);
/**
* @brief Set whether edges should be drawn as curved or as straight lines
*/
void SetCurved(bool e);
protected:
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
@@ -103,6 +108,8 @@ private:
NodeViewCommon::FlowDirection flow_dir_;
bool curved_;
};
OLIVE_NAMESPACE_EXIT
+17 -1
View File
@@ -30,7 +30,8 @@ OLIVE_NAMESPACE_ENTER
NodeViewScene::NodeViewScene(QObject *parent) :
QGraphicsScene(parent),
graph_(nullptr),
direction_(NodeViewCommon::kLeftToRight)
direction_(NodeViewCommon::kLeftToRight),
curved_edges_(true)
{
}
@@ -214,6 +215,7 @@ void NodeViewScene::AddEdge(NodeEdgePtr edge)
edge_ui->SetEdge(edge);
edge_ui->SetFlowDirection(direction_);
edge_ui->SetCurved(curved_edges_);
addItem(edge_ui);
edge_map_.insert(edge.get(), edge_ui);
@@ -293,6 +295,20 @@ void NodeViewScene::SetFilterMode(const NodeViewScene::FilterMode &f)
filter_mode_ = f;
}
bool NodeViewScene::GetEdgesAreCurved() const
{
return curved_edges_;
}
void NodeViewScene::SetEdgesAreCurved(bool curved)
{
curved_edges_ = curved;
foreach (NodeViewEdge* e, edge_map_) {
e->SetCurved(curved_edges_);
}
}
void NodeViewScene::NodePositionChanged(const QPointF &pos)
{
item_map_.value(static_cast<Node*>(sender()))->SetNodePosition(pos);
+9
View File
@@ -87,6 +87,8 @@ public:
void SetFilterMode(const FilterMode& f);
bool GetEdgesAreCurved() const;
public slots:
/**
* @brief Slot when a Node is added to a graph (SetGraph() connects this)
@@ -120,6 +122,11 @@ public slots:
*/
void RemoveEdge(NodeEdgePtr edge);
/**
* @brief Set whether edges in this scene should be curved or not
*/
void SetEdgesAreCurved(bool curved);
private:
static int DetermineWeight(Node* n);
@@ -133,6 +140,8 @@ private:
FilterMode filter_mode_;
bool curved_edges_;
private slots:
/**
* @brief Receiver for whenever a node position changes