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 
51 class PrimitiveTextGraphicsItem : 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  virtual ~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) 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 GraphicsLayer* layer) noexcept;
71 
72  // Inherited from IF_LayerObserver
73  void layerColorChanged(const GraphicsLayer& layer,
74  const QColor& newColor) noexcept override;
75  void layerHighlightColorChanged(const GraphicsLayer& layer,
76  const QColor& newColor) noexcept override;
77  void layerVisibleChanged(const GraphicsLayer& layer,
78  bool newVisible) noexcept override;
79  void layerEnabledChanged(const GraphicsLayer& layer,
80  bool newEnabled) noexcept override;
81  void layerDestroyed(const GraphicsLayer& layer) noexcept override;
82 
83  // Inherited from QGraphicsItem
84  QRectF boundingRect() const noexcept override { return mBoundingRect; }
85  QPainterPath shape() const noexcept override { return mShape; }
86  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
87  QWidget* widget = 0) noexcept override;
88 
89  // Operator Overloadings
91  delete;
92 
93 private: // Methods
94  void updateBoundingRectAndShape() noexcept;
95 
96 private: // Data
98  QString mText;
100  QFont mFont;
101  QPen mPen;
105  QPainterPath mShape;
106 };
107 
108 /*******************************************************************************
109  * End of File
110  ******************************************************************************/
111 
112 } // namespace librepcb
113 
114 #endif // LIBREPCB_PRIMITIVETEXTGRAPHICSITEM_H
QRectF mBoundingRect
Definition: primitivetextgraphicsitem.h:104
void setPosition(const Point &pos) noexcept
Definition: primitivetextgraphicsitem.cpp:61
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexceptoverride
Definition: primitivetextgraphicsitem.cpp:163
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:54
void layerHighlightColorChanged(const GraphicsLayer &layer, const QColor &newColor) noexceptoverride
Definition: primitivetextgraphicsitem.cpp:132
The IF_GraphicsLayerOblayerHighlightColorChangedserver class defines an interface for classes which c...
Definition: graphicslayer.h:227
Font
Definition: primitivetextgraphicsitem.h:55
void setAlignment(const Alignment &align) noexcept
Definition: primitivetextgraphicsitem.cpp:80
The Alignment class.
Definition: alignment.h:193
QPen mPen
Definition: primitivetextgraphicsitem.h:101
void layerColorChanged(const GraphicsLayer &layer, const QColor &newColor) noexceptoverride
Definition: primitivetextgraphicsitem.cpp:124
void layerVisibleChanged(const GraphicsLayer &layer, bool newVisible) noexceptoverride
Definition: primitivetextgraphicsitem.cpp:140
void setText(const QString &text) noexcept
Definition: primitivetextgraphicsitem.cpp:69
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:81
QPainterPath mShape
Definition: primitivetextgraphicsitem.h:105
void layerEnabledChanged(const GraphicsLayer &layer, bool newEnabled) noexceptoverride
Definition: primitivetextgraphicsitem.cpp:147
PrimitiveTextGraphicsItem(const PrimitiveTextGraphicsItem &other)=delete
void setRotation(const Angle &rot) noexcept
Definition: primitivetextgraphicsitem.cpp:65
QString mText
Definition: primitivetextgraphicsitem.h:98
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
void setLayer(const GraphicsLayer *layer) noexcept
Definition: primitivetextgraphicsitem.cpp:104
Alignment mAlignment
Definition: primitivetextgraphicsitem.h:99
QPainterPath shape() const noexceptoverride
Definition: primitivetextgraphicsitem.h:85
QRectF boundingRect() const noexceptoverride
Definition: primitivetextgraphicsitem.h:84
const GraphicsLayer * mLayer
Definition: primitivetextgraphicsitem.h:97
void layerDestroyed(const GraphicsLayer &layer) noexceptoverride
Definition: primitivetextgraphicsitem.cpp:153
void setHeight(const PositiveLength &height) noexcept
Definition: primitivetextgraphicsitem.cpp:74
QPen mPenHighlighted
Definition: primitivetextgraphicsitem.h:102
void updateBoundingRectAndShape() noexcept
Definition: primitivetextgraphicsitem.cpp:192
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:783
int mTextFlags
Definition: primitivetextgraphicsitem.h:103
QFont mFont
Definition: primitivetextgraphicsitem.h:100
The PrimitiveTextGraphicsItem class is the graphical representation of a text.
Definition: primitivetextgraphicsitem.h:51
void setFont(Font font) noexcept
Definition: primitivetextgraphicsitem.cpp:85