homescreenapp/hsutils/src/hswidgetpositioningonwidgetadd.cpp
changeset 36 cdae8c6c3876
parent 35 f9ce957a272c
child 60 30f14686fb04
--- a/homescreenapp/hsutils/src/hswidgetpositioningonwidgetadd.cpp	Fri Mar 19 09:27:44 2010 +0200
+++ b/homescreenapp/hsutils/src/hswidgetpositioningonwidgetadd.cpp	Fri Apr 16 14:54:01 2010 +0300
@@ -64,7 +64,8 @@
 */
 QList<QRectF> HsAnchorPointInBottomRight::convert(
     const QRectF &contentArea,
-    const QList<QRectF> &widgets)
+    const QList<QRectF> &rects,
+    const QPointF &startPoint)
 {
     QList<QRectF> toGeometries;
 
@@ -74,30 +75,49 @@
     qreal offset_y = k*offset_x;
     QPointF offsetPoint(offset_x, offset_y);
     
-    QLineF diagonal(contentArea.topLeft(), contentArea.bottomRight());
-    QLineF widgetRight(contentArea.center().x()+ widgets.at(0).width()/2,
-                       contentArea.top(),
-                       contentArea.center().x()+ widgets.at(0).width()/2,
-                       contentArea.bottom());
+    QPointF anchorPoint;
+   
+    if(startPoint.isNull()){
+
+        QLineF diagonal(contentArea.topLeft(), contentArea.bottomRight());
+        QLineF widgetRightSide(contentArea.center().x()+ rects.at(0).width()/2,
+                           contentArea.top(),
+                           contentArea.center().x()+ rects.at(0).width()/2,
+                           contentArea.bottom());
 
-    QPointF anchorPoint;
-    if(QLineF::BoundedIntersection != diagonal.intersect(widgetRight, &anchorPoint)) {
-        return widgets; //Return original since undefined error.
-                        //In this case widget's must be wider than the content area.
+        // right side line intersection with diagonal will be bottom right position
+        // for the first rect
+        if(QLineF::BoundedIntersection != 
+            diagonal.intersect(widgetRightSide, &anchorPoint)) {
+            return rects; //Return original since undefined error.
+                            //In this case widget's must be wider than the content area.
+        }
+    }else{
+        anchorPoint = startPoint - offsetPoint;
     }
 
-    //First widget to the center of the content area
-    foreach (QRectF g, widgets) {
-        g.moveBottomRight(anchorPoint);
-        toGeometries << g;
+    QRectF widgetRect;
+    for(int i=0;i<rects.count();++i) {
+        widgetRect = rects.at(i);
+        widgetRect.moveBottomRight(anchorPoint);
+        //if widget rect doesn't fit, try to move it
+        if(!contentArea.contains(widgetRect)) {
+            /*! precondition is that
+             widget's max height < content area height
+             widget's max widht < content area width
+            */
+            widgetRect.moveBottomRight(contentArea.bottomRight());
+            // anchorPoin is always previous bottom right
+            anchorPoint = widgetRect.bottomRight();
+        }
+        toGeometries << widgetRect;
         anchorPoint -= offsetPoint;
-        if(!contentArea.contains(anchorPoint)) {
-            anchorPoint = contentArea.bottomRight();
-        }
+        
     }
     return toGeometries;
 }
 
+
 /*!
     \class HsAnchorPointInCenter
     \brief Diagonal widget positioning algorithm.
@@ -110,8 +130,11 @@
 #endif //COVERAGE_MEASUREMENT
 QList<QRectF> HsAnchorPointInCenter::convert(
     const QRectF &contentArea,
-    const QList<QRectF> &widgets)
+    const QList<QRectF> &rects,
+    const QPointF &startPoint )
 {
+    Q_UNUSED(startPoint)
+
     QList<QRectF> toGeometries;
 
     //Offset for widgets' centers position to each other
@@ -122,7 +145,7 @@
 
     //First widget to the center of the content area
     QPointF anchorPoint = contentArea.center();
-    foreach (QRectF g, widgets) {
+    foreach (QRectF g, rects) {
         g.moveCenter(anchorPoint);
         toGeometries << g;
         anchorPoint -= offsetPoint;
@@ -133,6 +156,7 @@
     return toGeometries;
 }
 
+
 #ifdef COVERAGE_MEASUREMENT
 #pragma CTC ENDSKIP
 #endif //COVERAGE_MEASUREMENT