Skip to content

Commit

Permalink
documentation updated
Browse files Browse the repository at this point in the history
  • Loading branch information
uwerat committed Oct 11, 2024
1 parent b0a5edb commit d2b12bc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 33 deletions.
34 changes: 17 additions & 17 deletions src/controls/QskItemAnchors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ namespace
}
}

QskItemAnchors::QskItemAnchors( QQuickItem* anchoredItem )
: m_anchoredItem( anchoredItem )
QskItemAnchors::QskItemAnchors( QQuickItem* attachedItem )
: m_attachedItem( attachedItem )
{
}

Expand All @@ -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() );
Expand All @@ -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() );
Expand All @@ -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 );
Expand All @@ -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();
Expand Down Expand Up @@ -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 ) } );
Expand All @@ -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 ) ();
Expand All @@ -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;
Expand All @@ -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 ...
Expand All @@ -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 );
Expand All @@ -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();
Expand All @@ -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();
Expand Down
43 changes: 27 additions & 16 deletions src/controls/QskItemAnchors.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,46 @@ 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 )
*/
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;
Expand All @@ -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.
*/

Expand All @@ -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!=(
Expand Down

0 comments on commit d2b12bc

Please sign in to comment.