OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
GraphicsItem.h
Go to the documentation of this file.
1
4// ###########################################################################################################################################################################################################################################################################################################################
5
6#pragma once
7
8// OpenTwin header
9#include "OTCore/Flags.h"
10#include "OTCore/CoreTypes.h"
11#include "OTGui/Margins.h"
12#include "OTGui/GuiTypes.h"
17
18// Qt header
19#include <QtCore/qpoint.h>
20#include <QtWidgets/qgraphicsitem.h>
21#include <QtWidgets/qgraphicslayoutitem.h>
22
23// std header
24#include <list>
25#include <string>
26
27namespace ot {
28
29 class Painter2D;
30 class GraphicsItemCfg;
31 class GraphicsConnectionItem;
32
38 public:
39
40 // ###############################################################################################################################################
41
42 // Types
43
48 ItemResized
49 };
50
51 // ###############################################################################################################################################
52
53 // Public Static
54
57 static Painter2D* createSelectionBorderPainter(void);
58
61 static Painter2D* createHoverBorderPainter(void);
62
63 // ###############################################################################################################################################
64
65 // Constructor / Destructor
66
70 GraphicsItem(GraphicsItemCfg* _configuration);
71
73 virtual ~GraphicsItem();
74
75 // ###############################################################################################################################################
76
77 // Pure virtual functions
78
80 virtual void callPaint(QPainter* _painter, const QStyleOptionGraphicsItem* _opt, QWidget* _widget) = 0;
81
83 virtual QGraphicsLayoutItem* getQGraphicsLayoutItem(void) = 0;
84
86 virtual void prepareGraphicsItemGeometryChange(void) = 0;
87
89 virtual QSizeF graphicsItemSizeHint(Qt::SizeHint _hint, const QSizeF& _constrains) const = 0;
90
91 // ###############################################################################################################################################
92
93 // Virtual functions
94
99 virtual bool setupFromConfig(const GraphicsItemCfg* _cfg);
100
102 virtual void graphicsItemEventHandler(GraphicsItem* _sender, GraphicsItemEvent _event) {};
103
105 virtual void graphicsItemFlagsChanged(const GraphicsItemCfg::GraphicsItemFlags& _flags);
106
108 virtual void graphicsItemConfigurationChanged(const GraphicsItemCfg* _config);
109
112 virtual ot::GraphicsItem* findItem(const std::string& _itemName);
113
115 virtual void removeAllConnections(void);
116
117 virtual bool graphicsItemRequiresHover(void) const;
118
122 virtual void finalizeGraphicsItem(void) {};
123
124 // ###############################################################################################################################################
125
126 // Event handler
127
128 void handleMousePressEvent(QGraphicsSceneMouseEvent* _event);
129
132 bool handleMouseMoveEvent(QGraphicsSceneMouseEvent* _event);
133 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent* _event);
134 void handleHoverEnterEvent(QGraphicsSceneHoverEvent* _event);
135 void handleToolTip(QGraphicsSceneHoverEvent* _event);
136 void handleHoverLeaveEvent(QGraphicsSceneHoverEvent* _event);
137
139 QSizeF handleGetGraphicsItemSizeHint(Qt::SizeHint _hint, const QSizeF& _sizeHint) const;
140
143 QRectF handleGetGraphicsItemBoundingRect(const QRectF& _rect) const;
144
148 void handleItemChange(QGraphicsItem::GraphicsItemChange _change, const QVariant& _value);
149
150 void handleSetItemGeometry(const QRectF& _geom);
151
152 void raiseEvent(ot::GraphicsItem::GraphicsItemEvent _event);
153
157 virtual qreal calculateShortestDistanceToPoint(const QPointF& _pt) const override;
158
161 QRectF calculatePaintArea(const QSizeF& _innerSize);
162
163 // ###############################################################################################################################################
164
165 // Getter / Setter
166
167 virtual GraphicsScene* getGraphicsScene(void) const override;
168
169 GraphicsItem* getRootItem(void);
170
171 const GraphicsItem* getRootItem(void) const;
172
175 void setConfiguration(GraphicsItemCfg* _config);
176
178 const GraphicsItemCfg* const getConfiguration(void) const { return m_config; };
179
181 void setGraphicsItemPos(const QPointF& _pos);
182
184 void setGraphicsItemPos(const Point2DD& _pos);
185
187 const Point2DD& getGraphicsItemPos(void) const;
188
189 virtual void setParentGraphicsItem(GraphicsItem* _itm) { m_parent = _itm; };
190 GraphicsItem* getParentGraphicsItem(void) const { return m_parent; };
191
196 void setGraphicsItemFlag(ot::GraphicsItemCfg::GraphicsItemFlag _flag, bool _active = true);
197
200 void setGraphicsItemFlags(ot::GraphicsItemCfg::GraphicsItemFlags _flags);
201
204 const GraphicsItemCfg::GraphicsItemFlags& getGraphicsItemFlags(void) const;
205
208 void setGraphicsItemUid(const ot::UID& _uid);
209 const ot::UID& getGraphicsItemUid(void) const;
210
211 virtual void setGraphicsItemName(const std::string& _name);
212 const std::string& getGraphicsItemName(void) const;
213
214 void setGraphicsItemToolTip(const std::string& _toolTip);
215 const std::string& getGraphicsItemToolTip(void) const;
216
217 void setAdditionalTriggerDistance(const ot::MarginsD& _distance);
218 const ot::MarginsD& getAdditionalTriggerDistance(void) const;
219
221 virtual double getMaxAdditionalTriggerDistance(void) const;
222
223 void setGraphicsItemMinimumSize(double _width, double _height) { this->setGraphicsItemMinimumSize(QSizeF(_width, _height)); };
224 void setGraphicsItemMinimumSize(const QSizeF& _size);
225 QSizeF getGraphicsItemMinimumSize(void) const;
226
227 void setGraphicsItemMaximumSize(double _width, double _height) { this->setGraphicsItemMaximumSize(QSizeF(_width, _height)); };
228 void setGraphicsItemMaximumSize(const QSizeF& _size);
229 QSizeF getGraphicsItemMaximumSize(void) const;
230
231 void setGraphicsItemSizePolicy(ot::SizePolicy _policy);
232 ot::SizePolicy getGraphicsItemSizePolicy(void) const;
233
234 void setGraphicsItemAlignment(ot::Alignment _align);
235 ot::Alignment getGraphicsItemAlignment(void) const;
236
237 void setGraphicsItemMargins(const ot::MarginsD& _margins);
238 const ot::MarginsD& getGraphicsItemMargins(void) const;
239
240 void setConnectionDirection(ot::ConnectionDirection _direction);
241 ot::ConnectionDirection getConnectionDirection(void) const;
242
243 void setStringMap(const std::map<std::string, std::string>& _map);
244 const std::map<std::string, std::string>& getStringMap(void) const;
245
246 void setGraphicsItemTransform(const Transform& _transform);
247 const Transform& getGraphicsItemTransform(void) const;
248
249 void setForwardSizeChanges(bool _forward) { m_forwardSizeChanges = _forward; };
250 bool getForwardSizeChanges(void) const { return m_forwardSizeChanges; };
251
252 void storeConnection(GraphicsConnectionItem* _connection);
253
255 void forgetConnection(GraphicsConnectionItem* _connection);
256
257 void addGraphicsItemEventHandler(ot::GraphicsItem* _handler);
258 void removeGraphicsItemEventHandler(ot::GraphicsItem* _handler);
259
260 QSizeF applyGraphicsItemMargins(const QSizeF& _size) const;
261 QSizeF removeGraphicsItemMargins(const QSizeF& _size) const;
262
263 virtual void setGraphicsItemRequestedSize(const QSizeF& _size);
264 const QSizeF& graphicsItemRequestedSize(void) const { return m_requestedSize; };
265
266 std::list<ot::GraphicsConnectionCfg> getConnectionCfgs();
267
268 void setGraphicsItemSelected(bool _selected);
269 bool getGraphicsItemSelected(void) const;
270
272 void setBlockFlagNotifications(bool _block) { m_blockFlagNotifications = _block; };
273
275 bool getBlockFlagNotifications(void) const { return m_blockFlagNotifications; };
276
278 void setBlockConfigurationNotifications(bool _block) { m_blockConfigurationNotifications = _block; };
279
281 bool getBlockConfigurationNotifications(void) const { return m_blockConfigurationNotifications; };
282
284 void setCurrentPosAsMoveStart(void);
285
287 void notifyMoveIfRequired(void);
288
289 void parentItemTransformChanged(const QTransform& _parentTransform);
290
293 QRectF getTriggerBoundingRect(void) const;
294
295 // ###########################################################################################################################################################################################################################################################################################################################
296
297 // Protected notifier
298
299 protected:
300 virtual void graphicsElementStateChanged(const GraphicsElementStateFlags& _state) override;
301
306 template <class T> T* getItemConfiguration(void);
307
312 template <class T> const T* getItemConfiguration(void) const;
313
314 virtual void applyGraphicsItemTransform(void);
315
316 virtual void notifyChildsAboutTransformChange(const QTransform& _newTransform) {};
317
318 private:
319 ConnectionDirection calculateOutwardsConnectionDirection(void) const;
320
321 GraphicsItemCfg* m_config;
322
323 QPointF m_moveStartPt;
324 GraphicsItem* m_parent;
325
326 QSizeF m_requestedSize;
327
328 bool m_forwardSizeChanges;
329
330 bool m_blockFlagNotifications;
331 bool m_blockConfigurationNotifications;
332
333 std::list<GraphicsItem*> m_eventHandler;
334 std::list<GraphicsConnectionItem*> m_connections;
335 };
336
337}
338
#define OT_DECL_NODEFAULT(___class)
Removes the default copy constructor and assignment operator.
Definition OTClassHelper.h:22
#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
Definition GraphicsConnectionItem.h:25
Definition GraphicsElement.h:28
The GraphicsItemCfg is the base class for all graphics item configurations.
Definition GraphicsItemCfg.h:33
GraphicsItemFlag
GraphicsItemFlag.
Definition GraphicsItemCfg.h:37
Base class for all OpenTwin GraphicsItems GraphicsItems should be created by the GraphicsFactory and ...
Definition GraphicsItem.h:35
GraphicsItem * getParentGraphicsItem(void) const
Definition GraphicsItem.h:190
bool getBlockFlagNotifications(void) const
If enabled the item will not call graphicsItemFlagsChanged() when the flags have changed.
Definition GraphicsItem.h:275
GraphicsItemEvent
The GraphicsItemEvent is used to describe the type of an event that occured.
Definition GraphicsItem.h:46
@ ItemMoved
Definition GraphicsItem.h:47
virtual void notifyChildsAboutTransformChange(const QTransform &_newTransform)
Definition GraphicsItem.h:316
bool getBlockConfigurationNotifications(void) const
If enabled the item will not call graphicsItemConfigurationChanged() when the flags have changed.
Definition GraphicsItem.h:281
virtual void setParentGraphicsItem(GraphicsItem *_itm)
Definition GraphicsItem.h:189
void setGraphicsItemMaximumSize(double _width, double _height)
Definition GraphicsItem.h:227
void setGraphicsItemMinimumSize(double _width, double _height)
Definition GraphicsItem.h:223
const QSizeF & graphicsItemRequestedSize(void) const
Definition GraphicsItem.h:264
virtual void callPaint(QPainter *_painter, const QStyleOptionGraphicsItem *_opt, QWidget *_widget)=0
Calls QGraphicsItem::paint().
bool getForwardSizeChanges(void) const
Definition GraphicsItem.h:250
virtual void prepareGraphicsItemGeometryChange(void)=0
Calls QGraphicsLayoutItem::prepareGeometryChange().
void setForwardSizeChanges(bool _forward)
Definition GraphicsItem.h:249
virtual QGraphicsLayoutItem * getQGraphicsLayoutItem(void)=0
Returns the QGraphicsLayoutItem.
const GraphicsItemCfg *const getConfiguration(void) const
Returns the current configuration.
Definition GraphicsItem.h:178
virtual QSizeF graphicsItemSizeHint(Qt::SizeHint _hint, const QSizeF &_constrains) const =0
Calls QGraphicsLayoutItem::sizeHint().
void setBlockConfigurationNotifications(bool _block)
Definition GraphicsItem.h:278
void setBlockFlagNotifications(bool _block)
Definition GraphicsItem.h:272
virtual void finalizeGraphicsItem(void)
Will be called after setupFromConfig (i.e. if the item is completely created). Here the item structur...
Definition GraphicsItem.h:122
virtual void graphicsItemEventHandler(GraphicsItem *_sender, GraphicsItemEvent _event)
Will be called when this item was registered as an event handler and the child raised an event.
Definition GraphicsItem.h:102
Graphics Scene for ot::GraphicsItem Adding QGraphicsItems to the scene that do not inherit ot::Graphi...
Definition GraphicsScene.h:31
Definition Margins.h:98
Definition Painter2D.h:17
2D Point with double values
Definition Point2D.h:144
General item transformation.
Definition Transform.h:16
Definition Connector.h:8
SizePolicy
Size policy for UI elements.
Definition GuiTypes.h:58
ConnectionDirection
Describes in which direction a connetion from an item is starting.
Definition GuiTypes.h:65
unsigned long UID
Unique identifier (32 bit unsigned integer)
Definition CoreTypes.h:27
Alignment
Alignment.
Definition GuiTypes.h:21