documentation updated
This commit is contained in:
parent
b0a5edb0f3
commit
d2b12bcf44
@ -95,8 +95,8 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QskItemAnchors::QskItemAnchors( QQuickItem* anchoredItem )
|
QskItemAnchors::QskItemAnchors( QQuickItem* attachedItem )
|
||||||
: m_anchoredItem( anchoredItem )
|
: m_attachedItem( attachedItem )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,17 +106,17 @@ QskItemAnchors::~QskItemAnchors()
|
|||||||
|
|
||||||
bool QskItemAnchors::operator==( const QskItemAnchors& other ) const noexcept
|
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
|
QMarginsF QskItemAnchors::margins() const
|
||||||
{
|
{
|
||||||
if ( const auto anchors = qskGetAnchors( m_anchoredItem ) )
|
if ( const auto anchors = qskGetAnchors( m_attachedItem ) )
|
||||||
{
|
{
|
||||||
return QMarginsF( anchors->leftMargin(), anchors->topMargin(),
|
return QMarginsF( anchors->leftMargin(), anchors->topMargin(),
|
||||||
anchors->rightMargin(), anchors->bottomMargin() );
|
anchors->rightMargin(), anchors->bottomMargin() );
|
||||||
@ -127,7 +127,7 @@ QMarginsF QskItemAnchors::margins() const
|
|||||||
|
|
||||||
void QskItemAnchors::setMargins( const QMarginsF& margins )
|
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->setLeftMargin( margins.left() );
|
||||||
anchors->setRightMargin( margins.right() );
|
anchors->setRightMargin( margins.right() );
|
||||||
@ -138,7 +138,7 @@ void QskItemAnchors::setMargins( const QMarginsF& margins )
|
|||||||
|
|
||||||
void QskItemAnchors::setCenterOffset( Qt::Orientation orientation, qreal offset )
|
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 )
|
if ( orientation == Qt::Horizontal )
|
||||||
anchors->setHorizontalCenterOffset( offset );
|
anchors->setHorizontalCenterOffset( offset );
|
||||||
@ -149,7 +149,7 @@ void QskItemAnchors::setCenterOffset( Qt::Orientation orientation, qreal offset
|
|||||||
|
|
||||||
qreal QskItemAnchors::centerOffset( Qt::Orientation orientation )
|
qreal QskItemAnchors::centerOffset( Qt::Orientation orientation )
|
||||||
{
|
{
|
||||||
if ( const auto anchors = qskGetOrCreateAnchors( m_anchoredItem ) )
|
if ( const auto anchors = qskGetOrCreateAnchors( m_attachedItem ) )
|
||||||
{
|
{
|
||||||
if ( orientation == Qt::Horizontal )
|
if ( orientation == Qt::Horizontal )
|
||||||
return anchors->horizontalCenterOffset();
|
return anchors->horizontalCenterOffset();
|
||||||
@ -197,7 +197,7 @@ void QskItemAnchors::addAnchors( QQuickItem* baseItem, Qt::Orientations orientat
|
|||||||
void QskItemAnchors::addAnchor( Qt::AnchorPoint edge, QQuickItem* baseItem,
|
void QskItemAnchors::addAnchor( Qt::AnchorPoint edge, QQuickItem* baseItem,
|
||||||
Qt::AnchorPoint baseEdge )
|
Qt::AnchorPoint baseEdge )
|
||||||
{
|
{
|
||||||
if ( const auto anchors = qskGetOrCreateAnchors( m_anchoredItem ) )
|
if ( const auto anchors = qskGetOrCreateAnchors( m_attachedItem ) )
|
||||||
{
|
{
|
||||||
const auto& ops = operators( edge );
|
const auto& ops = operators( edge );
|
||||||
( anchors->*ops.setLine )( { baseItem, toQuickAnchor( baseEdge ) } );
|
( anchors->*ops.setLine )( { baseItem, toQuickAnchor( baseEdge ) } );
|
||||||
@ -206,7 +206,7 @@ void QskItemAnchors::addAnchor( Qt::AnchorPoint edge, QQuickItem* baseItem,
|
|||||||
|
|
||||||
void QskItemAnchors::removeAnchor( Qt::AnchorPoint edge )
|
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 );
|
const auto& ops = operators( edge );
|
||||||
( anchors->*ops.resetLine ) ();
|
( anchors->*ops.resetLine ) ();
|
||||||
@ -216,7 +216,7 @@ void QskItemAnchors::removeAnchor( Qt::AnchorPoint edge )
|
|||||||
|
|
||||||
QQuickItem* QskItemAnchors::baseItem( Qt::AnchorPoint edge ) const
|
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 );
|
const auto& ops = operators( edge );
|
||||||
return ( ( anchors->*ops.line ) () ).item;
|
return ( ( anchors->*ops.line ) () ).item;
|
||||||
@ -227,10 +227,10 @@ QQuickItem* QskItemAnchors::baseItem( Qt::AnchorPoint edge ) const
|
|||||||
|
|
||||||
Qt::AnchorPoint QskItemAnchors::basePosition( 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
|
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
|
value for it and QSkinny does not support the baseline concept at all
|
||||||
we are lying and report Qt::AnchorTop instead. Hm ...
|
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 )
|
void QskItemAnchors::setControlItem( QQuickItem* item, bool adjustSize )
|
||||||
{
|
{
|
||||||
if ( const auto anchors = qskGetOrCreateAnchors( m_anchoredItem ) )
|
if ( const auto anchors = qskGetOrCreateAnchors( m_attachedItem ) )
|
||||||
{
|
{
|
||||||
if ( adjustSize )
|
if ( adjustSize )
|
||||||
anchors->setFill( item );
|
anchors->setFill( item );
|
||||||
@ -256,7 +256,7 @@ void QskItemAnchors::setControlItem( QQuickItem* item, bool adjustSize )
|
|||||||
|
|
||||||
void QskItemAnchors::removeControlItem( bool adjustSize )
|
void QskItemAnchors::removeControlItem( bool adjustSize )
|
||||||
{
|
{
|
||||||
if ( auto anchors = qskGetAnchors( m_anchoredItem ) )
|
if ( auto anchors = qskGetAnchors( m_attachedItem ) )
|
||||||
{
|
{
|
||||||
if ( adjustSize )
|
if ( adjustSize )
|
||||||
anchors->resetFill();
|
anchors->resetFill();
|
||||||
@ -267,7 +267,7 @@ void QskItemAnchors::removeControlItem( bool adjustSize )
|
|||||||
|
|
||||||
QQuickItem* QskItemAnchors::controlItem( bool adjustSize ) const
|
QQuickItem* QskItemAnchors::controlItem( bool adjustSize ) const
|
||||||
{
|
{
|
||||||
if ( const auto anchors = qskGetAnchors( m_anchoredItem ) )
|
if ( const auto anchors = qskGetAnchors( m_attachedItem ) )
|
||||||
{
|
{
|
||||||
if ( adjustSize )
|
if ( adjustSize )
|
||||||
return anchors->fill();
|
return anchors->fill();
|
||||||
|
@ -17,24 +17,35 @@ class QQuickItem;
|
|||||||
QskItemAnchors is a C++ API to access the Qt/Quick anchoring,
|
QskItemAnchors is a C++ API to access the Qt/Quick anchoring,
|
||||||
that has been designed to be used from QML.
|
that has been designed to be used from QML.
|
||||||
|
|
||||||
Qt/Quick anchoring is a simple concept, that adjusts the
|
Qt/Quick anchoring is a simple concept, that allows to
|
||||||
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
|
- attach a border ( Qt::AnchorPoint ) of attachedItem to a border of a baseItem
|
||||||
that it is not capable of handling typical layout scenarios, like
|
- center attachedItem to the center of a controlItem
|
||||||
distributing the space of a bounding rectangle to a chain of
|
|
||||||
anchored children.
|
|
||||||
|
|
||||||
For some reason Qt/Quick anchoring allows to define conflicting definitions
|
The Qt/Quick implementation supports attaching/centering to the parent or
|
||||||
and resolves them by applying only one of the definitions in
|
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:
|
the following precedence:
|
||||||
|
|
||||||
1) fill
|
1) fill
|
||||||
2) centerIn
|
2) centerIn
|
||||||
3) anchors
|
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:
|
Limitations:
|
||||||
- access to baseline settings are not implemented
|
- access to baseline settings are not implemented
|
||||||
( for no other reason than Qt::AnchorPoint does not have it )
|
( for no other reason than Qt::AnchorPoint does not have it )
|
||||||
@ -42,10 +53,10 @@ class QQuickItem;
|
|||||||
class QSK_EXPORT QskItemAnchors
|
class QSK_EXPORT QskItemAnchors
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QskItemAnchors( QQuickItem* anchoredItem = nullptr );
|
QskItemAnchors( QQuickItem* attachedItem = nullptr );
|
||||||
~QskItemAnchors();
|
~QskItemAnchors();
|
||||||
|
|
||||||
QQuickItem* anchoredItem() const;
|
QQuickItem* attachedItem() const;
|
||||||
|
|
||||||
QQuickItem* baseItem( Qt::AnchorPoint ) const;
|
QQuickItem* baseItem( Qt::AnchorPoint ) const;
|
||||||
Qt::AnchorPoint basePosition( 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".
|
Qt/Quick anchoring knows the convenience modes "fill" and "centerIn".
|
||||||
Internally these modes are not(!) mapped to anchor definitions.
|
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.
|
of the controlItem. "fill" also adjusts the size.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -78,7 +89,7 @@ class QSK_EXPORT QskItemAnchors
|
|||||||
void removeControlItem( bool adjustSize );
|
void removeControlItem( bool adjustSize );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer< QQuickItem > m_anchoredItem;
|
QPointer< QQuickItem > m_attachedItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool QskItemAnchors::operator!=(
|
inline bool QskItemAnchors::operator!=(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user