Warning, /libraries/kirigami-addons/src/components/AbstractMaximizeComponent.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
0002 // SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 import Qt.labs.qmlmodels
0008 
0009 import org.kde.kirigami as Kirigami
0010 
0011 /**
0012  * @brief A popup that covers the entire window to show a content item.
0013  *
0014  * This component is designed to show a content item at the maximum size the
0015  * application window will allow. The typical use is for showing a maximized image
0016  * or other piece of media in an application, but it could be any item if desired.
0017  *
0018  * The popup also has a header bar which has a writable title, an optional leading
0019  * item to the left, a list of custom actions specified by the actions property
0020  * and an optional footer item.
0021  */
0022 QQC2.Popup {
0023     id: root
0024 
0025     /**
0026      * @brief The title of the overlay window.
0027      */
0028     property alias title: titleLabel.text
0029 
0030     /**
0031      * @brief The subtitle of the overlay window.
0032      *
0033      * The label will be hidden and the title centered if this is not provided.
0034      */
0035     property alias subtitle: subtitleLabel.text
0036 
0037     /**
0038      * @brief List of top row actions.
0039      *
0040      * Each action will be allocated a QQC2.ToolButton on the top row. All actions
0041      * are right aligned and appear next to the close button which is always present
0042      * so does not require specifying.
0043      */
0044     property alias actions: actionToolBar.actions
0045 
0046     /**
0047      * @brief The main content item in the view.
0048      *
0049      * The item will be the sized to fit the available space. If the item is
0050      * larger than the available space it will be shrunk to fit.
0051      *
0052      * @note If stretching the item isn't desirable the user needs to manage this,
0053      *       e.g. with a holding item. See ImageMaximizeDelegate.qml for an example.
0054      *
0055      * @sa ImageMaximizeDelegate.qml
0056      */
0057     property Item content
0058 
0059     /**
0060      * @brief Item to the left of the overlay title.
0061      */
0062     property Item leading
0063 
0064     /**
0065      * @brief Item at the bottom under the content.
0066      */
0067     property Item footer
0068 
0069     parent: applicationWindow().overlay
0070     closePolicy: QQC2.Popup.CloseOnEscape
0071     width: parent.width
0072     height: parent.height
0073     modal: true
0074     padding: 0
0075     background: Item {}
0076 
0077     Kirigami.OverlayZStacking.layer: Kirigami.OverlayZStacking.FullScreen
0078     z: Kirigami.OverlayZStacking.z
0079 
0080     ColumnLayout {
0081         anchors.fill: parent
0082         spacing: 0
0083 
0084         QQC2.Control {
0085             Layout.fillWidth: true
0086             contentItem: RowLayout {
0087                 spacing: Kirigami.Units.largeSpacing
0088 
0089                 Item {
0090                     id: leadingParent
0091                     Layout.preferredWidth: root.leading ? root.leading.implicitWidth : 0
0092                     Layout.preferredHeight: root.leading ? root.leading.implicitHeight : 0
0093                     visible: root.leading
0094                 }
0095                 ColumnLayout {
0096                     Layout.fillWidth: true
0097                     spacing: Kirigami.Units.smallSpacing
0098 
0099                     QQC2.Label {
0100                         id: titleLabel
0101                         Layout.fillWidth: true
0102                         Layout.maximumWidth: implicitWidth + Kirigami.Units.largeSpacing
0103                         font.weight: Font.Bold
0104                         elide: Text.ElideRight
0105                         textFormat: Text.PlainText
0106                     }
0107                     QQC2.Label {
0108                         id: subtitleLabel
0109                         Layout.fillWidth: true
0110                         Layout.maximumWidth: implicitWidth + Kirigami.Units.largeSpacing
0111                         visible: text !== ""
0112                         color: Kirigami.Theme.disabledTextColor
0113                         elide: Text.ElideRight
0114                         textFormat: Text.PlainText
0115                     }
0116                 }
0117                 Kirigami.ActionToolBar {
0118                     id: actionToolBar
0119                     alignment: Qt.AlignRight
0120                     display: QQC2.AbstractButton.IconOnly
0121                 }
0122                 QQC2.ToolButton {
0123                     Layout.preferredWidth: Kirigami.Units.gridUnit * 2
0124                     Layout.preferredHeight: Kirigami.Units.gridUnit * 2
0125                     display: QQC2.AbstractButton.IconOnly
0126 
0127                     action: Kirigami.Action {
0128                         text: i18nd("kirigami-addons6", "Close")
0129                         icon.name: "dialog-close"
0130                         onTriggered: root.close()
0131                     }
0132 
0133                     QQC2.ToolTip.text: text
0134                     QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0135                     QQC2.ToolTip.visible: hovered
0136                 }
0137             }
0138 
0139             background: Rectangle {
0140                 color: Kirigami.Theme.alternateBackgroundColor
0141             }
0142 
0143             Kirigami.Separator {
0144                 anchors {
0145                     left: parent.left
0146                     right: parent.right
0147                     bottom: parent.bottom
0148                 }
0149                 height: 1
0150             }
0151         }
0152         Item {
0153             id: contentParent
0154             Layout.fillWidth: true
0155             Layout.fillHeight: true
0156         }
0157         Item {
0158             id: footerParent
0159             Layout.fillWidth: true
0160             Layout.preferredHeight: root.footer ? root.footer.implicitHeight > Kirigami.Units.gridUnit * 12 ? Kirigami.Units.gridUnit * 12 : root.footer.implicitHeight : 0
0161             visible: root.footer && !root.hideCaption
0162         }
0163     }
0164 
0165     // TODO: blur
0166     QQC2.Overlay.modal: Rectangle {
0167         color: Qt.rgba(0, 0, 0, 0.5)
0168     }
0169 
0170     onLeadingChanged: {
0171         if (!root.leading) {
0172             return;
0173         }
0174         root.leading.parent = leadingParent;
0175         root.leading.anchors.fill = leadingParent;
0176     }
0177 
0178     onContentChanged: {
0179         if (!root.content) {
0180             return;
0181         }
0182         root.content.parent = contentParent;
0183         root.content.anchors.fill = contentParent;
0184     }
0185 
0186     onFooterChanged: {
0187         if (!root.footer) {
0188             return;
0189         }
0190         root.footer.parent = footerParent;
0191         root.footer.anchors.fill = footerParent;
0192     }
0193 }