TransitionItem.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::
17* @author Mirko Waechter ( mirko.waechter at kit dot edu)
18* @date 2014
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22#pragma once
23
24#include <memory>
25
26#include <QGraphicsPathItem>
27#include <qpropertyanimation.h>
28
30
31#include "MorphingItem.h"
32
34{
35 class Transition;
36 using TransitionPtr = std::shared_ptr<Transition>;
37 using TransitionCPtr = std::shared_ptr<const Transition>;
38 class StateInstance;
39 using StateInstancePtr = std::shared_ptr<StateInstance>;
40} // namespace armarx::statechartmodel
41
42namespace armarx
43{
44 class TransitionLabel;
45
47 public QObject,
48 public QGraphicsPathItem,
49 public MorphingItem,
50 public Logging
51 {
52 Q_OBJECT
53 Q_PROPERTY(QColor color READ getColor WRITE setColor)
55 public:
56 explicit TransitionItem(statechartmodel::TransitionCPtr transition,
57 QGraphicsItem* parent = 0);
58
60 signals:
61 void transitionEndPlaced(statechartmodel::TransitionCPtr transition, QPointF dropPosition);
62 void transitionSupportPointPlaced(QPointF dropPosition);
63 void transitionContextMenuRequested(statechartmodel::TransitionCPtr transition,
64 QPoint mouseScreenPos,
65 QPointF mouseItemPos);
66 public slots:
67 void setEditable(bool editable);
68 void recalcPath();
69 void recalcShape();
70 void setSelected(bool selected);
71 void attachToMouse(int supportPointIndex);
72 void highlightAnimation(int duration = 5000);
73 void updateLabel();
74
75 public:
76 void
77 paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
78 QPainterPath shape() const override;
79 QRectF boundingRect() const override;
80 // QGraphicsItem interface
81 bool isInitialTransition() const;
82 QPolygonF calcHull(QPainter* painter = 0) const;
83
84 QColor getColor() const;
85 void setColor(const QColor& color);
86 QColor getHighlightColor() const;
87 void setHighlightColor(const QColor& color);
88 statechartmodel::TransitionCPtr getTransition() const;
89
90 protected:
91 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
92 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
93 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
94 void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
95
96
97 QPolygonF shapePolygon;
98
99 private:
100 QPointF calcIntersection(statechartmodel::StateInstancePtr state,
101 const QPointF& supportPoint) const;
102 QPointF calcIntersection(statechartmodel::StateInstancePtr state,
103 QLineF centerLine,
104 const QPointF& supportPoint) const;
105 QPolygonF calcArrowHead(const QLineF& line);
106 void recalcLabelPose();
107 float calcLengthOfLine(QPointF start, QPointF end);
108
109
110 statechartmodel::TransitionCPtr transition;
111 QPolygonF arrowHead;
112 QRectF initialStateCircle;
113 TransitionLabel* transitionLabel;
114 int pointAttachedToMouse;
115 QColor color, highlightColor, normalColor;
116 QPropertyAnimation animation;
117 IceUtil::Time highlightAnimationStartTime;
118
119 // QGraphicsItem interface
120 protected:
121 void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
122 void hoverMoveEvent(QGraphicsSceneHoverEvent* event) override;
123 void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
124 };
125
126 class TransitionLabel : public QObject, public QGraphicsSimpleTextItem, public MorphingItem
127 {
128 Q_OBJECT
129 Q_PROPERTY(qreal fontPointSize READ fontPointSize WRITE setFontPointSize)
130 public:
131 TransitionLabel(QString labelText, QGraphicsItem* parent = 0);
132 // QGraphicsItem interface
133 void
134 paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
135 qreal fontPointSize() const;
136 qreal baseFontPointSize() const;
137 void setBaseFontPointSize(qreal newFontSize);
138 void setFontPointSize(qreal newFontSize);
139 void setEnlargedFontPointSize(qreal newFontSize);
140 void setHovering(bool hovering);
141 bool getHovering() const;
142
143 protected:
144 QPropertyAnimation animation;
148 };
149
150} // namespace armarx
#define option(type, fn)
MorphingItem(QGraphicsItem *derivedItem)
QPainterPath shape() const override
void highlightAnimation(int duration=5000)
void setHighlightColor(const QColor &color)
void attachToMouse(int supportPointIndex)
QPolygonF calcHull(QPainter *painter=0) const
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
QColor getHighlightColor() const
TransitionItem(statechartmodel::TransitionCPtr transition, QGraphicsItem *parent=0)
statechartmodel::TransitionCPtr getTransition() const
void setEditable(bool editable)
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
void transitionContextMenuRequested(statechartmodel::TransitionCPtr transition, QPoint mouseScreenPos, QPointF mouseItemPos)
IceUtil::Time getLastHighlightTimestamp() const
void transitionSupportPointPlaced(QPointF dropPosition)
void setColor(const QColor &color)
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override
void transitionEndPlaced(statechartmodel::TransitionCPtr transition, QPointF dropPosition)
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
QRectF boundingRect() const override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
void setSelected(bool selected)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
QPropertyAnimation animation
void setEnlargedFontPointSize(qreal newFontSize)
void setHovering(bool hovering)
void setBaseFontPointSize(qreal newFontSize)
void setFontPointSize(qreal newFontSize)
TransitionLabel(QString labelText, QGraphicsItem *parent=0)
std::shared_ptr< StateInstance > StateInstancePtr
std::shared_ptr< const Transition > TransitionCPtr
Definition Transition.h:91
std::shared_ptr< Transition > TransitionPtr
Definition Transition.h:90
This file offers overloads of toIce() and fromIce() functions for STL container types.