Warning, /frameworks/kirigami/src/controls/AbstractApplicationWindow.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 import QtQuick 2.12
0008 import QtQml 2.15
0009 import QtQuick.Controls 2.0 as QQC2
0010 import QtQuick.Window 2.5
0011 import org.kde.kirigami 2.4 as Kirigami
0012 import "templates/private" as TP
0013 /**
0014  * @brief A window that provides some basic features needed for all apps.
0015  *
0016  * An abstract application window is a top-level component that provides
0017  * several utilities for convenience such as:
0018  * * ::applicationWindow()
0019  * * ::globalDrawer
0020  * * ::pageStack
0021  * * ::wideScreen
0022  *
0023  * Use this class only if you need custom content for your application that is
0024  * different from the PageRow behavior recommended by the HIG and provided
0025  * by kirigami::AbstractApplicationWindow.
0026  *
0027  * Example usage:
0028  * @code{.qml}
0029  * import org.kde.kirigami 2.4 as Kirigami
0030  *
0031  * Kirigami.ApplicationWindow {
0032  *  [...]
0033  *     globalDrawer: Kirigami.GlobalDrawer {
0034  *         actions: [
0035  *            Kirigami.Action {
0036  *                text: "View"
0037  *                icon.name: "view-list-icons"
0038  *                Kirigami.Action {
0039  *                        text: "action 1"
0040  *                }
0041  *                Kirigami.Action {
0042  *                        text: "action 2"
0043  *                }
0044  *                Kirigami.Action {
0045  *                        text: "action 3"
0046  *                }
0047  *            },
0048  *            Kirigami.Action {
0049  *                text: "Sync"
0050  *                icon.name: "folder-sync"
0051  *            }
0052  *         ]
0053  *     }
0054  *
0055  *     contextDrawer: Kirigami.ContextDrawer {
0056  *         id: contextDrawer
0057  *     }
0058  *
0059  *     pageStack.initialPage: Kirigami.Page {
0060  *         actions.contextualActions: [
0061  *             Kirigami.Action {
0062  *                 text: "context action 1"
0063  *             },
0064  *             Kirigami.Action {
0065  *                 text: "context action 2"
0066  *             },
0067  *             Kirigami.Action {
0068  *                 text: "context action 3"
0069  *             }
0070  *         ]
0071  *     }
0072  *  [...]
0073  * }
0074  * @endcode
0075  * @inherit QtQuick.Controls.ApplicationWindow
0076  */
0077 QQC2.ApplicationWindow {
0078     id: root
0079 
0080 //BEGIN properties
0081     /**
0082      * @brief This property holds the stack used to allocate the pages and to
0083      * manage the transitions between them.
0084      *
0085      * Put a container here, such as QtQuick.Controls.StackView or PageRow.
0086      */
0087     property Item pageStack
0088 
0089     /**
0090      * @brief This property sets whether the standard chrome of the app is
0091      * visible.
0092      *
0093      * These are the action button, the drawer handles, and the application
0094      * header.
0095      *
0096      * default: ``true``
0097      */
0098     property bool controlsVisible: true
0099 
0100     /**
0101      * @brief This property holds the drawer for global actions.
0102      *
0103      * This drawer can be opened by sliding from the left screen edge
0104      * or by either pressing on the handle or sliding it to the right.
0105      *
0106      * @note It is recommended to use the GlobalDrawer here.
0107      * @property kirigami::OverlayDrawer globalDrawer
0108      */
0109     property OverlayDrawer globalDrawer
0110 
0111     /**
0112      * @brief This property specifies whether the application is in "widescreen" mode.
0113      *
0114      * This is enabled on desktops or horizontal tablets.
0115      *
0116      * @note Different styles can have their own logic for deciding this.
0117      */
0118     property bool wideScreen: width >= Kirigami.Units.gridUnit * 60
0119 
0120     /**
0121      * @brief This property holds the drawer for context-dependent actions.
0122      *
0123      * The drawer that will be opened by sliding from the right screen edge
0124      * or by dragging the ActionButton to the left.
0125      *
0126      * @note It is recommended to use the ContextDrawer class here.
0127      *
0128      * The context drawer will display the previously defined contextual
0129      * actions of the page that is currently active in the pageStack.
0130      *
0131      * Example usage:
0132      * @code{.qml}
0133      * import org.kde.kirigami 2.4 as Kirigami
0134      *
0135      * Kirigami.ApplicationWindow {
0136      *  [...]
0137      *     contextDrawer: Kirigami.ContextDrawer {
0138      *         id: contextDrawer
0139      *     }
0140      *  [...]
0141      * }
0142      * @endcode
0143      *
0144      * @code{.qml}
0145      * import org.kde.kirigami 2.4 as Kirigami
0146      *
0147      * Kirigami.Page {
0148      *   [...]
0149      *     // setting the contextual actions
0150      *     actions.contextualActions: [
0151      *         Kirigami.Action {
0152      *             icon.name: "edit"
0153      *             text: "Action text"
0154      *             onTriggered: {
0155      *                 // do stuff
0156      *             }
0157      *         },
0158      *         Kirigami.Action {
0159      *             icon.name: "edit"
0160      *             text: "Action text"
0161      *             onTriggered: {
0162      *                 // do stuff
0163      *             }
0164      *         }
0165      *     ]
0166      *   [...]
0167      * }
0168      * @endcode
0169      *
0170      * @property kirigami::ContextDrawer contextDrawer
0171      */
0172     property OverlayDrawer contextDrawer
0173 
0174     /**
0175      * @brief This property specifies whether the application is in reachable
0176      * mode for single hand use.
0177      *
0178      * The whole content of the application is moved down the screen to be
0179      * reachable with the thumb. If wideScreen is true, or reachableModeEnabled
0180      * is false, this property has no effect.
0181      *
0182      * @warning This property should be treated as readonly. Use
0183      * ``reachableModeEnabled`` instead.
0184      *
0185      * default: ``false``
0186      */
0187     property bool reachableMode: false
0188 
0189     /**
0190      * @brief This property sets whether reachable mode can be used.
0191      */
0192     property bool reachableModeEnabled: true
0193 
0194     /**
0195      * @brief This property holds a Kirigami action that will quit the
0196      * application when triggered.
0197      *
0198      * @since KDE Frameworks 5.76
0199      */
0200     readonly property Kirigami.Action quitAction: Kirigami.Action {
0201         text: qsTr("Quit")
0202         icon.name: "application-exit";
0203         shortcut: StandardKey.Quit
0204         onTriggered: source => root.close();
0205     }
0206 //END properties
0207 
0208 //BEGIN functions
0209     /**
0210      * @brief This function shows a passive notification at the bottom of the
0211      * app window lasting for few seconds, with an optional action button.
0212      *
0213      * @param message Notification's text message that is shown to the user.
0214      * @param timeout Notification's visibility duration. Possible values are:
0215      * "short", "long" or the number of milliseconds. Default is ``7000``.
0216      * @param actionText Notification's action button's text.
0217      * @param callBack A JavaScript function that will be executed when the user
0218      * clicks the button.
0219      */
0220     function showPassiveNotification(message, timeout, actionText, callBack) {
0221         notificationsObject.showNotification(message, timeout, actionText, callBack);
0222     }
0223 
0224    /**
0225     * @brief This function hides the passive notification at specified index,
0226     * if any is shown.
0227     *
0228     * @param index Index of the notification to hide. Default is 0
0229     * (oldest notification).
0230     */
0231     function hidePassiveNotification(index = 0) {
0232         notificationsObject.hideNotification(index);
0233     }
0234 
0235     /**
0236      * @brief This property returns a pointer
0237      * to the main instance of AbstractApplicationWindow.
0238      * 
0239      * This is available to any children of this window,
0240      * including those instantiated from separate QML files,
0241      * making interoperation with multiple files easier.
0242      * 
0243      * Use this whenever you need access to properties
0244      * that are available to the main AbstractApplicationWindow,
0245      * such as its ::pageStack or ::globalDrawer.
0246      * 
0247      * @see AbstractApplicationItem::applicationWindow()
0248      * @returns a pointer to the instantiated AbstractApplicationWindow.
0249      */
0250     function applicationWindow() {
0251         return root;
0252     }
0253 //END functions
0254 
0255     LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
0256     LayoutMirroring.childrenInherit: true
0257 
0258     color: Kirigami.Theme.backgroundColor
0259 
0260     TP.PassiveNotificationsManager {
0261         id: notificationsObject
0262         anchors.bottom: parent.bottom
0263         anchors.horizontalCenter: parent.horizontalCenter
0264         z: 1
0265     }
0266 
0267     MouseArea {
0268         parent: contentItem.parent
0269         z: 0
0270         anchors.fill: parent
0271         onClicked: mouse => {
0272             root.reachableMode = false;
0273         }
0274         visible: root.reachableMode && root.reachableModeEnabled
0275         Rectangle {
0276             anchors.fill: parent
0277             color: Qt.rgba(0, 0, 0, 0.3)
0278             opacity: 0.15
0279             Kirigami.Icon {
0280                 anchors.horizontalCenter: parent.horizontalCenter
0281                 y: x
0282                 width: Kirigami.Units.iconSizes.large
0283                 height: width
0284                 source: "go-up"
0285             }
0286         }
0287     }
0288 
0289     contentItem.z: 1
0290     contentItem.anchors.left: contentItem.parent.left
0291     contentItem.anchors.right: contentItem.parent.right
0292     contentItem.anchors.topMargin: root.wideScreen && header && controlsVisible ? header.height : 0
0293     contentItem.anchors.leftMargin: root.globalDrawer && root.globalDrawer.modal === false && (!root.pageStack || root.pageStack.leftSidebar !== root.globalDrawer) ? root.globalDrawer.width * root.globalDrawer.position : 0
0294     contentItem.anchors.rightMargin: root.contextDrawer && root.contextDrawer.modal === false ? root.contextDrawer.width * root.contextDrawer.position : 0
0295 
0296     Binding {
0297         when: menuBar !== undefined
0298         target: menuBar
0299         property: "x"
0300         value: -contentItem.x
0301         restoreMode: Binding.RestoreBinding
0302     }
0303     Binding {
0304         when: header !== undefined
0305         target: header
0306         property: "x"
0307         value: -contentItem.x
0308         restoreMode: Binding.RestoreBinding
0309     }
0310     Binding {
0311         when: footer !== undefined
0312         target: footer
0313         property: "x"
0314         value: -contentItem.x
0315         restoreMode: Binding.RestoreBinding
0316     }
0317 
0318     contentItem.transform: Translate {
0319         Behavior on y {
0320             NumberAnimation {
0321                 duration: Kirigami.Units.longDuration
0322                 easing.type: Easing.InOutQuad
0323             }
0324         }
0325         y: root.reachableMode && root.reachableModeEnabled && !root.wideScreen ? root.height/2 : 0
0326         x: root.globalDrawer && root.globalDrawer.modal === true && root.globalDrawer.toString().indexOf("SplitDrawer") === 0 ? root.globalDrawer.contentItem.width * root.globalDrawer.position : 0
0327     }
0328     //Don't want overscroll in landscape mode
0329     onWidthChanged: {
0330         if (width > height) {
0331             root.reachableMode = false;
0332         }
0333     }
0334     Binding {
0335         when: globalDrawer !== undefined && root.visible
0336         target: globalDrawer
0337         property: "parent"
0338         value: overlay
0339         restoreMode: Binding.RestoreBinding
0340     }
0341     Binding {
0342         when: contextDrawer !== undefined && root.visible
0343         target: contextDrawer
0344         property: "parent"
0345         value: overlay
0346         restoreMode: Binding.RestoreBinding
0347     }
0348     onPageStackChanged: pageStack.parent = contentItem;
0349 
0350     width: Kirigami.Settings.isMobile ? Kirigami.Units.gridUnit * 30 : Kirigami.Units.gridUnit * 55
0351     height: Kirigami.Settings.isMobile ? Kirigami.Units.gridUnit * 45 : Kirigami.Units.gridUnit * 40
0352     visible: true
0353 
0354     Component.onCompleted: {
0355         // Explicitly break the binding as we need this to be set only at startup.
0356         // if the bindings are active, after this the window is resized by the
0357         // compositor and then the bindings are reevaluated, then the window
0358         // size would reset ignoring what the compositor asked.
0359         // see BUG 433849
0360         root.width = root.width;
0361         root.height = root.height;
0362     }
0363 
0364     // This is needed because discover in mobile mode does not
0365     // close with the global drawer open.
0366     Shortcut {
0367         sequence: root.quitAction.shortcut
0368         context: Qt.ApplicationShortcut
0369         onActivated: root.close();
0370     }
0371 }