QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
qetshapeitem.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 The QElectroTech Team
3 This file is part of QElectroTech.
4
5 QElectroTech is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 QElectroTech is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef QETSHAPEITEM_H
19#define QETSHAPEITEM_H
20
21#include "../QetGraphicsItemModeler/qetgraphicshandleritem.h"
22#include "qetgraphicsitem.h"
23
24#include <QPen>
25
26class QDomElement;
27class QDomDocument;
29class QAction;
30
37{
38 Q_OBJECT
39
40 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
41 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
42 Q_PROPERTY(QRectF rect READ rect WRITE setRect)
43 Q_PROPERTY(QLineF line READ line WRITE setLine)
44 Q_PROPERTY(QPolygonF polygon READ polygon WRITE setPolygon)
45 Q_PROPERTY(bool close READ isClosed WRITE setClosed NOTIFY closeChanged)
46 Q_PROPERTY(qreal xRadius READ XRadius WRITE setXRadius NOTIFY XRadiusChanged)
47 Q_PROPERTY(qreal yRadius READ YRadius WRITE setYRadius NOTIFY YRadiusChanged)
48
49 signals:
50 void penChanged();
55
56
57 public:
58 enum ShapeType {Line =1,
61 Polygon =8 };
62 Q_ENUM (ShapeType)
63
64 enum { Type = UserType + 1008 };
65
67 QPointF,
68 QPointF = QPointF(0,0),
70 QGraphicsItem *parent = nullptr);
71 ~QetShapeItem() override;
72
73 //Enable the use of qgraphicsitem_cast to safely cast a
74 //QGraphicsItem into a QetShapeItem return the QGraphicsItem type
75 int type() const override { return Type; }
76
78 QPen pen() const {return m_pen;}
79 void setPen(const QPen &pen);
80 QBrush brush() const {return m_brush;}
81 void setBrush(const QBrush &brush);
83
84 virtual bool fromXml (const QDomElement &);
85 virtual QDomElement toXml (QDomDocument &document) const;
86 virtual bool toDXF (const QString &filepath,const QPen &pen);
87
88 void editProperty() override;
89 QString name() const override;
90
91 void setP2 (const QPointF &P2);
92 QLineF line() const{return QLineF(m_P1, m_P2);}
93 bool setLine (const QLineF &line);
94 QRectF rect() const{return QRectF(m_P1, m_P2);}
95 bool setRect (const QRectF &rect);
96 QPolygonF polygon() const {return m_polygon;}
97 bool setPolygon (const QPolygonF &polygon);
98 bool isClosed() const {return m_closed;}
99 void setClosed (bool close);
100 qreal XRadius() const {return m_xRadius;}
101 void setXRadius(qreal X);
102 qreal YRadius() const {return m_yRadius;}
103 void setYRadius(qreal Y);
104
105 //Methods available for polygon shape
106 int pointsCount () const;
107 void setNextPoint (QPointF P);
108 void removePoints (int number = 1);
109
110 QRectF boundingRect() const override;
111 QPainterPath shape() const override;
112
113 protected:
114 void paint(
115 QPainter *painter,
116 const QStyleOptionGraphicsItem *option,
117 QWidget *widget) override;
118 void hoverEnterEvent (QGraphicsSceneHoverEvent *event) override;
119 void hoverLeaveEvent (QGraphicsSceneHoverEvent *event) override;
120 void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
121 QVariant itemChange(
122 GraphicsItemChange change,
123 const QVariant &value) override;
124 bool sceneEventFilter(
125 QGraphicsItem *watched,
126 QEvent *event) override;
127 void contextMenuEvent(
128 QGraphicsSceneContextMenuEvent *event) override;
129
130 private:
131 void switchResizeMode();
132 void addHandler();
133 void adjusteHandlerPos();
134 void insertPoint();
135 void removePoint();
136
138 void handlerMouseMoveEvent(QGraphicsSceneMouseEvent *event);
140
142 private:
144 QPen m_pen;
145 QBrush m_brush;
146 QPointF m_P1,
154 bool m_closed = false,
157 QVector<QetGraphicsHandlerItem *> m_handler_vector;
160 qreal m_xRadius = 0,
164};
165#endif // QETSHAPEITEM_H
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
Definition qetgraphicshandleritem.h:37
Definition qetgraphicsitem.h:28
The QetShapeItem class this class is used to draw a basic shape (line, rectangle, ellipse) into a dia...
Definition qetshapeitem.h:37
virtual QDomElement toXml(QDomDocument &document) const
QetShapeItem::toXml Save this item to xml element.
Definition qetshapeitem.cpp:888
bool close
Definition qetshapeitem.h:45
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
QetShapeItem::paint Paint this item.
Definition qetshapeitem.cpp:303
QPolygonF polygon() const
Definition qetshapeitem.h:96
QBrush m_brush
Definition qetshapeitem.h:145
void removePoints(int number=1)
QetShapeItem::removePoints Number of point to remove on the polygon If number is superior to number o...
Definition qetshapeitem.cpp:231
bool m_modifie_radius_equaly
Definition qetshapeitem.h:155
void closeChanged()
void brushChanged()
QPointF m_context_menu_pos
Definition qetshapeitem.h:150
qreal xRadius
Definition qetshapeitem.h:46
@ Type
Definition qetshapeitem.h:64
QPointF m_P1
Definition qetshapeitem.h:146
QPolygonF m_polygon
Definition qetshapeitem.h:151
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
QetShapeItem::hoverEnterEvent Handle hover enter event.
Definition qetshapeitem.cpp:347
int pointsCount() const
QetShapeItem::pointCount.
Definition qetshapeitem.cpp:208
void setYRadius(qreal Y)
Definition qetshapeitem.cpp:196
void editProperty() override
QetShapeItem::editProperty Edit the property of this item.
Definition qetshapeitem.cpp:987
qreal m_yRadius
Definition qetshapeitem.h:161
QPen pen
Definition qetshapeitem.h:40
virtual bool fromXml(const QDomElement &)
QetShapeItem::fromXml Build this item from the xml description.
Definition qetshapeitem.cpp:846
QPointF m_P2
Definition qetshapeitem.h:147
QAction * m_insert_point
Definition qetshapeitem.h:158
void XRadiusChanged()
void YRadiusChanged()
int m_resize_mode
Definition qetshapeitem.h:156
void handlerMouseReleaseEvent()
QetShapeItem::handlerMouseReleaseEvent.
Definition qetshapeitem.cpp:790
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
QetShapeItem::itemChange.
Definition qetshapeitem.cpp:381
QRectF boundingRect() const override
QetShapeItem::boundingRect.
Definition qetshapeitem.cpp:252
bool setLine(const QLineF &line)
QetShapeItem::setLine Set item geometry to line (only available for line shape)
Definition qetshapeitem.cpp:126
ShapeType
Definition qetshapeitem.h:58
@ Polygon
Definition qetshapeitem.h:61
@ Ellipse
Definition qetshapeitem.h:60
@ Rectangle
Definition qetshapeitem.h:59
@ Line
Definition qetshapeitem.h:58
void switchResizeMode()
QetShapeItem::switchResizeMode.
Definition qetshapeitem.cpp:516
QAction * m_remove_point
Definition qetshapeitem.h:159
~QetShapeItem() override
Definition qetshapeitem.cpp:67
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
QetShapeItem::sceneEventFilter.
Definition qetshapeitem.cpp:420
bool setPolygon(const QPolygonF &polygon)
QetShapeItem::setPolygon Set this item geometry to polygon (only available if shape is a polyline)
Definition qetshapeitem.cpp:162
qreal yRadius
Definition qetshapeitem.h:47
bool m_closed
Definition qetshapeitem.h:154
void handlerMousePressEvent()
QetShapeItem::handlerMousePressEvent.
Definition qetshapeitem.cpp:712
void penChanged()
void handlerMouseMoveEvent(QGraphicsSceneMouseEvent *event)
QetShapeItem::handlerMouseMoveEvent.
Definition qetshapeitem.cpp:728
void removePoint()
Definition qetshapeitem.cpp:674
bool m_hovered
Definition qetshapeitem.h:152
int type() const override
Definition qetshapeitem.h:75
ShapeType shapeType() const
Definition qetshapeitem.h:82
QLineF line
Definition qetshapeitem.h:43
QPolygonF polygon
Definition qetshapeitem.h:44
QString name() const override
QetShapeItem::name.
Definition qetshapeitem.cpp:999
QPen m_pen
Definition qetshapeitem.h:144
void insertPoint()
Definition qetshapeitem.cpp:658
void setNextPoint(QPointF P)
QetShapeItem::setNextPoint Add a new point to the current polygon.
Definition qetshapeitem.cpp:218
QPointF m_old_P2
Definition qetshapeitem.h:149
void adjusteHandlerPos()
QetShapeItem::adjusteHandlerPos Adjust the position of the handler item.
Definition qetshapeitem.cpp:612
bool isClosed() const
Definition qetshapeitem.h:98
qreal m_old_yRadius
Definition qetshapeitem.h:163
int m_vector_index
Definition qetshapeitem.h:153
QPointF m_old_P1
Definition qetshapeitem.h:148
void setClosed(bool close)
QetShapeItem::setClosed Close this item, have effect only if this item is a polygon.
Definition qetshapeitem.cpp:178
QRectF rect() const
Definition qetshapeitem.h:94
QRectF rect
Definition qetshapeitem.h:42
QBrush brush
Definition qetshapeitem.h:41
void setP2(const QPointF &P2)
QetShapeItem::setP2 Set the second point of this item. If this item is a polyline,...
Definition qetshapeitem.cpp:106
ShapeType m_shapeType
ATTRIBUTES.
Definition qetshapeitem.h:143
QLineF line() const
Definition qetshapeitem.h:92
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Definition qetshapeitem.cpp:364
virtual bool toDXF(const QString &filepath, const QPen &pen)
QetShapeItem::toDXF Draw this element to the dxf document.
Definition qetshapeitem.cpp:949
QPainterPath shape() const override
QetShapeItem::shape.
Definition qetshapeitem.cpp:261
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
QetShapeItem::contextMenuEvent.
Definition qetshapeitem.cpp:458
qreal m_old_xRadius
Definition qetshapeitem.h:162
QPen pen() const
METHODS.
Definition qetshapeitem.h:78
qreal YRadius() const
Definition qetshapeitem.h:102
QPolygonF m_old_polygon
Definition qetshapeitem.h:151
bool setRect(const QRectF &rect)
QetShapeItem::setRect Set this item geometry to rect (only available if shape is a rectangle or an el...
Definition qetshapeitem.cpp:142
void setXRadius(qreal X)
Definition qetshapeitem.cpp:188
void setPen(const QPen &pen)
QetShapeItem::setPen Set the pen to use for draw the shape.
Definition qetshapeitem.cpp:78
void addHandler()
Definition qetshapeitem.cpp:567
QVector< QetGraphicsHandlerItem * > m_handler_vector
Definition qetshapeitem.h:157
qreal m_xRadius
Definition qetshapeitem.h:160
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
QetShapeItem::hoverLeaveEvent Handle hover leave event.
Definition qetshapeitem.cpp:358
qreal XRadius() const
Definition qetshapeitem.h:100
void setBrush(const QBrush &brush)
QetShapeItem::setBrush Set the brush to use for the fill the shape.
Definition qetshapeitem.cpp:91
QBrush brush() const
Definition qetshapeitem.h:80