1 /*
2     SPDX-License-Identifier: GPL-2.0-or-later
3     SPDX-FileCopyrightText: 2002-2021 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
4 */
5 
6 #ifndef SEQLINEWIDGET_H
7 #define SEQLINEWIDGET_H
8 
9 #include <QGraphicsLineItem>
10 
11 #include <QPen>
12 
13 class ObjectWidget;
14 class UMLScene;
15 
16 /**
17  * A sequence lifeline consists of the object widget at the top and
18  * a vertical line starting at the bottom edge of the object widget
19  * at half its width. The line grows downward when sequence messages
20  * are added such that the line always extends far enough to act as
21  * the background for all messages.
22  * This class represents only the line part of the lifeline.
23  *
24  * @short Widget class for graphical representation of sequence lines
25  * @author Paul Hensgen
26  * Bugs and comments to umbrello-devel@kde.org or https://bugs.kde.org
27  */
28 class SeqLineWidget : public QGraphicsLineItem
29 {
30 public:
31     SeqLineWidget(UMLScene *scene, ObjectWidget * pObject);
32     virtual ~SeqLineWidget();
33 
34     bool onWidget(const QPointF& p);
35 
36     bool onDestructionBox(const QPointF& p);
37 
38     void cleanup();
39 
40     void setupDestructionBox();
41 
42     void setStartPoint(int startX, int startY);
43 
44     /**
45      * Gets the length of the line.
46      *
47      * @return  Length of the line.
48      */
getLineLength()49     int getLineLength() const {
50         return m_nLengthY;
51     }
52 
53     /**
54      * Returns the @ref ObjectWidget associated with this sequence line.
55      *
56      * @return  Pointer to the associated ObjectWidget.
57      */
getObjectWidget()58     ObjectWidget * getObjectWidget() {
59         return m_pObject;
60     }
61 
62     void setEndOfLine(int yPosition);
63     void setLineColorCmd(const QColor &color);
64 
65 protected:
66     void cleanupDestructionBox();
67 
68     void moveDestructionBox();
69 
70     ObjectWidget* m_pObject;  ///< ObjectWidget associated with this sequence line
71     UMLScene*     m_scene;    ///< scene displayed on
72 
73     struct DestructionBox {
74         QGraphicsLineItem * line1{nullptr};
75         QGraphicsLineItem * line2{nullptr};
setLineColorCmdDestructionBox76         void setLineColorCmd(const QColor &color)
77         {
78             if (!line1)
79                 return;
80             QPen pen = line1->pen();
81             pen.setColor(color);
82             line1->setPen(pen);
83             line2->setPen(pen);
84         }
85 
setLine1PointsDestructionBox86         void setLine1Points(QRect rect) {
87             line1->setLine(rect.x(), rect.y(),
88                             rect.x() + rect.width(), rect.y() + rect.height());
89         }
setLine2PointsDestructionBox90         void setLine2Points(QRect rect) {
91             line2->setLine(rect.x(), rect.y() + rect.height(),
92                             rect.x() + rect.width(), rect.y());
93         }
94     } m_DestructionBox;  ///< the destruction box
95 
96     int m_nLengthY;  ///< the length of the line
97 
98     static int const m_nMouseDownEpsilonX;   ///< margin used for mouse clicks
99     void contextMenuEvent(QGraphicsSceneContextMenuEvent* event);
100 };
101 
102 #endif
103