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{
23 Q_OBJECT
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
49public:
50 HeaderFooterLayout(QQuickItem *parent = nullptr);
51 ~HeaderFooterLayout() override;
52
53 void setHeader(QQuickItem *item);
54 QQuickItem *header();
55
56 void setContentItem(QQuickItem *item);
57 QQuickItem *contentItem();
58
59 void setFooter(QQuickItem *item);
60 QQuickItem *footer();
61
62 /**
63 * @brief HeaderFooterLayout normally positions its header, footer and
64 * contentItem once per frame (at polish event). This method forces the it
65 * to recalculate the layout immediately.
66 */
67 Q_INVOKABLE void forceLayout();
68
69Q_SIGNALS:
70 void headerChanged();
71 void contentItemChanged();
72 void footerChanged();
73
74protected:
75 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
76 void componentComplete() override;
77 void updatePolish() override;
78
79private:
80 void markAsDirty();
81 void performLayout();
82 void updateImplicitSize();
83 void disconnectItem(QQuickItem *item);
84
85 QPointer<QQuickItem> m_header;
86 QPointer<QQuickItem> m_contentItem;
87 QPointer<QQuickItem> m_footer;
88
89 bool m_isDirty : 1;
90 bool m_performingLayout : 1;
91};
92
93#endif
94

source code of kirigami/src/headerfooterlayout.h