Kirigami-addons

FormCard.qml
1/*
2 * Copyright 2022 Devin Lin <devin@kde.org>
3 * SPDX-License-Identifier: LGPL-2.0-or-later
4 */
5
6import QtQuick 2.15
7import QtQuick.Controls 2.15
8import QtQuick.Layouts 1.15
9
10import org.kde.kirigami 2.19 as Kirigami
11
12import "private" as Private
13
14/**
15 * @brief A single card that follows a form style.
16 *
17 * This is the entrypoint component for FormCard.
18 *
19 * A FormCard consists of a container that can be used to create your
20 * own Settings pages. It has a different color than the background.
21 *
22 * Each FormCard can contain one or more Form delegates in its ::contentItem.
23 * To add more than one Form delegate to a FormCard, use a
24 * QtQuick.Layouts.ColumnLayout to group them.
25 *
26 * Multiple FormCards can be grouped with a QtQuick.Layouts.ColumnLayout to
27 * represent different Settings sections.
28 *
29 * Each section is expected to contain a FormCardHeader as the first
30 * delegate, which serves the role of a section title.
31 *
32 * The height of the FormCard matches the implicit height of the
33 * ::contentItem and does not need to be set, while the width is expected
34 * to be given by the parent, for example, via a Layout.fillWidth.
35 *
36 * @since KirigamiAddons 0.11.0
37 *
38 * @inherit QtQuick.Item
39 */
40Item {
41 id: root
42
43 /**
44 * @brief The delegates inside the Form card.
45 *
46 * This is where you should add new Form delegates.
47 */
48 default property alias delegates: internalColumn.data
49
50 /**
51 * @brief The maximum width of the card.
52 *
53 * This can be set to a specific value to force its delegates to wrap
54 * instead of using the entire width of the parent.
55 *
56 * default: `Kirigami.Units.gridUnit * 30`
57 *
58 * @see cardWidthRestricted
59 */
60 property real maximumWidth: Kirigami.Units.gridUnit * 30
61
62 /**
63 * @brief The padding used around the content edges.
64 *
65 * default: `0`
66 */
67 property real padding: 0
68 property real verticalPadding: padding
69 property real horizontalPadding: padding
70 property real topPadding: verticalPadding
71 property real bottomPadding: verticalPadding
72 property real leftPadding: horizontalPadding
73 property real rightPadding: horizontalPadding
74
75 /**
76 * Whether the card's width is being restricted.
77 */
78 readonly property bool cardWidthRestricted: root.width > root.maximumWidth
79
80 Kirigami.Theme.colorSet: Kirigami.Theme.View
81 Kirigami.Theme.inherit: false
82
83 Layout.fillWidth: true
84
85 implicitHeight: topPadding + bottomPadding + internalColumn.implicitHeight + rectangle.borderWidth * 2
86
87 Rectangle {
88 id: rectangle
89 readonly property real borderWidth: 1
90
91 // only have card radius if it isn't filling the entire width
92 radius: root.cardWidthRestricted ? Kirigami.Units.cornerRadius : 0
93 color: Kirigami.Theme.backgroundColor
94
95 anchors {
96 top: parent.top
97 bottom: parent.bottom
98 left: parent.left
99 right: parent.right
100
101 leftMargin: root.cardWidthRestricted ? Math.round((root.width - root.maximumWidth) / 2) : -1
102 rightMargin: root.cardWidthRestricted ? Math.round((root.width - root.maximumWidth) / 2) : -1
103 }
104
105 border {
106 color: Kirigami.ColorUtils.linearInterpolation(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, Kirigami.Theme.frameContrast)
107 width: borderWidth
108 }
109
110 ColumnLayout {
111 id: internalColumn
112
113 // used in FormDelegateBackground to determine whether to round corners of the background
114 readonly property bool _roundCorners: root.cardWidthRestricted
115
116 spacing: 0
117
118 // add 1 to margins to account for the border (so content doesn't overlap it)
119 anchors {
120 fill: parent
121 leftMargin: root.leftPadding + rectangle.borderWidth
122 rightMargin: root.rightPadding + rectangle.borderWidth
123 topMargin: root.topPadding + rectangle.borderWidth
124 bottomMargin: root.bottomPadding + rectangle.borderWidth
125 }
126 }
127 }
128}
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.