QElectroTech  0.70
partpolygon.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 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 PART_POLYGON_H
19 #define PART_POLYGON_H
20 
21 #include <QPolygonF>
23 
26 class QAction;
27 
34 {
35  Q_OBJECT
36 
37  Q_PROPERTY(bool closed READ isClosed WRITE setClosed)
38  Q_PROPERTY(QPolygonF polygon READ polygon WRITE setPolygon)
39 
40  // constructors, destructor
41  public:
42  PartPolygon(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
43  ~PartPolygon() override;
44 
45  private:
46  PartPolygon(const PartPolygon &);
47 
48  signals:
49  void closedChange();
50  void polygonChanged();
51 
52  // methods
53  public:
54  enum { Type = UserType + 1105 };
59  int type() const override { return Type; }
60  void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
61 
62  QString name() const override { return(QObject::tr("polygone", "element part name")); }
63  QString xmlName() const override { return(QString("polygon")); }
64  void fromXml(const QDomElement &) override;
65  const QDomElement toXml(QDomDocument &) const override;
66 
67  QPainterPath shape () const override;
68  QPainterPath shadowShape() const override;
69  QRectF boundingRect() const override;
70  bool isUseless() const override;
71  QRectF sceneGeometricRect() const override;
72 
73  void startUserTransformation(const QRectF &) override;
74  void handleUserTransformation(const QRectF &, const QRectF &) override;
76 
77  QPolygonF polygon () const;
78  void setPolygon (const QPolygonF &polygon);
79 
80  void addPoint (const QPointF &point);
81  void setLastPoint (const QPointF &point);
82  void removeLastPoint ();
83 
84  bool isClosed () const {return m_closed;}
85  void setClosed (bool close);
86 
87  protected:
88  QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
89  bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
90  void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
91 
92  private:
93  void adjusteHandlerPos();
94  void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
95  void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
96  void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
97  void sceneSelectionChanged ();
98 
99  void addHandler();
100  void removeHandler();
101  void insertPoint();
102  void removePoint();
103 
104 
105  bool m_closed;
106  QList<QPointF> saved_points_;
107  QPolygonF m_polygon;
109  int m_vector_index = -1;
110  QVector<QetGraphicsHandlerItem *> m_handler_vector;
111  QAction *m_insert_point,
114 };
115 #endif
int type() const override
Definition: partpolygon.h:59
void fromXml(const QDomElement &) override
PartPolygon::fromXml Import the properties of this polygon from a xml element.
Definition: partpolygon.cpp:85
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
QPolygonF polygon() const
void addPoint(const QPointF &point)
PartPolygon::addPoint Add new point to polygon.
void adjusteHandlerPos()
PartPolygon::adjusteHandlerPos.
void removeHandler()
PartPolygon::removeHandler Remove the handlers of this item.
void removePoint()
PartPolygon::removePoint remove a point on this polygon.
QVector< QetGraphicsHandlerItem * > m_handler_vector
Definition: partpolygon.h:110
void sceneSelectionChanged()
PartPolygon::sceneSelectionChanged When the scene selection change, if there are several primitive se...
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartPolygon::handlerMouseReleaseEvent.
int m_vector_index
Definition: partpolygon.h:109
QPainterPath shape() const override
PartPolygon::shape.
void setLastPoint(const QPointF &point)
PartPolygon::setLastPoint Set the last point of polygon to .
QString name() const override
Definition: partpolygon.h:62
void setClosed(bool close)
void addHandler()
PartPolygon::addHandler Add handlers for this item.
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
PartPolygon::paint Draw this polygon.
Definition: partpolygon.cpp:62
void polygonChanged()
The CustomElementGraphicPart class This class is the base for all home-made primitive like line...
QAction * m_insert_point
Definition: partpolygon.h:111
void insertPoint()
PartPolygon::insertPoint Insert a point in this polygone.
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartPolygon::handlerMousePressEvent.
QET::ScalingMethod preferredScalingMethod() const override
PartPolygon::preferredScalingMethod This method is called by the decorator when it needs to determine...
bool isClosed() const
Definition: partpolygon.h:84
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
void startUserTransformation(const QRectF &) override
PartPolygon::startUserTransformation Start the user-induced transformation, provided this primitive i...
QString xmlName() const override
Definition: partpolygon.h:63
void removeLastPoint()
PartPolygon::removeLastPoint Remove the last point of polygon.
QPointF m_context_menu_pos
Definition: partpolygon.h:113
QRectF boundingRect() const override
PartPolygon::boundingRect.
QIcon tr
Definition: qeticons.cpp:204
void handleUserTransformation(const QRectF &, const QRectF &) override
PartPolygon::handleUserTransformation Handle the user-induced transformation from initial_selection_r...
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
PartPolygon::sceneEventFilter.
void closedChange()
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartPolygon::itemChange.
QPainterPath shadowShape() const override
ScalingMethod
Supported types of interactive scaling, typically for a single element primitive. ...
Definition: qet.h:79
bool isUseless() const override
PartPolygon::isUseless.
The PartPolygon class This class represents a polygon primitive which may be used to compose the draw...
Definition: partpolygon.h:33
QRectF sceneGeometricRect() const override
PartPolygon::sceneGeometricRect.
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartPolygon::handlerMouseMoveEvent.
void setPolygon(const QPolygonF &polygon)
PartPolygon::setPolygon Sets the item&#39;s polygon to be the given polygon.
const QDomElement toXml(QDomDocument &) const override
PartPolygon::toXml Export this polygin in xml.
QPropertyUndoCommand * m_undo_command
Definition: partpolygon.h:108
QList< QPointF > saved_points_
Definition: partpolygon.h:106
QAction * m_remove_point
Definition: partpolygon.h:111
QPolygonF m_polygon
Definition: partpolygon.h:107