LibrePCB Developers Documentation
primitivepathgraphicsitem.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_PRIMITIVEPATHGRAPHICSITEM_H
21 #define LIBREPCB_PRIMITIVEPATHGRAPHICSITEM_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../graphics/graphicslayer.h"
27 #include "../units/all_length_units.h"
28 
29 #include <QtCore>
30 #include <QtWidgets>
31 
32 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 
37 /*******************************************************************************
38  * Class PrimitivePathGraphicsItem
39  ******************************************************************************/
40 
44 class PrimitivePathGraphicsItem : public QGraphicsItem {
45 public:
46  // Types
47  enum class ShapeMode {
51 
54  };
55 
56  // Constructors / Destructor
57  // PrimitivePathGraphicsItem() = delete;
59  explicit PrimitivePathGraphicsItem(QGraphicsItem* parent = nullptr) noexcept;
60  virtual ~PrimitivePathGraphicsItem() noexcept;
61 
62  // Setters
63  void setPosition(const Point& pos) noexcept;
64  void setRotation(const Angle& rot) noexcept;
65  void setPath(const QPainterPath& path) noexcept;
66  void setLineWidth(const UnsignedLength& width) noexcept;
67  void setLineLayer(const GraphicsLayer* layer) noexcept;
68  void setFillLayer(const GraphicsLayer* layer) noexcept;
69  void setShapeMode(ShapeMode mode) noexcept;
70 
71  // Inherited from QGraphicsItem
72  QRectF boundingRect() const noexcept override { return mBoundingRect; }
73  QPainterPath shape() const noexcept override { return mShape; }
74  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
75  QWidget* widget = 0) noexcept override;
76 
77  // Operator Overloadings
79  delete;
80 
81 private: // Methods
82  void layerEdited(const GraphicsLayer& layer,
83  GraphicsLayer::Event event) noexcept;
84  void updateColors() noexcept;
85  void updateBoundingRectAndShape() noexcept;
86  void updateVisibility() noexcept;
87 
88 protected: // Data
92  QPen mPen;
94  QBrush mBrush;
96  QPainterPath mPainterPath;
97  QRectF mBoundingRect;
98  QPainterPath mShape;
99 
100  // Slots
102 };
103 
104 /*******************************************************************************
105  * End of File
106  ******************************************************************************/
107 
108 } // namespace librepcb
109 
110 #endif // LIBREPCB_PRIMITIVEPATHGRAPHICSITEM_H
virtual ~PrimitivePathGraphicsItem() noexcept
Definition: primitivepathgraphicsitem.cpp:58
void updateBoundingRectAndShape() noexcept
Definition: primitivepathgraphicsitem.cpp:199
const GraphicsLayer * mFillLayer
Definition: primitivepathgraphicsitem.h:90
QPainterPath shape() const noexcept override
Definition: primitivepathgraphicsitem.h:73
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:50
QPen mPen
Definition: primitivepathgraphicsitem.h:92
void setFillLayer(const GraphicsLayer *layer) noexcept
Definition: primitivepathgraphicsitem.cpp:99
Definition: airwiresbuilder.cpp:32
QBrush mBrush
Definition: primitivepathgraphicsitem.h:94
PrimitivePathGraphicsItem(const PrimitivePathGraphicsItem &other)=delete
ShapeMode mShapeMode
Definition: primitivepathgraphicsitem.h:91
void setShapeMode(ShapeMode mode) noexcept
Definition: primitivepathgraphicsitem.cpp:113
void setPath(const QPainterPath &path) noexcept
Definition: primitivepathgraphicsitem.cpp:73
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
The PrimitivePathGraphicsItem class.
Definition: primitivepathgraphicsitem.h:44
const GraphicsLayer * mLineLayer
Definition: primitivepathgraphicsitem.h:89
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexcept override
Definition: primitivepathgraphicsitem.cpp:122
void setLineLayer(const GraphicsLayer *layer) noexcept
Definition: primitivepathgraphicsitem.cpp:85
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
QPainterPath mPainterPath
Definition: primitivepathgraphicsitem.h:96
void updateColors() noexcept
Definition: primitivepathgraphicsitem.cpp:176
void updateVisibility() noexcept
Definition: primitivepathgraphicsitem.cpp:211
void layerEdited(const GraphicsLayer &layer, GraphicsLayer::Event event) noexcept
Definition: primitivepathgraphicsitem.cpp:150
QPainterPath mShape
Definition: primitivepathgraphicsitem.h:98
Event
Definition: graphicslayer.h:140
QRectF mBoundingRect
Definition: primitivepathgraphicsitem.h:97
ShapeMode
Definition: primitivepathgraphicsitem.h:47
void setRotation(const Angle &rot) noexcept
Definition: primitivepathgraphicsitem.cpp:69
QBrush mBrushHighlighted
Definition: primitivepathgraphicsitem.h:95
QPen mPenHighlighted
Definition: primitivepathgraphicsitem.h:93
void setLineWidth(const UnsignedLength &width) noexcept
Definition: primitivepathgraphicsitem.cpp:78
GraphicsLayer::OnEditedSlot mOnLayerEditedSlot
Definition: primitivepathgraphicsitem.h:101
Only the area within the painter path is used as shape.
QRectF boundingRect() const noexcept override
Definition: primitivepathgraphicsitem.h:72
PrimitivePathGraphicsItem & operator=(const PrimitivePathGraphicsItem &rhs)=delete
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:673
void setPosition(const Point &pos) noexcept
Definition: primitivepathgraphicsitem.cpp:65