LibrePCB Developers Documentation
primitivezonegraphicsitem.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_PRIMITIVEZONEGRAPHICSITEM_H
21#define LIBREPCB_EDITOR_PRIMITIVEZONEGRAPHICSITEM_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
27
29
30#include <QtCore>
31#include <QtWidgets>
32
33/*******************************************************************************
34 * Namespace / Forward Declarations
35 ******************************************************************************/
36namespace librepcb {
37
38class Layer;
39
40namespace editor {
41
42class IF_GraphicsLayerProvider;
43
44/*******************************************************************************
45 * Class PrimitiveZoneGraphicsItem
46 ******************************************************************************/
47
51class PrimitiveZoneGraphicsItem : public QGraphicsItem {
52public:
53 // Constructors / Destructor
57 QGraphicsItem* parent = nullptr) noexcept;
58 virtual ~PrimitiveZoneGraphicsItem() noexcept;
59
60 // Getters
61
69 int getLineIndexAtPosition(const Point& pos) const noexcept;
70
75 QVector<int> getVertexIndicesAtPosition(const Point& pos) const noexcept;
76
77 // Setters
78 void setPosition(const Point& pos) noexcept;
79 void setRotation(const Angle& rot) noexcept;
80 void setAllLayers(const QSet<const Layer*>& layers) noexcept;
81 void setEnabledLayers(const QSet<const Layer*>& layers) noexcept;
82 void setOutline(const Path& path) noexcept;
83
93 void setEditable(bool editable) noexcept;
94
95 // Inherited Methods
96 QVariant itemChange(GraphicsItemChange change,
97 const QVariant& value) noexcept override;
98 QRectF boundingRect() const noexcept override {
99 return mBoundingRect +
102 }
103 QPainterPath shape() const noexcept override;
104 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
105 QWidget* widget = 0) noexcept override;
106
107 // Operator Overloadings
109 delete;
110
111private: // Methods
112 void layerEdited(const GraphicsLayer& layer,
113 GraphicsLayer::Event event) noexcept;
114 void updateColors() noexcept;
115 void updateBoundingRectAndShape() noexcept;
116 void updateBoundingRectMargin() noexcept;
117 void updateVisibility() noexcept;
118
119private: // Data
121 QVector<std::shared_ptr<GraphicsLayer>> mAllGraphicsLayers;
122 QVector<std::shared_ptr<GraphicsLayer>> mEnabledGraphicsLayers;
125
126 // Cached attributes
127 std::shared_ptr<GraphicsLayer> mLayer;
128 QPen mPen;
130 QBrush mBrush;
132 QPainterPath mPainterPath;
135 QPainterPath mShape;
140 };
141 QVector<VertexHandle> mVertexHandles;
142
143 // Slots
145};
146
147/*******************************************************************************
148 * End of File
149 ******************************************************************************/
150
151} // namespace editor
152} // namespace librepcb
153
154#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
The Layer class provides all supported geometry layers.
Definition: layer.h:40
The Path class represents a list of vertices connected by straight lines or circular arc segments.
Definition: path.h:58
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition: point.h:79
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:53
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers.
Definition: graphicslayer.h:111
The PrimitiveZoneGraphicsItem class.
Definition: primitivezonegraphicsitem.h:51
void setOutline(const Path &path) noexcept
Definition: primitivezonegraphicsitem.cpp:166
QPen mPenHighlighted
Definition: primitivezonegraphicsitem.h:129
void updateBoundingRectMargin() noexcept
Definition: primitivezonegraphicsitem.cpp:300
QRectF boundingRect() const noexcept override
Definition: primitivezonegraphicsitem.h:98
int getLineIndexAtPosition(const Point &pos) const noexcept
Definition: primitivezonegraphicsitem.cpp:81
qreal mBoundingRectMarginPx
Definition: primitivezonegraphicsitem.h:134
QVariant itemChange(GraphicsItemChange change, const QVariant &value) noexcept override
Definition: primitivezonegraphicsitem.cpp:200
QBrush mBrush
Definition: primitivezonegraphicsitem.h:130
QPainterPath mShape
Definition: primitivezonegraphicsitem.h:135
std::shared_ptr< GraphicsLayer > mLayer
Definition: primitivezonegraphicsitem.h:127
QBrush mBrushHighlighted
Definition: primitivezonegraphicsitem.h:131
PrimitiveZoneGraphicsItem(const PrimitiveZoneGraphicsItem &other)=delete
qreal mVertexHandleRadiusPx
Definition: primitivezonegraphicsitem.h:136
QPainterPath shape() const noexcept override
Definition: primitivezonegraphicsitem.cpp:208
GraphicsLayer::OnEditedSlot mOnLayerEditedSlot
Definition: primitivezonegraphicsitem.h:144
const IF_GraphicsLayerProvider & mLayerProvider
Definition: primitivezonegraphicsitem.h:120
QRectF mBoundingRect
Definition: primitivezonegraphicsitem.h:133
QVector< std::shared_ptr< GraphicsLayer > > mAllGraphicsLayers
Definition: primitivezonegraphicsitem.h:121
Path mOutline
Definition: primitivezonegraphicsitem.h:123
QVector< VertexHandle > mVertexHandles
Definition: primitivezonegraphicsitem.h:141
void layerEdited(const GraphicsLayer &layer, GraphicsLayer::Event event) noexcept
Definition: primitivezonegraphicsitem.cpp:251
QPainterPath mPainterPath
Definition: primitivezonegraphicsitem.h:132
void setEnabledLayers(const QSet< const Layer * > &layers) noexcept
Definition: primitivezonegraphicsitem.cpp:149
QPen mPen
Definition: primitivezonegraphicsitem.h:128
void setRotation(const Angle &rot) noexcept
Definition: primitivezonegraphicsitem.cpp:129
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexcept override
Definition: primitivezonegraphicsitem.cpp:212
QVector< int > getVertexIndicesAtPosition(const Point &pos) const noexcept
Definition: primitivezonegraphicsitem.cpp:108
QVector< std::shared_ptr< GraphicsLayer > > mEnabledGraphicsLayers
Definition: primitivezonegraphicsitem.h:122
bool mEditable
Definition: primitivezonegraphicsitem.h:124
void updateVisibility() noexcept
Definition: primitivezonegraphicsitem.cpp:315
void setEditable(bool editable) noexcept
Definition: primitivezonegraphicsitem.cpp:191
void setPosition(const Point &pos) noexcept
Definition: primitivezonegraphicsitem.cpp:125
void updateBoundingRectAndShape() noexcept
Definition: primitivezonegraphicsitem.cpp:292
void setAllLayers(const QSet< const Layer * > &layers) noexcept
Definition: primitivezonegraphicsitem.cpp:133
void updateColors() noexcept
Definition: primitivezonegraphicsitem.cpp:271
Definition: occmodel.cpp:77
Definition: primitivezonegraphicsitem.h:137
qreal maxGlowRadiusPx
Definition: primitivezonegraphicsitem.h:139
Point pos
Definition: primitivezonegraphicsitem.h:138