57 \brief Bounds center points of input geometries to |
57 \brief Bounds center points of input geometries to |
58 the given output rectangle. |
58 the given output rectangle. |
59 */ |
59 */ |
60 |
60 |
61 /*! |
61 /*! |
62 \class HsSimpleWidgetPositioningOnOrientationChange |
|
63 \brief Simpe widget positioning algorithm. |
|
64 |
|
65 Bounds center points of \a fromGeometries to the |
|
66 \a toRect. \a fromRect is not used by the algorithm. |
|
67 \verbatim |
|
68 ------ |
|
69 | A | |
|
70 | | |
|
71 | | |
|
72 | | |
|
73 ------ |
|
74 \endverbatim |
|
75 and after conversion widgets from A are moved to A': |
|
76 \verbatim |
|
77 |----------| |
|
78 |A' | |
|
79 |----------| |
|
80 \endverbatim |
|
81 and vice versa. |
|
82 */ |
|
83 QList<QRectF> HsSimpleWidgetPositioningOnOrientationChange::convert( |
|
84 const QRectF &fromRect, |
|
85 const QList<QRectF> &fromGeometries, |
|
86 const QRectF &toRect) |
|
87 { |
|
88 Q_UNUSED(fromRect) |
|
89 QList<QRectF> toGeometries; |
|
90 foreach (QRectF g, fromGeometries) { |
|
91 QPointF c(g.center()); |
|
92 qreal x = qBound(toRect.left(), c.x(), toRect.right()); |
|
93 qreal y = qBound(toRect.top(), c.y(), toRect.bottom()); |
|
94 g.moveCenter(QPointF(x, y)); |
|
95 toGeometries << g; |
|
96 } |
|
97 return toGeometries; |
|
98 } |
|
99 |
|
100 /*! |
|
101 \class HsAdvancedWidgetPositioningOnOrientationChange |
62 \class HsAdvancedWidgetPositioningOnOrientationChange |
102 \brief More advanced widget positioning algorithm. |
63 \brief More advanced widget positioning algorithm. |
103 |
64 |
104 Calculates new center points of |
65 Calculates new center points of |
105 \a fromGeometries when moving from \a fromRect to \a toRect. |
66 \a fromGeometries when moving from \a fromRect to \a toRect. |
125 const QRectF &fromRect, |
86 const QRectF &fromRect, |
126 const QList<QRectF> &fromGeometries, |
87 const QList<QRectF> &fromGeometries, |
127 const QRectF &toRect) |
88 const QRectF &toRect) |
128 { |
89 { |
129 QList<QRectF> toGeometries; |
90 QList<QRectF> toGeometries; |
130 // check if moving from landscape to portrait |
91 |
131 if ( fromRect.width() > fromRect.height() ) { |
92 // Portrait -> Landscape |
|
93 if (fromRect.width() < fromRect.height()) { |
132 foreach (QRectF g, fromGeometries) { |
94 foreach (QRectF g, fromGeometries) { |
133 QRectF leftHalf = QRectF(fromRect.x(), fromRect.y(), fromRect.width()/2, fromRect.height()); |
95 |
134 QPointF c(g.center()); |
96 QRectF tg(g.topLeft() - fromRect.topLeft(), g.size()); |
135 qreal x = 0; |
97 |
136 qreal y = 0; |
98 qreal x = tg.center().x() / fromRect.width(); |
137 if ( leftHalf.contains(c) ) { |
99 qreal y = tg.center().y() / (fromRect.height() / 2); |
138 x = qBound(toRect.left(), c.x(), toRect.right()); |
100 |
139 y = qBound(toRect.top(), c.y(), toRect.bottom()); |
101 if (y < 1) { |
|
102 x *= toRect.width() / 2; |
|
103 y *= toRect.height(); |
140 } else { |
104 } else { |
141 QRectF lowerHalf = QRectF(toRect.x(), toRect.y()+toRect.height()/2, toRect.width(), toRect.height()/2); |
105 x *= toRect.width() / 2; |
142 x = qBound(toRect.left(), c.x()-leftHalf.width(), toRect.right()); |
106 x += toRect.width() / 2; |
143 y = qBound(lowerHalf.top(), c.y()+leftHalf.height(), lowerHalf.bottom()); |
107 y -= 1; |
|
108 y *= toRect.height(); |
144 } |
109 } |
145 g.moveCenter(QPointF(x, y)); |
110 |
146 toGeometries << g; |
111 x = qBound(g.width() / 2, x, toRect.width() - g.width() / 2); |
|
112 y = qBound(g.height() / 2, y, toRect.height() - g.height() / 2); |
|
113 |
|
114 g.moveCenter(QPointF(x, y) + toRect.topLeft()); |
|
115 |
|
116 toGeometries.append(g); |
147 } |
117 } |
148 } |
118 } else { // Landscape -> Portrait |
149 else { // moving from portrait to landscape |
|
150 foreach (QRectF g, fromGeometries) { |
119 foreach (QRectF g, fromGeometries) { |
151 QRectF upperHalf = QRectF(fromRect.x(), fromRect.y(), fromRect.width(), fromRect.height()/2); |
120 |
152 QPointF c(g.center()); |
121 QRectF tg(g.topLeft() - fromRect.topLeft(), g.size()); |
153 qreal x = 0; |
122 |
154 qreal y = 0; |
123 qreal x = tg.center().x() / (fromRect.width() / 2); |
155 if ( upperHalf.contains(c) ) { |
124 qreal y = tg.center().y() / fromRect.height(); |
156 x = qBound(toRect.left(), c.x(), toRect.right()); |
125 |
157 y = qBound(toRect.top(), c.y(), toRect.bottom()); |
126 if (x < 1) { |
|
127 x *= toRect.width(); |
|
128 y *= toRect.height() / 2; |
158 } else { |
129 } else { |
159 QRectF rightHalf = QRectF(toRect.x()+toRect.width()/2, toRect.y(), toRect.width()/2, toRect.height()); |
130 x -= 1; |
160 x = qBound(rightHalf.left(), c.x()+rightHalf.width(), rightHalf.right()); |
131 x += toRect.width(); |
161 y = qBound(toRect.top(), c.y()-upperHalf.height(), toRect.bottom()); |
132 y *= toRect.height() / 2; |
|
133 y += toRect.height() / 2; |
162 } |
134 } |
163 g.moveCenter(QPointF(x, y)); |
135 |
164 toGeometries << g; |
136 x = qBound(g.width() / 2, x, toRect.width() - g.width() / 2); |
|
137 y = qBound(g.height() / 2, y, toRect.height() - g.height() / 2); |
|
138 |
|
139 g.moveCenter(QPointF(x, y) + toRect.topLeft()); |
|
140 |
|
141 toGeometries.append(g); |
165 } |
142 } |
166 } |
143 } |
167 |
144 |
168 return toGeometries; |
145 return toGeometries; |
169 } |
146 } |
170 |
|
171 /*! |
|
172 \class HsRelativePositionWidgetPositioningOnOrientationChange |
|
173 \brief More advanced widget positioning algorithm. |
|
174 |
|
175 Calculates new center points of |
|
176 \a fromGeometries when moving from \a fromRect to \a toRect. |
|
177 It calculates widget's relative position on the screen and then calculates new position on the target rect: |
|
178 \verbatim |
|
179 w |
|
180 ------- |
|
181 | A | |
|
182 |(x,y)| h |
|
183 | | |
|
184 | | |
|
185 ------- |
|
186 \endverbatim |
|
187 \verbatim |
|
188 w' |
|
189 |----------| |
|
190 |A'(x',y') | h' |
|
191 |----------| |
|
192 \endverbatim |
|
193 A(x,y) -> A'(x',y') where x'=x*w'/w and y'=y*h'/h and w=width of original rect and h=height of original rect and |
|
194 w'=width of target rect and h=height of target rect. |
|
195 */ |
|
196 #ifdef COVERAGE_MEASUREMENT |
|
197 #pragma CTC SKIP |
|
198 #endif //COVERAGE_MEASUREMENT |
|
199 QList<QRectF> HsRelativePositionWidgetPositioningOnOrientationChange::convert( |
|
200 const QRectF &fromRect, |
|
201 const QList<QRectF> &fromGeometries, |
|
202 const QRectF &toRect) |
|
203 { |
|
204 qreal xTransformation = toRect.width()/fromRect.width(); |
|
205 qreal yTransformation= toRect.height()/fromRect.height(); |
|
206 QList<QRectF> toGeometries; |
|
207 foreach (QRectF g, fromGeometries) { |
|
208 QPointF c(g.center()); |
|
209 qreal x = qBound(toRect.left(), c.x()*xTransformation, toRect.right()); |
|
210 qreal y = qBound(toRect.top(), c.y()*yTransformation, toRect.bottom()); |
|
211 g.moveCenter(QPointF(x, y)); |
|
212 toGeometries << g; |
|
213 } |
|
214 return toGeometries; |
|
215 } |
|
216 #ifdef COVERAGE_MEASUREMENT |
|
217 #pragma CTC ENDSKIP |
|
218 #endif //COVERAGE_MEASUREMENT |
|
219 |
|
220 |
|
221 /*! |
|
222 \class HsKeepCornerPositionWidgetPositioningOnOrientationChange |
|
223 \brief More advanced widget positioning algorithm. |
|
224 |
|
225 Calculates new center points of |
|
226 \a fromGeometries when moving from \a fromRect to \a toRect. |
|
227 It checks if left or right edge is closer to widget's center and keeps that distance same on the target rect. |
|
228 And same with upper and lower edges. |
|
229 \verbatim |
|
230 w |
|
231 ------- |
|
232 | A | |
|
233 |(x,y)| h |
|
234 | | |
|
235 | | |
|
236 ------- |
|
237 \endverbatim |
|
238 \verbatim |
|
239 w' |
|
240 |----------| |
|
241 |A'(x',y') | h' |
|
242 |----------| |
|
243 \endverbatim |
|
244 */ |
|
245 #ifdef COVERAGE_MEASUREMENT |
|
246 #pragma CTC SKIP |
|
247 #endif //COVERAGE_MEASUREMENT |
|
248 QList<QRectF> HsKeepCornerPositionWidgetPositioningOnOrientationChange::convert( |
|
249 const QRectF &fromRect, |
|
250 const QList<QRectF> &fromGeometries, |
|
251 const QRectF &toRect) |
|
252 { |
|
253 QList<QRectF> toGeometries; |
|
254 foreach (QRectF g, fromGeometries) { |
|
255 QPointF c(g.center()); |
|
256 qreal x = 0; |
|
257 qreal y = 0; |
|
258 if ( c.x()-fromRect.x() < fromRect.right() - c.x() ) { |
|
259 x = qBound(toRect.left(), c.x(), toRect.right()); |
|
260 } |
|
261 else { |
|
262 x = qBound(toRect.left(), toRect.right() - fromRect.right() + c.x(), toRect.right()); |
|
263 } |
|
264 if ( c.y()-fromRect.y() < fromRect.bottom() - c.y() ) { |
|
265 y = qBound(toRect.top(), c.y(), toRect.bottom()); |
|
266 } |
|
267 else { |
|
268 y = qBound(toRect.top(), toRect.bottom() - fromRect.bottom() + c.y(), toRect.bottom()); |
|
269 } |
|
270 g.moveCenter(QPointF(x, y)); |
|
271 toGeometries << g; |
|
272 } |
|
273 return toGeometries; |
|
274 } |
|
275 #ifdef COVERAGE_MEASUREMENT |
|
276 #pragma CTC ENDSKIP |
|
277 #endif //COVERAGE_MEASUREMENT |
|