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 2.15
0005 import QtQuick.Controls 2.15 as QQC2
0006 import QtQuick.Layouts 1.15
0007 import Qt.labs.qmlmodels 1.0
0008 
0009 import org.kde.kirigami 2.15 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     ColumnLayout {
0078         anchors.fill: parent
0079         spacing: 0
0080 
0081         QQC2.Control {
0082             Layout.fillWidth: true
0083             contentItem: RowLayout {
0084                 spacing: Kirigami.Units.largeSpacing
0085 
0086                 Item {
0087                     id: leadingParent
0088                     Layout.preferredWidth: root.leading ? root.leading.implicitWidth : 0
0089                     Layout.preferredHeight: root.leading ? root.leading.implicitHeight : 0
0090                     visible: root.leading
0091                 }
0092                 ColumnLayout {
0093                     Layout.fillWidth: true
0094                     spacing: Kirigami.Units.smallSpacing
0095 
0096                     QQC2.Label {
0097                         id: titleLabel
0098                         Layout.fillWidth: true
0099                         Layout.maximumWidth: implicitWidth + Kirigami.Units.largeSpacing
0100                         font.weight: Font.Bold
0101                         elide: Text.ElideRight
0102                         textFormat: Text.PlainText
0103                     }
0104                     QQC2.Label {
0105                         id: subtitleLabel
0106                         Layout.fillWidth: true
0107                         Layout.maximumWidth: implicitWidth + Kirigami.Units.largeSpacing
0108                         visible: text !== ""
0109                         color: Kirigami.Theme.disabledTextColor
0110                         elide: Text.ElideRight
0111                         textFormat: Text.PlainText
0112                     }
0113                 }
0114                 Kirigami.ActionToolBar {
0115                     id: actionToolBar
0116                     alignment: Qt.AlignRight
0117                     display: QQC2.AbstractButton.IconOnly
0118                 }
0119                 QQC2.ToolButton {
0120                     Layout.preferredWidth: Kirigami.Units.gridUnit * 2
0121                     Layout.preferredHeight: Kirigami.Units.gridUnit * 2
0122                     display: QQC2.AbstractButton.IconOnly
0123 
0124                     action: Kirigami.Action {
0125                         text: i18nd("kirigami-addons", "Close")
0126                         icon.name: "dialog-close"
0127                         onTriggered: root.close()
0128                     }
0129 
0130                     QQC2.ToolTip.text: text
0131                     QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0132                     QQC2.ToolTip.visible: hovered
0133                 }
0134             }
0135 
0136             background: Rectangle {
0137                 color: Kirigami.Theme.alternateBackgroundColor
0138             }
0139 
0140             Kirigami.Separator {
0141                 anchors {
0142                     left: parent.left
0143                     right: parent.right
0144                     bottom: parent.bottom
0145                 }
0146                 height: 1
0147             }
0148         }
0149         Item {
0150             id: contentParent
0151             Layout.fillWidth: true
0152             Layout.fillHeight: true
0153         }
0154         Item {
0155             id: footerParent
0156             Layout.fillWidth: true
0157             Layout.preferredHeight: root.footer ? root.footer.implicitHeight > Kirigami.Units.gridUnit * 12 ? Kirigami.Units.gridUnit * 12 : root.footer.implicitHeight : 0
0158             visible: root.footer && !root.hideCaption
0159         }
0160     }
0161 
0162     // TODO: blur
0163     QQC2.Overlay.modal: Rectangle {
0164         color: Qt.rgba(0, 0, 0, 0.5)
0165     }
0166 
0167     onLeadingChanged: {
0168         if (!root.leading) {
0169             return;
0170         }
0171         root.leading.parent = leadingParent;
0172         root.leading.anchors.fill = leadingParent;
0173     }
0174 
0175     onContentChanged: {
0176         if (!root.content) {
0177             return;
0178         }
0179         root.content.parent = contentParent;
0180         root.content.anchors.fill = contentParent;
0181     }
0182 
0183     onFooterChanged: {
0184         if (!root.footer) {
0185             return;
0186         }
0187         root.footer.parent = footerParent;
0188         root.footer.anchors.fill = footerParent;
0189     }
0190 }