homescreenapp/hsutils/inc/hswidgetpositioningonwidgetmove.h
branchRCL_3
changeset 82 5f0182e07bfb
equal deleted inserted replaced
79:f00a6757af32 82:5f0182e07bfb
       
     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 checkInactiveRectLieAboveOrBelowOfMovingRect();
       
   107     void checkInactiveRectVerticalEdgesInRange(qreal movingRectVerticalEdgePosition);
       
   108     void checkInactiveRectBetterFitForHorizontalSnapping(qreal containerVerticalEdgeToInactiveRectVerticalEdge,
       
   109                                                          qreal containerOtherVerticalEdgeToInactiveRectOtherVerticalEdge);
       
   110     void compareLeftSideOfMovingRectForSnapping();
       
   111     void compareRightSideOfMovingRectForSnapping();
       
   112     void checkInactiveRectLieLeftOrRightOfMovingRect();
       
   113     void checkInactiveRectHorizontalEdgesInRange(qreal movingRectHorizontalEdgePosition);
       
   114     void checkInactiveRectBetterFitForVerticalSnapping(qreal containerHorizontalEdgeToInactiveRectHorizontalEdge,
       
   115                                                        qreal containerOtherHorizontalEdgeToInactiveRectOtherHorizontalEdge);
       
   116     void compareTopOfMovingRectForSnapping();
       
   117     void compareBottomOfMovingRectForSnapping();
       
   118     void createVerticalLine();
       
   119     void createHorizontalLine();
       
   120     void extendVerticalLine();
       
   121     void extendHorizontalLine();
       
   122     void checkInactiveRectPositionToVerticalLine();
       
   123     void extendVerticalLineToIncludeInactiveRect();
       
   124     void checkInactiveRectPositionToHorizontalLine();
       
   125     void extendHorizontalLineToIncludeInactiveRect();
       
   126 
       
   127 private: //data
       
   128     QRectF mContainerRect;
       
   129 
       
   130     qreal mActiveRectWidth;
       
   131     qreal mActiveRectHeight;
       
   132 
       
   133     QList<HsSnapRectangle> mInactiveSnapRects;
       
   134 
       
   135     QRectF mInactiveRectToCompare;
       
   136     HsSnapRectangle mInactiveSnapRectToCompare;
       
   137     QRectF mMovingRect;
       
   138 
       
   139     qreal mMinDistancePosition;
       
   140     qreal mHorizontalSnapPosition;
       
   141     qreal mVerticalSnapPosition;
       
   142 
       
   143     bool mHorizontalSnapFound;
       
   144     QLineF mVerticalLine;
       
   145 
       
   146     bool mVerticalSnapFound;
       
   147     QLineF mHorizontalLine;
       
   148 
       
   149     bool mRectLieAbove;
       
   150     bool mLeftInRange;
       
   151     bool mRightInRange;
       
   152     bool mIsBetterFitHorizontalSnap;
       
   153     qreal mDistanceVerticalEdges;
       
   154     qreal mVerticalEdgeToLeftOfInactiveRect;
       
   155     qreal mVerticalEdgeToRightOfInactiveRect;
       
   156     qreal mMinVerticalEdgesDistance;
       
   157     qreal mVerticalDistance;
       
   158     qreal mVerticalDistanceFromSelectedRect;
       
   159     qreal mContainerVerticalEdgeDistance;
       
   160 
       
   161     bool mRectLieLeft;
       
   162     bool mTopInRange;
       
   163     bool mBottomInRange;
       
   164     bool mIsBetterFitVerticalSnap;
       
   165     qreal mDistanceHorizontalEdges;
       
   166     qreal mHorizontalEdgeToTopOfInactiveRect;
       
   167     qreal mHorizontalEdgeToBottomOfInactiveRect;
       
   168     qreal mMinHorizontalEdgesDistance;
       
   169     qreal mHorizontalDistance;
       
   170     qreal mHorizontalDistanceFromSelectedRect;
       
   171     qreal mContainerHorizontalEdgeDistance;
       
   172 
       
   173     bool mSnapEnabled;
       
   174     qreal mSnapForce;
       
   175     qreal mSnapGap;
       
   176 
       
   177     bool mRectVerticalEdgeLiesInLineWithVerticalLine;
       
   178     bool mRectLieAboveVerticalLine;
       
   179     bool mRectLieBelowVerticalLine;
       
   180 
       
   181     bool mRectHorizontalEdgeLiesInLineWithHorizontalLine;
       
   182     bool mRectLieLeftOfHorizontalLine;
       
   183     bool mRectLiesRightOfHorizontalLine;
       
   184 
       
   185     HOMESCREEN_TEST_FRIEND_CLASS(t_hsUtils)
       
   186 };
       
   187 
       
   188 #endif // HSWIDGETPOSITIONINGONWIDGETMOVE_H