1 /*
2     SPDX-License-Identifier: GPL-2.0-or-later
3     SPDX-FileCopyrightText: 2002-2020 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
4 */
5 
6 #ifndef FLOATINGTEXTWIDGET_H
7 #define FLOATINGTEXTWIDGET_H
8 
9 #include "basictypes.h"
10 #include "umlwidget.h"
11 
12 class LinkWidget;
13 class UMLScene;
14 
15 /**
16  * @short Displays a line of text or an operation.
17  *
18  * This is a multipurpose class. In its simplest form it will display a
19  * line of text.
20  * It can also be setup to be the text for an operation with regard to the
21  * @ref MessageWidget on the sequence diagram.
22  * It is also used for the text required for an association.
23  *
24  * The differences between all these different uses will be the popup menu
25  * that is associated with it.
26  *
27  * @author Paul Hensgen <phensgen@techie.com>
28  * @see UMLWidget
29  * Bugs and comments to umbrello-devel@kde.org or https://bugs.kde.org
30  */
31 class FloatingTextWidget : public UMLWidget
32 {
33     Q_OBJECT
34 public:
35     explicit FloatingTextWidget(UMLScene * scene, Uml::TextRole::Enum role = Uml::TextRole::Floating,
36                                 const QString& text = QString(), Uml::ID::Type id = Uml::ID::None);
37     virtual ~FloatingTextWidget();
38 
39     QString text() const;
40     void setText(const QString &t);
41 
42     void setTextcmd(const QString &t);
43 
44     QString preText() const;
45     void setPreText(const QString &t);
46 
47     QString postText() const;
48     void setPostText(const QString &t);
49 
50     QString displayText() const;
51 
52     bool isEmpty();
53 
54     void showChangeTextDialog();
55     bool showOperationDialog(bool enableAutoIncrement = true);
56     virtual bool showPropertiesDialog();
57 
58     LinkWidget* link() const;
59     void setLink(LinkWidget * l);
60 
61     bool activate(IDChangeLog* ChangeLog = 0);
62 
63     Uml::TextRole::Enum textRole() const;
64     void setTextRole(Uml::TextRole::Enum role);
65 
66     bool handleRename();
67     void changeName(const QString& newText);
68 
69     void setSequenceNumber(const QString &sequenceNumber);
70     QString sequenceNumber() const;
71 
72     static bool isTextValid(const QString &text);
73 
74     UMLWidget* onWidget(const QPointF& p);
75 
76     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
77 
78     virtual void saveToXMI1(QXmlStreamWriter& writer);
79     virtual bool loadFromXMI1(QDomElement& qElement);
80 
81 public Q_SLOTS:
82     virtual void slotMenuSelection(QAction* action);
83     void setMessageText();
84 
85 protected:
86     QSizeF minimumSize() const;
87 
88     virtual void moveWidgetBy(qreal diffX, qreal diffY);
89     virtual void constrainMovementForAllWidgets(qreal &diffX, qreal &diffY);
90 
91 private:
92     QPointF constrainPosition(qreal diffX, qreal diffY);
93 
94     /// The association or message widget we may be linked to.
95     LinkWidget * m_linkWidget;
96 
97     //////////////////// Data loaded/saved:
98 
99     /// Prepended text (such as for scope of association Role or method)
100     QString m_preText;
101     /// Ending text (such as bracket on changability notation for association Role)
102     QString m_postText;
103     /// The role the text widget will enact.
104     Uml::TextRole::Enum m_textRole;
105 
106     ////////
107 
108     /// The horizontal position the widget would have if its move wasn't constrained.
109     qreal m_unconstrainedPositionX;
110 
111     /// The vertical position the widget would have if its move wasn't constrained.
112     qreal m_unconstrainedPositionY;
113 
114     /// The X direction the widget was moved when the constrain was applied.
115     /// -1 means left, 1 means right.
116     int m_movementDirectionX;
117 
118     /// The Y direction the widget was moved when the constrain was applied.
119     /// -1 means up, 1 means down.
120     int m_movementDirectionY;
121 
122     /// Contains sequence number for sequence or collaboration diagram message.
123     QString m_SequenceNumber;
124 };
125 
126 #endif
127