Warning, /maui/mauikit/src/controls.5/ApplicationWindow.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 2.15
0021 import QtQuick.Controls 2.15 as QQC2
0022 import QtQuick.Window 2.15
0023 
0024 import QtQuick.Layouts 1.3
0025 import QtGraphicalEffects 1.0
0026 import Qt.labs.settings 1.0
0027 
0028 import org.mauikit.controls 1.3 as Maui
0029 
0030 import "private" as Private
0031 
0032 /*!
0033  \ since or*g.mauikit.controls 1.0
0034  \inqmlmodule org.mauikit.controls
0035  \brief A window that provides some basic features needed for all apps
0036  
0037  It's usually used as a root QML component for the application.
0038  By default it makes usage of the Maui Page control, so it packs a header and footer bar.
0039  The header can be moved to the bottom for better reachability in hand held devices.
0040  The Application window has some components already built in like an AboutDialog, a main application menu,
0041  and an optional property to add a global sidebar.
0042  
0043  The application can have client side decorations CSD by setting the attached property Maui.App.enabledCSD  to true,
0044  or globally by editing the configuration file located at /.config/Maui/mauiproject.conf.
0045  
0046  For more details you can refer to the Maui Page documentation for fine tweaking the application window main content.
0047  \code
0048  ApplicationWindow {
0049  id: root
0050  
0051  AppViews {
0052  anchors.fill: parent
0053  }
0054  }
0055  \endcode
0056  */
0057 QQC2.ApplicationWindow
0058 {
0059     id: root
0060 
0061     visible: true
0062     
0063     minimumHeight: Maui.Handy.isMobile ? 0 : Math.min(300, Screen.desktopAvailableHeight)
0064     minimumWidth: Maui.Handy.isMobile ? 0 : Math.min(200, Screen.desktopAvailableWidth)
0065 
0066     color: "transparent"
0067     flags: Maui.App.controls.enableCSD ? (Qt.FramelessWindowHint | Qt.Window ): (Qt.Window & ~Qt.FramelessWindowHint)
0068 
0069     Settings
0070     {
0071         property alias x: root.x
0072         property alias y: root.y
0073         property alias width: root.width
0074         property alias height: root.height
0075     }
0076 
0077     // Window shadows for CSD
0078     Loader
0079     {
0080         active: Maui.App.controls.enableCSD && !Maui.Handy.isMobile && Maui.Handy.isLinux
0081         asynchronous: true
0082         sourceComponent: Maui.WindowShadow
0083         {
0084             view: root
0085             radius: Maui.Style.radiusV
0086             strength: 7.8
0087         }
0088     }
0089 
0090     /***************************************************/
0091     /********************* COLORS *********************/
0092     /*************************************************/
0093     Maui.Theme.colorSet: Maui.Theme.View
0094 
0095     /*!
0096    \ qm*lproperty Item ApplicationWindow::content
0097    
0098    Items to be placed inside the ApplicationWindow.
0099    */
0100     default property alias content : _content.data
0101     
0102     /***************************************************/
0103     /******************** ALIASES *********************/
0104     /*************************************************/
0105     
0106     
0107     /*!
0108      \ qm*lproperty Dialog ApplicationWindow::dialog
0109      
0110      The internal dialogs used in the ApplicationWindow are loaded dynamically, so the current loaded dialog can be accessed
0111      via this property.
0112      */
0113     property alias dialog: dialogLoader.item
0114     
0115     
0116     /*!
0117      I f *the application window size is wide enough.
0118      This property can be changed to any random condition.
0119      Keep in mind this property is widely used in other MauiKit components to determined if items shoudl be hidden or collapsed, etc.
0120      */
0121     property bool isWide : root.width >= Maui.Style.units.gridUnit * 30
0122     
0123     /***************************************************/
0124     /**************** READONLY PROPS ******************/
0125     /*************************************************/
0126     /*!
0127      I f *the screen where the application is drawn is in portrait mode or not,
0128      other wise it is in landscape mode.
0129      */
0130     readonly property bool isMaximized: root.visibility === Window.Maximized
0131     readonly property bool isFullScreen: root.visibility === Window.FullScreen
0132     readonly property bool isPortrait: Screen.primaryOrientation === Qt.PortraitOrientation || Screen.primaryOrientation === Qt.InvertedPortraitOrientation
0133     readonly property bool showBorders: Maui.App.controls.enableCSD && root.visibility !== Window.FullScreen && !Maui.Handy.isMobile && root.visibility !== Window.Maximized
0134 
0135     background: null
0136 
0137     Item
0138     {
0139         anchors.fill: parent
0140 
0141         Item
0142         {
0143             id: _content
0144             anchors.fill: parent
0145         }
0146 
0147 
0148          Loader
0149             {
0150                 id: _toastAreaLoader
0151                 anchors.fill: parent
0152             }
0153 
0154         layer.enabled: root.showBorders
0155 
0156         layer.effect: OpacityMask
0157         {
0158             maskSource: Rectangle
0159             {
0160                 width: _content.width
0161                 height: _content.height
0162                 radius: Maui.Style.radiusV
0163             }
0164         }
0165     }
0166     
0167     Loader
0168     {
0169         active: root.showBorders
0170         visible: active
0171         z: ApplicationWindow.overlay.z + 9999
0172         anchors.fill: parent
0173         asynchronous: true
0174 
0175         sourceComponent: Rectangle
0176         {
0177             radius: Maui.Style.radiusV - 0.5
0178             color: "transparent"
0179             border.color: Qt.darker(Maui.Theme.backgroundColor, 2.3)
0180             opacity: 0.5
0181 
0182             Behavior on color
0183             {
0184                 Maui.ColorTransition{}
0185             }
0186 
0187             Rectangle
0188             {
0189                 anchors.fill: parent
0190                 anchors.margins: 1
0191                 color: "transparent"
0192                 radius: parent.radius - 0.5
0193                 border.color: Qt.lighter(Maui.Theme.backgroundColor, 2)
0194                 opacity: 0.7
0195 
0196                 Behavior on color
0197                 {
0198                     Maui.ColorTransition{}
0199                 }
0200             }
0201         }
0202     }
0203     
0204     Loader
0205     {
0206         asynchronous: true
0207         active: Maui.App.controls.enableCSD
0208         visible: active
0209         height: 16
0210         width: height
0211         anchors.bottom: parent.bottom
0212         anchors.left: parent.left
0213 
0214         sourceComponent: MouseArea
0215         {
0216             cursorShape: Qt.SizeBDiagCursor
0217             propagateComposedEvents: true
0218             preventStealing: false
0219 
0220             onPressed: mouse.accepted = false
0221 
0222             DragHandler
0223             {
0224                 grabPermissions: TapHandler.TakeOverForbidden
0225                 target: null
0226                 onActiveChanged: if (active)
0227                                  {
0228                                      root.startSystemResize(Qt.LeftEdge | Qt.BottomEdge);
0229                                  }
0230             }
0231         }
0232     }
0233     
0234     Loader
0235     {
0236         asynchronous: true
0237         active: Maui.App.controls.enableCSD
0238         visible: active
0239         height: 16
0240         width: height
0241         anchors.bottom: parent.bottom
0242         anchors.right: parent.right
0243 
0244         sourceComponent: MouseArea
0245         {
0246             cursorShape: Qt.SizeFDiagCursor
0247             propagateComposedEvents: true
0248             preventStealing: false
0249 
0250             onPressed: mouse.accepted = false
0251 
0252             DragHandler
0253             {
0254                 grabPermissions: TapHandler.TakeOverForbidden
0255                 target: null
0256                 onActiveChanged: if (active)
0257                                  {
0258                                      root.startSystemResize(Qt.RightEdge | Qt.BottomEdge);
0259                                  }
0260             }
0261         }
0262     }
0263 
0264     QQC2.Overlay.overlay.modal: Item
0265     {
0266         //       Loader
0267         //       {
0268         //         anchors.fill: parent
0269         //         active: Maui.Style.enableEffects
0270         //       sourceComponent: Item
0271         //       {
0272         //       ShaderEffectSource
0273         //       {
0274         //         id:_shaderSource
0275         //        anchors.fill: parent
0276         //         sourceItem: _content
0277         //       }
0278         //
0279         //       FastBlur
0280         //       {
0281         //         anchors.fill: parent
0282         //         source: _shaderSource
0283         //         radius: 64
0284         //       }
0285         //
0286         //       layer.enabled: true
0287         //       layer.effect: OpacityMask
0288         //       {
0289         //         maskSource: Rectangle
0290         //         {
0291         //           width: _content.width
0292         //           height: _content.height
0293         //           radius: Maui.Style.radiusV
0294         //         }
0295         //       }
0296         //       }
0297         //       }
0298         //
0299         Rectangle
0300         {
0301             color: Maui.Theme.backgroundColor
0302             anchors.fill: parent
0303             opacity : 0.8
0304             radius:  Maui.Style.radiusV
0305         }
0306     }
0307     
0308     QQC2.Overlay.overlay.modeless: Rectangle
0309     {
0310         radius:  Maui.Style.radiusV
0311 
0312         color: Qt.rgba( root.Maui.Theme.backgroundColor.r,  root.Maui.Theme.backgroundColor.g,  root.Maui.Theme.backgroundColor.b, 0.7)
0313         Behavior on opacity { NumberAnimation { duration: 150 } }
0314 
0315         Behavior on color
0316         {
0317             Maui.ColorTransition{}
0318         }
0319     }
0320 
0321     Loader
0322     {
0323         id: dialogLoader
0324     }
0325     
0326     Connections
0327     {
0328         target: Maui.Platform
0329         ignoreUnknownSignals: true
0330 
0331         function onShareFilesRequest(urls)
0332         {
0333             dialogLoader.source = "private/ShareDialog.qml"
0334             dialog.urls = urls
0335             dialog.open()
0336         }
0337     }
0338     
0339      Component.onCompleted:
0340         {
0341             // Explicitly break the binding as we need this to be set only at startup.
0342             // if the bindings are active, after this the window is resized by the
0343             // compositor and then the bindings are reevaluated, then the window
0344             // size would reset ignoring what the compositor asked.
0345             // see BUG 433849
0346             root.width = root.width;
0347             root.height = root.height;
0348         }   
0349     
0350     /**
0351      * Send an inline notification.
0352      * icon = icon to be used
0353      * title = the title
0354      * body = message of the notification
0355      * callback = function to be triggered if the notification dialog is accepted
0356      * timeout = time in milliseconds before the notification dialog is dismissed
0357      * buttonText = text in the accepted button
0358      */
0359     function notify(icon, title, body, callback, buttonText)
0360     {
0361         if(!_toastAreaLoader.item)
0362             {
0363                 _toastAreaLoader.setSource("qrc:/maui/kit/private/ToastArea.qml")
0364             }
0365             
0366         _toastAreaLoader.item.add(icon, title, body, callback, buttonText)
0367     }
0368     
0369     /**
0370      * Switch from full screen to normal size.
0371      */
0372     function toggleMaximized()
0373     {
0374         if (root.isMaximized)
0375         {
0376             root.showNormal();
0377         } else
0378         {
0379             root.showMaximized();
0380         }
0381     }
0382     
0383     function toggleFullscreen()
0384     {
0385         if (root.isFullScreen)
0386         {
0387             root.showNormal();
0388         } else
0389         {
0390             root.showFullScreen()();
0391         }
0392     }
0393     
0394     /**
0395      * Reference to the application main page
0396      */
0397     function window()
0398     {
0399         return root.contentItem;
0400     }
0401     
0402     function about()
0403     {
0404         dialogLoader.source = "qrc:/maui/kit/private/AboutDialog.qml"
0405         dialog.open()
0406     }
0407 }