1 /*
2   quickitemgeometry.cpp
3 
4   This file is part of GammaRay, the Qt application inspection and
5   manipulation tool.
6 
7   Copyright (C) 2014-2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8   Author: Anton Kreuzkamp <anton.kreuzkamp@kdab.com>
9 
10   Licensees holding valid commercial KDAB GammaRay licenses may use this file in
11   accordance with GammaRay Commercial License Agreement provided with the Software.
12 
13   Contact info@kdab.com if any conditions of this licensing are not clear to you.
14 
15   This program is free software; you can redistribute it and/or modify
16   it under the terms of the GNU General Public License as published by
17   the Free Software Foundation, either version 2 of the License, or
18   (at your option) any later version.
19 
20   This program is distributed in the hope that it will be useful,
21   but WITHOUT ANY WARRANTY; without even the implied warranty of
22   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23   GNU General Public License for more details.
24 
25   You should have received a copy of the GNU General Public License
26   along with this program.  If not, see <http://www.gnu.org/licenses/>.
27 */
28 
29 #include "quickitemgeometry.h"
30 
31 #include <QQuickItem>
32 #include <QtNumeric>
33 
34 namespace GammaRay {
35 
isValid() const36 bool GammaRay::QuickItemGeometry::isValid() const
37 {
38     return !qIsNaN(x) && !qIsNaN(y);
39 }
40 
scaleTo(qreal factor)41 void QuickItemGeometry::scaleTo(qreal factor)
42 {
43     if (!isValid())
44         return;
45 
46     itemRect = QRectF(
47                 itemRect.topLeft() * factor,
48                 itemRect.bottomRight() * factor);
49     boundingRect = QRectF(
50                 boundingRect.topLeft() * factor,
51                 boundingRect.bottomRight() * factor);
52     childrenRect = QRectF(
53                 childrenRect.topLeft() * factor,
54                 childrenRect.bottomRight() * factor);
55     backgroundRect = QRectF(
56                 backgroundRect.topLeft() * factor,
57                 backgroundRect.bottomRight() * factor);
58     contentItemRect = QRectF(
59                 contentItemRect.topLeft() * factor,
60                 contentItemRect.bottomRight() * factor);
61     transformOriginPoint = transformOriginPoint * factor;
62     leftMargin = leftMargin * factor;
63     horizontalCenterOffset = horizontalCenterOffset * factor;
64     rightMargin = rightMargin * factor;
65     topMargin = topMargin * factor;
66     verticalCenterOffset = verticalCenterOffset * factor;
67     bottomMargin = bottomMargin * factor;
68     baselineOffset = baselineOffset * factor;
69     x = x * factor;
70     y = y * factor;
71     if (!qIsNaN(padding)) {
72         padding = padding * factor;
73         leftPadding = leftPadding * factor;
74         rightPadding = rightPadding * factor;
75         topPadding = topPadding * factor;
76         bottomPadding = bottomPadding * factor;
77     }
78 }
79 
operator ==(const QuickItemGeometry & other) const80 bool QuickItemGeometry::operator==(const QuickItemGeometry &other) const
81 {
82     return
83         itemRect == other.itemRect &&
84         boundingRect == other.boundingRect &&
85         childrenRect == other.childrenRect &&
86         backgroundRect == other.backgroundRect &&
87         contentItemRect == other.contentItemRect &&
88         transformOriginPoint == other.transformOriginPoint &&
89         transform == other.transform &&
90         parentTransform == other.parentTransform &&
91         x == other.x &&
92         y == other.y &&
93         left == other.left &&
94         right == other.right &&
95         top == other.top &&
96         bottom == other.bottom &&
97         horizontalCenter == other.horizontalCenter &&
98         verticalCenter == other.verticalCenter &&
99         baseline == other.baseline &&
100         margins == other.margins &&
101         leftMargin == other.leftMargin &&
102         horizontalCenterOffset == other.horizontalCenterOffset &&
103         rightMargin == other.rightMargin &&
104         topMargin == other.topMargin &&
105         verticalCenterOffset == other.verticalCenterOffset &&
106         bottomMargin == other.bottomMargin &&
107         baselineOffset == other.baselineOffset &&
108         padding == other.padding &&
109         leftPadding == other.leftPadding &&
110         rightPadding == other.rightPadding &&
111         topPadding == other.topPadding &&
112         bottomPadding == other.bottomPadding &&
113         traceColor == other.traceColor &&
114         traceTypeName == other.traceTypeName &&
115         traceName == other.traceName
116     ;
117 }
118 
operator !=(const QuickItemGeometry & other) const119 bool QuickItemGeometry::operator!=(const QuickItemGeometry &other) const
120 {
121     return !operator==(other);
122 }
123 
operator <<(QDataStream & stream,const GammaRay::QuickItemGeometry & geometry)124 QDataStream &operator<<(QDataStream &stream, const GammaRay::QuickItemGeometry &geometry)
125 {
126     stream << geometry.itemRect
127            << geometry.boundingRect
128            << geometry.childrenRect
129            << geometry.backgroundRect
130            << geometry.contentItemRect
131 
132            << geometry.transformOriginPoint
133            << geometry.transform
134            << geometry.parentTransform
135 
136            << geometry.x
137            << geometry.y
138 
139            << geometry.left
140            << geometry.right
141            << geometry.top
142            << geometry.bottom
143            << geometry.horizontalCenter
144            << geometry.verticalCenter
145            << geometry.baseline
146 
147            << geometry.margins
148            << geometry.leftMargin
149            << geometry.horizontalCenterOffset
150            << geometry.rightMargin
151            << geometry.topMargin
152            << geometry.verticalCenterOffset
153            << geometry.bottomMargin
154            << geometry.baselineOffset
155 
156            << geometry.padding
157            << geometry.leftPadding
158            << geometry.rightPadding
159            << geometry.topPadding
160            << geometry.bottomPadding
161 
162            << geometry.traceColor
163            << geometry.traceTypeName
164            << geometry.traceName
165     ;
166 
167     return stream;
168 }
169 
operator >>(QDataStream & stream,GammaRay::QuickItemGeometry & geometry)170 QDataStream &operator>>(QDataStream &stream, GammaRay::QuickItemGeometry &geometry)
171 {
172     stream >> geometry.itemRect
173            >> geometry.boundingRect
174            >> geometry.childrenRect
175            >> geometry.backgroundRect
176            >> geometry.contentItemRect
177 
178            >> geometry.transformOriginPoint
179            >> geometry.transform
180            >> geometry.parentTransform
181 
182            >> geometry.x
183            >> geometry.y
184 
185            >> geometry.left
186            >> geometry.right
187            >> geometry.top
188            >> geometry.bottom
189            >> geometry.horizontalCenter
190            >> geometry.verticalCenter
191            >> geometry.baseline
192 
193            >> geometry.margins
194            >> geometry.leftMargin
195            >> geometry.horizontalCenterOffset
196            >> geometry.rightMargin
197            >> geometry.topMargin
198            >> geometry.verticalCenterOffset
199            >> geometry.bottomMargin
200            >> geometry.baselineOffset
201 
202            >> geometry.padding
203            >> geometry.leftPadding
204            >> geometry.rightPadding
205            >> geometry.topPadding
206            >> geometry.bottomPadding
207 
208            >> geometry.traceColor
209            >> geometry.traceTypeName
210            >> geometry.traceName
211     ;
212 
213     return stream;
214 }
215 }
216