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 
44 class LineGraphicsItem final : public QGraphicsItem {
45 public:
46  // Constructors / Destructor
47  // LineGraphicsItem() = delete;
48  LineGraphicsItem(const LineGraphicsItem& other) = delete;
49  explicit LineGraphicsItem(QGraphicsItem* parent = nullptr) noexcept;
50  ~LineGraphicsItem() noexcept;
51 
52  // Setters
53  void setPosition(const Point& pos) noexcept;
54  void setRotation(const Angle& rot) noexcept;
55  void setLine(const Point& p1, const Point& p2) noexcept;
56  void setLineWidth(const UnsignedLength& width) noexcept;
57  void setLayer(const GraphicsLayer* layer) noexcept;
58 
59  // Inherited from QGraphicsItem
60  QRectF boundingRect() const noexcept override { return mBoundingRect; }
61  QPainterPath shape() const noexcept override { return mShape; }
62  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
63  QWidget* widget = 0) noexcept override;
64 
65  // Operator Overloadings
66  LineGraphicsItem& operator=(const LineGraphicsItem& rhs) = delete;
67 
68 private: // Methods
69  void layerEdited(const GraphicsLayer& layer,
70  GraphicsLayer::Event event) noexcept;
71  void updateBoundingRectAndShape() noexcept;
72 
73 private: // Data
75  QPen mPen;
77  QLineF mLine;
78  QRectF mBoundingRect;
79  QPainterPath mShape;
80 
81  // Slots
83 };
84 
85 /*******************************************************************************
86  * End of File
87  ******************************************************************************/
88 
89 } // namespace librepcb
90 
91 #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:50
QPen mPen
Definition: linegraphicsitem.h:75
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexceptoverride
Definition: linegraphicsitem.cpp:96
GraphicsLayer::OnEditedSlot mOnLayerEditedSlot
Definition: linegraphicsitem.h:82
void setLine(const Point &p1, const Point &p2) noexcept
Definition: linegraphicsitem.cpp:66
QPainterPath mShape
Definition: linegraphicsitem.h:79
void layerEdited(const GraphicsLayer &layer, GraphicsLayer::Event event) noexcept
Definition: linegraphicsitem.cpp:112
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
QPen mPenHighlighted
Definition: linegraphicsitem.h:76
void setLineWidth(const UnsignedLength &width) noexcept
Definition: linegraphicsitem.cpp:71
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
The LineGraphicsItem class.
Definition: linegraphicsitem.h:44
QLineF mLine
Definition: linegraphicsitem.h:77
void setLayer(const GraphicsLayer *layer) noexcept
Definition: linegraphicsitem.cpp:77
QRectF boundingRect() const noexceptoverride
Definition: linegraphicsitem.h:60
QRectF mBoundingRect
Definition: linegraphicsitem.h:78
const GraphicsLayer * mLayer
Definition: linegraphicsitem.h:74
~LineGraphicsItem() noexcept
Definition: linegraphicsitem.cpp:51
QPainterPath shape() const noexceptoverride
Definition: linegraphicsitem.h:61
void updateBoundingRectAndShape() noexcept
Definition: linegraphicsitem.cpp:136
LineGraphicsItem(const LineGraphicsItem &other)=delete
void setRotation(const Angle &rot) noexcept
Definition: linegraphicsitem.cpp:62
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:659