Kirigami2

DialogHeaderTopContent.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 */
8
9import QtQuick
10import QtQuick.Layouts
11import QtQuick.Templates as T
12import QtQuick.Controls as QQC2
13import org.kde.kirigami as Kirigami
14
15/**
16 * @brief Standard top content for a Dialog, including header text and an
17 * optional close button.
18 *
19 * Provides appropriate padding and a bottom separator when the dialog's content
20 * is scrollable.
21 *
22 * Chiefly useful as the first item in a `ColumnLayout` inside a custom header,
23 * for when you want a custom header that only consists of extra content, and
24 * does not need to override the standard content. Example usage for a this:
25 *
26 * @code{.qml}
27 * import QtQuick
28 * import QtQuick.Layouts
29 * import org.kde.kirigami as Kirigami
30 * import org.kde.kirigami.dialogs as KDialogs
31 *
32 * Kirigami.Dialog {
33 * id: myDialog
34 *
35 * title: i18n("My Dialog")
36 *
37 * standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
38 *
39 * header: KDialogs.DialogHeader {
40 * dialog: myDialog
41 *
42 * contentItem: ColumnLayout {
43 * Spacing: Kirigami.Units.smallSpacing
44 *
45 * KDialogs.DialogHeaderTopContent {
46 * dialog: myDialog
47 * }
48 *
49 * [...]
50 * }
51 * }
52 * [...]
53 * }
54 * @endcode
55 * @inherit T.Control
56 */
57RowLayout {
58 id: root
59
60 /**
61 * @brief This property points to the parent dialog, some of whose properties
62 * need to be available here.
63 * @property T.Dialog dialog
64 */
65 required property T.Dialog dialog
66
67 /**
68 * @brief Whether the close button should be visible.
69 *
70 * Defaults to true.
71 *
72 * @property bool showCloseButton
73 */
74 property alias showCloseButton: closeButton.visible
75
76 spacing: Kirigami.Units.smallSpacing
77
78 Kirigami.Heading {
79 Layout.fillWidth: true
80 Layout.alignment: Qt.AlignVCenter
81
82 text: root.dialog.title.length === 0 ? " " : root.dialog.title // always have text to ensure header height
83 textFormat: Text.PlainText
84 elide: Text.ElideRight
85
86 // use tooltip for long text that is elided
87 QQC2.ToolTip.visible: truncated && titleHoverHandler.hovered
88 QQC2.ToolTip.text: root.dialog.title
89
90 HoverHandler {
91 id: titleHoverHandler
92 }
93 }
94
95 QQC2.ToolButton {
96 id: closeButton
97 Layout.alignment: Qt.AlignRight | Qt.AlignTop
98
99 icon.name: hovered ? "window-close" : "window-close-symbolic"
100 text: qsTr("Close", "@action:button close dialog")
101 display: QQC2.AbstractButton.IconOnly
102 visible: root.dialog?.showCloseButton ?? true
103
104 onClicked: root.dialog.reject()
105 }
106}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri May 2 2025 12:02:15 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.