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  ******************************************************************************/
39 namespace librepcb {
40 
41 class Layer;
42 class StrokeFont;
43 
44 /*******************************************************************************
45  * Class StrokeText
46  ******************************************************************************/
47 
51 class StrokeText final {
52  Q_DECLARE_TR_FUNCTIONS(StrokeText)
53 
54 public:
55  // Signals
56  enum class Event {
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, const QString& text) const
105  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 
136 private: // Data
138  const Layer* mLayer;
139  QString mText;
147  bool mMirrored;
149 };
150 
151 /*******************************************************************************
152  * Class StrokeTextList
153  ******************************************************************************/
154 
156  static constexpr const char* tagname = "stroke_text";
157 };
158 using StrokeTextList =
161 
162 /*******************************************************************************
163  * End of File
164  ******************************************************************************/
165 
166 } // namespace librepcb
167 
168 #endif
bool setLineSpacing(const StrokeTextSpacing &spacing) noexcept
Definition: stroketext.cpp:192
const Layer & getLayer() const noexcept
Definition: stroketext.h:88
const UnsignedLength & getStrokeWidth() const noexcept
Definition: stroketext.h:92
bool setPosition(const Point &pos) noexcept
Definition: stroketext.cpp:142
const QString & getText() const noexcept
Definition: stroketext.h:102
Signal< StrokeText, Event > onEdited
Definition: stroketext.h:70
Angle mRotation
Definition: stroketext.h:141
bool setHeight(const PositiveLength &height) noexcept
Definition: stroketext.cpp:162
Uuid mUuid
Definition: stroketext.h:137
bool setStrokeWidth(const UnsignedLength &strokeWidth) noexcept
Definition: stroketext.cpp:172
bool setText(const QString &text) noexcept
Definition: stroketext.cpp:132
bool setMirrored(bool mirrored) noexcept
Definition: stroketext.cpp:212
The Alignment class.
Definition: alignment.h:115
StrokeTextSpacing mLetterSpacing
Definition: stroketext.h:144
const StrokeTextSpacing & getLineSpacing() const noexcept
Definition: stroketext.h:96
Definition: occmodel.cpp:76
bool setAutoRotate(bool autoRotate) noexcept
Definition: stroketext.cpp:222
StrokeTextSpacing mLineSpacing
Definition: stroketext.h:145
Definition: stroketext.h:155
const Alignment & getAlign() const noexcept
Definition: stroketext.h:99
PositiveLength mHeight
Definition: stroketext.h:142
The Layer class provides all supported geometry layers.
Definition: layer.h:40
The StrokeText class.
Definition: stroketext.h:51
bool setLayer(const Layer &layer) noexcept
Definition: stroketext.cpp:122
const StrokeTextSpacing & getLetterSpacing() const noexcept
Definition: stroketext.h:93
bool setRotation(const Angle &rotation) noexcept
Definition: stroketext.cpp:152
const Layer * mLayer
Definition: stroketext.h:138
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:76
bool getAutoRotate() const noexcept
Definition: stroketext.h:101
Event
Definition: stroketext.h:56
Slot< StrokeText, Event > OnEditedSlot
Definition: stroketext.h:71
bool operator!=(const StrokeText &rhs) const noexcept
Definition: stroketext.h:131
Represents the letter- or line spacing configuration of a stroke text.
Definition: stroketextspacing.h:44
bool operator==(const StrokeText &rhs) const noexcept
Definition: stroketext.cpp:259
const Point & getPosition() const noexcept
Definition: stroketext.h:89
bool mAutoRotate
Definition: stroketext.h:148
StrokeText & operator=(const StrokeText &rhs) noexcept
Definition: stroketext.cpp:275
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
bool getMirrored() const noexcept
Definition: stroketext.h:100
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: stroketext.cpp:236
bool setAlign(const Alignment &align) noexcept
Definition: stroketext.cpp:202
const Angle & getRotation() const noexcept
Definition: stroketext.h:90
QString mText
Definition: stroketext.h:139
~StrokeText() noexcept
Definition: stroketext.cpp:100
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:785
QVector< Path > generatePaths(const StrokeFont &font) const noexcept
Definition: stroketext.cpp:107
UnsignedLength mStrokeWidth
Definition: stroketext.h:143
Point mPosition
Definition: stroketext.h:140
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:56
const Uuid & getUuid() const noexcept
Definition: stroketext.h:87
The StrokeFont class.
Definition: strokefont.h:54
const PositiveLength & getHeight() const noexcept
Definition: stroketext.h:91
The SExpression class.
Definition: sexpression.h:66
bool setLetterSpacing(const StrokeTextSpacing &spacing) noexcept
Definition: stroketext.cpp:182
bool mMirrored
Definition: stroketext.h:147
Alignment mAlign
Definition: stroketext.h:146
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:670