Warning, /maui/mauikit/src/controls.5/ListBrowser.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 import QtQuick.Controls 2.14
0022 
0023 import org.mauikit.controls 1.3 as Maui
0024 
0025 /**
0026  * ListBrowser
0027  * A global sidebar for the application window that can be collapsed.
0028  *
0029  *
0030  *
0031  *
0032  *
0033  *
0034  */
0035 Item
0036 {
0037     id: control
0038     focus: true
0039     clip: false
0040     
0041     implicitHeight: contentHeight + topPadding + bottomPadding
0042     implicitWidth: contentWidth + leftPadding + rightPadding    
0043     
0044     /**
0045      * model : var
0046      */
0047     property alias model : _listView.model
0048     
0049     /**
0050      * delegate : Component
0051      */
0052     property alias delegate : _listView.delegate
0053     
0054     /**
0055      * section : ListView.section
0056      */
0057     property alias section : _listView.section
0058     
0059     /**
0060      * contentY : int
0061      */
0062     property alias contentY: _listView.contentY
0063     
0064     /**
0065      * contentX : int
0066      */
0067     property alias contentX: _listView.contentX
0068     
0069     
0070     /**
0071      * currentIndex : int
0072      */
0073     property alias currentIndex : _listView.currentIndex
0074     
0075     /**
0076      * currentItem : Item
0077      */
0078     property alias currentItem : _listView.currentItem
0079     
0080     /**
0081      * count : int
0082      */
0083     property alias count : _listView.count
0084     
0085     /**
0086      * cacheBuffer : int
0087      */
0088     property alias cacheBuffer : _listView.cacheBuffer
0089     
0090     /**
0091      * orientation : ListView.orientation
0092      */
0093     property alias orientation: _listView.orientation
0094     
0095     /**
0096      * snapMode : ListView.snapMode
0097      */
0098     property alias snapMode: _listView.snapMode
0099     
0100     /**
0101      * spacing : int
0102      */
0103     property alias spacing: _listView.spacing
0104     
0105     /**
0106      * flickable : Flickable
0107      */
0108     property alias flickable : _listView
0109     
0110     /**
0111      * scrollView : ScrollView
0112      */
0113     property alias scrollView : _scrollView
0114     
0115     /**
0116      * contentHeight : int
0117      */
0118     property alias contentHeight : _listView.contentHeight
0119     
0120     /**
0121      * contentWidth : int
0122      */
0123     property alias contentWidth : _listView.contentWidth
0124     
0125     /**
0126      * atYEnd : bool
0127      */
0128     property alias atYEnd : _listView.atYEnd
0129     
0130     /**
0131      * atYBeginning : bool
0132      */
0133     property alias atYBeginning : _listView.atYBeginning
0134     
0135     /**
0136      * topPadding : int
0137      */
0138     property alias topPadding: _scrollView.topPadding
0139     
0140     /**
0141      * bottomPadding : int
0142      */
0143     property alias bottomPadding: _scrollView.bottomPadding
0144     
0145     /**
0146      * rightPadding : int
0147      */
0148     property alias rightPadding: _scrollView.rightPadding
0149     
0150     /**
0151      * leftPadding : int
0152      */
0153     property alias leftPadding: _scrollView.leftPadding
0154     
0155     /**
0156      * padding : int
0157      */
0158     property alias padding: _scrollView.padding
0159     
0160     /**
0161      * leftMargin : int
0162      */
0163     property int verticalScrollBarPolicy: 
0164     {
0165         if(control.orientation === ListView.Horizontal)
0166             return ScrollBar.AlwaysOff            
0167             
0168         switch(Maui.Style.scrollBarPolicy)
0169         {
0170             case Maui.Style.AlwaysOn: return ScrollBar.AlwaysOn;   
0171             case Maui.Style.AlwaysOff: return ScrollBar.AlwaysOff;   
0172             case Maui.Style.AsNeeded: return ScrollBar.AsNeeded;   
0173             case Maui.Style.AutoHide: return ScrollBar.AsNeeded;   
0174         }
0175     }
0176     
0177     /**
0178      * horizontalScrollBarPolicy : ScrollBar.policy
0179      */
0180     property int horizontalScrollBarPolicy: 
0181     {
0182         if(control.orientation === ListView.Vertical)
0183             return ScrollBar.AlwaysOff
0184             
0185             switch(Maui.Style.scrollBarPolicy)
0186     {
0187         case Maui.Style.AlwaysOn: return ScrollBar.AlwaysOn;   
0188         case Maui.Style.AlwaysOff: return ScrollBar.AlwaysOff;   
0189         case Maui.Style.AsNeeded: return ScrollBar.AsNeeded;   
0190         case Maui.Style.AutoHide: return ScrollBar.AsNeeded;   
0191     }
0192     }
0193     
0194     /**
0195      * holder : Holder
0196      */
0197     property alias holder : _holder
0198     
0199     /**
0200      * enableLassoSelection : bool
0201      */
0202     property bool enableLassoSelection : false
0203     
0204     /**
0205      * selectionMode : bool
0206      */
0207     property bool selectionMode: false
0208     
0209     /**
0210      * lassoRec : Rectangle
0211      */
0212     property alias lassoRec : selectLayer
0213     
0214     property alias header : _listView.header
0215     property alias footer : _listView.footer
0216     
0217     property alias availableWidth: _listView.width
0218     
0219     property alias availableHeight: _listView.height
0220     
0221     /**
0222      * itemsSelected :
0223      */
0224     signal itemsSelected(var indexes)
0225     
0226     /**
0227      * areaClicked :
0228      */
0229     signal areaClicked(var mouse)
0230     
0231     /**
0232      * areaRightClicked :
0233      */
0234     signal areaRightClicked()
0235     
0236     /**
0237      * keyPress :
0238      */
0239     signal keyPress(var event)    
0240     
0241     Keys.enabled : true
0242     Keys.forwardTo : _listView
0243     
0244     ScrollView
0245     {
0246         id: _scrollView
0247         anchors.fill: parent
0248         clip: control.clip
0249         // visible: !_holder.visible
0250         focus: true
0251         padding: Maui.Style.contentMargins
0252         orientation: _listView.orientation
0253         
0254         ScrollBar.horizontal.policy: control.horizontalScrollBarPolicy
0255         ScrollBar.vertical.policy: control.verticalScrollBarPolicy
0256         
0257         ListView
0258         {
0259             id: _listView
0260             focus: true
0261             property var selectedIndexes : []  
0262             
0263             clip: control.clip
0264             
0265             spacing: Maui.Style.defaultSpacing
0266             
0267             snapMode: ListView.NoSnap
0268             
0269             
0270             displayMarginBeginning: Maui.Style.toolBarHeight * 4
0271             displayMarginEnd: Maui.Style.toolBarHeight * 4
0272             
0273             boundsBehavior: Flickable.StopAtBounds
0274             boundsMovement: Flickable.StopAtBounds
0275             
0276             interactive: Maui.Handy.isTouch
0277             highlightFollowsCurrentItem: true
0278             highlightMoveDuration: 0
0279             highlightResizeDuration : 0
0280             
0281             keyNavigationEnabled : true
0282             keyNavigationWraps : true
0283             Keys.onPressed: control.keyPress(event)
0284                    
0285             Maui.Holder
0286             {
0287                 id: _holder
0288                 visible: false
0289                 anchors.fill : parent
0290                 
0291                 anchors.topMargin: _listView.headerItem ? _listView.headerItem.height : 0
0292                 anchors.bottomMargin: _listView.footerItem ?  _listView.footerItem.height : 0
0293             }   
0294             
0295             Loader
0296             {
0297                 asynchronous: true
0298                 z: -1
0299                 anchors.fill: parent
0300                 active: !Maui.Handy.hasTransientTouchInput && !Maui.Handy.isMobile
0301                 
0302                 sourceComponent: MouseArea
0303                 {
0304                     id: _mouseArea
0305                     
0306                     propagateComposedEvents: true
0307                     //             preventStealing: true
0308                     acceptedButtons:  Qt.RightButton | Qt.LeftButton
0309                     
0310                     onClicked:
0311                     {
0312                         control.areaClicked(mouse)
0313                         control.forceActiveFocus()
0314                         
0315                         if(mouse.button === Qt.RightButton)
0316                         {
0317                             control.areaRightClicked()
0318                             return
0319                         }
0320                     }
0321                     
0322                     onPositionChanged:
0323                     {
0324                         if(_mouseArea.pressed && control.enableLassoSelection && selectLayer.visible)
0325                         {
0326                             if(mouseX >= selectLayer.newX)
0327                             {
0328                                 selectLayer.width = (mouseX + 10) < (control.x + control.width) ? (mouseX - selectLayer.x) : selectLayer.width;
0329                             } else {
0330                                 selectLayer.x = mouseX < control.x ? control.x : mouseX;
0331                                 selectLayer.width = selectLayer.newX - selectLayer.x;
0332                             }
0333                             
0334                             if(mouseY >= selectLayer.newY) {
0335                                 selectLayer.height = (mouseY + 10) < (control.y + control.height) ? (mouseY - selectLayer.y) : selectLayer.height;
0336                                 if(!_listView.atYEnd &&  mouseY > (control.y + control.height))
0337                                     _listView.contentY += 10
0338                             } else {
0339                                 selectLayer.y = mouseY < control.y ? control.y : mouseY;
0340                                 selectLayer.height = selectLayer.newY - selectLayer.y;
0341                                 
0342                                 if(!_listView.atYBeginning && selectLayer.y === 0)
0343                                     _listView.contentY -= 10
0344                             }
0345                         }
0346                     }
0347                     
0348                     onPressed:
0349                     {
0350                         if (mouse.source === Qt.MouseEventNotSynthesized && control.enableLassoSelection && mouse.button === Qt.LeftButton && control.count > 0)
0351                         {
0352                             selectLayer.visible = true;
0353                             selectLayer.x = mouseX;
0354                             selectLayer.y = mouseY;
0355                             selectLayer.newX = mouseX;
0356                             selectLayer.newY = mouseY;
0357                             selectLayer.width = 0
0358                             selectLayer.height = 0;
0359                         }                    
0360                     }
0361                     
0362                     onPressAndHold:
0363                     {
0364                         if ( mouse.source !== Qt.MouseEventNotSynthesized && control.enableLassoSelection && !selectLayer.visible && !Maui.Handy.hasTransientTouchInput && !Maui.Handy.isAndroid)
0365                         {
0366                             selectLayer.visible = true;
0367                             selectLayer.x = mouseX;
0368                             selectLayer.y = mouseY;
0369                             selectLayer.newX = mouseX;
0370                             selectLayer.newY = mouseY;
0371                             selectLayer.width = 0
0372                             selectLayer.height = 0;
0373                             mouse.accepted = true
0374                         }else
0375                         {
0376                             mouse.accepted = false
0377                         }
0378                     }
0379                     
0380                     onReleased:
0381                     {
0382                         if(mouse.button !== Qt.LeftButton || !control.enableLassoSelection || !selectLayer.visible)
0383                         {
0384                             mouse.accepted = false
0385                             return;
0386                         }
0387                         
0388                         if(selectLayer.y > _listView.contentHeight)
0389                         {
0390                             return selectLayer.reset();
0391                         }
0392                         
0393                         var lassoIndexes = []
0394                         var limitY =  mouse.y === lassoRec.y ?  lassoRec.y+lassoRec.height : mouse.y
0395                         
0396                         for(var y = lassoRec.y; y < limitY; y+=10)
0397                         {
0398                             const index = _listView.indexAt(_listView.width/2,y+_listView.contentY)
0399                             if(!lassoIndexes.includes(index) && index>-1 && index< _listView.count)
0400                                 lassoIndexes.push(index)
0401                         }
0402                         
0403                         control.itemsSelected(lassoIndexes)
0404                         selectLayer.reset()
0405                     }
0406                 }
0407             }
0408             
0409             Maui.Rectangle
0410             {
0411                 id: selectLayer
0412                 property int newX: 0
0413                 property int newY: 0
0414                 height: 0
0415                 width: 0
0416                 x: 0
0417                 y: 0
0418                 visible: false
0419                 color: Qt.rgba(control.Maui.Theme.highlightColor.r,control.Maui.Theme.highlightColor.g, control.Maui.Theme.highlightColor.b, 0.2)
0420                 opacity: 0.7
0421                 
0422                 borderColor: control.Maui.Theme.highlightColor
0423                 borderWidth: 2
0424                 solidBorder: false
0425                 
0426                 function reset()
0427                 {
0428                     selectLayer.x = 0;
0429                     selectLayer.y = 0;
0430                     selectLayer.newX = 0;
0431                     selectLayer.newY = 0;
0432                     selectLayer.visible = false;
0433                     selectLayer.width = 0;
0434                     selectLayer.height = 0;
0435                 }
0436             }
0437         }
0438     }  
0439 }
0440 
0441