|
1 /* |
|
2 * Copyright (c) 2009 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 HSWIDGETPOSITIONINGONWIDGETMOVE_H |
|
19 #define HSWIDGETPOSITIONINGONWIDGETMOVE_H |
|
20 |
|
21 #include <QVariantHash> |
|
22 #include <QList> |
|
23 #include <QRectF> |
|
24 #include <QPointF> |
|
25 #include <QLineF> |
|
26 |
|
27 #include "hsutils_global.h" |
|
28 #include "hstest_global.h" |
|
29 |
|
30 HOMESCREEN_TEST_CLASS(t_hsUtils) |
|
31 |
|
32 class HSUTILS_EXPORT HsWidgetPositioningOnWidgetMove |
|
33 { |
|
34 public: |
|
35 class Result |
|
36 { |
|
37 public: |
|
38 Result() : hasHorizontalSnap(false), hasVerticalSnap(false), |
|
39 horizontalSnapPosition(0.0), verticalSnapPosition(0.0) |
|
40 { } |
|
41 bool isNull() const |
|
42 { return !hasHorizontalSnap && !hasVerticalSnap; } |
|
43 |
|
44 bool hasHorizontalSnap; |
|
45 bool hasVerticalSnap; |
|
46 qreal horizontalSnapPosition; |
|
47 qreal verticalSnapPosition; |
|
48 QLineF verticalSnapLine; |
|
49 QLineF horizontalSnapLine; |
|
50 }; |
|
51 |
|
52 virtual ~HsWidgetPositioningOnWidgetMove() {} |
|
53 |
|
54 virtual void setConfiguration(const QVariantHash &configuration) = 0; |
|
55 |
|
56 virtual void setPagePresentation(const QRectF &containerRect, |
|
57 const QList<QRectF> &inactiveRects, |
|
58 const QRectF &activeRect) = 0; |
|
59 |
|
60 virtual Result run(const QRectF &movingRect) = 0; |
|
61 |
|
62 static void setInstance(HsWidgetPositioningOnWidgetMove *instance); |
|
63 static HsWidgetPositioningOnWidgetMove *instance(); |
|
64 |
|
65 private: |
|
66 static HsWidgetPositioningOnWidgetMove *mInstance; |
|
67 }; |
|
68 |
|
69 class HsSnapRectangle |
|
70 { |
|
71 public: |
|
72 HsSnapRectangle() : rectangle(QRectF()) |
|
73 { } |
|
74 HsSnapRectangle(QRectF rect) : rectangle(rect), isLeftSnapableForAbove(true), isLeftSnapableForBelow(true), |
|
75 isRightSnapableForAbove(true), isRightSnapableForBelow(true), |
|
76 isTopSnapableForLeft(true), isTopSnapableForRight(true), |
|
77 isBottomSnapableForLeft(true), isBottomSnapableForRight(true) |
|
78 { } |
|
79 |
|
80 QRectF rectangle; |
|
81 bool isLeftSnapableForAbove; |
|
82 bool isLeftSnapableForBelow; |
|
83 bool isRightSnapableForAbove; |
|
84 bool isRightSnapableForBelow; |
|
85 bool isTopSnapableForLeft; |
|
86 bool isTopSnapableForRight; |
|
87 bool isBottomSnapableForLeft; |
|
88 bool isBottomSnapableForRight; |
|
89 }; |
|
90 |
|
91 class HSUTILS_EXPORT HsSnapToLines : public HsWidgetPositioningOnWidgetMove |
|
92 { |
|
93 public: |
|
94 HsSnapToLines(); |
|
95 |
|
96 void setConfiguration(const QVariantHash &configuration); |
|
97 |
|
98 void setPagePresentation(const QRectF &containerRect, |
|
99 const QList<QRectF> &inactiveRects, |
|
100 const QRectF &activeRect); |
|
101 |
|
102 Result run(const QRectF &movingRect); |
|
103 private: |
|
104 |
|
105 void createSnappableRectangles(const QList<QRectF> &inactiveRects); |
|
106 void checkForCenterSnapping(); |
|
107 void checkInactiveRectLieAboveOrBelowOfMovingRect(); |
|
108 void compareLeftSideOfMovingRectForSnapping(); |
|
109 void compareRightSideOfMovingRectForSnapping(); |
|
110 void checkInactiveRectLieLeftOrRightOfMovingRect(); |
|
111 void compareTopOfMovingRectForSnapping(); |
|
112 void compareBottomOfMovingRectForSnapping(); |
|
113 void extendVerticalLine(); |
|
114 void extendHorizontalLine(); |
|
115 void checkInactiveRectPositionToVerticalLine(); |
|
116 void extendVerticalLineToIncludeInactiveRect(); |
|
117 void checkInactiveRectPositionToHorizontalLine(); |
|
118 void extendHorizontalLineToIncludeInactiveRect(); |
|
119 |
|
120 private: //data |
|
121 QRectF mContainerRect; |
|
122 |
|
123 qreal mActiveRectWidth; |
|
124 qreal mActiveRectHeight; |
|
125 |
|
126 QList<HsSnapRectangle> mInactiveSnapRects; |
|
127 |
|
128 QRectF mInactiveRectToCompare; |
|
129 HsSnapRectangle mInactiveSnapRectToCompare; |
|
130 QRectF mMovingRect; |
|
131 qreal mHorizontalSnapPosition; |
|
132 qreal mVerticalSnapPosition; |
|
133 |
|
134 bool mHorizontalSnapFound; |
|
135 QLineF mVerticalLine; |
|
136 |
|
137 bool mVerticalSnapFound; |
|
138 QLineF mHorizontalLine; |
|
139 |
|
140 bool mRectLieAbove; |
|
141 bool mLeftInRange; |
|
142 bool mRightInRange; |
|
143 qreal mMinVerticalEdgesDistance; |
|
144 qreal mVerticalDistance; |
|
145 qreal mVerticalDistanceFromSelectedRect; |
|
146 qreal mContainerVerticalEdgeDistance; |
|
147 |
|
148 bool mRectLieLeft; |
|
149 bool mTopInRange; |
|
150 bool mBottomInRange; |
|
151 qreal mMinHorizontalEdgesDistance; |
|
152 qreal mHorizontalDistance; |
|
153 qreal mHorizontalDistanceFromSelectedRect; |
|
154 qreal mContainerHorizontalEdgeDistance; |
|
155 |
|
156 bool mSnapEnabled; |
|
157 qreal mSnapForce; |
|
158 qreal mSnapGap; |
|
159 qreal mSnapBorderGap; |
|
160 |
|
161 bool mRectVerticalEdgeLiesInLineWithVerticalLine; |
|
162 bool mRectLieAboveVerticalLine; |
|
163 bool mRectLieBelowVerticalLine; |
|
164 |
|
165 bool mRectHorizontalEdgeLiesInLineWithHorizontalLine; |
|
166 bool mRectLieLeftOfHorizontalLine; |
|
167 bool mRectLiesRightOfHorizontalLine; |
|
168 |
|
169 HOMESCREEN_TEST_FRIEND_CLASS(t_hsUtils) |
|
170 }; |
|
171 |
|
172 #endif // HSWIDGETPOSITIONINGONWIDGETMOVE_H |