erlu/src/items/ArrowItem.h

108 lines
4.1 KiB
C
Raw Normal View History

#pragma once
#include <QGraphicsPathItem>
#include <QPointer>
#include <QSet>
#include <optional>
#include <QString>
#include <QColor>
#include "BlockItem.h"
class JunctionItem;
class QGraphicsSimpleTextItem;
class ArrowItem final : public QGraphicsPathItem {
public:
enum { Type = UserType + 3 };
struct Endpoint {
QPointer<BlockItem> block;
QPointer<JunctionItem> junction;
BlockItem::Port port = BlockItem::Port::Input;
std::optional<QPointF> localPos; // точка на стороне блока (в локальных координатах)
std::optional<QPointF> scenePos; // произвольная точка на сцене (например, граница)
};
ArrowItem(QGraphicsItem* parent = nullptr);
~ArrowItem() override;
void setFrom(const Endpoint& ep);
void setTo(const Endpoint& ep);
void setTempEndPoint(const QPointF& scenePos); // когда тянем мышью
void finalize(); // убираем "временный" режим, если надо
Endpoint from() const { return m_from; }
Endpoint to() const { return m_to; }
QString label() const { return m_label; }
void setLabel(const QString& text);
QPointF labelOffset() const { return m_labelOffset; }
void setOffsets(qreal bend, qreal top, qreal bottom);
void setLabelOffset(const QPointF& off);
void setLabelHidden(bool hidden);
bool isLabelHidden() const { return m_labelHidden; }
void setLabelInherited(bool inherited);
bool isLabelInherited() const { return m_labelInherited; }
void setLabelSource(ArrowItem* src);
ArrowItem* labelSource() const { return m_labelSource; }
ArrowItem* labelSourceRoot() const;
qreal bendOffset() const { return m_bendOffset; }
qreal topOffset() const { return m_topOffset; }
qreal bottomOffset() const { return m_bottomOffset; }
int type() const override { return Type; }
bool isInterface() const { return m_isInterface; }
bool isInterfaceStub() const { return m_isInterface && m_interfaceStubOnly; }
bool isLabelLocked() const { return m_labelLocked; }
std::optional<Endpoint> interfaceEdge() const { return m_interfaceEdge; }
void setInterfaceStub(const Endpoint& edge, const QString& label);
void setInterfaceIsStub(bool stub);
void resetInterfaceStub();
void setLabelLocked(bool locked);
static void setVisualTheme(const QColor& lineColor, const QColor& textColor);
void updatePath();
std::optional<QPointF> hitTest(const QPointF& scenePos, qreal radius) const;
private:
удалено: build/.qt/QtDeploySupport.cmake удалено: build/.qt/QtDeployTargets.cmake удалено: build/CMakeCache.txt удалено: build/CMakeFiles/4.1.2/CMakeCXXCompiler.cmake удалено: build/CMakeFiles/4.1.2/CMakeDetermineCompilerABI_CXX.bin удалено: build/CMakeFiles/4.1.2/CMakeSystem.cmake удалено: build/CMakeFiles/4.1.2/CompilerIdCXX/CMakeCXXCompilerId.cpp удалено: build/CMakeFiles/4.1.2/CompilerIdCXX/a.out удалено: build/CMakeFiles/CMakeConfigureLog.yaml удалено: build/CMakeFiles/CMakeDirectoryInformation.cmake удалено: build/CMakeFiles/CMakeRuleHashes.txt удалено: build/CMakeFiles/InstallScripts.json удалено: build/CMakeFiles/Makefile.cmake удалено: build/CMakeFiles/Makefile2 удалено: build/CMakeFiles/TargetDirectories.txt удалено: build/CMakeFiles/cmake.check_cache удалено: build/CMakeFiles/idef0_editor.dir/DependInfo.cmake удалено: build/CMakeFiles/idef0_editor.dir/build.make удалено: build/CMakeFiles/idef0_editor.dir/cmake_clean.cmake удалено: build/CMakeFiles/idef0_editor.dir/compiler_depend.internal удалено: build/CMakeFiles/idef0_editor.dir/compiler_depend.make удалено: build/CMakeFiles/idef0_editor.dir/compiler_depend.ts удалено: build/CMakeFiles/idef0_editor.dir/depend.make удалено: build/CMakeFiles/idef0_editor.dir/flags.make удалено: build/CMakeFiles/idef0_editor.dir/idef0_editor_autogen/mocs_compilation.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/idef0_editor_autogen/mocs_compilation.cpp.o.d удалено: build/CMakeFiles/idef0_editor.dir/link.d удалено: build/CMakeFiles/idef0_editor.dir/link.txt удалено: build/CMakeFiles/idef0_editor.dir/progress.make удалено: build/CMakeFiles/idef0_editor.dir/src/MainWindow.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/src/MainWindow.cpp.o.d удалено: build/CMakeFiles/idef0_editor.dir/src/items/ArrowItem.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/src/items/ArrowItem.cpp.o.d удалено: build/CMakeFiles/idef0_editor.dir/src/items/BlockItem.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/src/items/BlockItem.cpp.o.d удалено: build/CMakeFiles/idef0_editor.dir/src/items/DiagramScene.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/src/items/DiagramScene.cpp.o.d удалено: build/CMakeFiles/idef0_editor.dir/src/items/JunctionItem.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/src/items/JunctionItem.cpp.o.d удалено: build/CMakeFiles/idef0_editor.dir/src/main.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/src/main.cpp.o.d удалено: build/CMakeFiles/idef0_editor_autogen.dir/AutogenInfo.json удалено: build/CMakeFiles/idef0_editor_autogen.dir/AutogenUsed.txt удалено: build/CMakeFiles/idef0_editor_autogen.dir/DependInfo.cmake удалено: build/CMakeFiles/idef0_editor_autogen.dir/ParseCache.txt удалено: build/CMakeFiles/idef0_editor_autogen.dir/build.make удалено: build/CMakeFiles/idef0_editor_autogen.dir/cmake_clean.cmake удалено: build/CMakeFiles/idef0_editor_autogen.dir/compiler_depend.internal удалено: build/CMakeFiles/idef0_editor_autogen.dir/compiler_depend.make удалено: build/CMakeFiles/idef0_editor_autogen.dir/compiler_depend.ts удалено: build/CMakeFiles/idef0_editor_autogen.dir/progress.make удалено: build/CMakeFiles/idef0_editor_autogen_timestamp_deps.dir/DependInfo.cmake удалено: build/CMakeFiles/idef0_editor_autogen_timestamp_deps.dir/build.make удалено: build/CMakeFiles/idef0_editor_autogen_timestamp_deps.dir/cmake_clean.cmake удалено: build/CMakeFiles/idef0_editor_autogen_timestamp_deps.dir/compiler_depend.make удалено: build/CMakeFiles/idef0_editor_autogen_timestamp_deps.dir/compiler_depend.ts удалено: build/CMakeFiles/idef0_editor_autogen_timestamp_deps.dir/progress.make удалено: build/CMakeFiles/progress.marks удалено: build/Makefile удалено: build/cmake_install.cmake удалено: build/idef0_editor удалено: build/idef0_editor_autogen/DWIBBXP2LJ/moc_BlockItem.cpp удалено: build/idef0_editor_autogen/DWIBBXP2LJ/moc_BlockItem.cpp.d удалено: build/idef0_editor_autogen/DWIBBXP2LJ/moc_DiagramScene.cpp удалено: build/idef0_editor_autogen/DWIBBXP2LJ/moc_DiagramScene.cpp.d удалено: build/idef0_editor_autogen/DWIBBXP2LJ/moc_JunctionItem.cpp удалено: build/idef0_editor_autogen/DWIBBXP2LJ/moc_JunctionItem.cpp.d удалено: build/idef0_editor_autogen/UVLADIE3JM/moc_MainWindow.cpp удалено: build/idef0_editor_autogen/UVLADIE3JM/moc_MainWindow.cpp.d удалено: build/idef0_editor_autogen/deps удалено: build/idef0_editor_autogen/moc_predefs.h удалено: build/idef0_editor_autogen/mocs_compilation.cpp удалено: build/idef0_editor_autogen/timestamp удалено: codex изменено: src/items/ArrowItem.cpp изменено: src/items/ArrowItem.h изменено: src/items/BlockItem.h изменено: src/items/DiagramScene.cpp изменено: src/items/DiagramScene.h
2026-02-23 00:23:03 +03:00
enum class DragPart { None, BendX, TopHorizontal, BottomHorizontal, FromEnd, ToEnd };
Endpoint m_from;
Endpoint m_to;
bool m_hasTempEnd = false;
QPointF m_tempEndScene;
qreal m_bendOffset = 0.0;
qreal m_topOffset = 0.0;
qreal m_bottomOffset = 0.0;
QString m_label;
QGraphicsSimpleTextItem* m_labelItem = nullptr;
bool m_labelHidden = false;
bool m_labelInherited = false;
QPointF m_labelOffset; // in scene-space relative to anchor point
bool m_labelDragging = false;
QPointF m_labelDragLastScene;
QVector<QPointF> m_lastPolyline;
bool m_isInterface = false;
bool m_interfaceStubOnly = false;
bool m_labelLocked = false;
std::optional<Endpoint> m_interfaceEdge;
ArrowItem* m_labelSource = nullptr;
static QColor s_lineColor;
static QColor s_textColor;
DragPart m_dragPart = DragPart::None;
QPointF m_lastDragScenePos;
void drawArrowHead(QPainterPath& path, const QPointF& tip, const QPointF& from);
QVector<QPointF> computePolyline() const;
static QPointF portDirection(const Endpoint& ep, bool isFrom, const QPointF& fallbackDir, const QGraphicsScene* scene);
static QVector<QPointF> simplifyPolyline(const QVector<QPointF>& pts);
static qreal distToSegment(const QPointF& p, const QPointF& a, const QPointF& b);
void updateLabelItem(const QVector<QPointF>& pts);
protected:
void hoverMoveEvent(QGraphicsSceneHoverEvent* e) override;
void mousePressEvent(QGraphicsSceneMouseEvent* e) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent* e) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent* e) override;
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* e) override;
удалено: build/.qt/QtDeploySupport.cmake удалено: build/.qt/QtDeployTargets.cmake удалено: build/CMakeCache.txt удалено: build/CMakeFiles/4.1.2/CMakeCXXCompiler.cmake удалено: build/CMakeFiles/4.1.2/CMakeDetermineCompilerABI_CXX.bin удалено: build/CMakeFiles/4.1.2/CMakeSystem.cmake удалено: build/CMakeFiles/4.1.2/CompilerIdCXX/CMakeCXXCompilerId.cpp удалено: build/CMakeFiles/4.1.2/CompilerIdCXX/a.out удалено: build/CMakeFiles/CMakeConfigureLog.yaml удалено: build/CMakeFiles/CMakeDirectoryInformation.cmake удалено: build/CMakeFiles/CMakeRuleHashes.txt удалено: build/CMakeFiles/InstallScripts.json удалено: build/CMakeFiles/Makefile.cmake удалено: build/CMakeFiles/Makefile2 удалено: build/CMakeFiles/TargetDirectories.txt удалено: build/CMakeFiles/cmake.check_cache удалено: build/CMakeFiles/idef0_editor.dir/DependInfo.cmake удалено: build/CMakeFiles/idef0_editor.dir/build.make удалено: build/CMakeFiles/idef0_editor.dir/cmake_clean.cmake удалено: build/CMakeFiles/idef0_editor.dir/compiler_depend.internal удалено: build/CMakeFiles/idef0_editor.dir/compiler_depend.make удалено: build/CMakeFiles/idef0_editor.dir/compiler_depend.ts удалено: build/CMakeFiles/idef0_editor.dir/depend.make удалено: build/CMakeFiles/idef0_editor.dir/flags.make удалено: build/CMakeFiles/idef0_editor.dir/idef0_editor_autogen/mocs_compilation.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/idef0_editor_autogen/mocs_compilation.cpp.o.d удалено: build/CMakeFiles/idef0_editor.dir/link.d удалено: build/CMakeFiles/idef0_editor.dir/link.txt удалено: build/CMakeFiles/idef0_editor.dir/progress.make удалено: build/CMakeFiles/idef0_editor.dir/src/MainWindow.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/src/MainWindow.cpp.o.d удалено: build/CMakeFiles/idef0_editor.dir/src/items/ArrowItem.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/src/items/ArrowItem.cpp.o.d удалено: build/CMakeFiles/idef0_editor.dir/src/items/BlockItem.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/src/items/BlockItem.cpp.o.d удалено: build/CMakeFiles/idef0_editor.dir/src/items/DiagramScene.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/src/items/DiagramScene.cpp.o.d удалено: build/CMakeFiles/idef0_editor.dir/src/items/JunctionItem.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/src/items/JunctionItem.cpp.o.d удалено: build/CMakeFiles/idef0_editor.dir/src/main.cpp.o удалено: build/CMakeFiles/idef0_editor.dir/src/main.cpp.o.d удалено: build/CMakeFiles/idef0_editor_autogen.dir/AutogenInfo.json удалено: build/CMakeFiles/idef0_editor_autogen.dir/AutogenUsed.txt удалено: build/CMakeFiles/idef0_editor_autogen.dir/DependInfo.cmake удалено: build/CMakeFiles/idef0_editor_autogen.dir/ParseCache.txt удалено: build/CMakeFiles/idef0_editor_autogen.dir/build.make удалено: build/CMakeFiles/idef0_editor_autogen.dir/cmake_clean.cmake удалено: build/CMakeFiles/idef0_editor_autogen.dir/compiler_depend.internal удалено: build/CMakeFiles/idef0_editor_autogen.dir/compiler_depend.make удалено: build/CMakeFiles/idef0_editor_autogen.dir/compiler_depend.ts удалено: build/CMakeFiles/idef0_editor_autogen.dir/progress.make удалено: build/CMakeFiles/idef0_editor_autogen_timestamp_deps.dir/DependInfo.cmake удалено: build/CMakeFiles/idef0_editor_autogen_timestamp_deps.dir/build.make удалено: build/CMakeFiles/idef0_editor_autogen_timestamp_deps.dir/cmake_clean.cmake удалено: build/CMakeFiles/idef0_editor_autogen_timestamp_deps.dir/compiler_depend.make удалено: build/CMakeFiles/idef0_editor_autogen_timestamp_deps.dir/compiler_depend.ts удалено: build/CMakeFiles/idef0_editor_autogen_timestamp_deps.dir/progress.make удалено: build/CMakeFiles/progress.marks удалено: build/Makefile удалено: build/cmake_install.cmake удалено: build/idef0_editor удалено: build/idef0_editor_autogen/DWIBBXP2LJ/moc_BlockItem.cpp удалено: build/idef0_editor_autogen/DWIBBXP2LJ/moc_BlockItem.cpp.d удалено: build/idef0_editor_autogen/DWIBBXP2LJ/moc_DiagramScene.cpp удалено: build/idef0_editor_autogen/DWIBBXP2LJ/moc_DiagramScene.cpp.d удалено: build/idef0_editor_autogen/DWIBBXP2LJ/moc_JunctionItem.cpp удалено: build/idef0_editor_autogen/DWIBBXP2LJ/moc_JunctionItem.cpp.d удалено: build/idef0_editor_autogen/UVLADIE3JM/moc_MainWindow.cpp удалено: build/idef0_editor_autogen/UVLADIE3JM/moc_MainWindow.cpp.d удалено: build/idef0_editor_autogen/deps удалено: build/idef0_editor_autogen/moc_predefs.h удалено: build/idef0_editor_autogen/mocs_compilation.cpp удалено: build/idef0_editor_autogen/timestamp удалено: codex изменено: src/items/ArrowItem.cpp изменено: src/items/ArrowItem.h изменено: src/items/BlockItem.h изменено: src/items/DiagramScene.cpp изменено: src/items/DiagramScene.h
2026-02-23 00:23:03 +03:00
bool adjustEndpoint(Endpoint& ep, const QPointF& delta);
};