umbrello 26.03.70-1a62d36
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
13class UMLWidget;
14class UMLScene;
15
27{
28public:
32 enum class GuideType {
33 None,
37 TopEdge,
40 };
41
45 struct GuideLine {
47 qreal position; // X coordinate for vertical lines, Y for horizontal
48
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
131private:
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;
165};
166
167#endif // ALIGNMENTGUIDE_H
Manages alignment guides and snapping for widget movement.
Definition: alignmentguide.h:27
QList< GuideLine > activeGuides() const
Definition: alignmentguide.cpp:359
QList< GuideLine > m_activeGuides
Definition: alignmentguide.h:162
~AlignmentGuide()
Definition: alignmentguide.cpp:28
UMLScene * m_scene
Definition: alignmentguide.h:161
qreal m_snapThreshold
Definition: alignmentguide.h:163
GuideType
Definition: alignmentguide.h:32
bool isEnabled() const
Definition: alignmentguide.cpp:425
void snapResize(UMLWidget *widget, qreal proposedWidth, qreal proposedHeight, qreal &newWidth, qreal &newHeight)
Definition: alignmentguide.cpp:219
AlignmentPoints getAlignmentPoints(UMLWidget *widget, const QPointF &pos) const
Definition: alignmentguide.cpp:35
void clear()
Definition: alignmentguide.cpp:367
QPointF snapPosition(UMLWidget *widget, const QPointF &proposedPos)
Definition: alignmentguide.cpp:72
void setEnabled(bool enabled)
Definition: alignmentguide.cpp:414
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
void setSnapThreshold(qreal threshold)
Definition: alignmentguide.cpp:375
bool m_enabled
Definition: alignmentguide.h:164
Definition: umlscene.h:66
The base class for graphical UML objects.
Definition: umlwidget.h:36
Definition: alignmentguide.h:135
qreal vCenter
Definition: alignmentguide.h:141
qreal bottom
Definition: alignmentguide.h:140
qreal right
Definition: alignmentguide.h:137
qreal hCenter
Definition: alignmentguide.h:138
qreal left
Definition: alignmentguide.h:136
qreal top
Definition: alignmentguide.h:139
Definition: alignmentguide.h:45
GuideLine(GuideType t, qreal pos)
Definition: alignmentguide.h:50
qreal position
Definition: alignmentguide.h:47
bool isHorizontal() const
Definition: alignmentguide.h:52
GuideType type
Definition: alignmentguide.h:46
bool isVertical() const
Definition: alignmentguide.h:58
GuideLine()
Definition: alignmentguide.h:49