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 ******************************************************************************/
37namespace librepcb {
38
39class Angle;
40class Point;
41
42namespace editor {
43
44/*******************************************************************************
45 * Class PrimitiveTextGraphicsItem
46 ******************************************************************************/
47
52class PrimitiveTextGraphicsItem final : public QGraphicsItem {
53public:
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
83private: // Methods
84 void layerEdited(const GraphicsLayer& layer,
85 GraphicsLayer::Event event) noexcept;
86 void updateBoundingRectAndShape() noexcept;
87
88private: // Data
89 std::shared_ptr<GraphicsLayer> mLayer;
90 QString mText;
91 QString mDisplayText;
93 QVector<QLineF> mOverlines;
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
The Alignment class.
Definition: alignment.h:115
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 PrimitiveTextGraphicsItem class is the graphical representation of a text.
Definition: primitivetextgraphicsitem.h:52
QString mDisplayText
Definition: primitivetextgraphicsitem.h:91
void setFont(Font font) noexcept
Definition: primitivetextgraphicsitem.cpp:111
QPen mPenHighlighted
Definition: primitivetextgraphicsitem.h:99
void setShapeEnabled(bool enabled) noexcept
Definition: primitivetextgraphicsitem.h:71
QRectF boundingRect() const noexcept override
Definition: primitivetextgraphicsitem.h:74
bool mRotate180
Definition: primitivetextgraphicsitem.h:96
QVector< QLineF > mOverlines
Definition: primitivetextgraphicsitem.h:93
Alignment mAlignment
Definition: primitivetextgraphicsitem.h:95
void setAlignment(const Alignment &align) noexcept
Definition: primitivetextgraphicsitem.cpp:106
void setLayer(const std::shared_ptr< GraphicsLayer > &layer) noexcept
Definition: primitivetextgraphicsitem.cpp:129
QPainterPath mShape
Definition: primitivetextgraphicsitem.h:102
std::shared_ptr< GraphicsLayer > mLayer
Definition: primitivetextgraphicsitem.h:89
QFont mFont
Definition: primitivetextgraphicsitem.h:97
Font
Definition: primitivetextgraphicsitem.h:55
QPainterPath shape() const noexcept override
Definition: primitivetextgraphicsitem.cpp:150
QString mText
Definition: primitivetextgraphicsitem.h:90
bool mParseOverlines
Definition: primitivetextgraphicsitem.h:92
GraphicsLayer::OnEditedSlot mOnLayerEditedSlot
Definition: primitivetextgraphicsitem.h:106
QRectF mBoundingRect
Definition: primitivetextgraphicsitem.h:101
void layerEdited(const GraphicsLayer &layer, GraphicsLayer::Event event) noexcept
Definition: primitivetextgraphicsitem.cpp:173
PositiveLength mHeight
Definition: primitivetextgraphicsitem.h:94
int mTextFlags
Definition: primitivetextgraphicsitem.h:100
QPen mPen
Definition: primitivetextgraphicsitem.h:98
void setRotation(const Angle &rot) noexcept
Definition: primitivetextgraphicsitem.cpp:76
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexcept override
Definition: primitivetextgraphicsitem.cpp:155
void setText(const QString &text, bool parseOverlines=false) noexcept
Definition: primitivetextgraphicsitem.cpp:89
void setHeight(const PositiveLength &height) noexcept
Definition: primitivetextgraphicsitem.cpp:98
bool mShapeEnabled
Definition: primitivetextgraphicsitem.h:103
PrimitiveTextGraphicsItem(const PrimitiveTextGraphicsItem &other)=delete
void setPosition(const Point &pos) noexcept
Definition: primitivetextgraphicsitem.cpp:72
void updateBoundingRectAndShape() noexcept
Definition: primitivetextgraphicsitem.cpp:196
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812