LibrePCB Developers Documentation
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_EDITOR_PRIMITIVETEXTGRAPHICSITEM_H
21 #define LIBREPCB_EDITOR_PRIMITIVETEXTGRAPHICSITEM_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "graphicslayer.h"
27 
30 
31 #include <QtCore>
32 #include <QtWidgets>
33 
34 /*******************************************************************************
35  * Namespace / Forward Declarations
36  ******************************************************************************/
37 namespace librepcb {
38 
39 class Angle;
40 class Point;
41 
42 namespace editor {
43 
44 /*******************************************************************************
45  * Class PrimitiveTextGraphicsItem
46  ******************************************************************************/
47 
52 class PrimitiveTextGraphicsItem final : public QGraphicsItem {
53 public:
54  // Types
55  enum class Font { SansSerif, Monospace };
56 
57  // Constructors / Destructor
58  // PrimitiveTextGraphicsItem() = delete;
60  explicit PrimitiveTextGraphicsItem(QGraphicsItem* parent = nullptr) noexcept;
61  ~PrimitiveTextGraphicsItem() noexcept;
62 
63  // Setters
64  void setPosition(const Point& pos) noexcept;
65  void setRotation(const Angle& rot) noexcept;
66  void setText(const QString& text, bool parseOverlines = false) noexcept;
67  void setHeight(const PositiveLength& height) noexcept;
68  void setAlignment(const Alignment& align) noexcept;
69  void setFont(Font font) noexcept;
70  void setLayer(const std::shared_ptr<GraphicsLayer>& layer) noexcept;
71  void setShapeEnabled(bool enabled) noexcept { mShapeEnabled = enabled; }
72 
73  // Inherited from QGraphicsItem
74  QRectF boundingRect() const noexcept override { return mBoundingRect; }
75  QPainterPath shape() const noexcept override;
76  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
77  QWidget* widget = 0) noexcept override;
78 
79  // Operator Overloadings
81  delete;
82 
83 private: // Methods
84  void layerEdited(const GraphicsLayer& layer,
85  GraphicsLayer::Event event) noexcept;
86  void updateBoundingRectAndShape() noexcept;
87 
88 private: // Data
89  std::shared_ptr<GraphicsLayer> mLayer;
90  QString mText;
91  QString mDisplayText;
93  QVector<QLineF> mOverlines;
96  bool mRotate180;
97  QFont mFont;
98  QPen mPen;
102  QPainterPath mShape;
104 
105  // Slots
107 };
108 
109 /*******************************************************************************
110  * End of File
111  ******************************************************************************/
112 
113 } // namespace editor
114 } // namespace librepcb
115 
116 #endif
QVector< QLineF > mOverlines
Definition: primitivetextgraphicsitem.h:93
Alignment mAlignment
Definition: primitivetextgraphicsitem.h:95
void setPosition(const Point &pos) noexcept
Definition: primitivetextgraphicsitem.cpp:72
void setText(const QString &text, bool parseOverlines=false) noexcept
Definition: primitivetextgraphicsitem.cpp:89
QRectF boundingRect() const noexcept override
Definition: primitivetextgraphicsitem.h:74
PrimitiveTextGraphicsItem & operator=(const PrimitiveTextGraphicsItem &rhs)=delete
QString mText
Definition: primitivetextgraphicsitem.h:90
The Alignment class.
Definition: alignment.h:115
Definition: occmodel.cpp:77
bool mParseOverlines
Definition: primitivetextgraphicsitem.h:92
The PrimitiveTextGraphicsItem class is the graphical representation of a text.
Definition: primitivetextgraphicsitem.h:52
GraphicsLayer::OnEditedSlot mOnLayerEditedSlot
Definition: primitivetextgraphicsitem.h:106
QRectF mBoundingRect
Definition: primitivetextgraphicsitem.h:101
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexcept override
Definition: primitivetextgraphicsitem.cpp:155
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
void setShapeEnabled(bool enabled) noexcept
Definition: primitivetextgraphicsitem.h:71
QPainterPath shape() const noexcept override
Definition: primitivetextgraphicsitem.cpp:150
PositiveLength mHeight
Definition: primitivetextgraphicsitem.h:94
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:53
Font
Definition: primitivetextgraphicsitem.h:55
void layerEdited(const GraphicsLayer &layer, GraphicsLayer::Event event) noexcept
Definition: primitivetextgraphicsitem.cpp:173
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:79
void setFont(Font font) noexcept
Definition: primitivetextgraphicsitem.cpp:111
bool mShapeEnabled
Definition: primitivetextgraphicsitem.h:103
QFont mFont
Definition: primitivetextgraphicsitem.h:97
QPen mPenHighlighted
Definition: primitivetextgraphicsitem.h:99
QPainterPath mShape
Definition: primitivetextgraphicsitem.h:102
std::shared_ptr< GraphicsLayer > mLayer
Definition: primitivetextgraphicsitem.h:89
int mTextFlags
Definition: primitivetextgraphicsitem.h:100
void setRotation(const Angle &rot) noexcept
Definition: primitivetextgraphicsitem.cpp:76
bool mRotate180
Definition: primitivetextgraphicsitem.h:96
QPen mPen
Definition: primitivetextgraphicsitem.h:98
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
QString mDisplayText
Definition: primitivetextgraphicsitem.h:91
void setLayer(const std::shared_ptr< GraphicsLayer > &layer) noexcept
Definition: primitivetextgraphicsitem.cpp:129
void setHeight(const PositiveLength &height) noexcept
Definition: primitivetextgraphicsitem.cpp:98
Event
Definition: graphicslayer.h:58
void updateBoundingRectAndShape() noexcept
Definition: primitivetextgraphicsitem.cpp:196
PrimitiveTextGraphicsItem(const PrimitiveTextGraphicsItem &other)=delete
void setAlignment(const Alignment &align) noexcept
Definition: primitivetextgraphicsitem.cpp:106
~PrimitiveTextGraphicsItem() noexcept
Definition: primitivetextgraphicsitem.cpp:65