Warning, /maui/mauikit/src/controls.5/ToolBar.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
0022 import QtQuick.Window 2.15
0023 
0024 import org.mauikit.controls 1.3 as Maui
0025 
0026 import QtQuick.Layouts 1.3
0027 
0028 import "private" as Private
0029 
0030 /**
0031  * ToolBar
0032  * A global sidebar for the application window that can be collapsed.
0033  *
0034  *
0035  *
0036  *
0037  *
0038  *
0039  */
0040 ToolBar
0041 {
0042     id: control    
0043     
0044     implicitHeight: preferredHeight + topPadding + bottomPadding    
0045   
0046     /**
0047      * content : RowLayout.data
0048      */
0049     default property alias content : leftRowContent.content
0050         
0051         /**
0052          * preferredHeight : int
0053          */
0054         property int preferredHeight: implicitContentHeight
0055         
0056         /**
0057          * forceCenterMiddleContent : bool
0058          */
0059         property bool forceCenterMiddleContent : true
0060         
0061         /**
0062          * leftContent : RowLayout.data
0063          */
0064         property alias leftContent : leftRowContent.content
0065         
0066         /**
0067          * middleContent : RowLayout.data
0068          */
0069         property alias middleContent : middleRowContent.data
0070         
0071         /**
0072          * rightContent : RowLayout.data
0073          */
0074         property alias rightContent : rightRowContent.content
0075         
0076         /**
0077          * farLeftContent : RowLayout.data
0078          */
0079         property alias farLeftContent : farLeftRowContent.content
0080         
0081         /**
0082          * farRightContent : RowLayout.data
0083          */
0084         property alias farRightContent : farRightRowContent.content
0085         
0086         /**
0087          * middleLayout : RowLayout
0088          */
0089         property alias middleLayout : middleRowContent
0090         
0091         /**
0092          * leftLayout : RowLayout
0093          */
0094         property alias leftLayout : leftRowContent
0095         
0096         /**
0097          * rightLayout : RowLayout
0098          */
0099         property alias rightLayout : rightRowContent
0100         
0101         /**
0102          * farRightLayout : RowLayout
0103          */
0104         property alias farRightLayout : farRightRowContent
0105         
0106         /**
0107          * rightLayout : RowLayout
0108          */
0109         property alias farLeftLayout : farLeftRowContent
0110         
0111         /**
0112          * layout : RowLayout
0113          */
0114         property alias layout : layout
0115         
0116         /**
0117          * fits : bool
0118          */
0119         readonly property alias fits : _scrollView.fits
0120         
0121         
0122         /**
0123          * count : int
0124          */
0125         readonly property int count : leftContent.length + middleContent.length + rightContent.length + farLeftContent.length + farRightContent.length
0126         
0127         /**
0128          * visibleCount: int
0129          */
0130         readonly property int visibleCount : leftRowContent.visibleChildren.length + middleRowContent.visibleChildren.length  + rightRowContent.visibleChildren.length + farLeftRowContent.visibleChildren.length  + farRightRowContent.visibleChildren.length
0131         
0132         
0133         property bool draggable : true
0134         
0135             Loader
0136             {
0137                 asynchronous: true
0138                 width: Maui.Style.iconSizes.medium
0139                 height: parent.height
0140                 active: !mainFlickable.atXEnd && !control.fits
0141                 visible: active
0142                 z: 999
0143                 parent: control.background
0144                 anchors
0145                 {
0146                     right: parent.right
0147                     top: parent.top
0148                     bottom: parent.bottom
0149                 }
0150                 
0151                 sourceComponent: Maui.EdgeShadow
0152                 {
0153                     edge: Qt.RightEdge
0154                 }
0155             }
0156             
0157             Loader
0158             {
0159                 parent: control.background
0160                 asynchronous: true
0161                 width: Maui.Style.iconSizes.medium
0162                 height: parent.height
0163                 active: !mainFlickable.atXBeginning && !control.fits
0164                 visible: active
0165                 z: 999
0166                 anchors
0167                 {
0168                     left: parent.left
0169                     top: parent.top
0170                     bottom: parent.bottom
0171                 }
0172                 
0173                 sourceComponent: Maui.EdgeShadow
0174                 {                    
0175                     edge: Qt.LeftEdge                    
0176                 }
0177             }
0178         
0179         contentItem: Item
0180         {
0181             implicitWidth: _mainLayout.implicitWidth 
0182             implicitHeight: _mainLayout.implicitHeight 
0183             clip: true
0184            
0185             Item
0186             {
0187                 id: _container
0188                 height: control.preferredHeight
0189                 width: parent.width
0190                 
0191                 property bool isHeader: control.position === ToolBar.Header
0192                 state: isHeader? "headerState" : "footerState"             
0193                 
0194                 Loader
0195                 {
0196                     asynchronous: true
0197                     active: !Maui.Handy.isMobile
0198                     sourceComponent: Maui.WheelHandler
0199                     {
0200                         target: mainFlickable
0201                         primaryOrientation : Qt.Horizontal
0202                     }
0203                 }
0204                 
0205                 Loader
0206                 {
0207                     active: !Maui.Handy.isMobile || control.draggable
0208                     asynchronous: true
0209                     anchors.fill: parent
0210                     sourceComponent: Item
0211                     {
0212                         DragHandler
0213                         {
0214                             acceptedDevices: PointerDevice.GenericPointer
0215                             grabPermissions:  PointerHandler.CanTakeOverFromItems | PointerHandler.CanTakeOverFromHandlersOfDifferentType | PointerHandler.ApprovesTakeOverByAnything
0216                             onActiveChanged: if (active) { control.Window.window.startSystemMove(); }
0217                         }
0218                     }
0219                 }
0220                
0221                 states: [State
0222                 {
0223                     name: "headerState" 
0224                     
0225                     AnchorChanges
0226                     {
0227                         target: _container
0228                         anchors.top: undefined
0229                         anchors.bottom: parent.bottom
0230                     }
0231                 },
0232                 
0233                 State
0234                 {
0235                    name: "footerState"
0236                     
0237                     AnchorChanges
0238                     {
0239                         target: _container
0240                         anchors.top: parent.top
0241                         anchors.bottom: undefined
0242                     }
0243                 }
0244                 ]
0245                 
0246                 RowLayout
0247                 {
0248                     id: _mainLayout
0249                     anchors.fill: parent
0250                     spacing: control.spacing
0251                     
0252                     Private.ToolBarSection
0253                     {
0254                         id: farLeftRowContent
0255                         Layout.fillHeight: true
0256                         Layout.maximumWidth: implicitWidth
0257                         Layout.minimumWidth: implicitWidth
0258                         spacing: control.spacing
0259                     }
0260                     
0261                     ScrollView
0262                     {
0263                         id: _scrollView
0264                         padding: 0
0265                         implicitHeight: layout.implicitHeight + topPadding + bottomPadding
0266                         readonly property bool fits : contentWidth < width
0267                         onFitsChanged: mainFlickable.returnToBounds()
0268                         
0269                         Layout.fillHeight: true
0270                         Layout.fillWidth: true
0271                         
0272                         contentWidth: layout.implicitWidth 
0273                         contentHeight: availableHeight
0274                         
0275                         ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
0276                         ScrollBar.vertical.policy: ScrollBar.AlwaysOff
0277                         
0278                         Flickable
0279                         {
0280                             id: mainFlickable
0281                             
0282                             flickableDirection: Flickable.HorizontalFlick
0283                             interactive: !control.fits && Maui.Handy.isTouch
0284                             
0285                             boundsBehavior: Flickable.StopAtBounds
0286                             boundsMovement :Flickable.StopAtBounds
0287                             
0288                             clip: true
0289                             
0290                             RowLayout
0291                             {
0292                                 id: layout
0293                                 
0294                                 width: _scrollView.availableWidth
0295                                 height: _scrollView.availableHeight
0296                                 
0297                                 spacing: control.spacing
0298                                 
0299                                 Private.ToolBarSection
0300                                 {
0301                                     id: leftRowContent
0302                                     
0303                                     Layout.fillHeight: true
0304                                     
0305                                     Layout.maximumWidth: implicitWidth
0306                                     Layout.minimumWidth: implicitWidth
0307                                     Layout.preferredWidth: implicitWidth
0308                                     //
0309                                     spacing: control.spacing
0310                                 }                            
0311                                 
0312                                 Item //helper to force center middle content
0313                                 {
0314                                     id: _h1
0315                                     visible: middleRowContent.visibleChildren.length && control.forceCenterMiddleContent
0316                                     
0317                                     readonly property int mwidth : visible ? Math.max((rightRowContent.implicitWidth + farRightRowContent.implicitWidth) - (leftRowContent.implicitWidth + farLeftRowContent.implicitWidth), 0) : 0
0318                                     
0319                                     Layout.minimumWidth: 0
0320                                     
0321                                     Layout.preferredWidth: mwidth
0322                                     Layout.maximumWidth: mwidth
0323                                     
0324                                     Layout.fillHeight: true
0325                                     Layout.fillWidth: true
0326                                 }
0327                                 
0328                                 Item
0329                                 {
0330                                     Layout.fillWidth: true
0331                                     Layout.fillHeight: true
0332                                     Layout.minimumWidth:implicitWidth
0333                                     implicitWidth:  middleRowContent.implicitWidth
0334                                     implicitHeight:  middleRowContent.implicitHeight
0335                                     //                                color: "yellow"
0336                                     RowLayout
0337                                     {
0338                                         id: middleRowContent
0339                                         anchors.fill: parent
0340                                         spacing: control.spacing
0341                                     }
0342                                 }
0343                                 
0344                                 Item //helper to force center middle content
0345                                 {
0346                                     id: _h2
0347                                     visible: middleRowContent.visibleChildren.length && control.forceCenterMiddleContent
0348                                     
0349                                     readonly property int mwidth : visible ? Math.max(( leftRowContent.implicitWidth + farLeftRowContent.implicitWidth) - (rightRowContent.implicitWidth + farRightRowContent.implicitWidth), 0) : 0
0350                                     
0351                                     Layout.minimumWidth: 0
0352                                     
0353                                     Layout.fillHeight: true
0354                                     Layout.fillWidth: true
0355                                     
0356                                     Layout.preferredWidth: mwidth
0357                                     Layout.maximumWidth: mwidth
0358                                 }
0359                                 
0360                                 Private.ToolBarSection
0361                                 {
0362                                     id: rightRowContent
0363                                     
0364                                     Layout.fillHeight: true
0365                                     
0366                                     Layout.maximumWidth: implicitWidth
0367                                     Layout.minimumWidth: implicitWidth
0368                                     Layout.preferredWidth: implicitWidth
0369                                     
0370                                     spacing: control.spacing
0371                                 }
0372                             }
0373                         }
0374                     }
0375                     
0376                     Private.ToolBarSection
0377                     {
0378                         id: farRightRowContent
0379                         Layout.fillHeight: true
0380                         Layout.maximumWidth: implicitWidth
0381                         Layout.minimumWidth: implicitWidth
0382                         spacing: control.spacing
0383                     }
0384                 }
0385             }            
0386         }
0387 }