2024-10-10 13:55:22 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) The authors
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QSK_ITEM_ANCHORS_H
|
|
|
|
#define QSK_ITEM_ANCHORS_H
|
|
|
|
|
|
|
|
#include "QskGlobal.h"
|
|
|
|
#include <qnamespace.h>
|
|
|
|
#include <qpointer.h>
|
|
|
|
|
|
|
|
class QMarginsF;
|
|
|
|
class QQuickItem;
|
|
|
|
|
|
|
|
/*
|
|
|
|
QskItemAnchors is a C++ API to access the Qt/Quick anchoring,
|
|
|
|
that has been designed to be used from QML.
|
|
|
|
|
2024-10-13 10:21:40 +00:00
|
|
|
Qt/Quick anchoring is a simple concept, that allows to attach
|
2024-10-13 10:33:44 +00:00
|
|
|
borders ( Qt::AnchorPoint ) of attachedItem to a border of
|
2024-10-13 10:21:40 +00:00
|
|
|
other items. It is up to the user to avoid cycles or conflicting
|
|
|
|
anchor chains.
|
2024-10-11 06:10:48 +00:00
|
|
|
|
2024-10-13 10:21:40 +00:00
|
|
|
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.
|
2024-10-11 06:10:48 +00:00
|
|
|
|
2024-10-13 10:21:40 +00:00
|
|
|
The Qt/Quick implementation supports attaching to the parent or
|
2024-10-11 06:10:48 +00:00
|
|
|
the siblings of attachedItem only ( conceptually this limitation
|
|
|
|
would not be necessary ).
|
|
|
|
|
2024-10-13 10:21:40 +00:00
|
|
|
Note that what is known in QML as "fill" or "centerIn" can be done
|
|
|
|
using setBorderAnchors or setCenterAnchors.
|
2024-10-11 06:10:48 +00:00
|
|
|
|
2024-10-10 13:55:22 +00:00
|
|
|
Limitations:
|
|
|
|
- access to baseline settings are not implemented
|
2024-10-10 14:01:02 +00:00
|
|
|
( for no other reason than Qt::AnchorPoint does not have it )
|
2024-10-10 13:55:22 +00:00
|
|
|
*/
|
|
|
|
class QSK_EXPORT QskItemAnchors
|
|
|
|
{
|
|
|
|
public:
|
2024-10-11 06:10:48 +00:00
|
|
|
QskItemAnchors( QQuickItem* attachedItem = nullptr );
|
2024-10-10 13:55:22 +00:00
|
|
|
~QskItemAnchors();
|
|
|
|
|
2024-10-11 06:10:48 +00:00
|
|
|
QQuickItem* attachedItem() const;
|
2024-10-10 13:55:22 +00:00
|
|
|
|
|
|
|
QQuickItem* baseItem( Qt::AnchorPoint ) const;
|
|
|
|
Qt::AnchorPoint basePosition( Qt::AnchorPoint ) const;
|
|
|
|
|
|
|
|
bool operator==( const QskItemAnchors& ) const noexcept;
|
|
|
|
bool operator!=( const QskItemAnchors& ) const noexcept;
|
|
|
|
|
|
|
|
QMarginsF margins() const;
|
|
|
|
void setMargins( const QMarginsF& );
|
|
|
|
|
2024-10-13 10:21:40 +00:00
|
|
|
void setCenterOffsets( qreal horizontalOffset, qreal verticalOffset );
|
2024-10-10 13:55:22 +00:00
|
|
|
void setCenterOffset( Qt::Orientation, qreal offset );
|
|
|
|
qreal centerOffset( Qt::Orientation );
|
|
|
|
|
2024-10-13 10:21:40 +00:00
|
|
|
// add to - or remove from - the list of anchors
|
2024-10-10 13:55:22 +00:00
|
|
|
void addAnchor( Qt::AnchorPoint, QQuickItem*, Qt::AnchorPoint );
|
|
|
|
void addAnchors( Qt::Corner, QQuickItem*, Qt::Corner );
|
|
|
|
void removeAnchor( Qt::AnchorPoint );
|
|
|
|
|
2024-10-13 10:21:40 +00:00
|
|
|
void clearAnchors();
|
2024-10-10 13:55:22 +00:00
|
|
|
|
2024-10-13 10:21:40 +00:00
|
|
|
// replacing the list of anchors
|
|
|
|
void setBorderAnchors( QQuickItem*, Qt::Orientations = Qt::Horizontal | Qt::Vertical );
|
|
|
|
void setCenterAnchors( QQuickItem*, Qt::Orientations = Qt::Horizontal | Qt::Vertical );
|
2024-10-10 13:55:22 +00:00
|
|
|
|
|
|
|
private:
|
2024-10-11 06:10:48 +00:00
|
|
|
QPointer< QQuickItem > m_attachedItem;
|
2024-10-10 13:55:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline bool QskItemAnchors::operator!=(
|
|
|
|
const QskItemAnchors& other ) const noexcept
|
|
|
|
{
|
|
|
|
return !( *this == other );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|