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 "MorphingItem.h"
25 
27 #include <QGraphicsPathItem>
28 #include <qpropertyanimation.h>
29 #include <memory>
30 
32 {
33  class Transition;
34  using TransitionPtr = std::shared_ptr<Transition>;
35  using TransitionCPtr = std::shared_ptr<const Transition>;
36  class StateInstance;
37  using StateInstancePtr = std::shared_ptr<StateInstance>;
38 }
39 
40 namespace armarx
41 {
42  class TransitionLabel;
43 
45  public QObject
46  , public QGraphicsPathItem
47  , public MorphingItem
48  , public Logging
49  {
50  Q_OBJECT
51  Q_PROPERTY(QColor color READ getColor WRITE setColor)
52  Q_PROPERTY(QColor highlightColor READ getHighlightColor WRITE setHighlightColor)
53  public:
54  explicit TransitionItem(statechartmodel::TransitionCPtr transition, QGraphicsItem* parent = 0);
55 
57  signals:
58  void transitionEndPlaced(statechartmodel::TransitionCPtr transition, QPointF dropPosition);
59  void transitionSupportPointPlaced(QPointF dropPosition);
60  void transitionContextMenuRequested(statechartmodel::TransitionCPtr transition, QPoint mouseScreenPos, QPointF mouseItemPos);
61  public slots:
62  void setEditable(bool editable);
63  void recalcPath();
64  void recalcShape();
65  void setSelected(bool selected);
66  void attachToMouse(int supportPointIndex);
67  void highlightAnimation(int duration = 5000);
68  void updateLabel();
69  public:
70  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
71  QPainterPath shape() const override;
72  QRectF boundingRect() const override;
73  // QGraphicsItem interface
74  bool isInitialTransition() const;
75  QPolygonF calcHull(QPainter* painter = 0) const;
76 
77  QColor getColor() const;
78  void setColor(const QColor& color);
79  QColor getHighlightColor() const;
80  void setHighlightColor(const QColor& color);
81  statechartmodel::TransitionCPtr getTransition() const;
82 
83  protected:
84  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
85  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
86  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
87  void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
88 
89 
90  QPolygonF shapePolygon;
91  private:
92  QPointF calcIntersection(statechartmodel::StateInstancePtr state, const QPointF& supportPoint) const;
93  QPointF calcIntersection(statechartmodel::StateInstancePtr state, QLineF centerLine, const QPointF& supportPoint) const;
94  QPolygonF calcArrowHead(const QLineF& line);
95  void recalcLabelPose();
96  float calcLengthOfLine(QPointF start, QPointF end);
97 
98 
99  statechartmodel::TransitionCPtr transition;
100  QPolygonF arrowHead;
101  QRectF initialStateCircle;
102  TransitionLabel* transitionLabel;
103  int pointAttachedToMouse;
104  QColor color, highlightColor, normalColor;
105  QPropertyAnimation animation;
106  IceUtil::Time highlightAnimationStartTime;
107 
108  // QGraphicsItem interface
109  protected:
110  void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
111  void hoverMoveEvent(QGraphicsSceneHoverEvent* event) override;
112  void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
113  };
114 
116  public QObject,
117  public QGraphicsSimpleTextItem,
118  public MorphingItem
119  {
120  Q_OBJECT
121  Q_PROPERTY(qreal fontPointSize READ fontPointSize WRITE setFontPointSize)
122  public:
123 
124  TransitionLabel(QString labelText, QGraphicsItem* parent = 0);
125  // QGraphicsItem interface
126  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
127  qreal fontPointSize() const;
128  qreal baseFontPointSize() const;
129  void setBaseFontPointSize(qreal newFontSize);
130  void setFontPointSize(qreal newFontSize);
131  void setEnlargedFontPointSize(qreal newFontSize);
132  void setHovering(bool hovering);
133  bool getHovering() const;
134  protected:
135  QPropertyAnimation animation;
136  bool hovering;
139  };
140 
141 }
142 
143 
armarx::TransitionItem::shapePolygon
QPolygonF shapePolygon
Definition: TransitionItem.h:90
armarx::TransitionItem::getHighlightColor
QColor getHighlightColor() const
Definition: TransitionItem.cpp:370
armarx::TransitionItem::updateLabel
void updateLabel()
Definition: TransitionItem.cpp:276
armarx::TransitionItem::contextMenuEvent
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
Definition: TransitionItem.cpp:795
armarx::TransitionLabel::hovering
bool hovering
Definition: TransitionItem.h:136
armarx::TransitionItem::transitionContextMenuRequested
void transitionContextMenuRequested(statechartmodel::TransitionCPtr transition, QPoint mouseScreenPos, QPointF mouseItemPos)
armarx::statechartmodel::TransitionPtr
std::shared_ptr< Transition > TransitionPtr
Definition: Transition.h:93
armarx::TransitionItem::attachToMouse
void attachToMouse(int supportPointIndex)
Definition: TransitionItem.cpp:257
armarx::TransitionItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Definition: TransitionItem.cpp:629
armarx::TransitionLabel::animation
QPropertyAnimation animation
Definition: TransitionItem.h:135
armarx::TransitionItem::getColor
QColor getColor() const
Definition: TransitionItem.cpp:359
armarx::MorphingItem
Definition: MorphingItem.h:39
IceUtil
Definition: Instance.h:21
armarx::statechartmodel::StateInstancePtr
std::shared_ptr< StateInstance > StateInstancePtr
Definition: StateInstance.h:138
armarx::TransitionItem::recalcPath
void recalcPath()
Definition: TransitionItem.cpp:129
armarx::TransitionItem::boundingRect
QRectF boundingRect() const override
Definition: TransitionItem.cpp:100
armarx::TransitionItem::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Definition: TransitionItem.cpp:719
armarx::TransitionItem::highlightAnimation
void highlightAnimation(int duration=5000)
Definition: TransitionItem.cpp:262
armarx::TransitionItem::setEditable
void setEditable(bool editable)
Definition: TransitionItem.cpp:124
MorphingItem.h
armarx::TransitionItem::recalcShape
void recalcShape()
Definition: TransitionItem.cpp:247
armarx::TransitionItem::setColor
void setColor(const QColor &color)
Definition: TransitionItem.cpp:364
armarx::TransitionItem::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition: TransitionItem.cpp:781
armarx::statechartmodel
Definition: XmlWriter.h:36
armarx::TransitionItem::hoverEnterEvent
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
Definition: TransitionItem.cpp:570
armarx::TransitionItem::mouseMoveEvent
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Definition: TransitionItem.cpp:760
armarx::TransitionLabel::fontEnlargedPointSize
qreal fontEnlargedPointSize
Definition: TransitionItem.h:138
armarx::TransitionLabel
Definition: TransitionItem.h:115
armarx::TransitionItem::getTransition
statechartmodel::TransitionCPtr getTransition() const
Definition: TransitionItem.cpp:565
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::TransitionItem
Definition: TransitionItem.h:44
armarx::TransitionItem::isInitialTransition
bool isInitialTransition() const
Definition: TransitionItem.cpp:114
armarx::TransitionItem::color
QColor color
Definition: TransitionItem.h:51
option
#define option(type, fn)
armarx::Logging
Base Class for all Logging classes.
Definition: Logging.h:232
armarx::TransitionLabel::fontBasePointSize
qreal fontBasePointSize
Definition: TransitionItem.h:137
armarx::statechartmodel::TransitionCPtr
std::shared_ptr< const Transition > TransitionCPtr
Definition: Transition.h:94
armarx::TransitionItem::setSelected
void setSelected(bool selected)
Definition: TransitionItem.cpp:252
armarx::TransitionItem::getLastHighlightTimestamp
IceUtil::Time getLastHighlightTimestamp() const
Definition: TransitionItem.cpp:79
armarx::TransitionItem::hoverMoveEvent
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override
Definition: TransitionItem.cpp:595
armarx::TransitionItem::hoverLeaveEvent
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
Definition: TransitionItem.cpp:611
armarx::TransitionItem::transitionSupportPointPlaced
void transitionSupportPointPlaced(QPointF dropPosition)
Logging.h
armarx::TransitionItem::transitionEndPlaced
void transitionEndPlaced(statechartmodel::TransitionCPtr transition, QPointF dropPosition)
armarx::TransitionItem::setHighlightColor
void setHighlightColor(const QColor &color)
Definition: TransitionItem.cpp:375
armarx::TransitionItem::shape
QPainterPath shape() const override
Definition: TransitionItem.cpp:84
armarx::TransitionItem::calcHull
QPolygonF calcHull(QPainter *painter=0) const
Definition: TransitionItem.cpp:293
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::TransitionItem::highlightColor
QColor highlightColor
Definition: TransitionItem.h:52