homescreenapp/hsutils/src/hswidgetpositioningonwidgetadd.cpp
author hgs
Wed, 18 Aug 2010 10:33:57 +0300
changeset 81 7dd137878ff8
parent 69 87476091b3f5
permissions -rw-r--r--
201033
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
69
hgs
parents: 62
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description: 
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
69
hgs
parents: 62
diff changeset
    18
#include <QLineF>
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
#include <QtGlobal>
69
hgs
parents: 62
diff changeset
    20
#include <QPointF>
hgs
parents: 62
diff changeset
    21
#include <math.h>
hgs
parents: 62
diff changeset
    22
hgs
parents: 62
diff changeset
    23
#include <HbInstance>
hgs
parents: 62
diff changeset
    24
hgs
parents: 62
diff changeset
    25
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
#include "hswidgetpositioningonwidgetadd.h"
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
const qreal offset = 40; //TODO: Implement this as configurable parameter
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
62
hgs
parents: 36
diff changeset
    30
hgs
parents: 36
diff changeset
    31
/*!
hgs
parents: 36
diff changeset
    32
    \class HsWidgetPositioningOnWidgetAdd
hgs
parents: 36
diff changeset
    33
    \ingroup group_hsutils
hgs
parents: 36
diff changeset
    34
    \brief 
hgs
parents: 36
diff changeset
    35
*/
hgs
parents: 36
diff changeset
    36
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
    \class HsWidgetPositioningOnWidgetAdd
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
    \brief Defines widget positioning on widget add.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
    Widget positioning on widget add sets positions for
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
    a set of home screen widgets added from application library.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
    Sets the positioning \a instance as the current one.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
    Deletes the existing instance if present.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
void HsWidgetPositioningOnWidgetAdd::setInstance(
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
    HsWidgetPositioningOnWidgetAdd *instance)
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
{
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    52
    if (mInstance)
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
        delete mInstance;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    54
    mInstance = instance;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    55
}
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
 
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    57
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
    Returns the current positioning instance.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    59
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
HsWidgetPositioningOnWidgetAdd *HsWidgetPositioningOnWidgetAdd::instance()
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
{
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    62
    return mInstance;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    63
}
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    64
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    65
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
    Stores the current positioning instance.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
HsWidgetPositioningOnWidgetAdd *HsWidgetPositioningOnWidgetAdd::mInstance = 0;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
    \class HsAnchorPointInBottomRight
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
    \brief Diagonal widget positioning algorithm.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
    
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    74
    Sets widget's lower right corner to follow content area's diagonal.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    75
    Widgets are positioned to certain offset to each other.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    76
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    77
QList<QRectF> HsAnchorPointInBottomRight::convert(
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
    const QRectF &contentArea,
69
hgs
parents: 62
diff changeset
    79
    const QList<QRectF> &existingRects,
hgs
parents: 62
diff changeset
    80
    const QList<QRectF> &newRects,
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
    81
    const QPointF &startPoint)
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    82
{
69
hgs
parents: 62
diff changeset
    83
    Q_UNUSED(existingRects);
hgs
parents: 62
diff changeset
    84
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    85
    QList<QRectF> toGeometries;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    86
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    87
    //Offset for widgets' bottom right position to each other
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    88
    qreal k = contentArea.height()/contentArea.width(); //slope of the diagonal
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    89
    qreal offset_x = offset/(sqrt(k + 1));
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    90
    qreal offset_y = k*offset_x;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    91
    QPointF offsetPoint(offset_x, offset_y);
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    92
    
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
    93
    QPointF anchorPoint;
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
    94
   
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
    95
    if(startPoint.isNull()){
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
    96
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
    97
        QLineF diagonal(contentArea.topLeft(), contentArea.bottomRight());
69
hgs
parents: 62
diff changeset
    98
        QLineF widgetRightSide(contentArea.center().x()+ newRects.at(0).width()/2,
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
    99
                           contentArea.top(),
69
hgs
parents: 62
diff changeset
   100
                           contentArea.center().x()+ newRects.at(0).width()/2,
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   101
                           contentArea.bottom());
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   102
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   103
        // right side line intersection with diagonal will be bottom right position
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   104
        // for the first rect
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   105
        if(QLineF::BoundedIntersection != 
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   106
            diagonal.intersect(widgetRightSide, &anchorPoint)) {
69
hgs
parents: 62
diff changeset
   107
            return newRects; //Return original since undefined error.
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   108
                            //In this case widget's must be wider than the content area.
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   109
        }
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   110
    }else{
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   111
        anchorPoint = startPoint - offsetPoint;
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   112
    }
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   113
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   114
    QRectF widgetRect;
69
hgs
parents: 62
diff changeset
   115
    for(int i=0;i<newRects.count();++i) {
hgs
parents: 62
diff changeset
   116
        widgetRect = newRects.at(i);
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   117
        widgetRect.moveBottomRight(anchorPoint);
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   118
        //if widget rect doesn't fit, try to move it
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   119
        if(!contentArea.contains(widgetRect)) {
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   120
            /*! precondition is that
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   121
             widget's max height < content area height
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   122
             widget's max widht < content area width
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   123
            */
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   124
            widgetRect.moveBottomRight(contentArea.bottomRight());
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   125
            // anchorPoin is always previous bottom right
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   126
            anchorPoint = widgetRect.bottomRight();
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   127
        }
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   128
        toGeometries << widgetRect;
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   129
        anchorPoint -= offsetPoint;
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   130
        
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   131
    }
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   132
    return toGeometries;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   133
}
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   134
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   135
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   136
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   137
    \class HsAnchorPointInCenter
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   138
    \brief Diagonal widget positioning algorithm.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   139
    
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   140
    Sets widget's center point to follow content area's diagonal.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   141
    Widgets are positioned to certain offset to each other.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   142
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   143
#ifdef COVERAGE_MEASUREMENT
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   144
#pragma CTC SKIP
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   145
#endif //COVERAGE_MEASUREMENT
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   146
QList<QRectF> HsAnchorPointInCenter::convert(
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   147
    const QRectF &contentArea,
69
hgs
parents: 62
diff changeset
   148
    const QList<QRectF> &existingRects,
hgs
parents: 62
diff changeset
   149
    const QList<QRectF> &newRects,
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   150
    const QPointF &startPoint )
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   151
{
69
hgs
parents: 62
diff changeset
   152
    Q_UNUSED(existingRects);
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   153
    Q_UNUSED(startPoint)
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   154
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   155
    QList<QRectF> toGeometries;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   156
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   157
    //Offset for widgets' centers position to each other
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   158
    qreal k = contentArea.height()/contentArea.width(); //slope of the diagonal
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   159
    qreal offset_x = offset/(sqrt(k + 1));
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   160
    qreal offset_y = k*offset_x;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   161
    QPointF offsetPoint(offset_x, offset_y);
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   162
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   163
    //First widget to the center of the content area
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   164
    QPointF anchorPoint = contentArea.center();
69
hgs
parents: 62
diff changeset
   165
    foreach (QRectF g, newRects) {
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
        g.moveCenter(anchorPoint);
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   167
        toGeometries << g;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   168
        anchorPoint -= offsetPoint;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   169
        if(!contentArea.contains(anchorPoint)) {
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   170
            anchorPoint = contentArea.bottomRight();
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   171
        }
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   172
    }
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   173
    return toGeometries;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   174
}
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   175
69
hgs
parents: 62
diff changeset
   176
/*!
hgs
parents: 62
diff changeset
   177
    \class HsWidgetOrganizer
hgs
parents: 62
diff changeset
   178
    \brief Advanced widget positioning algorithm.
hgs
parents: 62
diff changeset
   179
    
hgs
parents: 62
diff changeset
   180
    Organizes widget's starting from upper left corner towards right,
hgs
parents: 62
diff changeset
   181
    and then continues the on the next line.
hgs
parents: 62
diff changeset
   182
*/
hgs
parents: 62
diff changeset
   183
QList<QRectF> HsWidgetOrganizer::convert(
hgs
parents: 62
diff changeset
   184
    const QRectF &contentArea,
hgs
parents: 62
diff changeset
   185
    const QList<QRectF> &existingRects,
hgs
parents: 62
diff changeset
   186
    const QList<QRectF> &newRects,
hgs
parents: 62
diff changeset
   187
    const QPointF &startPoint)
hgs
parents: 62
diff changeset
   188
{
hgs
parents: 62
diff changeset
   189
    Q_UNUSED(startPoint)
hgs
parents: 62
diff changeset
   190
hgs
parents: 62
diff changeset
   191
    // TODO: maybe we can utilize start point in some use cases / optimizations?
hgs
parents: 62
diff changeset
   192
hgs
parents: 62
diff changeset
   193
    QList<QRectF> toGeometries;
hgs
parents: 62
diff changeset
   194
hgs
parents: 62
diff changeset
   195
    // TODO: anchor distance to configuration?
hgs
parents: 62
diff changeset
   196
    // TODO: optimize anchor distance based on new content amount
hgs
parents: 62
diff changeset
   197
    // TODO: snap value to same as anchor distance?
hgs
parents: 62
diff changeset
   198
    mAnchorDistance = 5;
hgs
parents: 62
diff changeset
   199
    QList<bool> temp;
hgs
parents: 62
diff changeset
   200
    mAnchors = temp;
hgs
parents: 62
diff changeset
   201
hgs
parents: 62
diff changeset
   202
    // test flag
81
hgs
parents: 69
diff changeset
   203
//    int test = 0;
69
hgs
parents: 62
diff changeset
   204
hgs
parents: 62
diff changeset
   205
    // initialize anchor network for widget positions
81
hgs
parents: 69
diff changeset
   206
//    if (test == 0) {
69
hgs
parents: 62
diff changeset
   207
        initAnchors(contentArea.size());
81
hgs
parents: 69
diff changeset
   208
//    } else {
hgs
parents: 69
diff changeset
   209
//        mAnchorDistance = 2;
hgs
parents: 69
diff changeset
   210
//        initAnchors(QSizeF(6,6));
hgs
parents: 69
diff changeset
   211
//    }
69
hgs
parents: 62
diff changeset
   212
hgs
parents: 62
diff changeset
   213
    // mark existing rects (widgets) reserved
hgs
parents: 62
diff changeset
   214
    foreach (QRectF rect, existingRects) {
hgs
parents: 62
diff changeset
   215
        // TODO: could mStartWidthAnchorPoint, mEndWidthAnchorPoint, mEndHeightAnchorPoint be somehow refactored better way?
hgs
parents: 62
diff changeset
   216
        mStartWidthAnchorPoint.setX(lenghtInAnchorPoints(rect.x() - contentArea.x()));
hgs
parents: 62
diff changeset
   217
        mEndWidthAnchorPoint.setX(lenghtInAnchorPoints(rect.x() + rect.width() - contentArea.x()));
hgs
parents: 62
diff changeset
   218
        mStartWidthAnchorPoint.setY(lenghtInAnchorPoints(rect.y() - contentArea.y()));
hgs
parents: 62
diff changeset
   219
        mEndHeightAnchorPoint.setY(lenghtInAnchorPoints(rect.y() + rect.height() - contentArea.y()));
hgs
parents: 62
diff changeset
   220
        // mark reserved anchor points
hgs
parents: 62
diff changeset
   221
        markReservedAnchors();
hgs
parents: 62
diff changeset
   222
        mStartWidthAnchorPoint = QPointF(0,0);
hgs
parents: 62
diff changeset
   223
        mEndWidthAnchorPoint = QPointF(0,0);
hgs
parents: 62
diff changeset
   224
        mEndHeightAnchorPoint = QPointF(0,0);
hgs
parents: 62
diff changeset
   225
    }
hgs
parents: 62
diff changeset
   226
hgs
parents: 62
diff changeset
   227
    QList<QRectF> notOrganizedRects;
hgs
parents: 62
diff changeset
   228
hgs
parents: 62
diff changeset
   229
    // get positions for all new rects (widgets)
hgs
parents: 62
diff changeset
   230
    for ( int i = 0; i < newRects.count(); i++) {
hgs
parents: 62
diff changeset
   231
        bool found = false;
81
hgs
parents: 69
diff changeset
   232
//        if (test == 0) {
69
hgs
parents: 62
diff changeset
   233
            // find first free anchor point for rect
hgs
parents: 62
diff changeset
   234
            found = getAnchorPoint(newRects.at(i).size());
81
hgs
parents: 69
diff changeset
   235
//        } else {
hgs
parents: 69
diff changeset
   236
//            found = getAnchorPoint(QSizeF(2,2));
hgs
parents: 69
diff changeset
   237
//        }
69
hgs
parents: 62
diff changeset
   238
hgs
parents: 62
diff changeset
   239
        if (found) {
hgs
parents: 62
diff changeset
   240
            // save to geometry list
hgs
parents: 62
diff changeset
   241
            toGeometries << QRectF(mStartWidthAnchorPoint.x() * mAnchorDistance + contentArea.x(),
hgs
parents: 62
diff changeset
   242
                                   mStartWidthAnchorPoint.y() * mAnchorDistance + contentArea.y(),
hgs
parents: 62
diff changeset
   243
                                   newRects.at(i).width(), newRects.at(i).height());
hgs
parents: 62
diff changeset
   244
            // mark new widgets rect reserved
hgs
parents: 62
diff changeset
   245
            markReservedAnchors();
hgs
parents: 62
diff changeset
   246
            // TODO: these optimizations could be used for empty page
hgs
parents: 62
diff changeset
   247
            //mStartWidthAnchorPoint.setX(mEndWidthAnchorPoint.x() + 1);
hgs
parents: 62
diff changeset
   248
            //mStartWidthAnchorPoint.setY(mEndWidthAnchorPoint.y());
hgs
parents: 62
diff changeset
   249
        } else {
hgs
parents: 62
diff changeset
   250
            // collect widgets that do not fit
hgs
parents: 62
diff changeset
   251
            notOrganizedRects << newRects.at(i);
hgs
parents: 62
diff changeset
   252
        }
hgs
parents: 62
diff changeset
   253
        // TODO: remove these to optimize for empty page
hgs
parents: 62
diff changeset
   254
        mStartWidthAnchorPoint = QPointF(0,0);
hgs
parents: 62
diff changeset
   255
        mEndWidthAnchorPoint = QPointF(0,0);
hgs
parents: 62
diff changeset
   256
    }
hgs
parents: 62
diff changeset
   257
hgs
parents: 62
diff changeset
   258
    // use center algorithm with offset for the rest widget that did not fit to screen
hgs
parents: 62
diff changeset
   259
    if (notOrganizedRects.count() > 0) {
hgs
parents: 62
diff changeset
   260
        QList<QRectF> tmpExistingRects;
hgs
parents: 62
diff changeset
   261
        tmpExistingRects += newRects;
hgs
parents: 62
diff changeset
   262
        tmpExistingRects += existingRects;
hgs
parents: 62
diff changeset
   263
        HsAnchorPointInCenter *centerAlgorithm = new HsAnchorPointInCenter();
hgs
parents: 62
diff changeset
   264
        QList<QRectF> calculatedRects =
hgs
parents: 62
diff changeset
   265
            centerAlgorithm->convert(contentArea, tmpExistingRects, notOrganizedRects, QPointF());
hgs
parents: 62
diff changeset
   266
        toGeometries += calculatedRects;
81
hgs
parents: 69
diff changeset
   267
        delete centerAlgorithm;
69
hgs
parents: 62
diff changeset
   268
    }
hgs
parents: 62
diff changeset
   269
hgs
parents: 62
diff changeset
   270
    return toGeometries;
hgs
parents: 62
diff changeset
   271
}
hgs
parents: 62
diff changeset
   272
hgs
parents: 62
diff changeset
   273
hgs
parents: 62
diff changeset
   274
/*!    
hgs
parents: 62
diff changeset
   275
    Initializes anchor points for context area
hgs
parents: 62
diff changeset
   276
*/
hgs
parents: 62
diff changeset
   277
bool HsWidgetOrganizer::initAnchors(const QSizeF &areaSize)
hgs
parents: 62
diff changeset
   278
{
hgs
parents: 62
diff changeset
   279
    // mandatory check ups
hgs
parents: 62
diff changeset
   280
    // TODO: these mAnchorDistance checks to earlier phase
hgs
parents: 62
diff changeset
   281
    if (areaSize == QSizeF(0,0) || areaSize.width() < mAnchorDistance ||
hgs
parents: 62
diff changeset
   282
        areaSize.height() < mAnchorDistance || mAnchorDistance == 0 || mAnchorDistance == 1) {
hgs
parents: 62
diff changeset
   283
        return false;
hgs
parents: 62
diff changeset
   284
    }
hgs
parents: 62
diff changeset
   285
    mAnchorColumns = 0;
hgs
parents: 62
diff changeset
   286
    mAnchorRows = 0;
hgs
parents: 62
diff changeset
   287
hgs
parents: 62
diff changeset
   288
    // TODO: can we optimize anchor amount utilizing minimum widget size
hgs
parents: 62
diff changeset
   289
    mAnchorColumns = lenghtInAnchorPoints(areaSize.width());
hgs
parents: 62
diff changeset
   290
    mAnchorRows = lenghtInAnchorPoints(areaSize.height());
hgs
parents: 62
diff changeset
   291
hgs
parents: 62
diff changeset
   292
    // create anchor network
81
hgs
parents: 69
diff changeset
   293
    for (int i = 0; i < (mAnchorRows * mAnchorColumns); i++) {
69
hgs
parents: 62
diff changeset
   294
        mAnchors << false;
hgs
parents: 62
diff changeset
   295
    }
hgs
parents: 62
diff changeset
   296
    // zero start points
hgs
parents: 62
diff changeset
   297
    mStartWidthAnchorPoint = QPointF(0,0);
hgs
parents: 62
diff changeset
   298
    mEndWidthAnchorPoint = QPointF(0,0);
hgs
parents: 62
diff changeset
   299
hgs
parents: 62
diff changeset
   300
    return true;
hgs
parents: 62
diff changeset
   301
}
hgs
parents: 62
diff changeset
   302
hgs
parents: 62
diff changeset
   303
/*!    
hgs
parents: 62
diff changeset
   304
    Finds anchor points for content size
hgs
parents: 62
diff changeset
   305
*/
hgs
parents: 62
diff changeset
   306
bool HsWidgetOrganizer::getAnchorPoint(const QSizeF &contentSize)
hgs
parents: 62
diff changeset
   307
{
hgs
parents: 62
diff changeset
   308
    bool anchorFound = false;
hgs
parents: 62
diff changeset
   309
hgs
parents: 62
diff changeset
   310
    while (anchorFound == false) {
hgs
parents: 62
diff changeset
   311
        // if no width found for content
hgs
parents: 62
diff changeset
   312
        if (!searchWidthSpace(contentSize)) {
hgs
parents: 62
diff changeset
   313
            // when content organized in height order remove this line for optimization
hgs
parents: 62
diff changeset
   314
            mStartWidthAnchorPoint = QPointF(0,0);
hgs
parents: 62
diff changeset
   315
            mEndWidthAnchorPoint = QPointF(0,0);
hgs
parents: 62
diff changeset
   316
            return false;
hgs
parents: 62
diff changeset
   317
        }
hgs
parents: 62
diff changeset
   318
        // search height for content
hgs
parents: 62
diff changeset
   319
        int height = lenghtInAnchorPoints(contentSize.height());
hgs
parents: 62
diff changeset
   320
        anchorFound = searchHeightSpace(height);
hgs
parents: 62
diff changeset
   321
    }
hgs
parents: 62
diff changeset
   322
    return true;
hgs
parents: 62
diff changeset
   323
}
hgs
parents: 62
diff changeset
   324
hgs
parents: 62
diff changeset
   325
/*!    
hgs
parents: 62
diff changeset
   326
    Searches anchor point width for content size
hgs
parents: 62
diff changeset
   327
*/
hgs
parents: 62
diff changeset
   328
bool HsWidgetOrganizer::searchWidthSpace(const QSizeF &contentSize) 
hgs
parents: 62
diff changeset
   329
{
hgs
parents: 62
diff changeset
   330
    int availableWidth = 0;    
hgs
parents: 62
diff changeset
   331
    int contentWidth = lenghtInAnchorPoints(contentSize.width());
hgs
parents: 62
diff changeset
   332
    // TODO: use this optimizations for empty page
hgs
parents: 62
diff changeset
   333
    //int contentHeight = lenghtInAnchorPoints(contentSize.height());
hgs
parents: 62
diff changeset
   334
    bool newRow = true;
hgs
parents: 62
diff changeset
   335
hgs
parents: 62
diff changeset
   336
    for (int i = getIndexForCoordinate(mStartWidthAnchorPoint); i <= mAnchors.count(); i++) {
hgs
parents: 62
diff changeset
   337
        // no width left on the page
hgs
parents: 62
diff changeset
   338
        if ((newRow == false) && ((i % (mAnchorColumns)) == 0)) {
hgs
parents: 62
diff changeset
   339
            availableWidth = 0;
hgs
parents: 62
diff changeset
   340
            // jump to new row
hgs
parents: 62
diff changeset
   341
            mStartWidthAnchorPoint.setX(0);
hgs
parents: 62
diff changeset
   342
            // TODO: use this optimizations for empty page
hgs
parents: 62
diff changeset
   343
            //mStartWidthAnchorPoint.setY(mStartWidthAnchorPoint.y() + contentHeight + 1);
hgs
parents: 62
diff changeset
   344
            mStartWidthAnchorPoint.setY(mStartWidthAnchorPoint.y() + 1);
hgs
parents: 62
diff changeset
   345
            i = getIndexForCoordinate(mStartWidthAnchorPoint) - 1;
hgs
parents: 62
diff changeset
   346
            // if no height found
hgs
parents: 62
diff changeset
   347
            if (i < 0) {
hgs
parents: 62
diff changeset
   348
                return false;
hgs
parents: 62
diff changeset
   349
            }
hgs
parents: 62
diff changeset
   350
            newRow = true;
hgs
parents: 62
diff changeset
   351
        } else {
hgs
parents: 62
diff changeset
   352
            // if enough width found
hgs
parents: 62
diff changeset
   353
            if (availableWidth == contentWidth) {
hgs
parents: 62
diff changeset
   354
                mEndWidthAnchorPoint = getAnchorCoordinates(i);
hgs
parents: 62
diff changeset
   355
                if (mEndWidthAnchorPoint == QPointF()) {
hgs
parents: 62
diff changeset
   356
                    return false;
hgs
parents: 62
diff changeset
   357
                }
hgs
parents: 62
diff changeset
   358
                return true;
hgs
parents: 62
diff changeset
   359
            }
hgs
parents: 62
diff changeset
   360
            // if anchor reserved
hgs
parents: 62
diff changeset
   361
            if (mAnchors[i] == true) {
hgs
parents: 62
diff changeset
   362
                availableWidth = 0;
hgs
parents: 62
diff changeset
   363
            } else {
hgs
parents: 62
diff changeset
   364
                // update available width
hgs
parents: 62
diff changeset
   365
                availableWidth = availableWidth + 1;
hgs
parents: 62
diff changeset
   366
            }
hgs
parents: 62
diff changeset
   367
            newRow = false;
hgs
parents: 62
diff changeset
   368
        }   
hgs
parents: 62
diff changeset
   369
    }
hgs
parents: 62
diff changeset
   370
    return false;
hgs
parents: 62
diff changeset
   371
}
hgs
parents: 62
diff changeset
   372
hgs
parents: 62
diff changeset
   373
/*!    
hgs
parents: 62
diff changeset
   374
    Searches anchor point area for content size
hgs
parents: 62
diff changeset
   375
*/
hgs
parents: 62
diff changeset
   376
bool HsWidgetOrganizer::searchHeightSpace(int contentHeight)
hgs
parents: 62
diff changeset
   377
{
hgs
parents: 62
diff changeset
   378
    mEndHeightAnchorPoint = QPointF(0,0);
hgs
parents: 62
diff changeset
   379
 
81
hgs
parents: 69
diff changeset
   380
    for (int i = mStartWidthAnchorPoint.x(); i <= mEndWidthAnchorPoint.x(); i++) {
hgs
parents: 69
diff changeset
   381
        for (int j = mStartWidthAnchorPoint.y(); j <= (mStartWidthAnchorPoint.y() + contentHeight); j++) {
69
hgs
parents: 62
diff changeset
   382
            int index = getIndexForCoordinate(QPointF(i,j));
hgs
parents: 62
diff changeset
   383
            // check that index is not out of bounds
hgs
parents: 62
diff changeset
   384
            if (index == -1) {
hgs
parents: 62
diff changeset
   385
                // update start width point one step
hgs
parents: 62
diff changeset
   386
                mStartWidthAnchorPoint.setX(mStartWidthAnchorPoint.x() + 1); 
hgs
parents: 62
diff changeset
   387
                return false;
hgs
parents: 62
diff changeset
   388
            }
hgs
parents: 62
diff changeset
   389
            // if anchor reserved
hgs
parents: 62
diff changeset
   390
            if (mAnchors[index] == true) {
hgs
parents: 62
diff changeset
   391
                // update start width point one step
hgs
parents: 62
diff changeset
   392
                mStartWidthAnchorPoint.setX(mStartWidthAnchorPoint.x() + 1);
hgs
parents: 62
diff changeset
   393
                return false;
hgs
parents: 62
diff changeset
   394
            }
hgs
parents: 62
diff changeset
   395
        }
hgs
parents: 62
diff changeset
   396
    }
hgs
parents: 62
diff changeset
   397
    mEndHeightAnchorPoint = QPointF(mEndWidthAnchorPoint.x(), mEndWidthAnchorPoint.y() + contentHeight);
hgs
parents: 62
diff changeset
   398
    return true;
hgs
parents: 62
diff changeset
   399
}
hgs
parents: 62
diff changeset
   400
hgs
parents: 62
diff changeset
   401
/*!    
hgs
parents: 62
diff changeset
   402
    Marks reserved anchor points based on pre-defined starting and ending points
hgs
parents: 62
diff changeset
   403
*/
hgs
parents: 62
diff changeset
   404
bool HsWidgetOrganizer::markReservedAnchors()
hgs
parents: 62
diff changeset
   405
{
hgs
parents: 62
diff changeset
   406
    for (int i = mStartWidthAnchorPoint.x(); i <= mEndWidthAnchorPoint.x(); i++) {
hgs
parents: 62
diff changeset
   407
        for (int j = mStartWidthAnchorPoint.y(); j <= mEndHeightAnchorPoint.y(); j++) {
hgs
parents: 62
diff changeset
   408
            mAnchors[getIndexForCoordinate(QPointF(i,j))] = true;
hgs
parents: 62
diff changeset
   409
        }
hgs
parents: 62
diff changeset
   410
    }
hgs
parents: 62
diff changeset
   411
    return true;
hgs
parents: 62
diff changeset
   412
}
hgs
parents: 62
diff changeset
   413
hgs
parents: 62
diff changeset
   414
/*!    
hgs
parents: 62
diff changeset
   415
    Returns pixel coordinate based on anchor coordinate
hgs
parents: 62
diff changeset
   416
*/
hgs
parents: 62
diff changeset
   417
QPointF HsWidgetOrganizer::getAnchorCoordinates(int index)
hgs
parents: 62
diff changeset
   418
{
hgs
parents: 62
diff changeset
   419
    if (index < mAnchors.count()) {
hgs
parents: 62
diff changeset
   420
        int x = index % mAnchorColumns;
hgs
parents: 62
diff changeset
   421
        int y = (index - x) / mAnchorColumns;
hgs
parents: 62
diff changeset
   422
        return QPointF(x,y);
hgs
parents: 62
diff changeset
   423
    } else {
hgs
parents: 62
diff changeset
   424
        return QPointF();
hgs
parents: 62
diff changeset
   425
    }
hgs
parents: 62
diff changeset
   426
}
hgs
parents: 62
diff changeset
   427
hgs
parents: 62
diff changeset
   428
/*!    
hgs
parents: 62
diff changeset
   429
    Returns anchor coordinate based on pixel coordinate
hgs
parents: 62
diff changeset
   430
*/
hgs
parents: 62
diff changeset
   431
int HsWidgetOrganizer::getIndexForCoordinate(QPointF position)
hgs
parents: 62
diff changeset
   432
{
hgs
parents: 62
diff changeset
   433
    int index = (position.y() * mAnchorColumns) + position.x();
hgs
parents: 62
diff changeset
   434
    if (index < mAnchors.count()) {
hgs
parents: 62
diff changeset
   435
        return index;
hgs
parents: 62
diff changeset
   436
    } else {
hgs
parents: 62
diff changeset
   437
        return -1;
hgs
parents: 62
diff changeset
   438
    }
hgs
parents: 62
diff changeset
   439
}
hgs
parents: 62
diff changeset
   440
hgs
parents: 62
diff changeset
   441
/*!    
hgs
parents: 62
diff changeset
   442
    Calculates pixel length as anchor points
hgs
parents: 62
diff changeset
   443
*/
hgs
parents: 62
diff changeset
   444
int HsWidgetOrganizer::lenghtInAnchorPoints(QVariant length)
hgs
parents: 62
diff changeset
   445
{
hgs
parents: 62
diff changeset
   446
    // check remainder
hgs
parents: 62
diff changeset
   447
    int remainder = length.toInt() % mAnchorDistance;
hgs
parents: 62
diff changeset
   448
    return ((length.toInt() - remainder) / mAnchorDistance);
hgs
parents: 62
diff changeset
   449
}
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   450
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   451
#ifdef COVERAGE_MEASUREMENT
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   452
#pragma CTC ENDSKIP
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   453
#endif //COVERAGE_MEASUREMENT
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   454