Warning, /maui/mauikit-filebrowsing/src/controls.5/TagsBar.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 import QtQuick.Layouts 1.12
0023 
0024 import org.mauikit.controls 1.2 as Maui
0025 
0026 import "private"
0027 
0028 /**
0029  * TagsBar
0030  * A global sidebar for the application window that can be collapsed.
0031  *
0032  *
0033  *
0034  *
0035  *
0036  *
0037  */
0038 Control
0039 {
0040     id: control
0041     focus: true
0042     implicitHeight: Maui.Style.toolBarHeight + topPadding + bottomPadding
0043     padding: Maui.Style.defaultPadding
0044     /**
0045      * listView : TagList
0046      */
0047     property alias listView : tagsList
0048     
0049     /**
0050      * count : int
0051      */
0052     property alias count : tagsList.count
0053     
0054     /**
0055      * editMode : bool
0056      */
0057     property bool editMode : false
0058     
0059     /**
0060      * allowEditMode : bool
0061      */
0062     property bool allowEditMode : false
0063     
0064     /**
0065      * list : TagsList
0066      */
0067     property alias list : tagsList.list
0068     
0069     /**
0070      * addClicked :
0071      */
0072     signal addClicked()
0073     
0074     /**
0075      * tagRemovedClicked :
0076      */
0077     signal tagRemovedClicked(int index)
0078     
0079     /**
0080      * tagClicked :
0081      */
0082     signal tagClicked(string tag)
0083     
0084     /**
0085      * tagsEdited :
0086      */
0087     signal tagsEdited(var tags)
0088     
0089     contentItem: RowLayout
0090 {
0091     id: _layout
0092     Loader
0093     {
0094         Layout.fillWidth: true
0095         Layout.fillHeight: true
0096         active: control.editMode
0097         visible: active
0098         asynchronous: true
0099         
0100         sourceComponent: TextField
0101         {
0102             id: editTagsEntry
0103             focus: true
0104             
0105             activeFocusOnPress : true
0106             
0107             text: list.tags.join(",")
0108             
0109             Component.onCompleted:
0110             {
0111                 editTagsEntry.forceActiveFocus()            
0112             }
0113             
0114             onAccepted:
0115             {
0116                 control.tagsEdited(getTags())
0117                 control.closeEditMode()
0118             }
0119             
0120             actions: Action
0121             {
0122                 icon.name: "checkbox"
0123                 onTriggered: editTagsEntry.accepted()
0124             }
0125             
0126             background: Rectangle
0127             {
0128                 color: "transparent"
0129             }
0130             
0131             function getTags()
0132             {
0133                 if(!editTagsEntry.text.length > 0)
0134                 {
0135                     return
0136                 }
0137                 
0138                 var tags = []
0139                 if(editTagsEntry.text.trim().length > 0)
0140                 {
0141                     var list = editTagsEntry.text.split(",")
0142                     
0143                     if(list.length > 0)
0144                     {
0145                         for(var i in list)
0146                         {
0147                             tags.push(list[i].trim())
0148                             
0149                         }
0150                     }
0151                 }
0152                 
0153                 return tags
0154             }
0155         }
0156     }
0157     
0158     TagList
0159     {
0160         id: tagsList
0161         Layout.fillWidth: true
0162         Layout.fillHeight: true
0163         visible: !control.editMode
0164         showPlaceHolder: allowEditMode
0165         showDeleteIcon: allowEditMode
0166         onTagRemoved: tagRemovedClicked(index)
0167         onTagClicked: control.tagClicked(tagsList.list.get(index).tag)
0168         
0169         onAreaClicked:
0170         {
0171             console.log("AREA CLICKED ON TAGS ABAR AREA");
0172             if(allowEditMode)
0173             {
0174                 goEditMode()
0175             }
0176         }
0177     }
0178 
0179     ToolButton
0180     {
0181         visible: Maui.Handy.isMobile && control.allowEditMode
0182         icon.name: "edit-entry"
0183         onClicked: goEditMode()
0184     }
0185 }
0186 
0187     background: null
0188 
0189     /**
0190      * 
0191      */
0192     function goEditMode()
0193     {
0194         control.forceActiveFocus()
0195         control.editMode = true
0196     }
0197     
0198     function closeEditMode()
0199     {
0200         control.editMode = false
0201     }    
0202 }