Kirigami2

headerfooterlayout.h
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 * replicates a little part of what Page does,
15 * It's a container with 3 properties, header, contentItem and footer
16 * which will be laid out oone on top of each other. It works better than a
17 * ColumnLayout when the elements are to be defined by properties by the
18 * user, which would require ugly reparenting dances and container items to
19 * maintain the layout well behaving.
20 */
21class HeaderFooterLayout : public QQuickItem
22{
24 QML_ELEMENT
25 /**
26 * @brief This property holds the page header item.
27 *
28 * The header item is positioned to the top,
29 * and resized to the width of the page. The default value is null.
30 */
31 Q_PROPERTY(QQuickItem *header READ header WRITE setHeader NOTIFY headerChanged FINAL)
32
33 /**
34 * @brief This property holds the visual content Item.
35 *
36 * It will be resized both in width and height with the layout resizing.
37 * Its height will be resized to still have room for the heder and footer
38 */
39 Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL)
40
41 /**
42 * @brief This property holds the page footer item.
43 *
44 * The footer item is positioned to the bottom,
45 * and resized to the width of the page. The default value is null.
46 */
47 Q_PROPERTY(QQuickItem *footer READ footer WRITE setFooter NOTIFY footerChanged FINAL)
48
49 /**
50 * @brief Space between contentItem and the header and footer items
51 *
52 * The content Item of the page will be positioned at this distance in pixels
53 * from the header and footer Items. The default value is zero.
54 *
55 * @since 6.13
56 */
57 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged FINAL)
58
59public:
60 HeaderFooterLayout(QQuickItem *parent = nullptr);
61 ~HeaderFooterLayout() override;
62
63 void setHeader(QQuickItem *item);
65
66 void setContentItem(QQuickItem *item);
68
69 void setFooter(QQuickItem *item);
71
72 void setSpacing(qreal spacing);
73 qreal spacing() const;
74
75 /**
76 * @brief HeaderFooterLayout normally positions its header, footer and
77 * contentItem once per frame (at polish event). This method forces the it
78 * to recalculate the layout immediately.
79 */
81
83 void headerChanged();
84 void spacingChanged();
85 void contentItemChanged();
86 void footerChanged();
87
88protected:
89 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
90 void componentComplete() override;
91 void updatePolish() override;
92
93private:
94 void markAsDirty();
95 void performLayout();
96 void updateImplicitSize();
97 void disconnectItem(QQuickItem *item);
98
99 QPointer<QQuickItem> m_header;
100 QPointer<QQuickItem> m_contentItem;
101 QPointer<QQuickItem> m_footer;
102
103 qreal m_spacing = 0;
104
105 bool m_isDirty : 1;
106 bool m_performingLayout : 1;
107};
108
109#endif
QQuickItem * footer
This property holds the page footer item.
QML_ELEMENTQQuickItem * header
This property holds the page header item.
Q_INVOKABLE void forceLayout()
HeaderFooterLayout normally positions its header, footer and contentItem once per frame (at polish ev...
qreal spacing
Space between contentItem and the header and footer items.
QQuickItem * contentItem
This property holds the visual content Item.
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QQuickItem(QQuickItem *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri May 2 2025 12:02:16 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.