src/declarative/graphicsitems/qdeclarativeanchors_p_p.h
changeset 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QDECLARATIVEANCHORS_P_H
       
    43 #define QDECLARATIVEANCHORS_P_H
       
    44 
       
    45 //
       
    46 //  W A R N I N G
       
    47 //  -------------
       
    48 //
       
    49 // This file is not part of the Qt API.  It exists purely as an
       
    50 // implementation detail.  This header file may change from version to
       
    51 // version without notice, or even be removed.
       
    52 //
       
    53 // We mean it.
       
    54 //
       
    55 
       
    56 #include "private/qdeclarativeanchors_p.h"
       
    57 #include "private/qdeclarativeitemchangelistener_p.h"
       
    58 #include <private/qobject_p.h>
       
    59 
       
    60 QT_BEGIN_NAMESPACE
       
    61 
       
    62 class QDeclarativeAnchorLine
       
    63 {
       
    64 public:
       
    65     QDeclarativeAnchorLine() : item(0), anchorLine(Invalid) {}
       
    66 
       
    67     enum AnchorLine {
       
    68         Invalid = 0x0,
       
    69         Left = 0x01,
       
    70         Right = 0x02,
       
    71         Top = 0x04,
       
    72         Bottom = 0x08,
       
    73         HCenter = 0x10,
       
    74         VCenter = 0x20,
       
    75         Baseline = 0x40,
       
    76         Horizontal_Mask = Left | Right | HCenter,
       
    77         Vertical_Mask = Top | Bottom | VCenter | Baseline
       
    78     };
       
    79 
       
    80     QGraphicsObject *item;
       
    81     AnchorLine anchorLine;
       
    82 };
       
    83 
       
    84 inline bool operator==(const QDeclarativeAnchorLine& a, const QDeclarativeAnchorLine& b)
       
    85 {
       
    86     return a.item == b.item && a.anchorLine == b.anchorLine;
       
    87 }
       
    88 
       
    89 class QDeclarativeAnchorsPrivate : public QObjectPrivate, public QDeclarativeItemChangeListener
       
    90 {
       
    91     Q_DECLARE_PUBLIC(QDeclarativeAnchors)
       
    92 public:
       
    93     QDeclarativeAnchorsPrivate(QGraphicsObject *i)
       
    94       : componentComplete(true), updatingMe(false), updatingHorizontalAnchor(0),
       
    95         updatingVerticalAnchor(0), updatingFill(0), updatingCenterIn(0), item(i), usedAnchors(0), fill(0),
       
    96         centerIn(0), leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0),
       
    97         margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)
       
    98     {
       
    99     }
       
   100 
       
   101     void clearItem(QGraphicsObject *);
       
   102 
       
   103     void addDepend(QGraphicsObject *);
       
   104     void remDepend(QGraphicsObject *);
       
   105     bool isItemComplete() const;
       
   106 
       
   107     bool componentComplete:1;
       
   108     bool updatingMe:1;
       
   109     uint updatingHorizontalAnchor:2;
       
   110     uint updatingVerticalAnchor:2;
       
   111     uint updatingFill:2;
       
   112     uint updatingCenterIn:2;
       
   113 
       
   114     void setItemHeight(qreal);
       
   115     void setItemWidth(qreal);
       
   116     void setItemX(qreal);
       
   117     void setItemY(qreal);
       
   118     void setItemPos(const QPointF &);
       
   119     void setItemSize(const QSizeF &);
       
   120 
       
   121     void updateOnComplete();
       
   122     void updateMe();
       
   123 
       
   124     // QDeclarativeItemGeometryListener interface
       
   125     void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &);
       
   126     void _q_widgetDestroyed(QObject *);
       
   127     void _q_widgetGeometryChanged();
       
   128     QDeclarativeAnchorsPrivate *anchorPrivate() { return this; }
       
   129 
       
   130     bool checkHValid() const;
       
   131     bool checkVValid() const;
       
   132     bool checkHAnchorValid(QDeclarativeAnchorLine anchor) const;
       
   133     bool checkVAnchorValid(QDeclarativeAnchorLine anchor) const;
       
   134     bool calcStretch(const QDeclarativeAnchorLine &edge1, const QDeclarativeAnchorLine &edge2, int offset1, int offset2, QDeclarativeAnchorLine::AnchorLine line, int &stretch);
       
   135 
       
   136     void updateHorizontalAnchors();
       
   137     void updateVerticalAnchors();
       
   138     void fillChanged();
       
   139     void centerInChanged();
       
   140 
       
   141     QGraphicsObject *item;
       
   142     QDeclarativeAnchors::Anchors usedAnchors;
       
   143 
       
   144     QGraphicsObject *fill;
       
   145     QGraphicsObject *centerIn;
       
   146 
       
   147     QDeclarativeAnchorLine left;
       
   148     QDeclarativeAnchorLine right;
       
   149     QDeclarativeAnchorLine top;
       
   150     QDeclarativeAnchorLine bottom;
       
   151     QDeclarativeAnchorLine vCenter;
       
   152     QDeclarativeAnchorLine hCenter;
       
   153     QDeclarativeAnchorLine baseline;
       
   154 
       
   155     qreal leftMargin;
       
   156     qreal rightMargin;
       
   157     qreal topMargin;
       
   158     qreal bottomMargin;
       
   159     qreal margins;
       
   160     qreal vCenterOffset;
       
   161     qreal hCenterOffset;
       
   162     qreal baselineOffset;
       
   163 };
       
   164 
       
   165 QT_END_NAMESPACE
       
   166 
       
   167 Q_DECLARE_METATYPE(QDeclarativeAnchorLine)
       
   168 
       
   169 #endif