LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
primitivecirclegraphicsitem.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_PRIMITIVECIRCLEGRAPHICSITEM_H
21 #define LIBREPCB_PRIMITIVECIRCLEGRAPHICSITEM_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 PrimitiveCircleGraphicsItem
39  ******************************************************************************/
40 
47 class PrimitiveCircleGraphicsItem : public QGraphicsItem,
49 public:
50  // Constructors / Destructor
51  // PrimitiveCircleGraphicsItem() = delete;
53  delete;
55  QGraphicsItem* parent = nullptr) noexcept;
56  virtual ~PrimitiveCircleGraphicsItem() noexcept;
57 
58  // Setters
59  void setPosition(const Point& pos) noexcept;
60  void setDiameter(const UnsignedLength& dia) noexcept;
61  void setLineWidth(const UnsignedLength& width) noexcept;
62  void setLineLayer(const GraphicsLayer* layer) noexcept;
63  void setFillLayer(const GraphicsLayer* layer) noexcept;
64 
65  // Inherited from IF_LayerObserver
66  void layerColorChanged(const GraphicsLayer& layer,
67  const QColor& newColor) noexcept override;
68  void layerHighlightColorChanged(const GraphicsLayer& layer,
69  const QColor& newColor) noexcept override;
70  void layerVisibleChanged(const GraphicsLayer& layer,
71  bool newVisible) noexcept override;
72  void layerEnabledChanged(const GraphicsLayer& layer,
73  bool newEnabled) noexcept override;
74  void layerDestroyed(const GraphicsLayer& layer) noexcept override;
75 
76  // Inherited from QGraphicsItem
77  virtual QRectF boundingRect() const noexcept override {
78  return mBoundingRect;
79  }
80  virtual QPainterPath shape() const noexcept override { return mShape; }
81  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
82  QWidget* widget = 0) noexcept override;
83 
84  // Operator Overloadings
85  PrimitiveCircleGraphicsItem& operator =(
86  const PrimitiveCircleGraphicsItem& rhs) = delete;
87 
88 private: // Methods
89  void updateColors() noexcept;
90  void updateBoundingRectAndShape() noexcept;
91  void updateVisibility() noexcept;
92 
93 private: // Data
96  QPen mPen;
98  QBrush mBrush;
100  QRectF mCircleRect;
102  QPainterPath mShape;
103 };
104 
105 /*******************************************************************************
106  * End of File
107  ******************************************************************************/
108 
109 } // namespace librepcb
110 
111 #endif // LIBREPCB_PRIMITIVECIRCLEGRAPHICSITEM_H
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:54
QPainterPath mShape
Definition: primitivecirclegraphicsitem.h:102
The IF_GraphicsLayerOblayerHighlightColorChangedserver class defines an interface for classes which c...
Definition: graphicslayer.h:227
void layerVisibleChanged(const GraphicsLayer &layer, bool newVisible) noexceptoverride
Definition: primitivecirclegraphicsitem.cpp:124
void setLineLayer(const GraphicsLayer *layer) noexcept
Definition: primitivecirclegraphicsitem.cpp:76
void layerEnabledChanged(const GraphicsLayer &layer, bool newEnabled) noexceptoverride
Definition: primitivecirclegraphicsitem.cpp:132
void updateVisibility() noexcept
Definition: primitivecirclegraphicsitem.cpp:205
void layerColorChanged(const GraphicsLayer &layer, const QColor &newColor) noexceptoverride
Definition: primitivecirclegraphicsitem.cpp:108
void setLineWidth(const UnsignedLength &width) noexcept
Definition: primitivecirclegraphicsitem.cpp:69
void updateBoundingRectAndShape() noexcept
Definition: primitivecirclegraphicsitem.cpp:196
virtual QPainterPath shape() const noexceptoverride
Definition: primitivecirclegraphicsitem.h:80
QBrush mBrush
Definition: primitivecirclegraphicsitem.h:98
QPen mPenHighlighted
Definition: primitivecirclegraphicsitem.h:97
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
QBrush mBrushHighlighted
Definition: primitivecirclegraphicsitem.h:99
const GraphicsLayer * mFillLayer
Definition: primitivecirclegraphicsitem.h:95
virtual QRectF boundingRect() const noexceptoverride
Definition: primitivecirclegraphicsitem.h:77
virtual ~PrimitiveCircleGraphicsItem() noexcept
Definition: primitivecirclegraphicsitem.cpp:49
QRectF mBoundingRect
Definition: primitivecirclegraphicsitem.h:101
QRectF mCircleRect
Definition: primitivecirclegraphicsitem.h:100
void updateColors() noexcept
Definition: primitivecirclegraphicsitem.cpp:173
void setFillLayer(const GraphicsLayer *layer) noexcept
Definition: primitivecirclegraphicsitem.cpp:90
QPen mPen
Definition: primitivecirclegraphicsitem.h:96
void layerHighlightColorChanged(const GraphicsLayer &layer, const QColor &newColor) noexceptoverride
Definition: primitivecirclegraphicsitem.cpp:116
void setDiameter(const UnsignedLength &dia) noexcept
Definition: primitivecirclegraphicsitem.cpp:63
void layerDestroyed(const GraphicsLayer &layer) noexceptoverride
Definition: primitivecirclegraphicsitem.cpp:140
PrimitiveCircleGraphicsItem(const PrimitiveCircleGraphicsItem &other)=delete
The PrimitiveCircleGraphicsItem class.
Definition: primitivecirclegraphicsitem.h:47
void setPosition(const Point &pos) noexcept
Definition: primitivecirclegraphicsitem.cpp:59
const GraphicsLayer * mLineLayer
Definition: primitivecirclegraphicsitem.h:94
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexceptoverride
Definition: primitivecirclegraphicsitem.cpp:155
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:662