From be0914c9c1381c247da9c8946277a698fea5d2f5 Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Fri, 4 Oct 2024 20:02:18 +0800 Subject: [PATCH] 1 --- StoryPresent/dag_layout.cpp | 5 ++++- StoryPresent/dag_present.cpp | 29 +++++++++++++++++------------ StoryPresent/dag_present.h | 4 ++-- StoryPresent/main.cpp | 2 +- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/StoryPresent/dag_layout.cpp b/StoryPresent/dag_layout.cpp index 1094cf8..f156de0 100644 --- a/StoryPresent/dag_layout.cpp +++ b/StoryPresent/dag_layout.cpp @@ -257,11 +257,14 @@ void DAGGraph::graph_layer_nodes_sort(int layer_index, QList a, std::shared_ptr b){ return a->sortNumber() < b->sortNumber(); }); + for (auto idx = 1; idx < nodes_within_current_layer.size(); ++idx) { auto prev = nodes_within_current_layer[idx - 1]; auto curr = nodes_within_current_layer[idx]; if (prev->sortNumber() == curr->sortNumber()) - curr->setSortNumber(curr->sortNumber() + DBL_MIN); + curr->setSortNumber(curr->sortNumber() + 0.000000000000001); } } diff --git a/StoryPresent/dag_present.cpp b/StoryPresent/dag_present.cpp index dcc9df3..f11ba2a 100644 --- a/StoryPresent/dag_present.cpp +++ b/StoryPresent/dag_present.cpp @@ -36,11 +36,11 @@ void ActivePresentNode::paint(QPainter* painter, const QStyleOptionGraphicsItem* PenetrateNode::PenetrateNode(double width, const QString& towards, const QString& to) : __GraphNodeBase(GraphNodeType::PenetrateNode), - width_store(width), from_name(towards), to_name(to) { + outline(QSizeF(20, 8)), from_name(towards), to_name(to) { } -void PenetrateNode::resizeWidth(double width) { - this->width_store = width; +void PenetrateNode::resizeOutline(double w, double h) { + this->outline = QSizeF(w, h); this->update(); } @@ -53,7 +53,7 @@ QString PenetrateNode::nodeTo() const { } QRectF PenetrateNode::boundingRect() const { - return QRectF(0, 0, this->width_store, 8); + return QRectF(QPointF(), this->outline); } void PenetrateNode::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { @@ -61,10 +61,11 @@ void PenetrateNode::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt painter->save(); + auto ypos = outline.height() / 2 - 3; if (this->isHighlighted()) - painter->fillRect(QRectF(0, 2, outline.width(), 4), Qt::red); + painter->fillRect(QRectF(0, ypos, outline.width(), 4), Qt::red); else - painter->fillRect(QRectF(0, 2, outline.width(), 4), Qt::black); + painter->fillRect(QRectF(0, ypos, outline.width(), 4), Qt::black); painter->restore(); } @@ -119,8 +120,8 @@ void TransitionCurve::paint(QPainter* painter, const QStyleOptionGraphicsItem* o painter->save(); painter->setRenderHint(QPainter::Antialiasing); - auto start_pos = aj_start_pos - QGraphicsItem::pos() + QPointF(0, start_rect.height() / 2); - auto end_pos = aj_end_pos - QGraphicsItem::pos() + QPointF(0, end_rect.height() / 2); + auto start_pos = aj_start_pos - QGraphicsItem::pos() + QPointF(0, (int) start_rect.height() / 2); + auto end_pos = aj_end_pos - QGraphicsItem::pos() + QPointF(0, (int) end_rect.height() / 2); auto line_epos = start_pos + QPointF(line_span, 0); auto control_pos0 = line_epos + QPointF((outline.width() - line_span) / 3, 0); @@ -193,13 +194,16 @@ QList DAGActiveView::layer_nodes_construction(const QHashboundingRect().width()); } - for (auto n : current_nodes_helper.keys()) { - if (n->nodeType() == GraphNodeType::PenetrateNode) { - static_cast(n)->resizeWidth(curr_layer_width); + if (prev_layer_helper.size()) { + prev_node_height = prev_layer_helper.keys().first()->boundingRect().height(); + for (auto n : current_nodes_helper.keys()) { + if (n->nodeType() == GraphNodeType::PenetrateNode) { + static_cast(n)->resizeOutline(curr_layer_width, prev_node_height); + } } } @@ -233,6 +237,7 @@ QList DAGActiveView::layer_nodes_construction(const QHash void DAGActiveView::updateWithEdges(QList arrows) { // 清除当前视图 this->scene_bind.clear(); diff --git a/StoryPresent/dag_present.h b/StoryPresent/dag_present.h index 59c6aee..e2a6bad 100644 --- a/StoryPresent/dag_present.h +++ b/StoryPresent/dag_present.h @@ -62,13 +62,13 @@ namespace dags { }; class PenetrateNode : public __GraphNodeBase { private: - double width_store = 20; + QSizeF outline; QString from_name, to_name; public: PenetrateNode(double width, const QString &from, const QString &to); - void resizeWidth(double width); + void resizeOutline(double width, double height); QString nodeFrom() const; QString nodeTo() const; diff --git a/StoryPresent/main.cpp b/StoryPresent/main.cpp index 73b048d..0fa862e 100644 --- a/StoryPresent/main.cpp +++ b/StoryPresent/main.cpp @@ -50,7 +50,7 @@ int main(int argc, char* argv[]) { graph_data::Arrow(u8"c中文测试", u8"d中文测试") << graph_data::Arrow(u8"b中文测试", u8"e中文测试") << graph_data::Arrow(u8"d中文测试", u8"e中文测试") << - graph_data::Arrow(u8"a中文测试", u8"e中文测试"); + graph_data::Arrow(u8"c中文测试", u8"e中文测试"); auto view = new dags::DAGActiveView; view->updateWithEdges(arrows); view->show();