Kirigami-addons

FormHeader.qml
1/*
2 * SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
3 * SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7import QtQuick 2.15
8import QtQuick.Controls 2.15 as QQC2
9import QtQuick.Templates 2.15 as T
10import QtQuick.Layouts 1.15
11
12import org.kde.kirigami 2.19 as Kirigami
13
14/**
15 * @brief A header item for a form card.
16 *
17 * @note The header should be placed above the card in a layout not as a child.
18 */
19Item {
20 id: root
21
22 /**
23 * @brief This property holds the header title.
24 *
25 * @property string title
26 */
27 property alias title: headerContent.text
28
29 property alias trailing: header.data
30
31 /**
32 * @brief The maximum width of the header.
33 */
34 property real maximumWidth: Kirigami.Units.gridUnit * 30
36 property list<T.Action> actions
37
38 /**
39 * @brief These properties hold the padding around the heading.
40 */
41 property real topPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
42 property real bottomPadding: Kirigami.Units.smallSpacing
43 property real leftPadding: cardWidthRestricted ? Kirigami.Units.smallSpacing : Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
44 property real rightPadding: cardWidthRestricted ? Kirigami.Units.smallSpacing : Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
45
46 /**
47 * @brief Whether the card's width is being restricted.
48 */
49 readonly property bool cardWidthRestricted: root.width > root.maximumWidth
50
51 Kirigami.Theme.colorSet: Kirigami.Theme.View
52 Kirigami.Theme.inherit: false
53
54 Layout.fillWidth: true
55
56 implicitHeight: header.implicitHeight
57 implicitWidth: header.implicitWidth + header.anchors.leftMargin + header.anchors.rightMargin
58
59 RowLayout {
60 id: header
61
62 anchors {
63 fill: parent
64 leftMargin: root.cardWidthRestricted ? Math.round((root.width - root.maximumWidth) / 2) : 0
65 rightMargin: root.cardWidthRestricted ? Math.round((root.width - root.maximumWidth) / 2) : 0
66 }
67
68 QQC2.Label {
69 id: headerContent
70
71 topPadding: root.topPadding
72 bottomPadding: root.bottomPadding
73 leftPadding: root.leftPadding
74 rightPadding: root.rightPadding
75
76 font.weight: Font.DemiBold
77 wrapMode: Text.WordWrap
78 Accessible.role: Accessible.Heading
79 Layout.fillWidth: true
80 }
81
82 Repeater {
83 model: root.actions
84
85 QQC2.ToolButton {
86 required property var modelData
87
88 action: modelData
89 visible: modelData
90 }
91 }
92 }
93}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 3 2024 11:46:57 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.