Warning, /maui/mauikit/src/controls.5/PopupPage.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.14
0021 
0022 import QtQuick.Controls 2.14
0023 import QtQuick.Layouts 1.3
0024 
0025 import org.mauikit.controls 1.3 as Maui
0026 
0027 import QtGraphicalEffects 1.0
0028 
0029 /*!
0030  * \since org.mauikit.controls 1.0
0031  * \inqmlmodule org.mauikit.controls
0032  *
0033  * A scrollable dialog popup, with a Page as its main content.
0034  * With default buttons styled, a close button and a predefiend layout.
0035  *
0036  * The dialog can be used with its main default ColumnLayout or with an Item stacked.
0037  *
0038  * The dialog contents will be hanlded by a ColumnLayout, so the positioning of its child elements should use the attached property
0039  * Layout.fillheight layout.fillWidth, etc.
0040  */
0041 Popup
0042 {
0043     id: control
0044 
0045     focus: true
0046 
0047     Maui.Theme.colorSet: Maui.Theme.Window
0048     Maui.Theme.inherit: false
0049 
0050     closePolicy: control.persistent ? Popup.NoAutoClose | Popup.CloseOnEscape : Popup.CloseOnEscape | Popup.CloseOnPressOutside
0051 
0052     maxWidth: 300
0053     maxHeight: implicitHeight
0054     implicitHeight: _layout.implicitHeight + topPadding + bottomPadding + topMargin + bottomMargin
0055 
0056     hint: 0.9
0057     heightHint: 0.9
0058     spacing: Maui.Style.space.big
0059 
0060     margins: 0
0061 
0062     filling: persistent && mWidth === control.parent.width
0063     /*!
0064    *    \qmlproperty list<Item> ApplicationWindow::scrollable
0065    *
0066    *    Default content will be added to a scrollable ColumnLayout.
0067    *    When adding a item keep on mind that to correctly have the scrollable behavior
0068    *    the item must have an implicit height. And the positioning should be done via the Layout attached properties.
0069    */
0070     default property alias scrollable : _scrollView.content
0071 
0072     /*!
0073      *    \qmlproperty list<Item> ApplicationWindow::stack
0074      *
0075      *    To skip the scrollable behavior there is a stacked component to which items can be added, this is also
0076      *    controlled by a ColumnLayout
0077      */
0078     property alias stack : _stack.data
0079 
0080     /*!
0081      *    \qmlproperty string ApplicationWindow::title
0082      *
0083      *    Default title text or title of the dialog page.
0084      */
0085     property alias title : _page.title
0086 
0087     /*!
0088      *    \qmlproperty bool ApplicationWindow::persistent
0089      *
0090      *    If the dialog should be closed when it loses focus or not.
0091      *    If it is marked as persistent a close button is shown in the header bar, other wise the header bar is
0092      *    hidden if there is not more elements on it.
0093      */
0094     property bool persistent : true
0095 
0096     /*!
0097      *    \qmlproperty Page ApplicationWindow::page
0098      *
0099      *    Access to the default dialog content.
0100      */
0101     property alias page : _page
0102 
0103     /*!
0104      *    \qmlproperty ToolBar ApplicationWindow::footBar
0105      *
0106      *    Dialog footer bar.
0107      */
0108     property alias footBar : _page.footBar
0109 
0110     /*!
0111      *    \qmlproperty ToolBar ApplicationWindow::headBar
0112      *
0113      *    Dialog header bar.
0114      */
0115     property alias headBar: _page.headBar
0116 
0117     /*!
0118      *    \qmlproperty bool closeButton
0119      *
0120      *    MouseArea for the close button when the dialog is marked as persistent.
0121      */
0122     property bool closeButtonVisible: control.persistent
0123 
0124     /*!
0125      *    \qmlproperty Flickable Dialog::closeButton
0126      *
0127      *    MouseArea for the close button when the dialog is marked as persistent.
0128      */
0129     property alias flickable : _scrollView.flickable
0130 
0131     /*!
0132      *    \qmlproperty ScrollView Dialog::scrollView
0133      *
0134      *    MouseArea for the close button when the dialog is marked as persistent.
0135      */
0136     property alias scrollView : _scrollView
0137 
0138     /*!
0139      *    \qmlproperty int ScrollBar::policy
0140      *
0141      *    MouseArea for the close button when the dialog is marked as persistent.
0142      */
0143     property int verticalScrollBarPolicy: ScrollBar.AsNeeded
0144 
0145 
0146     /*!
0147      *    \qmlproperty int ScrollBar::policy
0148      *
0149      *    MouseArea for the close button when the dialog is marked as persistent.
0150      */
0151     property int horizontalScrollBarPolicy: ScrollBar.AlwaysOff
0152 
0153     property bool autoClose : true
0154 
0155     /*!
0156      *    List of actions to be added to the dialog footer bar as styled buttons.
0157      */
0158     property list<Action> actions
0159 
0160     property alias actionBar : _defaultButtonsLayout
0161 
0162     /*!
0163      * Triggered when the accepted button is clicked.
0164      */
0165     signal accepted()
0166 
0167     /*!
0168      * Triggered when the rejected button is clicked.
0169      */
0170     signal rejected()
0171 
0172     signal closeTriggered()
0173 
0174     ColumnLayout
0175     {
0176         id: _layout
0177         anchors.fill: parent
0178         spacing: 0
0179 
0180         Maui.Page
0181         {
0182             id: _page
0183 
0184             clip: true
0185 
0186             Maui.Theme.colorSet: control.Maui.Theme.colorSet
0187 
0188             Layout.fillWidth: true
0189             Layout.fillHeight: true
0190 
0191             implicitHeight: Math.max(_scrollView.contentHeight + _scrollView.topPadding + _scrollView.bottomPadding, _stack.implicitHeight) + _page.footerContainer.implicitHeight + (_page.topPadding + _page.bottomPadding) + _page.headerContainer.implicitHeight + (_page.topMargin + _page.bottomMargin)
0192 
0193             headerPositioning: ListView.InlineHeader
0194 
0195             padding: 0
0196             margins: 0
0197 
0198             headBar.visible: control.persistent
0199             headBar.borderVisible: false
0200 
0201             background: null
0202 
0203             headBar.farRightContent: Loader
0204             {
0205                 asynchronous: true
0206                 visible: active
0207                 active: control.persistent && closeButtonVisible
0208 
0209                 sourceComponent: Maui.CloseButton
0210                 {
0211                     onClicked:
0212                     {
0213                         if(control.autoClose)
0214                         {
0215                             control.close()
0216                         }else
0217                         {
0218                             control.closeTriggered()
0219                         }
0220                     }
0221                 }
0222             }
0223 
0224             ColumnLayout
0225             {
0226                 id: _stack
0227 
0228                 anchors.fill: parent
0229 
0230                 spacing: control.spacing
0231             }
0232 
0233             Maui.ScrollColumn
0234             {
0235                 id: _scrollView
0236 
0237                 anchors.fill: parent
0238 
0239                 visible: _stack.children.length === 0
0240 
0241                 spacing: control.spacing
0242                 padding: Maui.Style.space.big
0243 
0244                 ScrollBar.horizontal.policy: control.horizontalScrollBarPolicy
0245                 ScrollBar.vertical.policy: control.verticalScrollBarPolicy
0246             }
0247         }
0248 
0249         GridLayout
0250         {
0251             id: _defaultButtonsLayout
0252 
0253             rowSpacing: Maui.Style.space.small
0254             columnSpacing: Maui.Style.space.small
0255 
0256             Layout.fillWidth: true
0257             Layout.margins: Maui.Style.contentMargins
0258 
0259             property bool isWide : control.width > Maui.Style.units.gridUnit*10
0260 
0261             visible: control.actions.length
0262 
0263             rows: isWide? 1 : _defaultButtonsLayout.children.length
0264             columns: isWide ? _defaultButtonsLayout.children.length : 1
0265 
0266             Repeater
0267             {
0268                 model: control.actions
0269 
0270                 Button
0271                 {
0272                     id: _actionButton
0273                     focus: true
0274                     Layout.fillWidth: true
0275 
0276                     action: modelData
0277                 }
0278             }
0279         }
0280     }
0281 }