LibrePCB Developers Documentation
polygongraphicsitem.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_EDITOR_POLYGONGRAPHICSITEM_H
21 #define LIBREPCB_EDITOR_POLYGONGRAPHICSITEM_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
29 
30 #include <QtCore>
31 #include <QtWidgets>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 namespace editor {
38 
39 class IF_GraphicsLayerProvider;
40 
41 /*******************************************************************************
42  * Class PolygonGraphicsItem
43  ******************************************************************************/
44 
49 public:
50  // Constructors / Destructor
51  PolygonGraphicsItem() = delete;
52  PolygonGraphicsItem(const PolygonGraphicsItem& other) = delete;
54  QGraphicsItem* parent = nullptr) noexcept;
55  virtual ~PolygonGraphicsItem() noexcept;
56 
57  // Getters
58  Polygon& getPolygon() noexcept { return mPolygon; }
59 
67  int getLineIndexAtPosition(const Point& pos) const noexcept;
68 
73  QVector<int> getVertexIndicesAtPosition(const Point& pos) const noexcept;
74 
75  // Setters
76 
86  void setEditable(bool editable) noexcept;
87 
88  // Inherited Methods
89  QVariant itemChange(GraphicsItemChange change,
90  const QVariant& value) noexcept override;
91  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
92  QWidget* widget = 0) noexcept override;
93 
94  // Operator Overloadings
96 
97 private: // Methods
98  void polygonEdited(const Polygon& polygon, Polygon::Event event) noexcept;
99  void updateFillLayer() noexcept;
100  void updatePath() noexcept;
101  void updateZValue() noexcept;
102  void updateBoundingRectMargin() noexcept;
103 
104 private: // Data
107  bool mEditable;
108 
109  // Cached attributes
111  struct VertexHandle {
114  };
115  QVector<VertexHandle> mVertexHandles;
116 
117  // Slots
119 };
120 
121 /*******************************************************************************
122  * End of File
123  ******************************************************************************/
124 
125 } // namespace editor
126 } // namespace librepcb
127 
128 #endif
qreal mVertexHandleRadiusPx
Definition: polygongraphicsitem.h:110
The PrimitivePathGraphicsItem class.
Definition: primitivepathgraphicsitem.h:50
void updatePath() noexcept
Definition: polygongraphicsitem.cpp:204
The PolygonGraphicsItem class.
Definition: polygongraphicsitem.h:48
virtual ~PolygonGraphicsItem() noexcept
Definition: polygongraphicsitem.cpp:63
QVector< VertexHandle > mVertexHandles
Definition: polygongraphicsitem.h:115
Definition: occmodel.cpp:77
Polygon::OnEditedSlot mOnEditedSlot
Definition: polygongraphicsitem.h:118
PolygonGraphicsItem & operator=(const PolygonGraphicsItem &rhs)=delete
void updateZValue() noexcept
Definition: polygongraphicsitem.cpp:223
Point pos
Definition: polygongraphicsitem.h:112
Event
Definition: polygon.h:50
Polygon & getPolygon() noexcept
Definition: polygongraphicsitem.h:58
qreal maxGlowRadiusPx
Definition: polygongraphicsitem.h:113
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:79
QVector< int > getVertexIndicesAtPosition(const Point &pos) const noexcept
Definition: polygongraphicsitem.cpp:96
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:111
bool mEditable
Definition: polygongraphicsitem.h:107
void setEditable(bool editable) noexcept
Definition: polygongraphicsitem.cpp:109
void updateBoundingRectMargin() noexcept
Definition: polygongraphicsitem.cpp:234
void updateFillLayer() noexcept
Definition: polygongraphicsitem.cpp:193
int getLineIndexAtPosition(const Point &pos) const noexcept
Definition: polygongraphicsitem.cpp:70
Definition: polygongraphicsitem.h:111
Polygon & mPolygon
Definition: polygongraphicsitem.h:105
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexcept override
Definition: polygongraphicsitem.cpp:122
const IF_GraphicsLayerProvider & mLayerProvider
Definition: polygongraphicsitem.h:106
The Polygon class.
Definition: polygon.h:45
void polygonEdited(const Polygon &polygon, Polygon::Event event) noexcept
Definition: polygongraphicsitem.cpp:165
QVariant itemChange(GraphicsItemChange change, const QVariant &value) noexcept override
Definition: polygongraphicsitem.cpp:114