-
Notifications
You must be signed in to change notification settings - Fork 7
/
QQuickExtraAnchors.cpp
196 lines (169 loc) · 5.98 KB
/
QQuickExtraAnchors.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include "QQuickExtraAnchors.h"
#include <QQmlProperty>
QQuickExtraAnchors::QQuickExtraAnchors (QObject * parent)
: QObject (parent)
, m_anchors (parent != Q_NULLPTR ? QQmlProperty (parent, "anchors").read ().value<QObject *> () : Q_NULLPTR)
, m_dockTop (Q_NULLPTR)
, m_dockLeft (Q_NULLPTR)
, m_dockRight (Q_NULLPTR)
, m_dockBottom (Q_NULLPTR)
, m_verticalFill (Q_NULLPTR)
, m_horizontalFill (Q_NULLPTR)
, m_topLeftCorner (Q_NULLPTR)
, m_topRightCorner (Q_NULLPTR)
, m_bottomLeftCorner (Q_NULLPTR)
, m_bottomRightCorner (Q_NULLPTR)
{ }
QQuickExtraAnchors * QQuickExtraAnchors::qmlAttachedProperties (QObject * object) {
return new QQuickExtraAnchors (object);
}
void QQuickExtraAnchors::defineAnchorLine (QQuickItem * otherItem, const Sides side) {
static const QVariant UNDEFINED = QVariant ();
if (m_anchors != Q_NULLPTR) {
QString lineName;
switch (side) {
case TOP: {
lineName = QStringLiteral ("top");
break;
}
case LEFT: {
lineName = QStringLiteral ("left");
break;
}
case RIGHT: {
lineName = QStringLiteral ("right");
break;
}
case BOTTOM: {
lineName = QStringLiteral ("bottom");
break;
}
}
if (!lineName.isEmpty ()) {
QQmlProperty prop (m_anchors, lineName);
if (otherItem != Q_NULLPTR) {
QQmlProperty tmp (otherItem, lineName);
prop.write (tmp.read ());
}
else {
prop.write (UNDEFINED);
}
}
}
}
/**************************** GETTERS ******************************/
QQuickItem * QQuickExtraAnchors::getTopDock (void) const {
return m_dockTop;
}
QQuickItem * QQuickExtraAnchors::getLeftDock (void) const {
return m_dockLeft;
}
QQuickItem * QQuickExtraAnchors::getRightDock (void) const {
return m_dockRight;
}
QQuickItem * QQuickExtraAnchors::getBottomDock (void) const {
return m_dockBottom;
}
QQuickItem * QQuickExtraAnchors::getVerticalFill (void) const {
return m_verticalFill;
}
QQuickItem * QQuickExtraAnchors::getHorizontalFill (void) const {
return m_horizontalFill;
}
QQuickItem * QQuickExtraAnchors::getTopLeftCorner (void) const {
return m_topLeftCorner;
}
QQuickItem * QQuickExtraAnchors::getTopRightCorner (void) const {
return m_topRightCorner;
}
QQuickItem * QQuickExtraAnchors::getBottomLeftCorner (void) const {
return m_bottomLeftCorner;
}
QQuickItem * QQuickExtraAnchors::getBottomRightCorner (void) const {
return m_bottomRightCorner;
}
/**************************** SETTERS ******************************/
void QQuickExtraAnchors::setTopDock (QQuickItem * dockTop) {
if (m_dockTop != dockTop) {
m_dockTop = dockTop;
defineAnchorLine (m_dockTop, TOP);
defineAnchorLine (m_dockTop, LEFT);
defineAnchorLine (m_dockTop, RIGHT);
emit topDockChanged (m_dockTop);
}
}
void QQuickExtraAnchors::setLeftDock (QQuickItem * dockLeft) {
if (m_dockLeft != dockLeft) {
m_dockLeft = dockLeft;
defineAnchorLine (m_dockLeft, TOP);
defineAnchorLine (m_dockLeft, LEFT);
defineAnchorLine (m_dockLeft, BOTTOM);
emit leftDockChanged (m_dockLeft);
}
}
void QQuickExtraAnchors::setRightDock (QQuickItem * dockRight) {
if (m_dockRight != dockRight) {
m_dockRight = dockRight;
defineAnchorLine (m_dockRight, TOP);
defineAnchorLine (m_dockRight, RIGHT);
defineAnchorLine (m_dockRight, BOTTOM);
emit rightDockChanged (m_dockRight);
}
}
void QQuickExtraAnchors::setBottomDock (QQuickItem * dockBottom) {
if (m_dockBottom != dockBottom) {
m_dockBottom = dockBottom;
defineAnchorLine (m_dockBottom, LEFT);
defineAnchorLine (m_dockBottom, RIGHT);
defineAnchorLine (m_dockBottom, BOTTOM);
emit bottomDockChanged (m_dockBottom);
}
}
void QQuickExtraAnchors::setVerticalFill (QQuickItem * verticalFill) {
if (m_verticalFill != verticalFill) {
m_verticalFill = verticalFill;
defineAnchorLine (m_verticalFill, TOP);
defineAnchorLine (m_verticalFill, BOTTOM);
emit verticalFillChanged (m_verticalFill);
}
}
void QQuickExtraAnchors::setHorizontalFill (QQuickItem * horizontalFill) {
if (m_horizontalFill != horizontalFill) {
m_horizontalFill = horizontalFill;
defineAnchorLine (m_horizontalFill, LEFT);
defineAnchorLine (m_horizontalFill, RIGHT);
emit horizontalFillChanged (m_horizontalFill);
}
}
void QQuickExtraAnchors::setTopLeftCorner (QQuickItem * topLeftCorner) {
if (m_topLeftCorner != topLeftCorner) {
m_topLeftCorner = topLeftCorner;
defineAnchorLine (m_topLeftCorner, TOP);
defineAnchorLine (m_topLeftCorner, LEFT);
emit topLeftCornerChanged (m_topLeftCorner);
}
}
void QQuickExtraAnchors::setTopRightCorner (QQuickItem * topRightCorner) {
if (m_topRightCorner != topRightCorner) {
m_topRightCorner = topRightCorner;
defineAnchorLine (m_topRightCorner, TOP);
defineAnchorLine (m_topRightCorner, RIGHT);
emit topRightCornerChanged (m_topRightCorner);
}
}
void QQuickExtraAnchors::setBottomLeftCorner (QQuickItem * bottomLeftCorner) {
if (m_bottomLeftCorner != bottomLeftCorner) {
m_bottomLeftCorner = bottomLeftCorner;
defineAnchorLine (m_bottomLeftCorner, LEFT);
defineAnchorLine (m_bottomLeftCorner, BOTTOM);
emit bottomLeftCornerChanged (m_bottomLeftCorner);
}
}
void QQuickExtraAnchors::setBottomRightCorner(QQuickItem * bottomRightCorner) {
if (m_bottomRightCorner != bottomRightCorner) {
m_bottomRightCorner = bottomRightCorner;
defineAnchorLine (m_bottomRightCorner, RIGHT);
defineAnchorLine (m_bottomRightCorner, BOTTOM);
emit bottomRightCornerChanged (m_bottomRightCorner);
}
}