LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
primitivetextgraphicsitem.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_PRIMITIVETEXTGRAPHICSITEM_H
21 #define LIBREPCB_PRIMITIVETEXTGRAPHICSITEM_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../alignment.h"
27 #include "../graphics/graphicslayer.h"
28 #include "../units/all_length_units.h"
29 
30 #include <QtCore>
31 #include <QtWidgets>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 
38 /*******************************************************************************
39  * Class PrimitiveTextGraphicsItem
40  ******************************************************************************/
41 
46 class PrimitiveTextGraphicsItem : public QGraphicsItem {
47 public:
48  // Types
49  enum class Font { SansSerif, Monospace };
50 
51  // Constructors / Destructor
52  // PrimitiveTextGraphicsItem() = delete;
54  explicit PrimitiveTextGraphicsItem(QGraphicsItem* parent = nullptr) noexcept;
55  virtual ~PrimitiveTextGraphicsItem() noexcept;
56 
57  // Setters
58  void setPosition(const Point& pos) noexcept;
59  void setRotation(const Angle& rot) noexcept;
60  void setText(const QString& text) noexcept;
61  void setHeight(const PositiveLength& height) noexcept;
62  void setAlignment(const Alignment& align) noexcept;
63  void setFont(Font font) noexcept;
64  void setLayer(const GraphicsLayer* layer) noexcept;
65 
66  // Inherited from QGraphicsItem
67  QRectF boundingRect() const noexcept override { return mBoundingRect; }
68  QPainterPath shape() const noexcept override { return mShape; }
69  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
70  QWidget* widget = 0) noexcept override;
71 
72  // Operator Overloadings
74  delete;
75 
76 private: // Methods
77  void layerEdited(const GraphicsLayer& layer,
78  GraphicsLayer::Event event) noexcept;
79  void updateBoundingRectAndShape() noexcept;
80 
81 private: // Data
83  QString mText;
85  QFont mFont;
86  QPen mPen;
89  QRectF mBoundingRect;
90  QPainterPath mShape;
91 
92  // Slots
94 };
95 
96 /*******************************************************************************
97  * End of File
98  ******************************************************************************/
99 
100 } // namespace librepcb
101 
102 #endif // LIBREPCB_PRIMITIVETEXTGRAPHICSITEM_H
QRectF mBoundingRect
Definition: primitivetextgraphicsitem.h:89
void setPosition(const Point &pos) noexcept
Definition: primitivetextgraphicsitem.cpp:60
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexceptoverride
Definition: primitivetextgraphicsitem.cpp:123
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:50
Font
Definition: primitivetextgraphicsitem.h:49
void setAlignment(const Alignment &align) noexcept
Definition: primitivetextgraphicsitem.cpp:79
The Alignment class.
Definition: alignment.h:184
QPen mPen
Definition: primitivetextgraphicsitem.h:86
void setText(const QString &text) noexcept
Definition: primitivetextgraphicsitem.cpp:68
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
QPainterPath mShape
Definition: primitivetextgraphicsitem.h:90
PrimitiveTextGraphicsItem(const PrimitiveTextGraphicsItem &other)=delete
void setRotation(const Angle &rot) noexcept
Definition: primitivetextgraphicsitem.cpp:64
QString mText
Definition: primitivetextgraphicsitem.h:83
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
void setLayer(const GraphicsLayer *layer) noexcept
Definition: primitivetextgraphicsitem.cpp:103
Alignment mAlignment
Definition: primitivetextgraphicsitem.h:84
QPainterPath shape() const noexceptoverride
Definition: primitivetextgraphicsitem.h:68
QRectF boundingRect() const noexceptoverride
Definition: primitivetextgraphicsitem.h:67
const GraphicsLayer * mLayer
Definition: primitivetextgraphicsitem.h:82
GraphicsLayer::OnEditedSlot mOnLayerEditedSlot
Definition: primitivetextgraphicsitem.h:93
void setHeight(const PositiveLength &height) noexcept
Definition: primitivetextgraphicsitem.cpp:73
QPen mPenHighlighted
Definition: primitivetextgraphicsitem.h:87
void updateBoundingRectAndShape() noexcept
Definition: primitivetextgraphicsitem.cpp:177
void layerEdited(const GraphicsLayer &layer, GraphicsLayer::Event event) noexcept
Definition: primitivetextgraphicsitem.cpp:152
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:780
int mTextFlags
Definition: primitivetextgraphicsitem.h:88
QFont mFont
Definition: primitivetextgraphicsitem.h:85
The PrimitiveTextGraphicsItem class is the graphical representation of a text.
Definition: primitivetextgraphicsitem.h:46
void setFont(Font font) noexcept
Definition: primitivetextgraphicsitem.cpp:84