1/*
2 * SPDX-FileCopyrightText: 2023 Marco Martin <mart@kde.org>
3 * SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7#ifndef HEADERFOOTERLAYOUT_H
8#define HEADERFOOTERLAYOUT_H
9
10#include <QQuickItem>
11#include <qtmetamacros.h>
12
13/*!
14 * \qmltype HeaderFooterLayout
15 * \inqmlmodule org.kde.kirigami.layouts
16 *
17 * \brief Replicates a little part of what Page does.
18 *
19 * It's a container with 3 properties, header, contentItem and footer
20 * which will be laid out oone on top of each other.
21 *
22 * It works better than a ColumnLayout when the elements are to be
23 * defined by properties by the user, which would require ugly
24 * reparenting dances and container items to
25 * maintain the layout well behaving.
26 */
27class HeaderFooterLayout : public QQuickItem
28{
29 Q_OBJECT
30 QML_ELEMENT
31 /*!
32 * \qmlproperty Item HeaderFooterLayout::header
33 * \brief This property holds the page header item.
34 *
35 * The header item is positioned to the top,
36 * and resized to the width of the page. The default value is null.
37 */
38 Q_PROPERTY(QQuickItem *header READ header WRITE setHeader NOTIFY headerChanged FINAL)
39
40 /*!
41 * \qmlproperty Item HeaderFooterLayout::contentItem
42 * \brief This property holds the visual content Item.
43 *
44 * It will be resized both in width and height with the layout resizing.
45 * Its height will be resized to still have room for the heder and footer
46 */
47 Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL)
48
49 /*!
50 * \qmlproperty Item HeaderFooterLayout::footer
51 * \brief This property holds the page footer item.
52 *
53 * The footer item is positioned to the bottom,
54 * and resized to the width of the page. The default value is null.
55 */
56 Q_PROPERTY(QQuickItem *footer READ footer WRITE setFooter NOTIFY footerChanged FINAL)
57
58 /*!
59 * \qmlproperty real HeaderFooterLayout::spacing
60 * \brief Space between contentItem and the header and footer items.
61 *
62 * The content Item of the page will be positioned at this distance in pixels
63 * from the header and footer Items. The default value is zero.
64 *
65 * @since 6.13
66 */
67 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged FINAL)
68
69public:
70 HeaderFooterLayout(QQuickItem *parent = nullptr);
71 ~HeaderFooterLayout() override;
72
73 void setHeader(QQuickItem *item);
74 QQuickItem *header();
75
76 void setContentItem(QQuickItem *item);
77 QQuickItem *contentItem();
78
79 void setFooter(QQuickItem *item);
80 QQuickItem *footer();
81
82 void setSpacing(qreal spacing);
83 qreal spacing() const;
84
85 /*!
86 * \qmlmethod void HeaderFooterLayout::forceLayout()
87 * \brief HeaderFooterLayout normally positions its header, footer and
88 * contentItem once per frame (at polish event). This method forces the it
89 * to recalculate the layout immediately.
90 */
91 Q_INVOKABLE void forceLayout();
92
93Q_SIGNALS:
94 void headerChanged();
95 void spacingChanged();
96 void contentItemChanged();
97 void footerChanged();
98
99protected:
100 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
101 void componentComplete() override;
102 void updatePolish() override;
103
104private:
105 void markAsDirty();
106 void performLayout();
107 void updateImplicitSize();
108 void disconnectItem(QQuickItem *item);
109
110 QPointer<QQuickItem> m_header;
111 QPointer<QQuickItem> m_contentItem;
112 QPointer<QQuickItem> m_footer;
113
114 qreal m_spacing = 0;
115
116 bool m_isDirty : 1;
117 bool m_performingLayout : 1;
118};
119
120#endif
121

source code of kirigami/src/layouts/headerfooterlayout.h