LibrePCB Developers Documentation
stroketext.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_CORE_STROKETEXT_H
21#define LIBREPCB_CORE_STROKETEXT_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../geometry/path.h"
27#include "../serialization/serializableobjectlist.h"
28#include "../types/alignment.h"
29#include "../types/angle.h"
30#include "../types/length.h"
31#include "../types/point.h"
32#include "../types/stroketextspacing.h"
33
34#include <QtCore>
35
36/*******************************************************************************
37 * Namespace / Forward Declarations
38 ******************************************************************************/
39namespace librepcb {
40
41class Layer;
42class StrokeFont;
43
44/*******************************************************************************
45 * Class StrokeText
46 ******************************************************************************/
47
51class StrokeText final {
52 Q_DECLARE_TR_FUNCTIONS(StrokeText)
53
54public:
55 // Signals
56 enum class Event {
57 UuidChanged,
58 LayerChanged,
59 TextChanged,
60 PositionChanged,
61 RotationChanged,
62 HeightChanged,
63 StrokeWidthChanged,
64 LetterSpacingChanged,
65 LineSpacingChanged,
66 AlignChanged,
67 MirroredChanged,
68 AutoRotateChanged,
69 };
72
73 // Constructors / Destructor
74 StrokeText() = delete;
75 StrokeText(const StrokeText& other) noexcept;
76 StrokeText(const Uuid& uuid, const StrokeText& other) noexcept;
77 StrokeText(const Uuid& uuid, const Layer& layer, const QString& text,
78 const Point& pos, const Angle& rotation,
79 const PositiveLength& height, const UnsignedLength& strokeWidth,
80 const StrokeTextSpacing& letterSpacing,
81 const StrokeTextSpacing& lineSpacing, const Alignment& align,
82 bool mirrored, bool autoRotate) noexcept;
83 explicit StrokeText(const SExpression& node);
84 ~StrokeText() noexcept;
85
86 // Getters
87 const Uuid& getUuid() const noexcept { return mUuid; }
88 const Layer& getLayer() const noexcept { return *mLayer; }
89 const Point& getPosition() const noexcept { return mPosition; }
90 const Angle& getRotation() const noexcept { return mRotation; }
91 const PositiveLength& getHeight() const noexcept { return mHeight; }
92 const UnsignedLength& getStrokeWidth() const noexcept { return mStrokeWidth; }
93 const StrokeTextSpacing& getLetterSpacing() const noexcept {
94 return mLetterSpacing;
95 }
96 const StrokeTextSpacing& getLineSpacing() const noexcept {
97 return mLineSpacing;
98 }
99 const Alignment& getAlign() const noexcept { return mAlign; }
100 bool getMirrored() const noexcept { return mMirrored; }
101 bool getAutoRotate() const noexcept { return mAutoRotate; }
102 const QString& getText() const noexcept { return mText; }
103 QVector<Path> generatePaths(const StrokeFont& font) const noexcept;
104 QVector<Path> generatePaths(const StrokeFont& font,
105 const QString& text) const noexcept;
106
107 // Setters
108 bool setLayer(const Layer& layer) noexcept;
109 bool setText(const QString& text) noexcept;
110 bool setPosition(const Point& pos) noexcept;
111 bool setRotation(const Angle& rotation) noexcept;
112 bool setHeight(const PositiveLength& height) noexcept;
113 bool setStrokeWidth(const UnsignedLength& strokeWidth) noexcept;
114 bool setLetterSpacing(const StrokeTextSpacing& spacing) noexcept;
115 bool setLineSpacing(const StrokeTextSpacing& spacing) noexcept;
116 bool setAlign(const Alignment& align) noexcept;
117 bool setMirrored(bool mirrored) noexcept;
118 bool setAutoRotate(bool autoRotate) noexcept;
119
120 // General Methods
121
127 void serialize(SExpression& root) const;
128
129 // Operator Overloadings
130 bool operator==(const StrokeText& rhs) const noexcept;
131 bool operator!=(const StrokeText& rhs) const noexcept {
132 return !(*this == rhs);
133 }
134 StrokeText& operator=(const StrokeText& rhs) noexcept;
135
136private: // Data
138 const Layer* mLayer;
139 QString mText;
149};
150
151/*******************************************************************************
152 * Class StrokeTextList
153 ******************************************************************************/
154
156 static constexpr const char* tagname = "stroke_text";
157};
161
162/*******************************************************************************
163 * End of File
164 ******************************************************************************/
165
166} // namespace librepcb
167
168#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 Layer class provides all supported geometry layers.
Definition: layer.h:40
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition: point.h:79
The SExpression class.
Definition: sexpression.h:69
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
The StrokeFont class.
Definition: strokefont.h:56
The StrokeText class.
Definition: stroketext.h:51
bool getMirrored() const noexcept
Definition: stroketext.h:100
bool setText(const QString &text) noexcept
Definition: stroketext.cpp:132
const Angle & getRotation() const noexcept
Definition: stroketext.h:90
Slot< StrokeText, Event > OnEditedSlot
Definition: stroketext.h:71
bool setPosition(const Point &pos) noexcept
Definition: stroketext.cpp:142
bool setLineSpacing(const StrokeTextSpacing &spacing) noexcept
Definition: stroketext.cpp:192
bool getAutoRotate() const noexcept
Definition: stroketext.h:101
Uuid mUuid
Definition: stroketext.h:137
StrokeText & operator=(const StrokeText &rhs) noexcept
Definition: stroketext.cpp:275
Event
Definition: stroketext.h:56
UnsignedLength mStrokeWidth
Definition: stroketext.h:143
const PositiveLength & getHeight() const noexcept
Definition: stroketext.h:91
QString mText
Definition: stroketext.h:139
const Layer & getLayer() const noexcept
Definition: stroketext.h:88
bool setLetterSpacing(const StrokeTextSpacing &spacing) noexcept
Definition: stroketext.cpp:182
QVector< Path > generatePaths(const StrokeFont &font) const noexcept
Definition: stroketext.cpp:107
const Alignment & getAlign() const noexcept
Definition: stroketext.h:99
const QString & getText() const noexcept
Definition: stroketext.h:102
Signal< StrokeText, Event > onEdited
Definition: stroketext.h:70
bool setStrokeWidth(const UnsignedLength &strokeWidth) noexcept
Definition: stroketext.cpp:172
Angle mRotation
Definition: stroketext.h:141
bool setLayer(const Layer &layer) noexcept
Definition: stroketext.cpp:122
bool mAutoRotate
Definition: stroketext.h:148
bool setHeight(const PositiveLength &height) noexcept
Definition: stroketext.cpp:162
bool setMirrored(bool mirrored) noexcept
Definition: stroketext.cpp:212
const Point & getPosition() const noexcept
Definition: stroketext.h:89
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: stroketext.cpp:236
const StrokeTextSpacing & getLineSpacing() const noexcept
Definition: stroketext.h:96
PositiveLength mHeight
Definition: stroketext.h:142
const Uuid & getUuid() const noexcept
Definition: stroketext.h:87
bool operator!=(const StrokeText &rhs) const noexcept
Definition: stroketext.h:131
const StrokeTextSpacing & getLetterSpacing() const noexcept
Definition: stroketext.h:93
Alignment mAlign
Definition: stroketext.h:146
bool setRotation(const Angle &rotation) noexcept
Definition: stroketext.cpp:152
const Layer * mLayer
Definition: stroketext.h:138
StrokeTextSpacing mLineSpacing
Definition: stroketext.h:145
const UnsignedLength & getStrokeWidth() const noexcept
Definition: stroketext.h:92
~StrokeText() noexcept
Definition: stroketext.cpp:100
bool setAutoRotate(bool autoRotate) noexcept
Definition: stroketext.cpp:222
bool mMirrored
Definition: stroketext.h:147
bool operator==(const StrokeText &rhs) const noexcept
Definition: stroketext.cpp:259
Point mPosition
Definition: stroketext.h:140
bool setAlign(const Alignment &align) noexcept
Definition: stroketext.cpp:202
StrokeTextSpacing mLetterSpacing
Definition: stroketext.h:144
Represents the letter- or line spacing configuration of a stroke text.
Definition: stroketextspacing.h:44
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
Definition: stroketext.h:155
static constexpr const char * tagname
Definition: stroketext.h:156