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 *
22 * @image html maximizedcomponent.png
23 */
24QQC2.Popup {
25 id: root
27 /**
28 * @brief The title of the overlay window.
29 */
30 property alias title: titleLabel.text
31
32 /**
33 * @brief The subtitle of the overlay window.
34 *
35 * The label will be hidden and the title centered if this is not provided.
36 */
37 property alias subtitle: subtitleLabel.text
38
39 /**
40 * @brief List of top row actions.
41 *
42 * Each action will be allocated a QQC2.ToolButton on the top row. All actions
43 * are right aligned and appear next to the close button which is always present
44 * so does not require specifying.
45 */
46 property alias actions: actionToolBar.actions
47
48 /**
49 * @brief The main content item in the view.
50 *
51 * The item will be the sized to fit the available space. If the item is
52 * larger than the available space it will be shrunk to fit.
53 *
54 * @note If stretching the item isn't desirable the user needs to manage this,
55 * e.g. with a holding item. See ImageMaximizeDelegate.qml for an example.
56 *
57 * @sa ImageMaximizeDelegate.qml
58 */
59 property Item content
61 /**
62 * @brief Item to the left of the overlay title.
63 */
64 property Item leading
65
66 /**
67 * @brief Item at the bottom under the content.
68 */
69 property Item footer
70
71 parent: applicationWindow().overlay
72 closePolicy: QQC2.Popup.CloseOnEscape
73 width: parent.width
74 height: parent.height
75 modal: true
76 padding: 0
77 background: Item {}
78
79 Kirigami.OverlayZStacking.layer: Kirigami.OverlayZStacking.FullScreen
80 z: Kirigami.OverlayZStacking.z
81
82 ColumnLayout {
83 anchors.fill: parent
84 spacing: 0
85
86 QQC2.Control {
87 Layout.fillWidth: true
88 contentItem: RowLayout {
89 spacing: Kirigami.Units.largeSpacing
90
91 Item {
92 id: leadingParent
93 Layout.preferredWidth: root.leading ? root.leading.implicitWidth : 0
94 Layout.preferredHeight: root.leading ? root.leading.implicitHeight : 0
95 visible: root.leading
96 }
97 ColumnLayout {
98 Layout.fillWidth: true
99 spacing: Kirigami.Units.smallSpacing
100
101 QQC2.Label {
102 id: titleLabel
103 Layout.fillWidth: true
104 Layout.maximumWidth: implicitWidth + Kirigami.Units.largeSpacing
105 font.weight: Font.Bold
106 elide: Text.ElideRight
107 textFormat: Text.PlainText
108 }
109 QQC2.Label {
110 id: subtitleLabel
111 Layout.fillWidth: true
112 Layout.maximumWidth: implicitWidth + Kirigami.Units.largeSpacing
113 visible: text !== ""
114 color: Kirigami.Theme.disabledTextColor
115 elide: Text.ElideRight
116 textFormat: Text.PlainText
117 }
118 }
119 Kirigami.ActionToolBar {
120 id: actionToolBar
121 alignment: Qt.AlignRight
122 display: QQC2.AbstractButton.IconOnly
123 }
124 QQC2.ToolButton {
125 Layout.preferredWidth: Kirigami.Units.gridUnit * 2
126 Layout.preferredHeight: Kirigami.Units.gridUnit * 2
127 display: QQC2.AbstractButton.IconOnly
128
129 action: Kirigami.Action {
130 text: i18nd("kirigami-addons6", "Close")
131 icon.name: "dialog-close"
132 onTriggered: root.close()
133 }
134
135 QQC2.ToolTip.text: text
136 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
137 QQC2.ToolTip.visible: hovered
138 }
139 }
140
141 background: Rectangle {
142 color: Kirigami.Theme.alternateBackgroundColor
143 }
144
145 Kirigami.Separator {
146 anchors {
147 left: parent.left
148 right: parent.right
149 bottom: parent.bottom
150 }
151 height: 1
152 }
153 }
154 Item {
155 id: contentParent
156 Layout.fillWidth: true
157 Layout.fillHeight: true
158 }
159 Item {
160 id: footerParent
161 Layout.fillWidth: true
162 Layout.preferredHeight: root.footer ? root.footer.implicitHeight > Kirigami.Units.gridUnit * 12 ? Kirigami.Units.gridUnit * 12 : root.footer.implicitHeight : 0
163 visible: root.footer && !root.hideCaption
164 }
165 }
166
167 // TODO: blur
168 QQC2.Overlay.modal: Rectangle {
169 color: Qt.rgba(0, 0, 0, 0.5)
170 }
171
172 onLeadingChanged: {
173 if (!root.leading) {
174 return;
175 }
176 root.leading.parent = leadingParent;
177 root.leading.anchors.fill = leadingParent;
178 }
179
180 onContentChanged: {
181 if (!root.content) {
182 return;
183 }
184 root.content.parent = contentParent;
185 root.content.anchors.fill = contentParent;
186 }
187
188 onFooterChanged: {
189 if (!root.footer) {
190 return;
191 }
192 root.footer.parent = footerParent;
193 root.footer.anchors.fill = footerParent;
194 }
195}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.