Warning, /maui/mauikit/examples/SelectionBar.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick
0002 import QtQuick.Controls
0003 import QtQuick.Layouts
0004 import org.mauikit.controls as Maui
0005 
0006 Maui.ApplicationWindow
0007 {
0008     id: root
0009 
0010     Maui.Page
0011     {
0012         id: _page
0013         anchors.fill: parent
0014 
0015         Maui.Controls.showCSD: true
0016 
0017         floatingFooter: true
0018         flickable: _listBrowser.flickable //helps to keep the content from under the selectionbar at the end.
0019 
0020         headBar.leftContent: Switch
0021         {
0022             text: "Single selection"
0023             checked: _selectionBar.singleSelection
0024             onToggled: _selectionBar.singleSelection = !_selectionBar.singleSelection
0025         }
0026 
0027         Maui.ListBrowser
0028         {
0029             id: _listBrowser
0030 
0031             anchors.fill: parent
0032 
0033             model: 60
0034 
0035             delegate: Maui.ListBrowserDelegate
0036             {
0037                 id: _delegate
0038 
0039                 property string id : index // we need an unique ID for the selectionbar
0040 
0041                 width: ListView.view.width
0042 
0043                 label1.text: "An example delegate."
0044                 label2.text: "The ID of this element is " + id
0045 
0046                 iconSource: "folder"
0047 
0048                 checkable: true
0049 
0050                 Connections
0051                 {
0052                     target: _selectionBar
0053                     function onUriRemoved(uri) //watch when a uri is removed from the selection bar
0054                     {
0055                         if(uri == _delegate.id)
0056                         {
0057                             _delegate.checked = false
0058                         }
0059                     }
0060 
0061                     function onUriAdded(uri) //watch when an uri is sucessfully added and mark the delegate as checked
0062                     {
0063                         if(uri == _delegate.id)
0064                         {
0065                             _delegate.checked = true
0066                         }
0067                     }
0068 
0069                     function onCleared() //watch when the selection has been cleared and uncheck all the delegates
0070                     {
0071                         _delegate.checked = false
0072                     }
0073                 }
0074 
0075                 onToggled: (state) =>
0076                            {
0077                                if(state)
0078                                {
0079                                    _selectionBar.append(_delegate.id, ({'title': "Testing"}))
0080                                }else
0081                                {
0082                                    _selectionBar.removeAtUri(_delegate.id)
0083                                }
0084                            } // when the item is toggled, we mark it as checked and add it to the selection bar, otherwise we unchecked it and remove it from selection.
0085             }
0086         }
0087 
0088         footer: Maui.SelectionBar
0089         {
0090             id: _selectionBar
0091 
0092             anchors.horizontalCenter: parent.horizontalCenter
0093             width: Math.min(parent.width-(Maui.Style.space.medium*2), implicitWidth)
0094             maxListHeight: root.height - (Maui.Style.contentMargins*2)
0095 
0096             Action
0097             {
0098                 icon.name: "love"
0099                 onTriggered: console.log(_selectionBar.getSelectedUrisString())
0100             }
0101 
0102             Action
0103             {
0104                 icon.name: "folder"
0105                 onTriggered: console.log(_selectionBar.contains("0"))
0106             }
0107 
0108             Action
0109             {
0110                 icon.name: "list-add"
0111             }
0112 
0113             onExitClicked: clear()
0114         }
0115     }
0116 }
0117