KCMUtils

SimpleKCM.qml
1/*
2 SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7import QtQuick
8import QtQuick.Controls as QQC2
9import org.kde.kirigami as Kirigami
10
11/**
12 * This component is intended to be used as root item for
13 * KCMs with arbitrary content. Often a Kirigami.FormLayout
14 * is used as main element.
15 * It is possible to specify a header and footer component.
16 * @code
17 * import org.kde.kcmutils as KCMUtils
18 * import org.kde.kirigami as Kirigami
19 *
20 * KCMUtils.SimpleKCM {
21 * Kirigami.FormLayout {
22 * TextField {
23 * Kirigami.FormData.label: "Label:"
24 * }
25 * TextField {
26 * Kirigami.FormData.label: "Label:"
27 * }
28 * }
29 * footer: Item {...}
30 * }
31 * @endcode
32 * @inherits org.kde.kirigami.ScrollablePage
33 */
34Kirigami.ScrollablePage {
35 id: root
37 readonly property int margins: 6 // Layout_ChildMarginWidth from Breeze
38
39 /**
40 * extraFooterTopPadding: bool
41 * @deprecated unused
42 * Default: false
43 */
44 property bool extraFooterTopPadding: false
45
46 /**
47 * headerPaddingEnabled: bool
48 * Whether the contents of the header will have automatic padding around it.
49 * Should be disabled when using an InlineMessage or custom content item in
50 * the header that's intended to touch the window edges.
51 * Default: false
52 */
53 property bool headerPaddingEnabled: false
54
55 function __itemVisible(item: Item): bool {
56 return item !== null && item.visible && item.implicitHeight > 0;
57 }
58
59 function __headerContentVisible(): bool {
60 return __itemVisible(headerParent.contentItem);
61 }
62
63 property bool __flickableOverflows: flickable.contentHeight + flickable.topMargin + flickable.bottomMargin > flickable.height
64
65 // Context properties are not reliable
66 title: (typeof kcm !== "undefined") ? kcm.name : ""
67
68 // Make pages fill the whole view by default
69 Kirigami.ColumnView.fillWidth: true
70
71 property bool sidebarMode: false
72
73 topPadding: margins
74 leftPadding: margins
75 rightPadding: margins
76 bottomPadding: margins
77
78 header: Column {
79 Kirigami.Padding {
80 id: headerParent
81
82 anchors {
83 left: parent.left
84 right: parent.right
85 }
86
87 height: root.__headerContentVisible() ? undefined : 0
88 padding: root.headerPaddingEnabled ? root.margins : 0
89 }
90
91 // When the header is visible, we need to add a line below to separate
92 // it from the view
93 Kirigami.Separator {
94 anchors {
95 left: parent.left
96 right: parent.right
97 }
98
99 visible: root.__headerContentVisible()
100 }
101 }
102
103 function __swapContentIntoContainer(property: string, container: Item): void {
104 const content = this[property];
105 const rootContainer = container.parent;
106
107 if (content && content !== rootContainer) {
108 // Revert the effect of repeated onHeaderChanged invocations
109 // during initialization in Page super-type.
110 content.anchors.top = undefined;
111
112 this[property] = rootContainer;
113 container.contentItem = content;
114 }
115 }
116
117 function __adoptOverlaySheets(): void {
118 // Search overlaysheets in contentItem, parent to root if found
119 for (const object of contentItem.data) {
120 if (object instanceof Kirigami.OverlaySheet) {
121 if (object.parent === null) {
122 object.parent = this;
123 }
124 data.push(object);
125 }
126 }
127 }
128
129 Component.onCompleted: {
130 __swapContentIntoContainer("header", headerParent);
131 __adoptOverlaySheets();
132 }
133}
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:20 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.