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 /*******************************************************************************
21 * Includes
22 ******************************************************************************/
23 #include "alignment.h"
24
25 #include <QtCore>
26
27 /*******************************************************************************
28 * Namespace
29 ******************************************************************************/
30 namespace librepcb {
31
32 /*******************************************************************************
33 * Class HAlign
34 ******************************************************************************/
35
mirror()36 HAlign& HAlign::mirror() noexcept {
37 switch (mAlign) {
38 case Qt::AlignLeft:
39 mAlign = Qt::AlignRight;
40 break;
41 case Qt::AlignRight:
42 mAlign = Qt::AlignLeft;
43 break;
44 case Qt::AlignHCenter:
45 break;
46 default:
47 Q_ASSERT(false);
48 break;
49 }
50 return *this;
51 }
52
53 /*******************************************************************************
54 * Class VAlign
55 ******************************************************************************/
56
mirror()57 VAlign& VAlign::mirror() noexcept {
58 switch (mAlign) {
59 case Qt::AlignTop:
60 mAlign = Qt::AlignBottom;
61 break;
62 case Qt::AlignBottom:
63 mAlign = Qt::AlignTop;
64 break;
65 case Qt::AlignVCenter:
66 break;
67 default:
68 Q_ASSERT(false);
69 break;
70 }
71 return *this;
72 }
73
74 /*******************************************************************************
75 * Class VAlign
76 ******************************************************************************/
77
Alignment(const SExpression & node,const Version & fileFormat)78 Alignment::Alignment(const SExpression& node, const Version& fileFormat) {
79 try {
80 mH = deserialize<HAlign>(node.getChild("@0"), fileFormat);
81 mV = deserialize<VAlign>(node.getChild("@1"), fileFormat);
82 } catch (const Exception& e) {
83 throw FileParseError(__FILE__, __LINE__, node.getFilePath(), -1, -1,
84 QString(), e.getMsg());
85 }
86 }
87
mirror()88 Alignment& Alignment::mirror() noexcept {
89 mH.mirror();
90 mV.mirror();
91 return *this;
92 }
93
mirrorH()94 Alignment& Alignment::mirrorH() noexcept {
95 mH.mirror();
96 return *this;
97 }
98
mirrorV()99 Alignment& Alignment::mirrorV() noexcept {
100 mV.mirror();
101 return *this;
102 }
103
serialize(SExpression & root) const104 void Alignment::serialize(SExpression& root) const {
105 root.appendChild(mH);
106 root.appendChild(mV);
107 }
108
109 /*******************************************************************************
110 * End of File
111 ******************************************************************************/
112
113 } // namespace librepcb
114