90
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#ifndef ONLY_MENU_TESTCASES
|
|
19 |
|
|
20 |
#include "t_hsutils.h"
|
|
21 |
#include "hsapp_defs.h"
|
|
22 |
|
|
23 |
#define SNAP_GAP_VALUE 6
|
|
24 |
#define SNAP_FORCE_VALUE 30
|
|
25 |
#define SNAP_ENABLED_VALUE true
|
|
26 |
#define SNAP_DISABLED_VALUE false
|
|
27 |
|
|
28 |
Q_DECLARE_METATYPE(QList<QRectF>)
|
|
29 |
Q_DECLARE_METATYPE(HsWidgetPositioningOnWidgetMove::Result)
|
|
30 |
|
|
31 |
void t_hsUtils::testWidgetPositioningOnWidgetMoveInstance()
|
|
32 |
{
|
|
33 |
QVERIFY(!HsWidgetPositioningOnWidgetMove::instance());
|
|
34 |
HsWidgetPositioningOnWidgetMove::setInstance(0);
|
|
35 |
QVERIFY(!HsWidgetPositioningOnWidgetMove::instance());
|
|
36 |
HsWidgetPositioningOnWidgetMove *snapToLines = new HsSnapToLines;
|
|
37 |
HsWidgetPositioningOnWidgetMove::setInstance(snapToLines);
|
|
38 |
QVERIFY(HsWidgetPositioningOnWidgetMove::instance() == snapToLines);
|
|
39 |
HsWidgetPositioningOnWidgetMove::setInstance(0);
|
|
40 |
QVERIFY(!HsWidgetPositioningOnWidgetMove::instance());
|
|
41 |
}
|
|
42 |
|
|
43 |
void t_hsUtils::testHsSnapToLinesConstruct()
|
|
44 |
{
|
|
45 |
HsSnapToLines *sl = new HsSnapToLines();
|
|
46 |
|
|
47 |
QVERIFY(sl->mContainerRect.isNull());
|
|
48 |
|
|
49 |
QVERIFY(qFuzzyCompare(sl->mActiveRectWidth, 0));
|
|
50 |
QVERIFY(qFuzzyCompare(sl->mActiveRectHeight, 0));
|
|
51 |
|
|
52 |
QVERIFY(sl->mInactiveSnapRects.isEmpty());
|
|
53 |
|
|
54 |
QVERIFY(sl->mInactiveRectToCompare.isNull());
|
|
55 |
|
|
56 |
QVERIFY(sl->mInactiveSnapRectToCompare.rectangle.isNull());
|
|
57 |
QVERIFY(sl->mMovingRect.isNull());
|
|
58 |
|
|
59 |
QVERIFY(qFuzzyCompare(sl->mMinDistancePosition, 0));
|
|
60 |
QVERIFY(qFuzzyCompare(sl->mHorizontalSnapPosition, 0));
|
|
61 |
QVERIFY(qFuzzyCompare(sl->mVerticalSnapPosition, 0));
|
|
62 |
|
|
63 |
QVERIFY(!sl->mHorizontalSnapFound);
|
|
64 |
QVERIFY(sl->mVerticalLine.isNull());
|
|
65 |
|
|
66 |
QVERIFY(!sl->mVerticalSnapFound);
|
|
67 |
QVERIFY(sl->mHorizontalLine.isNull());
|
|
68 |
|
|
69 |
QVERIFY(!sl->mRectLieAbove);
|
|
70 |
QVERIFY(!sl->mLeftInRange);
|
|
71 |
QVERIFY(!sl->mRightInRange);
|
|
72 |
QVERIFY(!sl->mIsBetterFitHorizontalSnap);
|
|
73 |
QVERIFY(qFuzzyCompare(sl->mDistanceVerticalEdges, 0));
|
|
74 |
QVERIFY(qFuzzyCompare(sl->mVerticalEdgeToLeftOfInactiveRect, 0));
|
|
75 |
QVERIFY(qFuzzyCompare(sl->mVerticalEdgeToRightOfInactiveRect, 0));
|
|
76 |
QVERIFY(qFuzzyCompare(sl->mMinVerticalEdgesDistance, 0));
|
|
77 |
QVERIFY(qFuzzyCompare(sl->mVerticalDistance, 0));
|
|
78 |
QVERIFY(qFuzzyCompare(sl->mVerticalDistanceFromSelectedRect, 0));
|
|
79 |
QVERIFY(qFuzzyCompare(sl->mContainerVerticalEdgeDistance, 0));
|
|
80 |
|
|
81 |
QVERIFY(!sl->mRectLieLeft);
|
|
82 |
QVERIFY(!sl->mTopInRange);
|
|
83 |
QVERIFY(!sl->mBottomInRange);
|
|
84 |
QVERIFY(!sl->mIsBetterFitVerticalSnap);
|
|
85 |
QVERIFY(qFuzzyCompare(sl->mDistanceHorizontalEdges, 0));
|
|
86 |
QVERIFY(qFuzzyCompare(sl->mHorizontalEdgeToTopOfInactiveRect, 0));
|
|
87 |
QVERIFY(qFuzzyCompare(sl->mHorizontalEdgeToBottomOfInactiveRect, 0));
|
|
88 |
QVERIFY(qFuzzyCompare(sl->mMinHorizontalEdgesDistance, 0));
|
|
89 |
QVERIFY(qFuzzyCompare(sl->mHorizontalDistance, 0));
|
|
90 |
QVERIFY(qFuzzyCompare(sl->mHorizontalDistanceFromSelectedRect, 0));
|
|
91 |
QVERIFY(qFuzzyCompare(sl->mContainerHorizontalEdgeDistance, 0));
|
|
92 |
|
|
93 |
QVERIFY(!sl->mSnapEnabled);
|
|
94 |
QVERIFY(qFuzzyCompare(sl->mSnapForce, 0));
|
|
95 |
QVERIFY(qFuzzyCompare(sl->mSnapGap, 0));
|
|
96 |
|
|
97 |
QVERIFY(!sl->mRectVerticalEdgeLiesInLineWithVerticalLine);
|
|
98 |
QVERIFY(!sl->mRectLieAboveVerticalLine);
|
|
99 |
QVERIFY(!sl->mRectLieBelowVerticalLine);
|
|
100 |
|
|
101 |
QVERIFY(!sl->mRectHorizontalEdgeLiesInLineWithHorizontalLine);
|
|
102 |
QVERIFY(!sl->mRectLieLeftOfHorizontalLine);
|
|
103 |
QVERIFY(!sl->mRectLiesRightOfHorizontalLine);
|
|
104 |
|
|
105 |
delete sl;
|
|
106 |
}
|
|
107 |
|
|
108 |
void t_hsUtils::testHsSnapToLines_data()
|
|
109 |
{
|
|
110 |
QTest::addColumn<QRectF>("containerArea");
|
|
111 |
QTest::addColumn<QList<QRectF> >("inActiveRects");
|
|
112 |
QTest::addColumn<QRectF>("activeRect");
|
|
113 |
QTest::addColumn<QRectF>("movingRect");
|
|
114 |
QTest::addColumn<HsWidgetPositioningOnWidgetMove::Result>("expectedResult");
|
|
115 |
|
|
116 |
{
|
|
117 |
QTest::newRow("widgetOverlap")
|
|
118 |
<< QRectF(0, 0, 1000, 1000)
|
|
119 |
<< (QList<QRectF>() << QRectF(250, 250, 500, 500) << QRectF(200, 200, 100, 100) << QRectF(700, 200, 100, 100)
|
|
120 |
<< QRectF(700, 700, 100, 100) << QRectF(200, 700, 100, 100))
|
|
121 |
<< QRectF(0, 0, 800, 150)
|
|
122 |
<< QRectF(100, 100, 880, 165)
|
|
123 |
<< HsWidgetPositioningOnWidgetMove::Result();
|
|
124 |
}
|
|
125 |
|
|
126 |
{
|
|
127 |
QTest::newRow("oneWidgetOutOfSnapDistance")
|
|
128 |
<< QRectF(0, 0, 1000, 1000)
|
|
129 |
<< (QList<QRectF>())
|
|
130 |
<< QRectF(5, 5, 100, 100)
|
|
131 |
<< QRectF(3, 3, 110, 110)
|
|
132 |
<< HsWidgetPositioningOnWidgetMove::Result();
|
|
133 |
}
|
|
134 |
|
|
135 |
{
|
|
136 |
HsWidgetPositioningOnWidgetMove::Result snapResultCenter;
|
|
137 |
QTest::newRow("oneWidgetInCenterWithoutSnapping")
|
|
138 |
<< QRectF(0, 0, 1000, 1000)
|
|
139 |
<< (QList<QRectF>())
|
|
140 |
<< QRectF(5, 5, 200, 200)
|
|
141 |
<< QRectF(390, 390, 200, 200)
|
|
142 |
<< snapResultCenter;
|
|
143 |
}
|
|
144 |
|
|
145 |
{
|
|
146 |
//Data for snapping to Left Edge of Inactive Rectangle.
|
|
147 |
HsWidgetPositioningOnWidgetMove::Result snapResultLeftEdge;
|
|
148 |
snapResultLeftEdge.hasHorizontalSnap = true;
|
|
149 |
snapResultLeftEdge.horizontalSnapPosition = 100;
|
|
150 |
snapResultLeftEdge.verticalSnapLine = QLineF(100, 90, 100, 610);
|
|
151 |
QTest::newRow("snapToLeftEdgeOfInactiveRect")
|
|
152 |
<< QRectF(0, 0, 1000, 1000)
|
|
153 |
<< (QList<QRectF>() << QRectF(100, 100, 100, 100) << QRectF(175, 75, 100, 150))
|
|
154 |
<< QRectF(0, 0, 500, 100)
|
|
155 |
<< QRectF(110, 500, 500, 100)
|
|
156 |
<< snapResultLeftEdge;
|
|
157 |
}
|
|
158 |
|
|
159 |
{
|
|
160 |
//Data for snapping to Left Edge of Inactive Rectangle,
|
|
161 |
//one inactive rectangle lies below the moving rectangle
|
|
162 |
//one inactive rectangle lies above the moving rectangle. This rectangle does not offer big enough space for moving rectangle's width
|
|
163 |
HsWidgetPositioningOnWidgetMove::Result snapResultLeftEdgeBelowRect;
|
|
164 |
snapResultLeftEdgeBelowRect.hasHorizontalSnap = true;
|
|
165 |
snapResultLeftEdgeBelowRect.horizontalSnapPosition = 10 - SNAP_GAP_VALUE;
|
|
166 |
snapResultLeftEdgeBelowRect.verticalSnapLine = QLineF(560, 910, 560, 390);
|
|
167 |
QTest::newRow("snapToLeftEdgeOfInactiveRectWhichLiesBelow")
|
|
168 |
<< QRectF(0, 0, 1000, 1000)
|
|
169 |
<< (QList<QRectF>() << QRectF(550, 200, 200, 150) << QRectF(560, 800, 200, 100))
|
|
170 |
<< QRectF(5, 0, 550, 100)
|
|
171 |
<< QRectF(5, 400, 550, 100)
|
|
172 |
<< snapResultLeftEdgeBelowRect;
|
|
173 |
}
|
|
174 |
|
|
175 |
{
|
|
176 |
//Data for snapping to Left Edge of Inactive Rectangle.
|
|
177 |
//The data is similar to one above, except that the rectangle can fit into the space now.
|
|
178 |
HsWidgetPositioningOnWidgetMove::Result snapResultLeftEdgeRectLiesAbove;
|
|
179 |
snapResultLeftEdgeRectLiesAbove.hasHorizontalSnap = true;
|
|
180 |
snapResultLeftEdgeRectLiesAbove.horizontalSnapPosition = 50 - SNAP_GAP_VALUE;
|
|
181 |
snapResultLeftEdgeRectLiesAbove.verticalSnapLine = QLineF(550, 510, 550, 190);
|
|
182 |
QTest::newRow("snapToLeftEdgeOfInactiveRectWhichLiesAbove")
|
|
183 |
<< QRectF(0, 0, 1000, 1000)
|
|
184 |
<< (QList<QRectF>() << QRectF(560, 800, 200, 100) << QRectF(550, 200, 200, 150))
|
|
185 |
<< QRectF(5, 0, 500, 100)
|
|
186 |
<< QRectF(55, 400, 500, 100)
|
|
187 |
<< snapResultLeftEdgeRectLiesAbove;
|
|
188 |
}
|
|
189 |
|
|
190 |
{
|
|
191 |
//Data for snapping to the left Edge of Inactive rect which are already alligned
|
|
192 |
//and the bottom of already alligned widgets on the bottom
|
|
193 |
HsWidgetPositioningOnWidgetMove::Result snapResultRectsAllignedOnLeftAndBottom;
|
|
194 |
snapResultRectsAllignedOnLeftAndBottom.hasHorizontalSnap = true;
|
|
195 |
snapResultRectsAllignedOnLeftAndBottom.horizontalSnapPosition = 100;
|
|
196 |
snapResultRectsAllignedOnLeftAndBottom.verticalSnapLine = QLineF(100, 910, 100, 90);
|
|
197 |
snapResultRectsAllignedOnLeftAndBottom.hasVerticalSnap = true;
|
|
198 |
snapResultRectsAllignedOnLeftAndBottom.verticalSnapPosition = 820; //The width of the rectangle is 90
|
|
199 |
snapResultRectsAllignedOnLeftAndBottom.horizontalSnapLine = QLineF(80, 910, 910, 910);
|
|
200 |
QTest::newRow("snapToLeftAndBottomEdgeOfTwoAllignedRects")
|
|
201 |
<< QRectF(0, 0, 1000, 1000)
|
|
202 |
<< (QList<QRectF>() << QRectF(100, 400, 150, 125) << QRectF(100, 100, 100, 100) << QRectF(450, 820, 100, 90) << QRectF(750, 750, 150, 160))
|
|
203 |
<< QRectF(50, 750, 100, 90)
|
|
204 |
<< QRectF(90, 800, 120, 100)
|
|
205 |
<< snapResultRectsAllignedOnLeftAndBottom;
|
|
206 |
}
|
|
207 |
|
|
208 |
{
|
|
209 |
//Data for snapping to the Right side of already alligned widgets on the right side
|
|
210 |
//and top of already alligned widgets
|
|
211 |
HsWidgetPositioningOnWidgetMove::Result snapResultRectsAllignedOnRightAndTop;
|
|
212 |
snapResultRectsAllignedOnRightAndTop.hasHorizontalSnap = true;
|
|
213 |
snapResultRectsAllignedOnRightAndTop.horizontalSnapPosition = 540;
|
|
214 |
snapResultRectsAllignedOnRightAndTop.verticalSnapLine = QLineF(600, 60, 600, 910);
|
|
215 |
snapResultRectsAllignedOnRightAndTop.hasVerticalSnap = true;
|
|
216 |
snapResultRectsAllignedOnRightAndTop.verticalSnapPosition = 50;
|
|
217 |
snapResultRectsAllignedOnRightAndTop.horizontalSnapLine = QLineF(40, 50, 620, 50);
|
|
218 |
QTest::newRow("snapToRightAndTopEdgeOfTwoAllignedRects")
|
|
219 |
<< QRectF(0, 0, 1000, 1000)
|
|
220 |
<< (QList<QRectF>() << QRectF(300, 50, 50, 300) << QRectF(500, 500, 100, 100) << QRectF(50, 50, 150, 150) << QRectF(400, 800, 200, 100))
|
|
221 |
<< QRectF(500, 50, 60, 100)
|
|
222 |
<< QRectF(550, 70, 60, 100)
|
|
223 |
<< snapResultRectsAllignedOnRightAndTop;
|
|
224 |
}
|
|
225 |
|
|
226 |
{
|
|
227 |
//Data for snapping to the left Edge of one Inactive rect and top edge of another Inactive rect
|
|
228 |
//distance of both edges of the rectangle are at the same distance from the edge under comparison
|
|
229 |
HsWidgetPositioningOnWidgetMove::Result snapResultSameDistanceToMovingEdgesSnapToLeftAndTopEdge;
|
|
230 |
snapResultSameDistanceToMovingEdgesSnapToLeftAndTopEdge.hasHorizontalSnap = true;
|
|
231 |
snapResultSameDistanceToMovingEdgesSnapToLeftAndTopEdge.horizontalSnapPosition = 100;
|
|
232 |
snapResultSameDistanceToMovingEdgesSnapToLeftAndTopEdge.verticalSnapLine = QLineF(100, 450, 100, 90);
|
|
233 |
snapResultSameDistanceToMovingEdgesSnapToLeftAndTopEdge.hasVerticalSnap = true;
|
|
234 |
snapResultSameDistanceToMovingEdgesSnapToLeftAndTopEdge.verticalSnapPosition = 380;
|
|
235 |
snapResultSameDistanceToMovingEdgesSnapToLeftAndTopEdge.horizontalSnapLine = QLineF(70, 380, 690, 380);
|
|
236 |
QTest::newRow("snapToLeftEdgeAndTopEdgeOfInactiveRectDistanceToMovingRectsEdgesSame")
|
|
237 |
<< QRectF(0, 0, 1000, 1000)
|
|
238 |
<< (QList<QRectF>() << QRectF(100, 100, 200, 100) << QRectF(600, 380, 80, 300))
|
|
239 |
<< QRectF(0, 0, 40, 40)
|
|
240 |
<< QRectF(80, 400, 40, 40)
|
|
241 |
<< snapResultSameDistanceToMovingEdgesSnapToLeftAndTopEdge;
|
|
242 |
}
|
|
243 |
|
|
244 |
{
|
|
245 |
//Data for snapping when the inactive widgets edges are equal distance from the Left and top edge of Moving Rect
|
|
246 |
HsWidgetPositioningOnWidgetMove::Result snapResultMovingRectLeftAndTopEdgeSameDistance;
|
|
247 |
snapResultMovingRectLeftAndTopEdgeSameDistance.hasHorizontalSnap = true;
|
|
248 |
snapResultMovingRectLeftAndTopEdgeSameDistance.horizontalSnapPosition = 80;
|
|
249 |
snapResultMovingRectLeftAndTopEdgeSameDistance.verticalSnapLine = QLineF(80, 90, 80, 450);
|
|
250 |
snapResultMovingRectLeftAndTopEdgeSameDistance.hasVerticalSnap = true;
|
|
251 |
snapResultMovingRectLeftAndTopEdgeSameDistance.verticalSnapPosition = 80;
|
|
252 |
snapResultMovingRectLeftAndTopEdgeSameDistance.horizontalSnapLine = QLineF(90, 80, 450, 80);
|
|
253 |
QTest::newRow("movingRectsLeftAndtopEdgeAreEqualDistanceFromInactiveRectsEdges")
|
|
254 |
<< QRectF(0, 0, 1000, 1000)
|
|
255 |
<< (QList<QRectF>() << QRectF(280, 400, 40, 40) << QRectF(80, 400, 40, 40) << QRectF(400, 180, 40, 40) << QRectF(400, 80, 40, 40))
|
|
256 |
<< QRectF(50, 50, 200, 100)
|
|
257 |
<< QRectF(100, 100, 200, 100)
|
|
258 |
<< snapResultMovingRectLeftAndTopEdgeSameDistance;
|
|
259 |
}
|
|
260 |
|
|
261 |
{
|
|
262 |
//Data for snapping the Right and Bootom edge of moving rect which are equal distance from Inactive rects edges
|
|
263 |
HsWidgetPositioningOnWidgetMove::Result snapResultMovingRectRightAndBottomEdgeSameDistance;
|
|
264 |
snapResultMovingRectRightAndBottomEdgeSameDistance.hasHorizontalSnap = true;
|
|
265 |
snapResultMovingRectRightAndBottomEdgeSameDistance.horizontalSnapPosition = 690;
|
|
266 |
snapResultMovingRectRightAndBottomEdgeSameDistance.verticalSnapLine = QLineF(840, 190, 840, 950);
|
|
267 |
snapResultMovingRectRightAndBottomEdgeSameDistance.hasVerticalSnap = true;
|
|
268 |
snapResultMovingRectRightAndBottomEdgeSameDistance.verticalSnapPosition = 710;
|
|
269 |
snapResultMovingRectRightAndBottomEdgeSameDistance.horizontalSnapLine = QLineF(190, 860, 860, 860);
|
|
270 |
QTest::newRow("movingRectsRightAndBottomEdgeAreEqualDistanceFromInactiveRectsEdges")
|
|
271 |
<< QRectF(0, 0, 1000, 1000)
|
|
272 |
<< (QList<QRectF>() << QRectF(680, 200, 40, 40) << QRectF(800, 200, 40, 40) << QRectF(800, 900, 40, 40)
|
|
273 |
<< QRectF(200, 670, 40, 40) << QRectF(200, 820, 40, 40))
|
|
274 |
<< QRectF(650, 640, 150, 150)
|
|
275 |
<< QRectF(700, 690, 150, 150)
|
|
276 |
<< snapResultMovingRectRightAndBottomEdgeSameDistance;
|
|
277 |
}
|
|
278 |
|
|
279 |
{
|
|
280 |
//Data for snapping to Right Edge of Inactive Rectangle, inactive rect lies above the Moving rect,
|
|
281 |
//distance of moving rect's right edge from the inactive widget's right edge is equal to
|
|
282 |
//the distance of moving widget's left edge from the inactive widget's left edge.
|
|
283 |
HsWidgetPositioningOnWidgetMove::Result snapResultRightEdge;
|
|
284 |
snapResultRightEdge.hasHorizontalSnap = true;
|
|
285 |
snapResultRightEdge.horizontalSnapPosition = 200;
|
|
286 |
snapResultRightEdge.verticalSnapLine = QLineF(900, 90, 900, 610);
|
|
287 |
QTest::newRow("snapToRightEdgeOfInactiveRect")
|
|
288 |
<< QRectF(0, 0, 1000, 1000)
|
|
289 |
<< (QList<QRectF>() << QRectF(725, 75, 100, 150) << QRectF(800, 100, 100, 100))
|
|
290 |
<< QRectF(225, 500, 700, 100)
|
|
291 |
<< QRectF(225, 500, 700, 100)
|
|
292 |
<< snapResultRightEdge;
|
|
293 |
}
|
|
294 |
|
|
295 |
{
|
|
296 |
//Data for snapping to Top Edge of Inactive Rectangle.
|
|
297 |
HsWidgetPositioningOnWidgetMove::Result snapResultTopEdge;
|
|
298 |
snapResultTopEdge.hasVerticalSnap = true;
|
|
299 |
snapResultTopEdge.verticalSnapPosition = 100;
|
|
300 |
snapResultTopEdge.horizontalSnapLine = QLineF(90, 100, 630, 100);
|
|
301 |
QTest::newRow("snapToTopEdgeOfInactiveRect")
|
|
302 |
<< QRectF(0, 0, 1000, 1000)
|
|
303 |
<< (QList<QRectF>() << QRectF(100, 100, 100, 100) << QRectF(75, 175, 150, 100) << QRectF(100, 600, 100, 100) << QRectF(75, 675, 150, 100))
|
|
304 |
<< QRectF(400, 120, 200, 400)
|
|
305 |
<< QRectF(400, 120, 220, 440)
|
|
306 |
<< snapResultTopEdge;
|
|
307 |
}
|
|
308 |
|
|
309 |
{
|
|
310 |
//Data for snapping to Bottom Edge of Inactive Rectangle.
|
|
311 |
HsWidgetPositioningOnWidgetMove::Result snapResultBottomEdge;
|
|
312 |
snapResultBottomEdge.hasVerticalSnap = true;
|
|
313 |
snapResultBottomEdge.verticalSnapPosition = 315;
|
|
314 |
snapResultBottomEdge.horizontalSnapLine = QLineF(65, 800, 855, 800);
|
|
315 |
QTest::newRow("snapToBottomEdgeOfInactiveRect")
|
|
316 |
<< QRectF(0, 0, 1000, 1000)
|
|
317 |
<< (QList<QRectF>() << QRectF(100, 100, 100, 100) << QRectF(75, 175, 150, 100) << QRectF(100, 600, 100, 100) << QRectF(75, 675, 150, 125))
|
|
318 |
<< QRectF(600, 300, 220, 485)
|
|
319 |
<< QRectF(625, 325, 220, 485)
|
|
320 |
<< snapResultBottomEdge;
|
|
321 |
}
|
|
322 |
|
|
323 |
}
|
|
324 |
|
|
325 |
void t_hsUtils::testHsSnapToLines()
|
|
326 |
{
|
|
327 |
QFETCH(QRectF, containerArea);
|
|
328 |
QFETCH(QList<QRectF>, inActiveRects);
|
|
329 |
QFETCH(QRectF, activeRect);
|
|
330 |
QFETCH(QRectF, movingRect);
|
|
331 |
QFETCH(HsWidgetPositioningOnWidgetMove::Result, expectedResult);
|
|
332 |
|
|
333 |
HsWidgetPositioningOnWidgetMove::setInstance(new HsSnapToLines);
|
|
334 |
|
|
335 |
QVariantHash snapConfiguration;
|
|
336 |
snapConfiguration[Hs::snapEnabled] = QString::number(SNAP_ENABLED_VALUE);
|
|
337 |
snapConfiguration[Hs::snapForce] = QString::number(SNAP_FORCE_VALUE);
|
|
338 |
snapConfiguration[Hs::snapGap] = QString::number(SNAP_GAP_VALUE);
|
|
339 |
|
|
340 |
HsWidgetPositioningOnWidgetMove::instance()->setConfiguration(snapConfiguration);
|
|
341 |
HsWidgetPositioningOnWidgetMove::instance()->setPagePresentation(containerArea, inActiveRects, activeRect);
|
|
342 |
HsWidgetPositioningOnWidgetMove::Result convertedResult = HsWidgetPositioningOnWidgetMove::instance()->run(movingRect);
|
|
343 |
|
|
344 |
QVERIFY(hsResultCompare(convertedResult, expectedResult));
|
|
345 |
}
|
|
346 |
|
|
347 |
void t_hsUtils::testHsSnapToLinesSnapDisabled_data()
|
|
348 |
{
|
|
349 |
QTest::addColumn<QRectF>("containerArea");
|
|
350 |
QTest::addColumn< QList<QRectF> >("inActiveRects");
|
|
351 |
QTest::addColumn<QRectF>("activeRect");
|
|
352 |
QTest::addColumn<QRectF>("movingRect");
|
|
353 |
QTest::addColumn<HsWidgetPositioningOnWidgetMove::Result>("expectedResult");
|
|
354 |
|
|
355 |
QTest::newRow("SnapDisabled")
|
|
356 |
<< QRectF(0, 0, 1000, 1000)
|
|
357 |
<< (QList<QRectF>())
|
|
358 |
<< QRectF(5, 5, 200, 200)
|
|
359 |
<< QRectF(380, 380, 200, 200)
|
|
360 |
<< HsWidgetPositioningOnWidgetMove::Result();
|
|
361 |
}
|
|
362 |
|
|
363 |
void t_hsUtils::testHsSnapToLinesSnapDisabled()
|
|
364 |
{
|
|
365 |
QFETCH(QRectF, containerArea);
|
|
366 |
QFETCH(QList<QRectF>, inActiveRects);
|
|
367 |
QFETCH(QRectF, activeRect);
|
|
368 |
QFETCH(QRectF, movingRect);
|
|
369 |
QFETCH(HsWidgetPositioningOnWidgetMove::Result, expectedResult);
|
|
370 |
|
|
371 |
HsWidgetPositioningOnWidgetMove::setInstance(new HsSnapToLines);
|
|
372 |
|
|
373 |
QVariantHash snapConfiguration;
|
|
374 |
snapConfiguration[Hs::snapEnabled] = QString::number(SNAP_DISABLED_VALUE);
|
|
375 |
|
|
376 |
HsWidgetPositioningOnWidgetMove::instance()->setConfiguration(snapConfiguration);
|
|
377 |
HsWidgetPositioningOnWidgetMove::instance()->setPagePresentation(containerArea, inActiveRects, activeRect);
|
|
378 |
HsWidgetPositioningOnWidgetMove::Result convertedResult = HsWidgetPositioningOnWidgetMove::instance()->run(movingRect);
|
|
379 |
|
|
380 |
QVERIFY(hsResultCompare(convertedResult, expectedResult));
|
|
381 |
}
|
|
382 |
|
|
383 |
bool t_hsUtils::hsLineCompare(QLineF l1, QLineF l2)
|
|
384 |
{
|
|
385 |
if ((l1.p1() == l2.p1() || l1.p1() == l2.p2())
|
|
386 |
&& (l1.p2() == l2.p1() || l1.p2() == l2.p2())) {
|
|
387 |
return true;
|
|
388 |
}
|
|
389 |
else {
|
|
390 |
return false;
|
|
391 |
}
|
|
392 |
}
|
|
393 |
|
|
394 |
bool t_hsUtils::hsResultCompare(const HsWidgetPositioningOnWidgetMove::Result& sr1, const HsWidgetPositioningOnWidgetMove::Result& sr2)
|
|
395 |
{
|
|
396 |
bool resultsAreSame = false;
|
|
397 |
bool horizontalLinesSame = false;
|
|
398 |
bool verticalLinesSame = false;
|
|
399 |
|
|
400 |
qDebug() << "Converted Result = " <<sr1.hasHorizontalSnap <<sr1.horizontalSnapPosition<<sr1.hasVerticalSnap<<sr1.verticalSnapPosition;
|
|
401 |
qDebug() << "Expectted Result = " <<sr2.hasHorizontalSnap <<sr2.horizontalSnapPosition<<sr2.hasVerticalSnap<<sr2.verticalSnapPosition;
|
|
402 |
|
|
403 |
if ((sr1.hasHorizontalSnap == sr2.hasHorizontalSnap)
|
|
404 |
&& (sr1.horizontalSnapPosition == sr2.horizontalSnapPosition)
|
|
405 |
&& (sr1.hasVerticalSnap == sr2.hasVerticalSnap)
|
|
406 |
&& (sr1.verticalSnapPosition == sr2.verticalSnapPosition)) {
|
|
407 |
//Check if Horizontal Snap Position Exists and compare the vertical line
|
|
408 |
if (sr1.hasHorizontalSnap) {
|
|
409 |
QLineF l1 = sr1.verticalSnapLine;
|
|
410 |
QLineF l2 = sr2.verticalSnapLine;
|
|
411 |
verticalLinesSame = hsLineCompare(l1, l2);
|
|
412 |
qDebug() << "Converted Vertical Line = " << l1.x1() << l1.y1() << l1.x2() << l1.y2();
|
|
413 |
qDebug() << "Expected Vertical Line = " << l2.x1() << l2.y1() << l2.x2() << l2.y2();
|
|
414 |
qDebug() << "Vertical lines are same = " << verticalLinesSame;
|
|
415 |
}
|
|
416 |
else {
|
|
417 |
verticalLinesSame = true;
|
|
418 |
}
|
|
419 |
|
|
420 |
//Check if Vertical Snap Position Exists and compare the horizontal line
|
|
421 |
if (sr1.hasVerticalSnap) {
|
|
422 |
QLineF l1 = sr1.horizontalSnapLine;
|
|
423 |
QLineF l2 = sr2.horizontalSnapLine;
|
|
424 |
horizontalLinesSame = hsLineCompare(l1, l2);
|
|
425 |
qDebug() << "Converted Horizontal Line = " << l1.x1() << l1.y1() << l1.x2() << l1.y2();
|
|
426 |
qDebug() << "Expected Horizontal Line = " << l2.x1() << l2.y1() << l2.x2() << l2.y2();
|
|
427 |
qDebug() << "Horizontal lines are same = " << horizontalLinesSame;
|
|
428 |
}
|
|
429 |
else {
|
|
430 |
horizontalLinesSame = true;
|
|
431 |
}
|
|
432 |
|
|
433 |
if (horizontalLinesSame && verticalLinesSame) {
|
|
434 |
resultsAreSame = true;
|
|
435 |
}
|
|
436 |
}
|
|
437 |
|
|
438 |
if ( !resultsAreSame) {
|
|
439 |
qDebug() << "results are not the same!!!";
|
|
440 |
}
|
|
441 |
return resultsAreSame;
|
|
442 |
}
|
|
443 |
#endif
|