QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskItemAnchors.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_ITEM_ANCHORS_H
7#define QSK_ITEM_ANCHORS_H
8
9#include "QskGlobal.h"
10#include <qnamespace.h>
11#include <qpointer.h>
12
13class QMarginsF;
14class QQuickItem;
15
16/*
17 QskItemAnchors is a C++ API to access the Qt/Quick anchoring.
18
19 Qt/Quick anchoring is a simple concept, that allows to attach
20 borders ( Qt::AnchorPoint ) of one item ( attachedItem ) to borders of
21 other items ( settledItem ).
22
23 In opposite to anchoring layouts ( f.e QGraphicsAnchorLayout, QskAnchorLayout )
24 the positions of the anchors are provided - not calculated. That makes
25 Qt/Quick anchoring unsuitable for scenarios, where the space of
26 a bounding rectangle has to be distributed.
27
28 The implementation supports attaching to the parent or the siblings
29 of attachedItem only ( conceptually this limitation would not be necessary ).
30
31 Note that what is known in QML as "fill" or "centerIn" can be done
32 using setBorderAnchors or setCenterAnchors. However the basic layout
33 functionality provided from QskControl::autoLayoutChildren usually
34 offers a more efficient implementation for most situations.
35
36 Limitations:
37 - access to baseline settings are not implemented
38 ( for no other reason than Qt::AnchorPoint does not have it )
39 */
40class QSK_EXPORT QskItemAnchors
41{
42 public:
43 QskItemAnchors( QQuickItem* attachedItem = nullptr );
45
46 QQuickItem* attachedItem() const;
47
48 QQuickItem* settledItem( Qt::AnchorPoint ) const;
49 Qt::AnchorPoint settledItemAnchorPoint( Qt::AnchorPoint ) const;
50
51 bool operator==( const QskItemAnchors& ) const noexcept;
52 bool operator!=( const QskItemAnchors& ) const noexcept;
53
54 QMarginsF margins() const;
55 void setMargins( const QMarginsF& );
56
57 void setCenterOffsets( qreal horizontalOffset, qreal verticalOffset );
58 void setCenterOffset( Qt::Orientation, qreal offset );
59 qreal centerOffset( Qt::Orientation );
60
61 // add to - or remove from - the list of anchors
62 void addAnchor( Qt::AnchorPoint, QQuickItem*, Qt::AnchorPoint );
63 void addAnchors( Qt::Corner, QQuickItem*, Qt::Corner );
64 void removeAnchor( Qt::AnchorPoint );
65
66 void clearAnchors();
67
68 // replacing the list of anchors
69 void setBorderAnchors( QQuickItem*, Qt::Orientations = Qt::Horizontal | Qt::Vertical );
70 void setCenterAnchors( QQuickItem*, Qt::Orientations = Qt::Horizontal | Qt::Vertical );
71
72 private:
73 QPointer< QQuickItem > m_attachedItem;
74};
75
76inline bool QskItemAnchors::operator!=(
77 const QskItemAnchors& other ) const noexcept
78{
79 return !( *this == other );
80}
81
82#endif