umbrello  26.08.1
Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology
alignmentguide.h
Go to the documentation of this file.
1 /*
2  SPDX-License-Identifier: GPL-2.0-or-later
3  SPDX-FileCopyrightText: 2025 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
4 */
5 
6 #ifndef ALIGNMENTGUIDE_H
7 #define ALIGNMENTGUIDE_H
8 
9 #include <QPointF>
10 #include <QList>
11 #include <QLineF>
12 
13 class UMLWidget;
14 class UMLScene;
15 
27 {
28 public:
32  enum class GuideType {
33  None,
34  LeftEdge,
35  RightEdge,
37  TopEdge,
38  BottomEdge,
40  };
41 
45  struct GuideLine {
47  qreal position; // X coordinate for vertical lines, Y for horizontal
48 
49  GuideLine() : type(GuideType::None), position(0.0) {}
50  GuideLine(GuideType t, qreal pos) : type(t), position(pos) {}
51 
52  bool isHorizontal() const {
53  return type == GuideType::TopEdge ||
56  }
57 
58  bool isVertical() const {
59  return type == GuideType::LeftEdge ||
62  }
63  };
64 
65  explicit AlignmentGuide(UMLScene *scene);
67 
75  QPointF snapPosition(UMLWidget *widget, const QPointF &proposedPos);
76 
86  void snapResize(UMLWidget *widget, qreal proposedWidth, qreal proposedHeight,
87  qreal &newWidth, qreal &newHeight);
88 
94  QList<GuideLine> activeGuides() const;
95 
99  void clear();
100 
106  void setSnapThreshold(qreal threshold);
107 
115  qreal snapThreshold() const;
116 
122  void setEnabled(bool enabled);
123 
129  bool isEnabled() const;
130 
131 private:
136  qreal left;
137  qreal right;
138  qreal hCenter; // horizontal center
139  qreal top;
140  qreal bottom;
141  qreal vCenter; // vertical center
142  };
143 
144  AlignmentPoints getAlignmentPoints(UMLWidget *widget, const QPointF &pos) const;
145 
157  void findBestSnap(qreal position, const QList<qreal> &candidates,
158  qreal &minDistance, qreal &bestSnap, qreal &offset,
159  GuideType &bestGuideType, GuideType guideType) const;
160 
162  QList<GuideLine> m_activeGuides;
164  bool m_enabled;
165 };
166 
167 #endif // ALIGNMENTGUIDE_H
AlignmentGuide(UMLScene *scene)
Definition: alignmentguide.cpp:21
qreal m_snapThreshold
Definition: alignmentguide.h:163
AlignmentPoints getAlignmentPoints(UMLWidget *widget, const QPointF &pos) const
Definition: alignmentguide.cpp:35
GuideType
Definition: alignmentguide.h:32
bool isHorizontal() const
Definition: alignmentguide.h:52
qreal hCenter
Definition: alignmentguide.h:138
~AlignmentGuide()
Definition: alignmentguide.cpp:28
qreal right
Definition: alignmentguide.h:137
void setEnabled(bool enabled)
Definition: alignmentguide.cpp:414
qreal vCenter
Definition: alignmentguide.h:141
qreal left
Definition: alignmentguide.h:136
bool m_enabled
Definition: alignmentguide.h:164
Definition: alignmentguide.h:135
bool isVertical() const
Definition: alignmentguide.h:58
Manages alignment guides and snapping for widget movement.
Definition: alignmentguide.h:26
qreal top
Definition: alignmentguide.h:139
void clear()
Definition: alignmentguide.cpp:367
GuideLine()
Definition: alignmentguide.h:49
qreal position
Definition: alignmentguide.h:47
Definition: alignmentguide.h:45
void snapResize(UMLWidget *widget, qreal proposedWidth, qreal proposedHeight, qreal &newWidth, qreal &newHeight)
Definition: alignmentguide.cpp:219
GuideLine(GuideType t, qreal pos)
Definition: alignmentguide.h:50
QList< GuideLine > m_activeGuides
Definition: alignmentguide.h:162
void findBestSnap(qreal position, const QList< qreal > &candidates, qreal &minDistance, qreal &bestSnap, qreal &offset, GuideType &bestGuideType, GuideType guideType) const
Definition: alignmentguide.cpp:54
qreal snapThreshold() const
Definition: alignmentguide.cpp:384
UMLScene * m_scene
Definition: alignmentguide.h:161
qreal bottom
Definition: alignmentguide.h:140
bool isEnabled() const
Definition: alignmentguide.cpp:425
QPointF snapPosition(UMLWidget *widget, const QPointF &proposedPos)
Definition: alignmentguide.cpp:72
void setSnapThreshold(qreal threshold)
Definition: alignmentguide.cpp:375
GuideType type
Definition: alignmentguide.h:46
Definition: umlscene.h:65
QList< GuideLine > activeGuides() const
Definition: alignmentguide.cpp:359
The base class for graphical UML objects.
Definition: umlwidget.h:35