LibrePCB Developers Documentation
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_EDITOR_LINEGRAPHICSITEM_H
21#define LIBREPCB_EDITOR_LINEGRAPHICSITEM_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "graphicslayer.h"
27
29
30#include <QtCore>
31#include <QtWidgets>
32
33/*******************************************************************************
34 * Namespace / Forward Declarations
35 ******************************************************************************/
36namespace librepcb {
37
38class Angle;
39class Point;
40
41namespace editor {
42
43/*******************************************************************************
44 * Class LineGraphicsItem
45 ******************************************************************************/
46
50class LineGraphicsItem final : public QGraphicsItem {
51public:
52 // Constructors / Destructor
53 // LineGraphicsItem() = delete;
54 LineGraphicsItem(const LineGraphicsItem& other) = delete;
55 explicit LineGraphicsItem(QGraphicsItem* parent = nullptr) noexcept;
56 virtual ~LineGraphicsItem() noexcept;
57
58 // Setters
59 void setPosition(const Point& pos) noexcept;
60 void setRotation(const Angle& rot) noexcept;
61 void setLine(const Point& p1, const Point& p2) noexcept;
62 void setLineWidth(const UnsignedLength& width) noexcept;
63 void setLayer(const std::shared_ptr<GraphicsLayer>& layer) noexcept;
64
65 // Inherited from QGraphicsItem
66 QRectF boundingRect() const noexcept override { return mBoundingRect; }
67 QPainterPath shape() const noexcept override;
68 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
69 QWidget* widget = 0) noexcept override;
70
71 // Operator Overloadings
72 LineGraphicsItem& operator=(const LineGraphicsItem& rhs) = delete;
73
74private: // Methods
75 void layerEdited(const GraphicsLayer& layer,
76 GraphicsLayer::Event event) noexcept;
77 void updateBoundingRectAndShape() noexcept;
78
79private: // Data
80 std::shared_ptr<GraphicsLayer> mLayer;
81 QPen mPen;
83 QLineF mLine;
85 QPainterPath mShape;
86
87 // Slots
89};
90
91/*******************************************************************************
92 * End of File
93 ******************************************************************************/
94
95} // namespace editor
96} // namespace librepcb
97
98#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
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 LineGraphicsItem class.
Definition: linegraphicsitem.h:50
QPen mPenHighlighted
Definition: linegraphicsitem.h:82
void setLine(const Point &p1, const Point &p2) noexcept
Definition: linegraphicsitem.cpp:69
LineGraphicsItem(const LineGraphicsItem &other)=delete
QRectF boundingRect() const noexcept override
Definition: linegraphicsitem.h:66
void setLayer(const std::shared_ptr< GraphicsLayer > &layer) noexcept
Definition: linegraphicsitem.cpp:80
QLineF mLine
Definition: linegraphicsitem.h:83
QPainterPath mShape
Definition: linegraphicsitem.h:85
std::shared_ptr< GraphicsLayer > mLayer
Definition: linegraphicsitem.h:80
QPainterPath shape() const noexcept override
Definition: linegraphicsitem.cpp:100
GraphicsLayer::OnEditedSlot mOnLayerEditedSlot
Definition: linegraphicsitem.h:88
QRectF mBoundingRect
Definition: linegraphicsitem.h:84
void layerEdited(const GraphicsLayer &layer, GraphicsLayer::Event event) noexcept
Definition: linegraphicsitem.cpp:120
QPen mPen
Definition: linegraphicsitem.h:81
void setRotation(const Angle &rot) noexcept
Definition: linegraphicsitem.cpp:65
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexcept override
Definition: linegraphicsitem.cpp:104
void setLineWidth(const UnsignedLength &width) noexcept
Definition: linegraphicsitem.cpp:74
void setPosition(const Point &pos) noexcept
Definition: linegraphicsitem.cpp:61
void updateBoundingRectAndShape() noexcept
Definition: linegraphicsitem.cpp:142
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696