src/hbcore/layouts/hbanchorlayout.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
   267 {
   267 {
   268     return ( ( anchor->direction() == HbAnchor::Positive )?(1):(-1) );
   268     return ( ( anchor->direction() == HbAnchor::Positive )?(1):(-1) );
   269 }
   269 }
   270 
   270 
   271 
   271 
   272 /*!
       
   273     Returns list of effective anchors - those which has mappings to QGraphicsItem
       
   274     \return list of effective anchors.
       
   275 */
       
   276 QList<HbAnchor*> HbAnchorLayout::effectiveAnchors()
       
   277 {
       
   278     Q_D( HbAnchorLayout );
       
   279     d->resolveAnchors();
       
   280     return d->mResolvedAnchors;
       
   281 }
       
   282 
       
   283 /*!
       
   284     Returns list of all anchors set to this layout
       
   285     \return list of all anchors.
       
   286 */
       
   287 QList<HbAnchor*> HbAnchorLayout::anchors() const
       
   288 {
       
   289     Q_D( const HbAnchorLayout );
       
   290     return d->mAllAnchors;
       
   291 }
       
   292 
       
   293 /*
   272 /*
   294     \class HbAnchorLayoutPrivate
   273     \class HbAnchorLayoutPrivate
   295     \internal
   274     \internal
   296 */
   275 */
   297 HbAnchorLayoutPrivate::HbAnchorLayoutPrivate() : mEquationsDirty(false), mValid(true), mInvalidateCalled( false ), mWrongAnchors( false ),
   276 HbAnchorLayoutPrivate::HbAnchorLayoutPrivate() : mEquationsDirty(false), mValid(true), mInvalidateCalled( false ), mWrongAnchors( false ),
  1006 
   985 
  1007         qDeleteAll( *el );
   986         qDeleteAll( *el );
  1008 
   987 
  1009         vs->clear();
   988         vs->clear();
  1010         el->clear();
   989         el->clear();
       
   990 
       
   991         if( type == Vertical ) {
       
   992             mLayoutVarV = 0;
       
   993         } else {
       
   994             mLayoutVarH = 0;
       
   995         }
       
   996 
  1011 
   997 
  1012 
   998 
  1013         GraphVertex *layoutStart = new GraphVertex();
   999         GraphVertex *layoutStart = new GraphVertex();
  1014         GraphVertex *layoutMiddle = new GraphVertex();
  1000         GraphVertex *layoutMiddle = new GraphVertex();
  1015         GraphVertex *layoutEnd = new GraphVertex();
  1001         GraphVertex *layoutEnd = new GraphVertex();
  1778 
  1764 
  1779     bool modified = false;
  1765     bool modified = false;
  1780 
  1766 
  1781     if ( !nodeId.isNull() && ( item != 0 ) ) {
  1767     if ( !nodeId.isNull() && ( item != 0 ) ) {
  1782 
  1768 
       
  1769         QString oldMapping = this->nodeId( item );
       
  1770         if (!oldMapping.isEmpty()) {
       
  1771             removeMapping(oldMapping);
       
  1772         }
       
  1773 
  1783         for( int i = 0; i < d->mAllAnchors.size(); i++ ) {
  1774         for( int i = 0; i < d->mAllAnchors.size(); i++ ) {
  1784             HbAnchor *anchor = d->mAllAnchors.at(i);
  1775             HbAnchor *anchor = d->mAllAnchors.at(i);
  1785             if( anchor->startItem() == item ) {
  1776             if( anchor->startItem() == item ) {
  1786                 anchor->d_ptr->mStartId = nodeId;
  1777                 anchor->d_ptr->mStartId = nodeId;
  1787                 modified = true;
  1778                 modified = true;
  2005     \return node id for given item.
  1996     \return node id for given item.
  2006 */
  1997 */
  2007 QString HbAnchorLayout::nodeId( QGraphicsLayoutItem *item ) const
  1998 QString HbAnchorLayout::nodeId( QGraphicsLayoutItem *item ) const
  2008 {
  1999 {
  2009     Q_D( const HbAnchorLayout );
  2000     Q_D( const HbAnchorLayout );
  2010     if( d->mItemToNodeIdMap.contains( item ) ) {
  2001     return d->mItemToNodeIdMap.value( item );
  2011         return d->mItemToNodeIdMap.value( item );
       
  2012     }
       
  2013     return QString();
       
  2014 }
  2002 }
  2015 
  2003 
  2016 /*!
  2004 /*!
  2017     Returns list of node ids that are mentioned in anchors list.
  2005     Returns list of node ids that are mentioned in anchors list.
  2018     \return list of node ids.
  2006     \return list of node ids.
  2043 QGraphicsLayoutItem *HbAnchorLayout::itemByNodeId( const QString& nodeId ) const
  2031 QGraphicsLayoutItem *HbAnchorLayout::itemByNodeId( const QString& nodeId ) const
  2044 {
  2032 {
  2045     Q_D( const HbAnchorLayout );
  2033     Q_D( const HbAnchorLayout );
  2046     return d->mItemToNodeIdMap.key( nodeId );
  2034     return d->mItemToNodeIdMap.key( nodeId );
  2047 }
  2035 }
       
  2036 
       
  2037 /*!
       
  2038     Returns list of effective anchors - those which has mappings to QGraphicsItem
       
  2039     \return list of effective anchors.
       
  2040 */
       
  2041 QList<HbAnchor*> HbAnchorLayout::effectiveAnchors()
       
  2042 {
       
  2043     Q_D( HbAnchorLayout );
       
  2044     d->resolveAnchors();
       
  2045     return d->mResolvedAnchors;
       
  2046 }
       
  2047 
       
  2048 /*!
       
  2049     Returns list of all anchors set to this layout
       
  2050     \return list of all anchors.
       
  2051 */
       
  2052 QList<HbAnchor*> HbAnchorLayout::anchors() const
       
  2053 {
       
  2054     Q_D( const HbAnchorLayout );
       
  2055     return d->mAllAnchors;
       
  2056 }
       
  2057 
       
  2058 
       
  2059 /*!
       
  2060     Returns actual length of given anchor in current layout configuration
       
  2061     \param anchor whose length need to be determined.
       
  2062     \return actual length of anchor or -1 if this anchor is not layouted (or doesn't exist at all)
       
  2063 */
       
  2064 qreal HbAnchorLayout::anchorLength( HbAnchor *anchor ) const
       
  2065 {
       
  2066     Q_D( const HbAnchorLayout );
       
  2067 
       
  2068     Variable *anchorVar = d->mVariablesHorizontal.findVariable( anchor );
       
  2069     if( anchorVar && d->mSolutionHorizontal.contains( anchorVar ) ) {
       
  2070         return qAbs( d->mSolutionHorizontal.value( anchorVar ) );
       
  2071     }
       
  2072 
       
  2073     anchorVar = d->mVariablesVertical.findVariable( anchor );
       
  2074     if( anchorVar && d->mSolutionVertical.contains( anchorVar ) ) {
       
  2075         return qAbs( d->mSolutionVertical.value( anchorVar ) );
       
  2076     }
       
  2077     return -1;
       
  2078 }
       
  2079 
  2048 
  2080 
  2049 
  2081 
  2050 /*!
  2082 /*!
  2051     \reimp
  2083     \reimp
  2052 */
  2084 */