Kirigami2

DialogHeader.qml
1/*
2 SPDX-FileCopyrightText: 2021 Devin Lin <espidev@gmail.com>
3 SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
4 SPDX-FileCopyrightText: 2022 ivan tkachenko <me@ratijas.tk>
5 SPDX-FileCopyrightText: 2025 Nate Graham <nate@kde.org>
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8pragma ComponentBehavior: Bound
9
10import QtQuick
11import QtQuick.Templates as T
12import org.kde.kirigami as Kirigami
13import org.kde.kirigami.dialogs as KDialogs
14
15/**
16 * @brief Base for a header, to be used as the header: item of a Dialog.
17 *
18 * Provides appropriate padding and a bottom separator when the dialog's content
19 * is scrollable.
20 *
21 * Chiefly useful as the base element of a custom header. Example usage for this:
22 *
23 * @code{.qml}
24 * import QtQuick
25 * import org.kde.kirigami as Kirigami
26 * import org.kde.kirigami.dialogs as KD
27 *
28 * Kirigami.Dialog {
29 * id: myDialog
30 *
31 * title: i18n("My Dialog")
32 *
33 * standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
34 *
35 * header: KDialogs.DialogHeader {
36 * dialog: myDialog
37 * contentItem: [...]
38 * }
39 * [...]
40 * }
41 * @endcode
42 * @inherit T.Control
43 */
44T.Control {
45 id: root
46
47 /**
48 * @brief This property points to the parent dialog, some of whose properties
49 * need to be available here.
50 * @property T.Dialog dialog
51 */
52 required property T.Dialog dialog
53
54 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
55 implicitContentWidth + leftPadding + rightPadding)
56 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
57 implicitContentHeight + topPadding + bottomPadding)
58
59 padding: Kirigami.Units.largeSpacing
60 bottomPadding: verticalPadding + headerSeparator.implicitHeight // add space for bottom separator
61
62 // Bottom separator shown when content is scrollable
63 background: Item {
64 Kirigami.Separator {
65 id: headerSeparator
66 width: parent.width
67 anchors.bottom: parent.bottom
68 visible: if (root.dialog.contentItem instanceof T.Pane || root.dialog.contentItem instanceof Flickable) {
69 return root.dialog.contentItem.contentHeight > root.dialog.implicitContentHeight;
70 } else {
71 return false;
72 }
73 }
74 }
75
76 contentItem: KDialogs.DialogHeaderTopContent {
77 dialog: root.dialog
78 }
79}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 28 2025 11:50:27 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.