LibrePCB Developers Documentation
alignment.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_ALIGNMENT_H
21#define LIBREPCB_CORE_ALIGNMENT_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../exceptions.h"
27#include "../serialization/sexpression.h"
28
29#include <QtCore>
30
31/*******************************************************************************
32 * Namespace / Forward Declarations
33 ******************************************************************************/
34namespace librepcb {
35
36/*******************************************************************************
37 * Class HAlign
38 ******************************************************************************/
39
43class HAlign final {
44 Q_DECLARE_TR_FUNCTIONS(HAlign)
45
46public:
47 HAlign() noexcept : mAlign(Qt::AlignLeft) {}
48 HAlign(const HAlign& other) noexcept : mAlign(other.mAlign) {}
49 Qt::AlignmentFlag toQtAlignFlag() const noexcept { return mAlign; }
50 HAlign& mirror() noexcept;
51 HAlign mirrored() const noexcept { return HAlign(*this).mirror(); }
52 static HAlign left() noexcept { return HAlign(Qt::AlignLeft); }
53 static HAlign center() noexcept { return HAlign(Qt::AlignHCenter); }
54 static HAlign right() noexcept { return HAlign(Qt::AlignRight); }
55 HAlign& operator=(const HAlign& rhs) noexcept {
56 mAlign = rhs.mAlign;
57 return *this;
58 }
59 bool operator==(const HAlign& rhs) const noexcept {
60 return mAlign == rhs.mAlign;
61 }
62 bool operator!=(const HAlign& rhs) const noexcept {
63 return mAlign != rhs.mAlign;
64 }
65
66private:
67 explicit HAlign(Qt::AlignmentFlag align) noexcept : mAlign(align) {}
68
69 Qt::AlignmentFlag mAlign;
70};
71
72/*******************************************************************************
73 * Class VAlign
74 ******************************************************************************/
75
79class VAlign final {
80 Q_DECLARE_TR_FUNCTIONS(VAlign)
81
82public:
83 VAlign() noexcept : mAlign(Qt::AlignTop) {}
84 VAlign(const VAlign& other) noexcept : mAlign(other.mAlign) {}
85 Qt::AlignmentFlag toQtAlignFlag() const noexcept { return mAlign; }
86 VAlign& mirror() noexcept;
87 VAlign mirrored() const noexcept { return VAlign(*this).mirror(); }
88 static VAlign top() noexcept { return VAlign(Qt::AlignTop); }
89 static VAlign center() noexcept { return VAlign(Qt::AlignVCenter); }
90 static VAlign bottom() noexcept { return VAlign(Qt::AlignBottom); }
91 VAlign& operator=(const VAlign& rhs) noexcept {
92 mAlign = rhs.mAlign;
93 return *this;
94 }
95 bool operator==(const VAlign& rhs) const noexcept {
96 return mAlign == rhs.mAlign;
97 }
98 bool operator!=(const VAlign& rhs) const noexcept {
99 return mAlign != rhs.mAlign;
100 }
101
102private:
103 explicit VAlign(Qt::AlignmentFlag align) noexcept : mAlign(align) {}
104
105 Qt::AlignmentFlag mAlign;
106};
107
108/*******************************************************************************
109 * Class Alignment
110 ******************************************************************************/
111
115class Alignment final {
116 Q_DECLARE_TR_FUNCTIONS(Alignment)
117
118public:
119 Alignment() noexcept : mH(HAlign::left()), mV(VAlign::bottom()) {}
120 Alignment(const Alignment& other) noexcept : mH(other.mH), mV(other.mV) {}
121 explicit Alignment(const HAlign& h, const VAlign& v) noexcept
122 : mH(h), mV(v) {}
123 explicit Alignment(const SExpression& node);
124 const HAlign getH() const noexcept { return mH; }
125 const VAlign getV() const noexcept { return mV; }
126 void setH(const HAlign& h) noexcept { mH = h; }
127 void setV(const VAlign& v) noexcept { mV = v; }
128 Qt::Alignment toQtAlign() const noexcept {
129 return mH.toQtAlignFlag() | mV.toQtAlignFlag();
130 }
131 Alignment& mirror() noexcept;
132 Alignment& mirrorH() noexcept;
133 Alignment& mirrorV() noexcept;
134 Alignment mirrored() const noexcept { return Alignment(*this).mirror(); }
135 Alignment mirroredH() const noexcept { return Alignment(*this).mirrorH(); }
136 Alignment mirroredV() const noexcept { return Alignment(*this).mirrorV(); }
137
143 void serialize(SExpression& root) const;
144
145 Alignment& operator=(const Alignment& rhs) noexcept {
146 mH = rhs.mH;
147 mV = rhs.mV;
148 return *this;
149 }
150 bool operator==(const Alignment& rhs) const noexcept {
151 return mH == rhs.mH && mV == rhs.mV;
152 }
153 bool operator!=(const Alignment& rhs) const noexcept {
154 return mH != rhs.mH || mV != rhs.mV;
155 }
156
157private:
160};
161
162/*******************************************************************************
163 * End of File
164 ******************************************************************************/
165
166} // namespace librepcb
167
168Q_DECLARE_METATYPE(librepcb::HAlign)
169Q_DECLARE_METATYPE(librepcb::VAlign)
170
171#endif
The Alignment class.
Definition: alignment.h:115
Alignment & mirror() noexcept
Definition: alignment.cpp:141
Alignment(const HAlign &h, const VAlign &v) noexcept
Definition: alignment.h:121
Alignment & operator=(const Alignment &rhs) noexcept
Definition: alignment.h:145
Qt::Alignment toQtAlign() const noexcept
Definition: alignment.h:128
Alignment mirroredV() const noexcept
Definition: alignment.h:136
Alignment mirrored() const noexcept
Definition: alignment.h:134
const HAlign getH() const noexcept
Definition: alignment.h:124
Alignment & mirrorH() noexcept
Definition: alignment.cpp:147
const VAlign getV() const noexcept
Definition: alignment.h:125
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: alignment.cpp:157
VAlign mV
Definition: alignment.h:159
Alignment mirroredH() const noexcept
Definition: alignment.h:135
void setV(const VAlign &v) noexcept
Definition: alignment.h:127
Alignment() noexcept
Definition: alignment.h:119
HAlign mH
Definition: alignment.h:158
Alignment(const Alignment &other) noexcept
Definition: alignment.h:120
bool operator!=(const Alignment &rhs) const noexcept
Definition: alignment.h:153
Alignment & mirrorV() noexcept
Definition: alignment.cpp:152
void setH(const HAlign &h) noexcept
Definition: alignment.h:126
bool operator==(const Alignment &rhs) const noexcept
Definition: alignment.h:150
The HAlign class.
Definition: alignment.h:43
Qt::AlignmentFlag mAlign
Definition: alignment.h:69
HAlign mirrored() const noexcept
Definition: alignment.h:51
HAlign() noexcept
Definition: alignment.h:47
Qt::AlignmentFlag toQtAlignFlag() const noexcept
Definition: alignment.h:49
bool operator==(const HAlign &rhs) const noexcept
Definition: alignment.h:59
HAlign & operator=(const HAlign &rhs) noexcept
Definition: alignment.h:55
static HAlign right() noexcept
Definition: alignment.h:54
HAlign(Qt::AlignmentFlag align) noexcept
Definition: alignment.h:67
HAlign & mirror() noexcept
Definition: alignment.cpp:36
bool operator!=(const HAlign &rhs) const noexcept
Definition: alignment.h:62
static HAlign left() noexcept
Definition: alignment.h:52
HAlign(const HAlign &other) noexcept
Definition: alignment.h:48
static HAlign center() noexcept
Definition: alignment.h:53
The SExpression class.
Definition: sexpression.h:69
The VAlign class.
Definition: alignment.h:79
Qt::AlignmentFlag mAlign
Definition: alignment.h:105
bool operator!=(const VAlign &rhs) const noexcept
Definition: alignment.h:98
static VAlign bottom() noexcept
Definition: alignment.h:90
static VAlign top() noexcept
Definition: alignment.h:88
Qt::AlignmentFlag toQtAlignFlag() const noexcept
Definition: alignment.h:85
VAlign(const VAlign &other) noexcept
Definition: alignment.h:84
VAlign(Qt::AlignmentFlag align) noexcept
Definition: alignment.h:103
VAlign & operator=(const VAlign &rhs) noexcept
Definition: alignment.h:91
VAlign mirrored() const noexcept
Definition: alignment.h:87
VAlign & mirror() noexcept
Definition: alignment.cpp:86
VAlign() noexcept
Definition: alignment.h:83
static VAlign center() noexcept
Definition: alignment.h:89
bool operator==(const VAlign &rhs) const noexcept
Definition: alignment.h:95
Definition: occmodel.cpp:77