diff --git a/src/controls/QskItemAnchors.cpp b/src/controls/QskItemAnchors.cpp index f5d1475ee..f4e932983 100644 --- a/src/controls/QskItemAnchors.cpp +++ b/src/controls/QskItemAnchors.cpp @@ -95,8 +95,8 @@ namespace } } -QskItemAnchors::QskItemAnchors( QQuickItem* anchoredItem ) - : m_anchoredItem( anchoredItem ) +QskItemAnchors::QskItemAnchors( QQuickItem* attachedItem ) + : m_attachedItem( attachedItem ) { } @@ -106,17 +106,17 @@ QskItemAnchors::~QskItemAnchors() bool QskItemAnchors::operator==( const QskItemAnchors& other ) const noexcept { - return m_anchoredItem.data() == other.m_anchoredItem.data(); + return m_attachedItem.data() == other.m_attachedItem.data(); } -QQuickItem* QskItemAnchors::anchoredItem() const +QQuickItem* QskItemAnchors::attachedItem() const { - return m_anchoredItem; + return m_attachedItem; } QMarginsF QskItemAnchors::margins() const { - if ( const auto anchors = qskGetAnchors( m_anchoredItem ) ) + if ( const auto anchors = qskGetAnchors( m_attachedItem ) ) { return QMarginsF( anchors->leftMargin(), anchors->topMargin(), anchors->rightMargin(), anchors->bottomMargin() ); @@ -127,7 +127,7 @@ QMarginsF QskItemAnchors::margins() const void QskItemAnchors::setMargins( const QMarginsF& margins ) { - if ( const auto anchors = qskGetOrCreateAnchors( m_anchoredItem ) ) + if ( const auto anchors = qskGetOrCreateAnchors( m_attachedItem ) ) { anchors->setLeftMargin( margins.left() ); anchors->setRightMargin( margins.right() ); @@ -138,7 +138,7 @@ void QskItemAnchors::setMargins( const QMarginsF& margins ) void QskItemAnchors::setCenterOffset( Qt::Orientation orientation, qreal offset ) { - if ( const auto anchors = qskGetOrCreateAnchors( m_anchoredItem ) ) + if ( const auto anchors = qskGetOrCreateAnchors( m_attachedItem ) ) { if ( orientation == Qt::Horizontal ) anchors->setHorizontalCenterOffset( offset ); @@ -149,7 +149,7 @@ void QskItemAnchors::setCenterOffset( Qt::Orientation orientation, qreal offset qreal QskItemAnchors::centerOffset( Qt::Orientation orientation ) { - if ( const auto anchors = qskGetOrCreateAnchors( m_anchoredItem ) ) + if ( const auto anchors = qskGetOrCreateAnchors( m_attachedItem ) ) { if ( orientation == Qt::Horizontal ) return anchors->horizontalCenterOffset(); @@ -197,7 +197,7 @@ void QskItemAnchors::addAnchors( QQuickItem* baseItem, Qt::Orientations orientat void QskItemAnchors::addAnchor( Qt::AnchorPoint edge, QQuickItem* baseItem, Qt::AnchorPoint baseEdge ) { - if ( const auto anchors = qskGetOrCreateAnchors( m_anchoredItem ) ) + if ( const auto anchors = qskGetOrCreateAnchors( m_attachedItem ) ) { const auto& ops = operators( edge ); ( anchors->*ops.setLine )( { baseItem, toQuickAnchor( baseEdge ) } ); @@ -206,7 +206,7 @@ void QskItemAnchors::addAnchor( Qt::AnchorPoint edge, QQuickItem* baseItem, void QskItemAnchors::removeAnchor( Qt::AnchorPoint edge ) { - if ( const auto anchors = qskGetAnchors( m_anchoredItem ) ) + if ( const auto anchors = qskGetAnchors( m_attachedItem ) ) { const auto& ops = operators( edge ); ( anchors->*ops.resetLine ) (); @@ -216,7 +216,7 @@ void QskItemAnchors::removeAnchor( Qt::AnchorPoint edge ) QQuickItem* QskItemAnchors::baseItem( Qt::AnchorPoint edge ) const { - if ( const auto anchors = qskGetAnchors( m_anchoredItem ) ) + if ( const auto anchors = qskGetAnchors( m_attachedItem ) ) { const auto& ops = operators( edge ); return ( ( anchors->*ops.line ) () ).item; @@ -227,10 +227,10 @@ QQuickItem* QskItemAnchors::baseItem( Qt::AnchorPoint edge ) const Qt::AnchorPoint QskItemAnchors::basePosition( Qt::AnchorPoint edge ) const { - if ( const auto anchors = qskGetAnchors( m_anchoredItem ) ) + if ( const auto anchors = qskGetAnchors( m_attachedItem ) ) { /* - Anchoring to the baseline of the anchoredItem might have been + Anchoring to the baseline of the attachedItem might have been done in QML code. As Qt::AnchorPoint does not have a corresponding value for it and QSkinny does not support the baseline concept at all we are lying and report Qt::AnchorTop instead. Hm ... @@ -245,7 +245,7 @@ Qt::AnchorPoint QskItemAnchors::basePosition( Qt::AnchorPoint edge ) const void QskItemAnchors::setControlItem( QQuickItem* item, bool adjustSize ) { - if ( const auto anchors = qskGetOrCreateAnchors( m_anchoredItem ) ) + if ( const auto anchors = qskGetOrCreateAnchors( m_attachedItem ) ) { if ( adjustSize ) anchors->setFill( item ); @@ -256,7 +256,7 @@ void QskItemAnchors::setControlItem( QQuickItem* item, bool adjustSize ) void QskItemAnchors::removeControlItem( bool adjustSize ) { - if ( auto anchors = qskGetAnchors( m_anchoredItem ) ) + if ( auto anchors = qskGetAnchors( m_attachedItem ) ) { if ( adjustSize ) anchors->resetFill(); @@ -267,7 +267,7 @@ void QskItemAnchors::removeControlItem( bool adjustSize ) QQuickItem* QskItemAnchors::controlItem( bool adjustSize ) const { - if ( const auto anchors = qskGetAnchors( m_anchoredItem ) ) + if ( const auto anchors = qskGetAnchors( m_attachedItem ) ) { if ( adjustSize ) return anchors->fill(); diff --git a/src/controls/QskItemAnchors.h b/src/controls/QskItemAnchors.h index 189185593..0ba5a4487 100644 --- a/src/controls/QskItemAnchors.h +++ b/src/controls/QskItemAnchors.h @@ -17,24 +17,35 @@ class QQuickItem; QskItemAnchors is a C++ API to access the Qt/Quick anchoring, that has been designed to be used from QML. - Qt/Quick anchoring is a simple concept, that adjusts the - geometry of the anchoredItem whenever the geometry of - a baseItem/controlItem has changed. A baseItem/controlItem - needs to be the parent or a sibling of the anchoredItem. - - Note that Qt/Quick anchoring is labeled as "positioner", what means - that it is not capable of handling typical layout scenarios, like - distributing the space of a bounding rectangle to a chain of - anchored children. - - For some reason Qt/Quick anchoring allows to define conflicting definitions - and resolves them by applying only one of the definitions in + Qt/Quick anchoring is a simple concept, that allows to + + - attach a border ( Qt::AnchorPoint ) of attachedItem to a border of a baseItem + - center attachedItem to the center of a controlItem + + The Qt/Quick implementation supports attaching/centering to the parent or + the siblings of attachedItem only ( conceptually this limitation + would not be necessary ). + + While it is possible to have attachments for each border you can't + center and attach at the same time. + + The expected logic would be, that defining an attachment disables + centering and v.v. - however the implementation tolerates conflicts. + Even worse is is possible to define centering ( = centerIn ) and + center-/resizing ( = fill ) to different items at the same time. + + These conflicts are resolved by applying only one of the definitions in the following precedence: 1) fill 2) centerIn 3) anchors + Note that Qt/Quick ( in opposite to Qt/GraphicsView ) anchoring + is not capable of handling typical layout scenarios, like distributing + the space of a bounding rectangle to a chain of anchored children. + For those you can use QskAnchorLayout/QskAnchorBox. + Limitations: - access to baseline settings are not implemented ( for no other reason than Qt::AnchorPoint does not have it ) @@ -42,10 +53,10 @@ class QQuickItem; class QSK_EXPORT QskItemAnchors { public: - QskItemAnchors( QQuickItem* anchoredItem = nullptr ); + QskItemAnchors( QQuickItem* attachedItem = nullptr ); ~QskItemAnchors(); - QQuickItem* anchoredItem() const; + QQuickItem* attachedItem() const; QQuickItem* baseItem( Qt::AnchorPoint ) const; Qt::AnchorPoint basePosition( Qt::AnchorPoint ) const; @@ -69,7 +80,7 @@ class QSK_EXPORT QskItemAnchors Qt/Quick anchoring knows the convenience modes "fill" and "centerIn". Internally these modes are not(!) mapped to anchor definitions. - Both modes are setting the center point of the anchoredItem to the center + Both modes are setting the center point of the attachedItem to the center of the controlItem. "fill" also adjusts the size. */ @@ -78,7 +89,7 @@ class QSK_EXPORT QskItemAnchors void removeControlItem( bool adjustSize ); private: - QPointer< QQuickItem > m_anchoredItem; + QPointer< QQuickItem > m_attachedItem; }; inline bool QskItemAnchors::operator!=(