OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
GraphicsConnectionItem.h
Go to the documentation of this file.
1
4// ###########################################################################################################################################################################################################################################################################################################################
5
6#pragma once
7
8// OpenTwin header
9#include "OTCore/CoreTypes.h"
11#include "OTGui/GuiTypes.h"
14
15// Qt header
16#include <QtCore/qrect.h>
17#include <QtGui/qpen.h>
18#include <QtGui/qpainterpath.h>
19#include <QtWidgets/qgraphicsitem.h>
20
21namespace ot {
22
23 class GraphicsItem;
24
25 class OT_WIDGETS_API_EXPORT GraphicsConnectionItem : public QGraphicsItem, public GraphicsElement {
27 public:
30
31 // ###########################################################################################################################################################################################################################################################################################################################
32
33 // QGraphicsItem
34
35 virtual QRectF boundingRect(void) const override;
36 virtual void paint(QPainter* _painter, const QStyleOptionGraphicsItem* _opt, QWidget* _widget) override;
37 virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange _change, const QVariant& _value) override;
38 virtual void mousePressEvent(QGraphicsSceneMouseEvent* _event) override;
39 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* _event) override;
40 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* _event) override;
41 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* _event) override;
42
43 // ###########################################################################################################################################################################################################################################################################################################################
44
45 // Graphics Base
46
50 virtual qreal calculateShortestDistanceToPoint(const QPointF& _pt) const override;
51
53 virtual QGraphicsItem* getQGraphicsItem(void) override;
54
56 virtual const QGraphicsItem* getQGraphicsItem(void) const override;
57
58 // ###########################################################################################################################################################################################################################################################################################################################
59
62 bool setConfiguration(const ot::GraphicsConnectionCfg& _cfg);
63
65 const GraphicsConnectionCfg& getConfiguration(void) const { return m_config; };
66
67 void setLineShape(GraphicsConnectionCfg::ConnectionShape _shape) { m_config.setLineShape(_shape); this->update(); };
68 GraphicsConnectionCfg::ConnectionShape getLineShape(void) const { return m_config.getLineShape(); };
69
70 void setLineWidth(double _width) { m_config.setLineWidth(_width); this->update(); };
71 double getLineWidth(void) const { return m_config.getLineWidth(); };
72
73 void setLineColor(const ot::Color& _color) { m_config.setLineColor(_color); this->update(); };
74
77 void setLinePainter(ot::Painter2D* _painter) { m_config.setLinePainter(_painter); this->update(); };
78
81 const ot::Painter2D* getLinePainter(void) const { return m_config.getLinePainter(); };
82
83 void setLineStyle(const OutlineF& _style) { m_config.setLineStyle(_style); this->update(); };
84 const OutlineF& getLineStyle(void) const { return m_config.getLineStyle(); };
85
86 void setHandleState(bool _handlesState);
87 bool getHandleState(void) const;
88
89 void updateConnectionView(void);
90
94 void connectItems(GraphicsItem* _origin, GraphicsItem* _dest);
95
99 void disconnectItems(void);
100
105 void forgetItem(const GraphicsItem* _item);
106
107 GraphicsItem* originItem(void) const { return m_origin; };
108 GraphicsItem* destItem(void) const { return m_dest; };
109
113 void updateConnectionInformation(void);
114
115 protected:
116 virtual void graphicsElementStateChanged(const GraphicsElementStateFlags& _flags) override;
117
118 private:
119 void calculatePainterPath(QPainterPath& _path) const;
120 void calculateDirectLinePath(QPainterPath& _path) const;
121 void calculateSmoothLinePath(QPainterPath& _path) const;
122 void calculateSmoothLineStep(const QPointF& _origin, const QPointF& _destination, double _halfdistX, double _halfdistY, QPointF& _control, ot::ConnectionDirection _direction) const;
123 void calculateXYLinePath(QPainterPath& _path) const;
124 void calculateYXLinePath(QPainterPath& _path) const;
125 void calculateAutoXYLinePath(QPainterPath& _path) const;
126 qreal calculateShortestDistanceToPointDirect(const QPointF& _pt) const;
127 qreal calculateShortestDistanceToPointSmooth(const QPointF& _pt) const;
128 qreal calculateShortestDistanceToPointXY(const QPointF& _pt) const;
129 qreal calculateShortestDistanceToPointYX(const QPointF& _pt) const;
130 qreal calculateShortestDistanceToPointAutoXY(const QPointF& _pt) const;
131
132 GraphicsConnectionCfg::ConnectionShape calculateAutoXYShape(void) const;
133
134 ot::Alignment calculateConnectionDirectionAlignment(void) const;
135
136 GraphicsConnectionCfg m_config;
137
138 GraphicsItem* m_origin;
139 GraphicsItem* m_dest;
140
141 QRectF m_lastRect;
142
143 };
144
145}
This file contains defines that may be used simplyfy class creation.
#define OT_DECL_NOCOPY(___class)
Removes the default copy constructor and assignment operator.
Definition OTClassHelper.h:14
#define OT_WIDGETS_API_EXPORT
Definition OTWidgetsAPIExport.h:12
The Color class is used to represent RGBA colors with integer values.
Definition Color.h:72
Definition GraphicsConnectionCfg.h:22
ConnectionShape
Definition GraphicsConnectionCfg.h:24
Definition GraphicsConnectionItem.h:25
const GraphicsConnectionCfg & getConfiguration(void) const
Creates a configuration object containing the items origin and destination information.
Definition GraphicsConnectionItem.h:65
GraphicsItem * originItem(void) const
Definition GraphicsConnectionItem.h:107
double getLineWidth(void) const
Definition GraphicsConnectionItem.h:71
const OutlineF & getLineStyle(void) const
Definition GraphicsConnectionItem.h:84
void setLineStyle(const OutlineF &_style)
Definition GraphicsConnectionItem.h:83
GraphicsItem * destItem(void) const
Definition GraphicsConnectionItem.h:108
void setLineWidth(double _width)
Definition GraphicsConnectionItem.h:70
const ot::Painter2D * getLinePainter(void) const
Returns the current line painter. The item keeps ownership of the painter.
Definition GraphicsConnectionItem.h:81
void setLinePainter(ot::Painter2D *_painter)
Sets the line painter. The item takes ownership of the painter.
Definition GraphicsConnectionItem.h:77
void setLineColor(const ot::Color &_color)
Definition GraphicsConnectionItem.h:73
void setLineShape(GraphicsConnectionCfg::ConnectionShape _shape)
Definition GraphicsConnectionItem.h:67
GraphicsConnectionCfg::ConnectionShape getLineShape(void) const
Definition GraphicsConnectionItem.h:68
Definition GraphicsElement.h:28
Base class for all OpenTwin GraphicsItems GraphicsItems should be created by the GraphicsFactory and ...
Definition GraphicsItem.h:35
The OutlineF class is used to describe how a outline should look like.
Definition Outline.h:161
Definition Painter2D.h:17
Definition Connector.h:8
ConnectionDirection
Describes in which direction a connetion from an item is starting.
Definition GuiTypes.h:65
Alignment
Alignment.
Definition GuiTypes.h:21