LibrePCB Developers Documentation
Loading...
Searching...
No Matches
image.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_IMAGE_H
21#define LIBREPCB_CORE_IMAGE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../serialization/serializableobjectlist.h"
27#include "../types/angle.h"
28#include "../types/fileproofname.h"
29#include "../types/length.h"
30#include "../types/point.h"
31
32#include <QtCore>
33#include <QtGui>
34
35#include <optional>
36
37/*******************************************************************************
38 * Namespace / Forward Declarations
39 ******************************************************************************/
40namespace librepcb {
41
42/*******************************************************************************
43 * Class Image
44 ******************************************************************************/
45
49class Image final {
50 Q_DECLARE_TR_FUNCTIONS(Image)
51
52public:
53 // Signals
65
66 // Constructors / Destructor
67 Image() = delete;
68 Image(const Image& other) noexcept;
69 Image(const Uuid& uuid, const Image& other) noexcept;
70 Image(const Uuid& uuid, const FileProofName& fileName, const Point& pos,
71 const Angle& rotation, const PositiveLength& width,
72 const PositiveLength& height,
73 const std::optional<UnsignedLength>& borderWidth) noexcept;
74 explicit Image(const SExpression& node);
75 ~Image() noexcept;
76
77 // Getters
78 const Uuid& getUuid() const noexcept { return mUuid; }
79 const FileProofName& getFileName() const noexcept { return mFileName; }
80 QString getFileBasename() const noexcept;
81 QString getFileExtension() const noexcept;
82 const Point& getPosition() const noexcept { return mPosition; }
83 Point getCenter() const noexcept;
84 const Angle& getRotation() const noexcept { return mRotation; }
85 const PositiveLength& getWidth() const noexcept { return mWidth; }
86 const PositiveLength& getHeight() const noexcept { return mHeight; }
87 const std::optional<UnsignedLength>& getBorderWidth() const noexcept {
88 return mBorderWidth;
89 }
90
91 // Setters
92 bool setFileName(const FileProofName& name) noexcept;
93 bool setPosition(const Point& pos) noexcept;
94 bool setRotation(const Angle& rotation) noexcept;
95 bool setWidth(const PositiveLength& width) noexcept;
96 bool setHeight(const PositiveLength& height) noexcept;
97 bool setBorderWidth(const std::optional<UnsignedLength>& width) noexcept;
98
99 // General Methods
100
106 void serialize(SExpression& root) const;
107
108 // Operator Overloadings
109 bool operator==(const Image& rhs) const noexcept;
110 bool operator!=(const Image& rhs) const noexcept { return !(*this == rhs); }
111 Image& operator=(const Image& rhs) noexcept;
112
113 // Static Methods.
114
128 static const QStringList& getSupportedExtensions() noexcept;
129
146 static std::optional<QImage> tryLoad(const QByteArray& data,
147 const QString& format,
148 QString* errorMsg = nullptr) noexcept;
149
150private: // Data
158};
159
160/*******************************************************************************
161 * Class ImageList
162 ******************************************************************************/
163
165 static constexpr const char* tagname = "image";
166};
169
170/*******************************************************************************
171 * End of File
172 ******************************************************************************/
173
174} // namespace librepcb
175
176#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition angle.h:76
The Image class.
Definition image.h:49
const Angle & getRotation() const noexcept
Definition image.h:84
const PositiveLength & getWidth() const noexcept
Definition image.h:85
bool setPosition(const Point &pos) noexcept
Definition image.cpp:134
static const QStringList & getSupportedExtensions() noexcept
Get all supported file extensions.
Definition image.cpp:235
QString getFileBasename() const noexcept
Definition image.cpp:104
Signal< Image, Event > onEdited
Definition image.h:63
QString getFileExtension() const noexcept
Definition image.cpp:112
const FileProofName & getFileName() const noexcept
Definition image.h:79
Uuid mUuid
Definition image.h:151
bool operator==(const Image &rhs) const noexcept
Definition image.cpp:206
Event
Definition image.h:54
const PositiveLength & getHeight() const noexcept
Definition image.h:86
Slot< Image, Event > OnEditedSlot
Definition image.h:64
Angle mRotation
Definition image.h:154
bool setHeight(const PositiveLength &height) noexcept
Definition image.cpp:164
Point getCenter() const noexcept
Definition image.cpp:116
const Point & getPosition() const noexcept
Definition image.h:82
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition image.cpp:189
PositiveLength mHeight
Definition image.h:156
const Uuid & getUuid() const noexcept
Definition image.h:78
static std::optional< QImage > tryLoad(const QByteArray &data, const QString &format, QString *errorMsg=nullptr) noexcept
Try loading an image file.
Definition image.cpp:259
bool setWidth(const PositiveLength &width) noexcept
Definition image.cpp:154
bool setRotation(const Angle &rotation) noexcept
Definition image.cpp:144
Image & operator=(const Image &rhs) noexcept
Definition image.cpp:217
const std::optional< UnsignedLength > & getBorderWidth() const noexcept
Definition image.h:87
bool setBorderWidth(const std::optional< UnsignedLength > &width) noexcept
Definition image.cpp:174
std::optional< UnsignedLength > mBorderWidth
Definition image.h:157
~Image() noexcept
Definition image.cpp:97
Point mPosition
Definition image.h:153
FileProofName mFileName
Definition image.h:152
PositiveLength mWidth
Definition image.h:155
bool operator!=(const Image &rhs) const noexcept
Definition image.h:110
bool setFileName(const FileProofName &name) noexcept
Definition image.cpp:124
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
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 Slot class is used to receive signals from non-QObject derived classes.
Definition signalslot.h:170
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition uuid.h:56
Definition occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition length.h:694
type_safe::constrained_type< QString, FileProofNameConstraint, FileProofNameVerifier > FileProofName
Definition fileproofname.h:90
Definition uuid.h:186
Definition image.h:164