homescreenapp/hsutils/src/hswidgetpositioningonwidgetadd.cpp
changeset 85 35368b604b28
parent 77 4b195f3bea29
equal deleted inserted replaced
77:4b195f3bea29 85:35368b604b28
   198     mAnchorDistance = 5;
   198     mAnchorDistance = 5;
   199     QList<bool> temp;
   199     QList<bool> temp;
   200     mAnchors = temp;
   200     mAnchors = temp;
   201 
   201 
   202     // test flag
   202     // test flag
   203     int test = 0;
   203 //    int test = 0;
   204 
   204 
   205     // initialize anchor network for widget positions
   205     // initialize anchor network for widget positions
   206     if (test == 0) {
   206 //    if (test == 0) {
   207         initAnchors(contentArea.size());
   207         initAnchors(contentArea.size());
   208     } else {
   208 //    } else {
   209         mAnchorDistance = 2;
   209 //        mAnchorDistance = 2;
   210         initAnchors(QSizeF(6,6));
   210 //        initAnchors(QSizeF(6,6));
   211     }
   211 //    }
   212 
   212 
   213     // mark existing rects (widgets) reserved
   213     // mark existing rects (widgets) reserved
   214     foreach (QRectF rect, existingRects) {
   214     foreach (QRectF rect, existingRects) {
   215         // TODO: could mStartWidthAnchorPoint, mEndWidthAnchorPoint, mEndHeightAnchorPoint be somehow refactored better way?
   215         // TODO: could mStartWidthAnchorPoint, mEndWidthAnchorPoint, mEndHeightAnchorPoint be somehow refactored better way?
   216         mStartWidthAnchorPoint.setX(lenghtInAnchorPoints(rect.x() - contentArea.x()));
   216         mStartWidthAnchorPoint.setX(lenghtInAnchorPoints(rect.x() - contentArea.x()));
   227     QList<QRectF> notOrganizedRects;
   227     QList<QRectF> notOrganizedRects;
   228 
   228 
   229     // get positions for all new rects (widgets)
   229     // get positions for all new rects (widgets)
   230     for ( int i = 0; i < newRects.count(); i++) {
   230     for ( int i = 0; i < newRects.count(); i++) {
   231         bool found = false;
   231         bool found = false;
   232         if (test == 0) {
   232 //        if (test == 0) {
   233             // find first free anchor point for rect
   233             // find first free anchor point for rect
   234             found = getAnchorPoint(newRects.at(i).size());
   234             found = getAnchorPoint(newRects.at(i).size());
   235         } else {
   235 //        } else {
   236             found = getAnchorPoint(QSizeF(2,2));
   236 //            found = getAnchorPoint(QSizeF(2,2));
   237         }
   237 //        }
   238 
   238 
   239         if (found) {
   239         if (found) {
   240             // save to geometry list
   240             // save to geometry list
   241             toGeometries << QRectF(mStartWidthAnchorPoint.x() * mAnchorDistance + contentArea.x(),
   241             toGeometries << QRectF(mStartWidthAnchorPoint.x() * mAnchorDistance + contentArea.x(),
   242                                    mStartWidthAnchorPoint.y() * mAnchorDistance + contentArea.y(),
   242                                    mStartWidthAnchorPoint.y() * mAnchorDistance + contentArea.y(),
   262         tmpExistingRects += existingRects;
   262         tmpExistingRects += existingRects;
   263         HsAnchorPointInCenter *centerAlgorithm = new HsAnchorPointInCenter();
   263         HsAnchorPointInCenter *centerAlgorithm = new HsAnchorPointInCenter();
   264         QList<QRectF> calculatedRects =
   264         QList<QRectF> calculatedRects =
   265             centerAlgorithm->convert(contentArea, tmpExistingRects, notOrganizedRects, QPointF());
   265             centerAlgorithm->convert(contentArea, tmpExistingRects, notOrganizedRects, QPointF());
   266         toGeometries += calculatedRects;
   266         toGeometries += calculatedRects;
       
   267         delete centerAlgorithm;
   267     }
   268     }
   268 
   269 
   269     return toGeometries;
   270     return toGeometries;
   270 }
   271 }
   271 
   272 
   287     // TODO: can we optimize anchor amount utilizing minimum widget size
   288     // TODO: can we optimize anchor amount utilizing minimum widget size
   288     mAnchorColumns = lenghtInAnchorPoints(areaSize.width());
   289     mAnchorColumns = lenghtInAnchorPoints(areaSize.width());
   289     mAnchorRows = lenghtInAnchorPoints(areaSize.height());
   290     mAnchorRows = lenghtInAnchorPoints(areaSize.height());
   290 
   291 
   291     // create anchor network
   292     // create anchor network
   292     for (int i = 0; i < (mAnchorRows * mAnchorColumns); i = i++) {
   293     for (int i = 0; i < (mAnchorRows * mAnchorColumns); i++) {
   293         mAnchors << false;
   294         mAnchors << false;
   294     }
   295     }
   295     // zero start points
   296     // zero start points
   296     mStartWidthAnchorPoint = QPointF(0,0);
   297     mStartWidthAnchorPoint = QPointF(0,0);
   297     mEndWidthAnchorPoint = QPointF(0,0);
   298     mEndWidthAnchorPoint = QPointF(0,0);
   374 */
   375 */
   375 bool HsWidgetOrganizer::searchHeightSpace(int contentHeight)
   376 bool HsWidgetOrganizer::searchHeightSpace(int contentHeight)
   376 {
   377 {
   377     mEndHeightAnchorPoint = QPointF(0,0);
   378     mEndHeightAnchorPoint = QPointF(0,0);
   378  
   379  
   379     for (int i = mStartWidthAnchorPoint.x(); i <= mEndWidthAnchorPoint.x(); i = i++) {
   380     for (int i = mStartWidthAnchorPoint.x(); i <= mEndWidthAnchorPoint.x(); i++) {
   380         for (int j = mStartWidthAnchorPoint.y(); j <= (mStartWidthAnchorPoint.y() + contentHeight); j = j++) {
   381         for (int j = mStartWidthAnchorPoint.y(); j <= (mStartWidthAnchorPoint.y() + contentHeight); j++) {
   381             int index = getIndexForCoordinate(QPointF(i,j));
   382             int index = getIndexForCoordinate(QPointF(i,j));
   382             // check that index is not out of bounds
   383             // check that index is not out of bounds
   383             if (index == -1) {
   384             if (index == -1) {
   384                 // update start width point one step
   385                 // update start width point one step
   385                 mStartWidthAnchorPoint.setX(mStartWidthAnchorPoint.x() + 1); 
   386                 mStartWidthAnchorPoint.setX(mStartWidthAnchorPoint.x() + 1);