LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
linegraphicsitem.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_LINEGRAPHICSITEM_H
21 #define LIBREPCB_LINEGRAPHICSITEM_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 LineGraphicsItem
39  ******************************************************************************/
40 
47 class LineGraphicsItem final : public QGraphicsItem,
49 public:
50  // Constructors / Destructor
51  // LineGraphicsItem() = delete;
52  LineGraphicsItem(const LineGraphicsItem& other) = delete;
53  explicit LineGraphicsItem(QGraphicsItem* parent = nullptr) noexcept;
54  ~LineGraphicsItem() noexcept;
55 
56  // Setters
57  void setPosition(const Point& pos) noexcept;
58  void setRotation(const Angle& rot) noexcept;
59  void setLine(const Point& p1, const Point& p2) noexcept;
60  void setLineWidth(const UnsignedLength& width) noexcept;
61  void setLayer(const GraphicsLayer* layer) noexcept;
62 
63  // Inherited from IF_LayerObserver
64  void layerColorChanged(const GraphicsLayer& layer,
65  const QColor& newColor) noexcept override;
66  void layerHighlightColorChanged(const GraphicsLayer& layer,
67  const QColor& newColor) noexcept override;
68  void layerVisibleChanged(const GraphicsLayer& layer,
69  bool newVisible) noexcept override;
70  void layerEnabledChanged(const GraphicsLayer& layer,
71  bool newEnabled) noexcept override;
72  void layerDestroyed(const GraphicsLayer& layer) noexcept override;
73 
74  // Inherited from QGraphicsItem
75  QRectF boundingRect() const noexcept override { return mBoundingRect; }
76  QPainterPath shape() const noexcept override { return mShape; }
77  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
78  QWidget* widget = 0) noexcept override;
79 
80  // Operator Overloadings
81  LineGraphicsItem& operator=(const LineGraphicsItem& rhs) = delete;
82 
83 private: // Methods
84  void updateBoundingRectAndShape() noexcept;
85 
86 private: // Data
88  QPen mPen;
90  QLineF mLine;
91  QRectF mBoundingRect;
92  QPainterPath mShape;
93 };
94 
95 /*******************************************************************************
96  * End of File
97  ******************************************************************************/
98 
99 } // namespace librepcb
100 
101 #endif // LIBREPCB_LINEGRAPHICSITEM_H
void setPosition(const Point &pos) noexcept
Definition: linegraphicsitem.cpp:58
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:54
The IF_GraphicsLayerOblayerHighlightColorChangedserver class defines an interface for classes which c...
Definition: graphicslayer.h:227
QPen mPen
Definition: linegraphicsitem.h:88
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexceptoverride
Definition: linegraphicsitem.cpp:134
void setLine(const Point &p1, const Point &p2) noexcept
Definition: linegraphicsitem.cpp:66
QPainterPath mShape
Definition: linegraphicsitem.h:92
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:81
QPen mPenHighlighted
Definition: linegraphicsitem.h:89
void setLineWidth(const UnsignedLength &width) noexcept
Definition: linegraphicsitem.cpp:71
void layerColorChanged(const GraphicsLayer &layer, const QColor &newColor) noexceptoverride
Definition: linegraphicsitem.cpp:96
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
void layerHighlightColorChanged(const GraphicsLayer &layer, const QColor &newColor) noexceptoverride
Definition: linegraphicsitem.cpp:104
The LineGraphicsItem class.
Definition: linegraphicsitem.h:47
QLineF mLine
Definition: linegraphicsitem.h:90
void setLayer(const GraphicsLayer *layer) noexcept
Definition: linegraphicsitem.cpp:77
QRectF boundingRect() const noexceptoverride
Definition: linegraphicsitem.h:75
QRectF mBoundingRect
Definition: linegraphicsitem.h:91
void layerEnabledChanged(const GraphicsLayer &layer, bool newEnabled) noexceptoverride
Definition: linegraphicsitem.cpp:119
const GraphicsLayer * mLayer
Definition: linegraphicsitem.h:87
~LineGraphicsItem() noexcept
Definition: linegraphicsitem.cpp:49
QPainterPath shape() const noexceptoverride
Definition: linegraphicsitem.h:76
void updateBoundingRectAndShape() noexcept
Definition: linegraphicsitem.cpp:150
LineGraphicsItem(const LineGraphicsItem &other)=delete
void layerDestroyed(const GraphicsLayer &layer) noexceptoverride
Definition: linegraphicsitem.cpp:125
void setRotation(const Angle &rot) noexcept
Definition: linegraphicsitem.cpp:62
void layerVisibleChanged(const GraphicsLayer &layer, bool newVisible) noexceptoverride
Definition: linegraphicsitem.cpp:112
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:662