Kirigami-addons

BottomDrawer.qml
1// SPDX-FileCopyrightText: 2023 Mathis BrĂ¼chert <mbb@kaidan.im>
2//
3// SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
4
5import QtQuick
6import QtQuick.Controls as QQC2
7import org.kde.kirigami as Kirigami
8import QtQuick.Layouts
9
10/**
11* @brief A bottom drawer component with a drag indicator.
12*
13* Example:
14* @code{.qml}
15* import org.kde.kirigamiaddons.delegates 1.0 as Delegates
16* import org.kde.kirigamiaddons.components 1.0 as Components
17*
18* Components.BottomDrawer {
19* id: drawer
20*
21* headerContentItem: Kirigami.Heading {
22* text: "Drawer"
23* }
24*
25* Delegates.RoundedItemDelegate {
26* text: "Action 1"
27* icon.name: "list-add"
28* onClicked: {
29* doSomething()
30* drawer.close()
31* }
32* }
33
34* Delegates.RoundedItemDelegate {
35* text: "Action 1"
36* icon.name: "list-add"
37* onClicked: {
38* doSomething()
39* drawer.close()
40* }
41* }
42* }
43* @endcode
44*
45* @image html bottomdrawer.png
46*
47* @since KirigamiAddons 0.12.0
48*/
49QQC2.Drawer {
50 id: root
51
52 /**
53 * @brief This property holds the content item of the drawer
54 */
55 default property alias drawerContentItem: drawerContent.contentItem
56
57 /**
58 * @brief This property holds the content item of the drawer header
59 *
60 * when no headerContentItem is set, the header will not be displayed
61 */
62 property alias headerContentItem: headerContent.contentItem
63
64 component Handle: Rectangle {
65 color: Kirigami.Theme.textColor
66 radius: height
67 opacity: 0.5
68
69 implicitWidth: Math.round(Kirigami.Units.gridUnit * 2.5)
70 implicitHeight: Math.round(Kirigami.Units.gridUnit / 4)
71
72 Layout.margins: Kirigami.Units.mediumSpacing
73 Layout.alignment: Qt.AlignHCenter
74 }
75
76 edge: Qt.BottomEdge
77 width: applicationWindow().width
78 height: Math.min(contentItem.implicitHeight, Math.round(applicationWindow().height * 0.8))
79
80 // makes sure the drawer is not able to be opened when not trigered
81 interactive : false
82
83 background: Kirigami.ShadowedRectangle {
84 corners {
85 topRightRadius: Kirigami.Units.largeSpacing
86 topLeftRadius: Kirigami.Units.largeSpacing
87 }
88
89 shadow {
90 size: Kirigami.Units.gridUnit
91 color: Qt.rgba(0, 0, 0, 0.5)
92 }
93
94 color: Kirigami.Theme.backgroundColor
95 }
96
97 onAboutToShow: root.interactive = true
98 onClosed: root.interactive = false
99
100 contentItem: ColumnLayout {
101 spacing: 0
102
103 Kirigami.ShadowedRectangle {
104 id: headerBackground
105
106 visible: headerContentItem
107 height: header.implicitHeight
108
109 Kirigami.Theme.colorSet: Kirigami.Theme.Window
110 color: Kirigami.Theme.backgroundColor
111
112 Layout.fillWidth: true
113
114 corners {
115 topRightRadius: 10
116 topLeftRadius: 10
117 }
118
119 ColumnLayout{
120 id:header
121
122 anchors.fill: parent
123 spacing:0
124 clip: true
125
126 Handle {
127 // drag indicator displayed when there is a headerContentItem
128 id: handle
129 }
130
131 QQC2.Control {
132 id: headerContent
133
134 topPadding: 0
135 leftPadding: Kirigami.Units.mediumSpacing + handle.height
136 rightPadding: Kirigami.Units.mediumSpacing + handle.height
137 bottomPadding: Kirigami.Units.mediumSpacing + handle.height
138
139 Layout.fillHeight: true
140 Layout.fillWidth: true
141 }
142 }
143 }
144
145 Handle {
146 // drag indecator displayed when there is no headerContentItem
147 visible: !headerContentItem
148 Layout.topMargin: Kirigami.Units.largeSpacing
149 Layout.bottomMargin: Kirigami.Units.largeSpacing
150 }
151
152 Kirigami.Separator {
153 Layout.fillWidth: true
154 }
155
156 QQC2.Control {
157 id: drawerContent
158
159 Layout.fillWidth: true
160 Layout.fillHeight: true
161
162 leftPadding: 0
163 rightPadding: 0
164 topPadding: 0
165 bottomPadding: 0
166
167 background: Rectangle {
168 Kirigami.Theme.colorSet: Kirigami.Theme.View
169 Kirigami.Theme.inherit: false
170 color: Kirigami.Theme.backgroundColor
171 }
172 }
173 }
174}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.