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
8import QtQuick.Controls as QQC2
9import QtQuick.Templates as T
10import QtQuick.Layouts
11
12import org.kde.kirigami 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 spacing: Kirigami.Units.smallSpacing
63
64 anchors {
65 fill: parent
66 leftMargin: root.cardWidthRestricted ? Math.round((root.width - root.maximumWidth) / 2) : 0
67 rightMargin: root.cardWidthRestricted ? Math.round((root.width - root.maximumWidth) / 2) : 0
68 }
69
70 QQC2.Label {
71 id: headerContent
72
73 topPadding: root.topPadding
74 bottomPadding: root.bottomPadding
75 leftPadding: root.leftPadding
76 rightPadding: root.rightPadding
77
78 font.weight: Font.DemiBold
79 wrapMode: Text.WordWrap
80 Accessible.role: Accessible.Heading
81 Layout.fillWidth: true
82 }
83
84 Repeater {
85 model: root.actions
86
87 QQC2.ToolButton {
88 required property var modelData
89
90 action: modelData
91 visible: modelData
92 }
93 }
94 }
95}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:12:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.