Warning, /maui/mauikit/src/style.5/TextField.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.Window 2.15
0022 
0023 import org.mauikit.controls 1.3 as Maui
0024 import QtQuick.Layouts 1.3
0025 
0026 import QtQuick.Templates 2.15 as T
0027 
0028 /**
0029  * TextField
0030  * A global sidebar for the application window that can be collapsed.
0031  *
0032  *
0033  *
0034  *
0035  *
0036  *
0037  */
0038 T.TextField
0039 {
0040     id: control
0041     
0042     Maui.Theme.colorSet: Maui.Theme.Button
0043     Maui.Theme.inherit: false
0044     
0045     clip: true
0046     
0047     hoverEnabled: !Maui.Handy.isMobile
0048     
0049     opacity: control.enabled ? 1 : 0.5
0050     
0051     color: Maui.Theme.textColor
0052     selectionColor: Maui.Theme.highlightColor
0053     selectedTextColor: Maui.Theme.highlightedTextColor
0054     focus: true
0055     
0056     implicitHeight: _layout.implicitHeight + topPadding + bottomPadding
0057     implicitWidth: 200 
0058     
0059     verticalAlignment: Text.AlignVCenter
0060     horizontalAlignment: Text.AlignLeft
0061     
0062     padding: 0
0063     property int spacing: Maui.Style.space.small
0064         
0065     leftPadding: icon.visible ? icon.implicitWidth + Maui.Style.space.medium + Maui.Style.space.small : Maui.Style.space.medium
0066     rightPadding: _rightLayout.implicitWidth + Maui.Style.space.medium
0067     
0068     selectByMouse: !Maui.Handy.isMobile
0069     renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering
0070     
0071     persistentSelection: true
0072     font: Maui.Style.defaultFont
0073     
0074     wrapMode: TextInput.NoWrap
0075 
0076     /**
0077      * menu : Menu
0078      */
0079     property alias menu : entryMenu
0080     
0081     /**
0082      * actions : RowLayout
0083      */
0084     property list<T.Action> actions
0085     
0086     property alias icon : _icon
0087 
0088     property alias rightContent : _rightLayout.data
0089     
0090     /**
0091      * cleared
0092      */
0093     signal cleared()
0094         
0095     /**
0096      * contentDropped :
0097      */
0098     signal contentDropped(var drop)
0099     
0100     onPressAndHold: !Maui.Handy.isMobile ? entryMenu.show() : undefined
0101     onPressed:
0102     {
0103         if(!Maui.Handy.isMobile && event.button === Qt.RightButton)
0104             entryMenu.show()
0105     }
0106     
0107     Keys.enabled: true  
0108     
0109     Shortcut
0110     {
0111         sequence: StandardKey.Escape
0112         onActivated: 
0113         {
0114             control.clear()
0115             control.cleared()
0116         }
0117     }
0118 
0119     Behavior on leftPadding 
0120     {
0121         NumberAnimation 
0122         {
0123             duration: Maui.Style.units.longDuration
0124             easing.type: Easing.InOutQuad
0125         }
0126     }
0127     
0128     Behavior on rightPadding 
0129     {
0130         NumberAnimation
0131         {
0132             duration: Maui.Style.units.longDuration
0133             easing.type: Easing.InOutQuad
0134         }
0135     }    
0136     
0137      RowLayout
0138     {
0139         id: _layout
0140        anchors.fill: parent   
0141             anchors.leftMargin: Maui.Style.space.medium
0142             spacing: control.spacing 
0143                         
0144         Maui.Icon
0145         {
0146             id: _icon
0147             visible: source ? true : false
0148             implicitHeight: visible ? 16 : 0
0149             implicitWidth: height
0150             color: control.color   
0151         }
0152         
0153         Item
0154         {
0155             Layout.preferredHeight: Maui.Style.iconSize + (Maui.Style.defaultPadding * 2) //simulate the implicitHeight of common button controls
0156             
0157         }
0158 
0159         Item
0160         {
0161            Layout.fillWidth: true
0162            visible: !placeholder.visible
0163         }
0164 
0165         Label
0166         {
0167             id: placeholder
0168             Layout.fillWidth: true
0169             text: control.placeholderText
0170             font: control.font
0171             color: control.color
0172             verticalAlignment: control.verticalAlignment
0173             elide: Text.ElideRight
0174             wrapMode: Text.NoWrap
0175             
0176             visible: opacity > 0
0177             opacity: !control.length && !control.preeditText && !control.activeFocus ? 0.5 : 0  
0178                        
0179             
0180             Behavior on opacity 
0181             {
0182                 NumberAnimation
0183                 {
0184                     duration: Maui.Style.units.longDuration
0185                     easing.type: Easing.InOutQuad
0186                 }
0187             }  
0188         }      
0189         
0190         Row
0191         {
0192             id: _rightLayout
0193             
0194             z: parent.z + 1
0195             spacing: control.spacing 
0196             
0197             ToolButton
0198             {
0199                 id: clearButton
0200                 flat: true
0201                 focusPolicy: Qt.NoFocus
0202                 
0203                 visible: control.text.length || control.activeFocus
0204                 icon.name: "edit-clear"
0205                 
0206                 onClicked:
0207                 {
0208                     control.clear()
0209                     cleared()
0210                 }
0211             }
0212             
0213             Repeater
0214             {
0215                 model: control.actions
0216                 
0217                 ToolButton
0218                 {
0219                     flat: !checkable
0220                     focusPolicy: Qt.NoFocus
0221                     action: modelData
0222                 }
0223             }
0224         }
0225     }
0226     
0227     
0228     Maui.ContextualMenu
0229     {
0230         id: entryMenu
0231         
0232         MenuItem
0233         {
0234             text: i18nd("mauikit", "Copy")
0235             onTriggered: control.copy()
0236             enabled: control.selectedText.length
0237         }
0238         
0239         MenuItem
0240         {
0241             text: i18nd("mauikit", "Cut")
0242             onTriggered: control.cut()
0243             enabled: control.selectedText.length
0244         }
0245         
0246         MenuItem
0247         {
0248             text: i18nd("mauikit", "Paste")
0249             onTriggered:
0250             {
0251                 var text = control.paste()
0252                 control.insert(control.cursorPosition, text)
0253             }
0254         }
0255         
0256         MenuItem
0257         {
0258             text: i18nd("mauikit", "Select All")
0259             onTriggered: control.selectAll()
0260             enabled: control.text.length
0261         }
0262         
0263         MenuItem
0264         {
0265             text: i18nd("mauikit", "Undo")
0266             onTriggered: control.undo()
0267             enabled: control.canUndo
0268         }
0269         
0270         MenuItem
0271         {
0272             text: i18nd("mauikit", "Redo")
0273             onTriggered: control.redo()
0274             enabled: control.canRedo
0275         }
0276     }
0277     
0278     Loader
0279     {
0280         asynchronous: true
0281         sourceComponent: DropArea
0282         {            
0283             onDropped:
0284             {
0285                 console.log(drop.text, drop.html)
0286                 if (drop.hasText)
0287                 {
0288                     control.text += drop.text
0289                     
0290                 }else if(drop.hasUrls)
0291                 {
0292                     control.text = drop.urls
0293                 }
0294                 
0295                 control.contentDropped(drop)
0296             }
0297         }
0298     }
0299     
0300     background: Rectangle 
0301     {       
0302         color: control.enabled ? (control.hovered ? Maui.Theme.hoverColor :  Maui.Theme.backgroundColor) : "transparent"
0303         
0304         radius: Maui.Style.radiusV
0305         
0306         Behavior on color
0307         {
0308             Maui.ColorTransition{}
0309         }
0310     }
0311 }