Kirigami-addons

AbstractMaximizeComponent.qml
1// SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
2// SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
3
4import QtQuick
5import QtQuick.Controls as QQC2
6import QtQuick.Layouts
7import Qt.labs.qmlmodels
8
9import org.kde.kirigami as Kirigami
10
11/**
12 * @brief A popup that covers the entire window to show a content item.
13 *
14 * This component is designed to show a content item at the maximum size the
15 * application window will allow. The typical use is for showing a maximized image
16 * or other piece of media in an application, but it could be any item if desired.
17 *
18 * The popup also has a header bar which has a writable title, an optional leading
19 * item to the left, a list of custom actions specified by the actions property
20 * and an optional footer item.
21 */
22QQC2.Popup {
23 id: root
25 /**
26 * @brief The title of the overlay window.
27 */
28 property alias title: titleLabel.text
29
30 /**
31 * @brief The subtitle of the overlay window.
32 *
33 * The label will be hidden and the title centered if this is not provided.
34 */
35 property alias subtitle: subtitleLabel.text
36
37 /**
38 * @brief List of top row actions.
39 *
40 * Each action will be allocated a QQC2.ToolButton on the top row. All actions
41 * are right aligned and appear next to the close button which is always present
42 * so does not require specifying.
43 */
44 property alias actions: actionToolBar.actions
45
46 /**
47 * @brief The main content item in the view.
48 *
49 * The item will be the sized to fit the available space. If the item is
50 * larger than the available space it will be shrunk to fit.
51 *
52 * @note If stretching the item isn't desirable the user needs to manage this,
53 * e.g. with a holding item. See ImageMaximizeDelegate.qml for an example.
54 *
55 * @sa ImageMaximizeDelegate.qml
56 */
57 property Item content
59 /**
60 * @brief Item to the left of the overlay title.
61 */
62 property Item leading
63
64 /**
65 * @brief Item at the bottom under the content.
66 */
67 property Item footer
68
69 parent: applicationWindow().overlay
70 closePolicy: QQC2.Popup.CloseOnEscape
71 width: parent.width
72 height: parent.height
73 modal: true
74 padding: 0
75 background: Item {}
76
77 Kirigami.OverlayZStacking.layer: Kirigami.OverlayZStacking.FullScreen
78 z: Kirigami.OverlayZStacking.z
79
80 ColumnLayout {
81 anchors.fill: parent
82 spacing: 0
83
84 QQC2.Control {
85 Layout.fillWidth: true
86 contentItem: RowLayout {
87 spacing: Kirigami.Units.largeSpacing
88
89 Item {
90 id: leadingParent
91 Layout.preferredWidth: root.leading ? root.leading.implicitWidth : 0
92 Layout.preferredHeight: root.leading ? root.leading.implicitHeight : 0
93 visible: root.leading
94 }
95 ColumnLayout {
96 Layout.fillWidth: true
97 spacing: Kirigami.Units.smallSpacing
98
99 QQC2.Label {
100 id: titleLabel
101 Layout.fillWidth: true
102 Layout.maximumWidth: implicitWidth + Kirigami.Units.largeSpacing
103 font.weight: Font.Bold
104 elide: Text.ElideRight
105 textFormat: Text.PlainText
106 }
107 QQC2.Label {
108 id: subtitleLabel
109 Layout.fillWidth: true
110 Layout.maximumWidth: implicitWidth + Kirigami.Units.largeSpacing
111 visible: text !== ""
112 color: Kirigami.Theme.disabledTextColor
113 elide: Text.ElideRight
114 textFormat: Text.PlainText
115 }
116 }
117 Kirigami.ActionToolBar {
118 id: actionToolBar
119 alignment: Qt.AlignRight
120 display: QQC2.AbstractButton.IconOnly
121 }
122 QQC2.ToolButton {
123 Layout.preferredWidth: Kirigami.Units.gridUnit * 2
124 Layout.preferredHeight: Kirigami.Units.gridUnit * 2
125 display: QQC2.AbstractButton.IconOnly
126
127 action: Kirigami.Action {
128 text: i18nd("kirigami-addons6", "Close")
129 icon.name: "dialog-close"
130 onTriggered: root.close()
131 }
132
133 QQC2.ToolTip.text: text
134 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
135 QQC2.ToolTip.visible: hovered
136 }
137 }
138
139 background: Rectangle {
140 color: Kirigami.Theme.alternateBackgroundColor
141 }
142
143 Kirigami.Separator {
144 anchors {
145 left: parent.left
146 right: parent.right
147 bottom: parent.bottom
148 }
149 height: 1
150 }
151 }
152 Item {
153 id: contentParent
154 Layout.fillWidth: true
155 Layout.fillHeight: true
156 }
157 Item {
158 id: footerParent
159 Layout.fillWidth: true
160 Layout.preferredHeight: root.footer ? root.footer.implicitHeight > Kirigami.Units.gridUnit * 12 ? Kirigami.Units.gridUnit * 12 : root.footer.implicitHeight : 0
161 visible: root.footer && !root.hideCaption
162 }
163 }
164
165 // TODO: blur
166 QQC2.Overlay.modal: Rectangle {
167 color: Qt.rgba(0, 0, 0, 0.5)
168 }
169
170 onLeadingChanged: {
171 if (!root.leading) {
172 return;
173 }
174 root.leading.parent = leadingParent;
175 root.leading.anchors.fill = leadingParent;
176 }
177
178 onContentChanged: {
179 if (!root.content) {
180 return;
181 }
182 root.content.parent = contentParent;
183 root.content.anchors.fill = contentParent;
184 }
185
186 onFooterChanged: {
187 if (!root.footer) {
188 return;
189 }
190 root.footer.parent = footerParent;
191 root.footer.anchors.fill = footerParent;
192 }
193}
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.