QElectroTech  0.8-dev
partpolygon.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 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:
47 
48  signals:
49  void closedChange();
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  void setHandlerColor(QPointF pos, const QColor &color) final;
88  void resetAllHandlerColor() final;
89 
90  protected:
91  QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
92  bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
93  void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
94 
95  private:
96  void adjusteHandlerPos();
97  void handlerMousePressEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
98  void handlerMouseMoveEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
99  void handlerMouseReleaseEvent (QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event);
100  void sceneSelectionChanged ();
101 
102  void addHandler();
103  void removeHandler();
104  void insertPoint();
105  void removePoint();
106 
107 
108  bool m_closed;
109  QList<QPointF> saved_points_;
110  QPolygonF m_polygon;
112  int m_vector_index = -1;
114  QAction *m_insert_point,
117 };
118 #endif
PartPolygon::saved_points_
QList< QPointF > saved_points_
Definition: partpolygon.h:109
qetgraphicshandlerutility.h
PartPolygon::paint
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
PartPolygon::paint Draw this polygon.
Definition: partpolygon.cpp:62
PartPolygon::m_remove_point
QAction * m_remove_point
Definition: partpolygon.h:115
ElementScene::snapToGrid
QPointF snapToGrid(QPointF point)
ElementScene::snapToGrid Rounds the coordinates of the point passed as a parameter so that this point...
Definition: elementscene.cpp:1270
QetGraphicsHandlerItem::Type
@ Type
Definition: qetgraphicshandleritem.h:42
ElementScene::undoStack
QUndoStack & undoStack()
ElementScene::undoStack.
Definition: elementscene.cpp:603
PartPolygon::handlerMousePressEvent
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartPolygon::handlerMousePressEvent.
Definition: partpolygon.cpp:417
PartPolygon::m_closed
bool m_closed
Definition: partpolygon.h:108
CustomElementGraphicPart
The CustomElementGraphicPart class This class is the base for all home-made primitive like line,...
Definition: customelementgraphicpart.h:36
PartPolygon::removeHandler
void removeHandler()
PartPolygon::removeHandler Remove the handlers of this item.
Definition: partpolygon.cpp:498
PartPolygon::m_handler_vector
QVector< QetGraphicsHandlerItem * > m_handler_vector
Definition: partpolygon.h:113
PartPolygon::Type
@ Type
Definition: partpolygon.h:54
PartPolygon::setHandlerColor
void setHandlerColor(QPointF pos, const QColor &color) final
PartPolygon::setHandlerColor Set the handler at pos pos (in polygon coordinate) to color color.
Definition: partpolygon.cpp:266
PartPolygon::fromXml
void fromXml(const QDomElement &) override
PartPolygon::fromXml Import the properties of this polygon from a xml element.
Definition: partpolygon.cpp:85
CustomElementGraphicPart::stylesToXml
void stylesToXml(QDomElement &) const
CustomElementGraphicPart::stylesToXml Write the curent style to xml element. The style are stored lik...
Definition: customelementgraphicpart.cpp:162
PartPolygon::xmlName
QString xmlName() const override
Definition: partpolygon.h:63
PartPolygon::shadowShape
QPainterPath shadowShape() const override
Definition: partpolygon.cpp:577
QPropertyUndoCommand::setNewValue
void setNewValue(const QVariant &new_value)
QPropertyUndoCommand::setNewValue Set the new value of the property (set with redo) to new_value.
Definition: qpropertyundocommand.cpp:83
PartPolygon::isClosed
bool isClosed() const
Definition: partpolygon.h:84
PartPolygon::m_polygon
QPolygonF m_polygon
Definition: partpolygon.h:110
PartPolygon::polygon
QPolygonF polygon
Definition: partpolygon.h:38
PartPolygon::removeLastPoint
void removeLastPoint()
PartPolygon::removeLastPoint Remove the last point of polygon.
Definition: partpolygon.cpp:243
PartPolygon::setPolygon
void setPolygon(const QPolygonF &polygon)
PartPolygon::setPolygon Sets the item's polygon to be the given polygon.
Definition: partpolygon.cpp:205
PartPolygon::m_insert_point
QAction * m_insert_point
Definition: partpolygon.h:114
PartPolygon::adjusteHandlerPos
void adjusteHandlerPos()
PartPolygon::adjusteHandlerPos.
Definition: partpolygon.cpp:393
PartPolygon::addPoint
void addPoint(const QPointF &point)
PartPolygon::addPoint Add new point to polygon.
Definition: partpolygon.cpp:219
PartPolygon
The PartPolygon class This class represents a polygon primitive which may be used to compose the draw...
Definition: partpolygon.h:34
PartPolygon::~PartPolygon
~PartPolygon() override
PartPolygon::~PartPolygon.
Definition: partpolygon.cpp:49
PartPolygon::handleUserTransformation
void handleUserTransformation(const QRectF &, const QRectF &) override
PartPolygon::handleUserTransformation Handle the user-induced transformation from initial_selection_r...
Definition: partpolygon.cpp:175
CustomElementGraphicPart::stylesFromXml
void stylesFromXml(const QDomElement &)
CustomElementGraphicPart::stylesFromXml Read the style used by this, from a xml element.
Definition: customelementgraphicpart.cpp:508
qetelementeditor.h
PartPolygon::setLastPoint
void setLastPoint(const QPointF &point)
PartPolygon::setLastPoint Set the last point of polygon to point.
Definition: partpolygon.cpp:230
PartPolygon::addHandler
void addHandler()
PartPolygon::addHandler Add handlers for this item.
Definition: partpolygon.cpp:478
qeticons.h
PartPolygon::resetAllHandlerColor
void resetAllHandlerColor() final
PartPolygon::resetAllHandlerColor Reset the color of every handlers.
Definition: partpolygon.cpp:279
PartPolygon::shape
QPainterPath shape() const override
PartPolygon::shape.
Definition: partpolygon.cpp:562
ElementScene::editor
QETElementEditor * editor() const
ElementScene::editor.
Definition: elementscene.cpp:683
PartPolygon::m_context_menu_pos
QPointF m_context_menu_pos
Definition: partpolygon.h:116
PartPolygon::closedChange
void closedChange()
PartPolygon::sceneGeometricRect
QRectF sceneGeometricRect() const override
PartPolygon::sceneGeometricRect.
Definition: partpolygon.cpp:153
PartPolygon::sceneEventFilter
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
PartPolygon::sceneEventFilter.
Definition: partpolygon.cpp:332
PartPolygon::polygonChanged
void polygonChanged()
elementscene.h
PartPolygon::PartPolygon
PartPolygon(const PartPolygon &)
PartPolygon::handlerMouseMoveEvent
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartPolygon::handlerMouseMoveEvent.
Definition: partpolygon.cpp:431
PartPolygon::preferredScalingMethod
QET::ScalingMethod preferredScalingMethod() const override
PartPolygon::preferredScalingMethod This method is called by the decorator when it needs to determine...
Definition: partpolygon.cpp:188
qpropertyundocommand.h
PartPolygon::boundingRect
QRectF boundingRect() const override
PartPolygon::boundingRect.
Definition: partpolygon.cpp:595
qetgraphicshandleritem.h
QetGraphicsHandlerItem
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
Definition: qetgraphicshandleritem.h:37
PartPolygon::type
int type() const override
Definition: partpolygon.h:59
CustomElementGraphicPart::m_hovered
bool m_hovered
Definition: customelementgraphicpart.h:323
PartPolygon::startUserTransformation
void startUserTransformation(const QRectF &) override
PartPolygon::startUserTransformation Start the user-induced transformation, provided this primitive i...
Definition: partpolygon.cpp:163
PartPolygon::m_undo_command
QPropertyUndoCommand * m_undo_command
Definition: partpolygon.h:111
PartPolygon::toXml
const QDomElement toXml(QDomDocument &) const override
PartPolygon::toXml Export this polygin in xml.
Definition: partpolygon.cpp:116
PartPolygon::insertPoint
void insertPoint()
PartPolygon::insertPoint Insert a point in this polygone.
Definition: partpolygon.cpp:511
customelementgraphicpart.h
PartPolygon::contextMenuEvent
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
Definition: partpolygon.cpp:366
SHADOWS_HEIGHT
#define SHADOWS_HEIGHT
Definition: customelementgraphicpart.h:37
CustomElementGraphicPart::color
Color color
Definition: customelementgraphicpart.h:44
PartPolygon::removePoint
void removePoint()
PartPolygon::removePoint remove a point on this polygon.
Definition: partpolygon.cpp:528
CustomElementPart::elementScene
virtual ElementScene * elementScene() const
Definition: customelementpart.cpp:37
PartPolygon::closed
bool closed
Definition: partpolygon.h:37
CustomElementPart::mapPoints
QList< QPointF > mapPoints(const QRectF &, const QRectF &, const QList< QPointF > &)
Definition: customelementpart.cpp:69
PartPolygon::sceneSelectionChanged
void sceneSelectionChanged()
PartPolygon::sceneSelectionChanged When the scene selection change, if there are several primitive se...
Definition: partpolygon.cpp:466
QET::ScalingMethod
ScalingMethod
Supported types of interactive scaling, typically for a single element primitive.
Definition: qet.h:81
CustomElementGraphicPart::applyStylesToQPainter
void applyStylesToQPainter(QPainter &) const
CustomElementGraphicPart::applyStylesToQPainter Apply the current style to the QPainter.
Definition: customelementgraphicpart.cpp:885
PartPolygon::m_vector_index
int m_vector_index
Definition: partpolygon.h:112
CustomElementGraphicPart::penWeight
qreal penWeight() const
CustomElementGraphicPart::penWeight.
Definition: customelementgraphicpart.cpp:109
QET::RoundScaleRatios
@ RoundScaleRatios
adjust the scaling movement so that the induced scaling ratios are rounded
Definition: qet.h:84
QetGraphicsHandlerUtility::polygonForInsertPoint
static QPolygonF polygonForInsertPoint(const QPolygonF &old_polygon, bool closed, const QPointF &pos)
QetGraphicsHandlerUtility::polygonForInsertPoint.
Definition: qetgraphicshandlerutility.cpp:213
QETElementEditor::contextMenu
void contextMenu(QPoint p, QList< QAction * > actions=QList< QAction * >())
QETElementEditor::contextMenu Display a context menu, with all available action.
Definition: qetelementeditor.cpp:431
ElementScene::Normal
@ Normal
Definition: elementscene.h:46
QPropertyUndoCommand
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
Definition: qpropertyundocommand.h:34
PartPolygon::handlerMouseReleaseEvent
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartPolygon::handlerMouseReleaseEvent.
Definition: partpolygon.cpp:451
QetGraphicsHandlerItem::handlerForPoint
static QVector< QetGraphicsHandlerItem * > handlerForPoint(const QVector< QPointF > &points, int size=10)
QetGraphicsHandlerItem::handlerForPoint.
Definition: qetgraphicshandleritem.cpp:87
QET::Icons::Add
QIcon Add
Definition: qeticons.cpp:24
partpolygon.h
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
PartPolygon::itemChange
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartPolygon::itemChange.
Definition: partpolygon.cpp:292
PartPolygon::PartPolygon
PartPolygon(QETElementEditor *editor, QGraphicsItem *parent=nullptr)
PartPolygon::PartPolygon Constructor.
Definition: partpolygon.cpp:33
QET::attributeIsAReal
bool attributeIsAReal(const QDomElement &, const QString &, qreal *=nullptr)
Definition: qet.cpp:231
QETElementEditor
Definition: qetelementeditor.h:33
PartPolygon::setClosed
void setClosed(bool close)
Definition: partpolygon.cpp:252
PartPolygon::isUseless
bool isUseless() const override
PartPolygon::isUseless.
Definition: partpolygon.cpp:136
CustomElementGraphicPart::drawShadowShape
void drawShadowShape(QPainter *painter)
CustomElementGraphicPart::drawShadowShape Draw a transparent blue shadow arround the shape of this it...
Definition: customelementgraphicpart.cpp:1240
PartPolygon::name
QString name() const override
Definition: partpolygon.h:62
QET::Icons::Remove
QIcon Remove
Definition: qeticons.cpp:155