LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dimensionsglobal.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef DIMENSIONSGLOBAL_H_
23 #define DIMENSIONSGLOBAL_H_
24 
25 #include <qglobal.h>
26 #include <qmath.h>
27 #include <QRectF>
28 #include <QPoint>
29 #include <QPointF>
30 #include <QUuid>
31 #include <QHash>
32 #include <QVariantMap>
33 
34 class QStateMachine;
35 class QState;
36 class QGraphicsScene;
37 
38 namespace DimensionsGlobal
39 {
40 
41 namespace RectCornerName
42 {
43  enum Enum
44  {
49  };
50 }
51 namespace RectPointName
52 {
53  enum Enum
54  {
64  };
65 }
66 
67 qreal roundDownF(qreal v);
68 qint32 roundDown(qreal v);
69 qreal roundUpF(qreal v);
70 qint32 roundUp(qreal v);
71 bool isZeroF(qreal v);
72 
73 qint32 Even(qint32 v);
74 quint32 Even(quint32 v);
75 
76 quint32 approximateDistance(const QPoint& p1,const QPoint& p2);
77 quint32 approximateDistance(const QPointF& pf1,const QPointF& pf2);
78 
79 qint32 realAsPixelPosition(const qreal v);
80 qint32 realAsPixelSize(const qreal v);
81 QPoint realPointAsPixelPosition(const QPointF& p);
82 QPoint realPointAsPixelSize(const QPointF& p);
83 QRectF realRectToPixelCompatibleForm(const QRectF& rect);
84 
85 QPointF positionFromSizeF(const QSizeF& s);
86 QPointF positionFromSize(const QSize& s);
87 QPointF positionFromFraction(const QPointF& basePoint,
88  const QSizeF& distance,const qreal xFractional, const qreal yFractional);
89 //returns the point that is the center, if "origin" passed in is the assumed top-left
90 // this is essentially a convenience function of positionFromFraction()
91 QPointF reoriginTopLeftToCenter(const QPointF& origin,const QSizeF& size);
92 //and this one is the opposite
93 QPointF reoriginCenterTopLeft(const QPointF& origin,const QSizeF& size);
94 
95 //REPOSITIONING HELPERS - unlike most of the other functions here, these DO NOT "fix" real values
96 // to be consistent with screen/pixel coordinates.
97 QPointF realPointOnRectF(const QRectF&,RectPointName::Enum pointName);
98 QRectF moveRectFcopy(const QRectF& rect,const QPointF& moveToPoint,RectPointName::Enum referencePointName);
99 QRectF& moveRectF(QRectF& rect,const QPointF& moveToPoint,RectPointName::Enum referencePointName);
100 QRectF relativeGeom(const QRectF& geometry,const QPointF& position);
101 
102 //divides the size by the "fractionals" (divisors). Just like everything else here, use this for
103 // consistent calculations throughout w.r.t. rounding
104 QSizeF fractionalSizeF(const QSizeF& size,const qreal wFractional, const qreal hFractional);
105 QSize fractionalSize(const QSizeF& size,const qreal wFractional, const qreal hFractional);
106 
107 qreal fractionalSizeF(qreal v,qreal fractional);
108 quint32 fractionalSize(quint32 v,qreal fractional);
109 qreal fractionalSizeF(qreal v,quint32 fractional);
110 quint32 fractionalSize(quint32 v,quint32 fractional);
111 
112 //use this to get consistent bounding rectangles around a center point
113 QRectF realRectAroundRealPoint(const QPointF& centerPt,const QSizeF& rectSize);
114 QRectF realRectAroundRealPoint(const QSizeF& rectSize); //assumes center is (0.0,0.0)
115 QRectF realRectAroundRealPoint(const QSize& rectSize); //assumes center is (0.0,0.0)
116 
117 //use this for "smaller squares into bigger square" class of problems
118 quint32 howManyFitHorizontally(const quint32 cellWidth,const quint32 areaWidth);
119 quint32 howManyFitHorizontally(const qreal cellWidthF,const qreal areaWidthF);
120 quint32 howManyFitHorizontally(const QSize& cellSize,const QSize& areaSize);
121 quint32 howManyFitHorizontally(const QSizeF& cellSizeF,const QSizeF& areaSizeF);
122 
123 quint32 maxCellWidth(const quint32 howManyCells,const quint32 areaWidth);
124 quint32 maxCellWidth(const quint32 howManyCells,const qreal areaWidthF);
125 quint32 maxCellWidth(const quint32 howManyCells,const QSize& areaSize);
126 quint32 maxCellWidth(const quint32 howManyCells,const QSizeF& areaSizeF);
127 
128 quint32 indentForCenteredDimensions(const quint32 outerDimension,const quint32 innerDimension);
129 qreal indentForCenteredDimensions(const qreal outerDimensionF,const qreal innerDimensionF);
130 
131 //these don't actually have to be rects since it uses only the sizes and returns a point *offset* (not absolute point)
132 // from the outer rect's top left corner to the inner rect's top left corner in order to get them centered
133 // the fact that the functions take QRect and not QSize is a convenience
134 QPointF centerRectInRect(const QRectF& outer,const QRectF& inner);
135 QPoint centerRectInRectPixelAlign(const QRectF& outer,const QRectF& inner);
136 QPoint centerRectInRectPixelAlign(const QRect& outer,const QRect& inner);
137 
138 //this one is needed for gestures, since they seem to be coming in within a "global" coordinate space.
139 // (Don't know why we haven't fixed this since it seems useless and error-prone for it to not be in at least
140 // the scene cs)
141 
142 QPointF mapFromGlobalCS(const QPointF& globalPointF);
143 
144 //Access to the graphics scene...since this will be kind of fuzzy, depending on how the rest
145 // of sysmgr changes, i'm making a single access point to it here, so that the rest of Dimensions
146 // can just rely on it being correct, and there is only 1 place to modify when changes do occur.
147 // it CAN return NULL in cases when the scene isn't available (should be rare/hopefully never),
148 // so check for that in the caller and NEVER hold the reference for later
149 QGraphicsScene * globalGraphicsScene();
150 
151 // FSM setup
152 
153 QState * createFSMState(const QString& stateName,QState * parent = 0);
154 
155 //VISUAL-HACKS:
156 typedef QVariantMap VHDescriptor;
157 
158 }
159 
160 int qHash(const QUuid&);
161 
162 #endif /* DIMENSIONSGLOBAL_H_ */