umbrello 26.03.70-1a62d36 Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
26 class AlignmentGuide
27{
28 public:
32 enum class GuideType {
33 None,
34 LeftEdge,
35 RightEdge,
36 HorizontalCenter,
37 TopEdge,
38 BottomEdge,
39 VerticalCenter
40 };
41
45 struct GuideLine {
46 GuideType type;
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 ||
54 type == GuideType::BottomEdge ||
55 type == GuideType::VerticalCenter;
56 }
57
58 bool isVertical() const {
59 return type == GuideType::LeftEdge ||
60 type == GuideType::RightEdge ||
61 type == GuideType::HorizontalCenter;
62 }
63 };
64
65 explicit AlignmentGuide(UMLScene *scene);
66 ~AlignmentGuide();
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:
135 struct AlignmentPoints {
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
161 UMLScene *m_scene;
162 QList<GuideLine> m_activeGuides;
163 qreal m_snapThreshold;
164 bool m_enabled;
165};
166
167#endif // ALIGNMENTGUIDE_H
AlignmentGuide
Manages alignment guides and snapping for widget movement.
Definition: alignmentguide.h:27
AlignmentGuide::activeGuides
QList< GuideLine > activeGuides() const
Definition: alignmentguide.cpp:359
AlignmentGuide::m_activeGuides
QList< GuideLine > m_activeGuides
Definition: alignmentguide.h:162
AlignmentGuide::~AlignmentGuide
~AlignmentGuide()
Definition: alignmentguide.cpp:28
AlignmentGuide::m_scene
UMLScene * m_scene
Definition: alignmentguide.h:161
AlignmentGuide::m_snapThreshold
qreal m_snapThreshold
Definition: alignmentguide.h:163
AlignmentGuide::GuideType
GuideType
Definition: alignmentguide.h:32
AlignmentGuide::GuideType::None
@ None
AlignmentGuide::GuideType::BottomEdge
@ BottomEdge
AlignmentGuide::GuideType::HorizontalCenter
@ HorizontalCenter
AlignmentGuide::GuideType::TopEdge
@ TopEdge
AlignmentGuide::GuideType::RightEdge
@ RightEdge
AlignmentGuide::GuideType::VerticalCenter
@ VerticalCenter
AlignmentGuide::GuideType::LeftEdge
@ LeftEdge
AlignmentGuide::isEnabled
bool isEnabled() const
Definition: alignmentguide.cpp:425
AlignmentGuide::snapResize
void snapResize(UMLWidget *widget, qreal proposedWidth, qreal proposedHeight, qreal &newWidth, qreal &newHeight)
Definition: alignmentguide.cpp:219
AlignmentGuide::getAlignmentPoints
AlignmentPoints getAlignmentPoints(UMLWidget *widget, const QPointF &pos) const
Definition: alignmentguide.cpp:35
AlignmentGuide::clear
void clear()
Definition: alignmentguide.cpp:367
AlignmentGuide::snapPosition
QPointF snapPosition(UMLWidget *widget, const QPointF &proposedPos)
Definition: alignmentguide.cpp:72
AlignmentGuide::setEnabled
void setEnabled(bool enabled)
Definition: alignmentguide.cpp:414
AlignmentGuide::findBestSnap
void findBestSnap(qreal position, const QList< qreal > &candidates, qreal &minDistance, qreal &bestSnap, qreal &offset, GuideType &bestGuideType, GuideType guideType) const
Definition: alignmentguide.cpp:54
AlignmentGuide::snapThreshold
qreal snapThreshold() const
Definition: alignmentguide.cpp:384
AlignmentGuide::setSnapThreshold
void setSnapThreshold(qreal threshold)
Definition: alignmentguide.cpp:375
AlignmentGuide::m_enabled
bool m_enabled
Definition: alignmentguide.h:164
UMLScene
Definition: umlscene.h:66
UMLWidget
The base class for graphical UML objects.
Definition: umlwidget.h:36
AlignmentGuide::AlignmentPoints
Definition: alignmentguide.h:135
AlignmentGuide::AlignmentPoints::vCenter
qreal vCenter
Definition: alignmentguide.h:141
AlignmentGuide::AlignmentPoints::bottom
qreal bottom
Definition: alignmentguide.h:140
AlignmentGuide::AlignmentPoints::right
qreal right
Definition: alignmentguide.h:137
AlignmentGuide::AlignmentPoints::hCenter
qreal hCenter
Definition: alignmentguide.h:138
AlignmentGuide::AlignmentPoints::left
qreal left
Definition: alignmentguide.h:136
AlignmentGuide::AlignmentPoints::top
qreal top
Definition: alignmentguide.h:139
AlignmentGuide::GuideLine
Definition: alignmentguide.h:45
AlignmentGuide::GuideLine::GuideLine
GuideLine(GuideType t, qreal pos)
Definition: alignmentguide.h:50
AlignmentGuide::GuideLine::position
qreal position
Definition: alignmentguide.h:47
AlignmentGuide::GuideLine::isHorizontal
bool isHorizontal() const
Definition: alignmentguide.h:52
AlignmentGuide::GuideLine::type
GuideType type
Definition: alignmentguide.h:46
AlignmentGuide::GuideLine::isVertical
bool isVertical() const
Definition: alignmentguide.h:58
AlignmentGuide::GuideLine::GuideLine
GuideLine()
Definition: alignmentguide.h:49