Warning, /maui/mauikit/src/controls.5/private/BaseWindow.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   Copyright 2018 Camilo Higuita <milo.h@aol.com>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU Library General Public License as
0006  *   published by the Free Software Foundation; either version 2, or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU General Public License for more details
0013  *
0014  *   You should have received a copy of the GNU Library General Public
0015  *   License along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018  */
0019 
0020 import QtQuick 
0021 
0022 import QtQuick.Window 
0023 import QtQuick.Controls
0024 
0025 import Qt5Compat.GraphicalEffects
0026 
0027 import org.mauikit.controls as Maui
0028 
0029 /**
0030  * @inherit QtQuick.Window
0031  * @brief A base window implementation for window dialogs and the main application window.
0032  * For using a detached dialog window use the WindowDialog control.
0033  */
0034 
0035 Window
0036 {
0037     id: root
0038     
0039     visible: true
0040     
0041     minimumHeight: Maui.Handy.isMobile ? 0 : Math.min(300, Screen.desktopAvailableHeight)
0042     minimumWidth: Maui.Handy.isMobile ? 0 : Math.min(200, Screen.desktopAvailableWidth)
0043     
0044     color: "transparent"
0045     flags: Maui.App.controls.enableCSD ? (Qt.FramelessWindowHint | Qt.Window ): (Qt.Window & ~Qt.FramelessWindowHint)
0046     
0047     // Window shadows for CSD
0048     Loader
0049     {
0050         active: Maui.App.controls.enableCSD && !Maui.Handy.isMobile && Maui.Handy.isLinux
0051         asynchronous: true
0052         sourceComponent: Maui.WindowShadow
0053         {
0054             view: root
0055             radius: Maui.Style.radiusV
0056             strength: 7.8
0057         }
0058     }
0059     
0060     /***************************************************/
0061     /********************* COLORS *********************/
0062     /*************************************************/
0063     Maui.Theme.colorSet: Maui.Theme.Window
0064     
0065     /**
0066      * @brief Items to be placed inside the ApplicationWindow.
0067      * This is used as the default container, and it helps to correctly mask the contents when using CSD with rounded border corners.
0068      * @property list<QtObject> content
0069      **/
0070     default property alias content : _content.data
0071         
0072         /***************************************************/
0073         /**************** READONLY PROPS ******************/
0074         /*************************************************/      
0075         
0076         /**
0077          * @brief  Determines when the application window size is wide enough.
0078          * This property can be changed to any arbitrary condition. This will affect how some controls are positioned and displayed - as for a true wide value, it will assume there is more space to place contents, or for a `false` value it will work in the opposite way.
0079          * Keep in mind this property is widely used in other MauiKit components to determined if items should be hidden,  collapsed, or expanded, etc.
0080          **/
0081         property bool isWide : root.width >= Maui.Style.units.gridUnit * 30
0082         
0083         /**
0084          * @brief Convenient property to check if the application window surface is maximized.
0085          **/
0086         readonly property bool isMaximized: root.visibility === Window.Maximized
0087         
0088         /**
0089          * @brief Convenient property to check if the application window is in a full screen mode.
0090          **/
0091         readonly property bool isFullScreen: root.visibility === Window.FullScreen
0092         
0093         /**
0094          * @brief Convenient property to check if the application window is in portrait mode, otherwise it means it is in landscape mode.
0095          **/
0096         readonly property bool isPortrait: Screen.primaryOrientation === Qt.PortraitOrientation || Screen.primaryOrientation === Qt.InvertedPortraitOrientation
0097         
0098         Item
0099         {
0100             id: _container
0101             anchors.fill: parent
0102             readonly property bool showBorders: Maui.App.controls.enableCSD && root.visibility !== Window.FullScreen && !Maui.Handy.isMobile && root.visibility !== Window.Maximized
0103             
0104             Item
0105             {
0106                 id: _content
0107                 anchors.fill: parent
0108             }
0109             
0110             Loader
0111             {
0112                 id: _toastAreaLoader
0113                 anchors.fill: parent                
0114             }
0115             
0116             layer.enabled: _container.showBorders
0117             layer.effect: OpacityMask
0118             {
0119                 maskSource: Rectangle
0120                 {
0121                     width: _content.width
0122                     height: _content.height
0123                     radius: Maui.Style.radiusV
0124                 }
0125             }
0126         }
0127         
0128         Loader
0129         {
0130             active: _container.showBorders
0131             visible: active
0132             z: Overlay.overlay.z
0133             anchors.fill: parent
0134             asynchronous: true
0135             
0136             sourceComponent: Rectangle
0137             {
0138                 radius: Maui.Style.radiusV
0139                 color: "transparent"
0140                 border.color: Qt.darker(Maui.Theme.backgroundColor, 3)
0141                 opacity: 0.7
0142                 
0143                 Behavior on color
0144                 {
0145                     Maui.ColorTransition{}
0146                 }
0147                 
0148                 Rectangle
0149                 {
0150                     anchors.fill: parent
0151                     anchors.margins: 1
0152                     color: "transparent"
0153                     radius: parent.radius
0154                     border.color: Qt.lighter(Maui.Theme.backgroundColor, 2)
0155                     opacity: 0.7
0156                     
0157                     Behavior on color
0158                     {
0159                         Maui.ColorTransition{}
0160                     }
0161                 }
0162             }
0163         }
0164         
0165         Loader
0166         {
0167             asynchronous: true
0168             active: Maui.App.controls.enableCSD
0169             visible: active
0170             height: 16
0171             width: height
0172             anchors.bottom: parent.bottom
0173             anchors.left: parent.left
0174             
0175             sourceComponent: Item
0176             {
0177                 MouseArea
0178                 {
0179                     anchors.fill: parent
0180                     cursorShape: Qt.SizeBDiagCursor
0181                     acceptedButtons: Qt.NoButton // don't handle actual events
0182                 }
0183                 
0184                 DragHandler
0185                 {
0186                     grabPermissions: TapHandler.TakeOverForbidden
0187                     target: null
0188                     onActiveChanged: (active) => 
0189                     {
0190                         if (active)
0191                         {
0192                             root.startSystemResize(Qt.LeftEdge | Qt.BottomEdge);
0193                         }
0194                     }
0195                 }
0196             }
0197         }
0198         
0199         Loader
0200         {
0201             asynchronous: true
0202             active: Maui.App.controls.enableCSD
0203             visible: active
0204             height: 16
0205             width: height
0206             anchors.bottom: parent.bottom
0207             anchors.right: parent.right
0208             
0209             sourceComponent: Item
0210             {
0211                 MouseArea
0212                 {
0213                     anchors.fill: parent
0214                     cursorShape: Qt.SizeFDiagCursor
0215                     acceptedButtons: Qt.NoButton // don't handle actual events
0216                 }
0217                 
0218                 DragHandler
0219                 {
0220                     grabPermissions: TapHandler.TakeOverForbidden
0221                     target: null
0222                     onActiveChanged: if (active)
0223                     {
0224                         root.startSystemResize(Qt.RightEdge | Qt.BottomEdge)
0225                     }
0226                 }
0227             }
0228         }
0229         
0230         Overlay.overlay.modal: Item
0231         {
0232             Rectangle
0233             {
0234                 color: Maui.Theme.backgroundColor
0235                 anchors.fill: parent
0236                 opacity : 0.8
0237                 radius:  Maui.Style.radiusV
0238             }
0239         }
0240         
0241         Overlay.overlay.modeless: Rectangle
0242         {
0243             radius:  Maui.Style.radiusV
0244             
0245             color: Qt.rgba( root.Maui.Theme.backgroundColor.r,  root.Maui.Theme.backgroundColor.g,  root.Maui.Theme.backgroundColor.b, 0.7)
0246             Behavior on opacity { NumberAnimation { duration: 150 } }
0247             
0248             Behavior on color
0249             {
0250                 Maui.ColorTransition{}
0251             }
0252         }
0253         
0254         Component.onCompleted:
0255         {
0256             // Explicitly break the binding as we need this to be set only at startup.
0257             // if the bindings are active, after this the window is resized by the
0258             // compositor and then the bindings are reevaluated, then the window
0259             // size would reset ignoring what the compositor asked.
0260             // see BUG 433849
0261             root.width = root.width;
0262             root.height = root.height;
0263         }      
0264         
0265         /**
0266          * @brief Switch between maximized and normal state
0267          **/
0268         function toggleMaximized()
0269         {
0270             if (root.isMaximized)
0271             {
0272                 root.showNormal();
0273             } else
0274             {
0275                 root.showMaximized();
0276             }
0277         }
0278         
0279         /**
0280          * @brief Switch between full-screen mode and normal mode
0281          **/
0282         function toggleFullscreen()
0283         {
0284             if (root.isFullScreen)
0285             {
0286                 root.showNormal();
0287             } else
0288             {
0289                 root.showFullScreen()();
0290             }
0291         }
0292         
0293         /**
0294          * @brief Send an inline notification
0295          * @param icon icon name to be used
0296          * @param title the notification title
0297          * @param body the message body of the notification
0298          * @param callback a callback function to be triggered when the action button is pressed, this is represented as a button
0299          * @param buttonText the text associated to the previous callback function, to be used in the button
0300          **/
0301         function notify(icon, title, body, callback, buttonText)
0302         {
0303             if(!_toastAreaLoader.item)
0304             {
0305                 _toastAreaLoader.setSource("ToastArea.qml")
0306             }
0307             _toastAreaLoader.item.add(icon, title, body, callback, buttonText)
0308         }        
0309 }