Warning, /maui/mauikit/src/controls.5/ItemDelegate.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 import QtQuick.Templates 2.15 as T
0025 
0026 /**
0027  * ItemDelegate
0028  * A global sidebar for the application window that can be collapsed.
0029  *
0030  *
0031  *
0032  *
0033  *
0034  *
0035  */
0036 T.Control
0037 {
0038     id: control
0039     
0040     hoverEnabled: !Maui.Handy.isMobile
0041     
0042     padding: 0
0043     
0044     focus: true
0045 
0046     ToolTip.delay: 1000
0047     ToolTip.timeout: 5000
0048     ToolTip.visible: control.hovered && control.tooltipText
0049     ToolTip.text: control.tooltipText
0050 
0051     /**
0052       * tooltipText : string
0053       */
0054     property string tooltipText
0055 
0056 
0057     /**
0058      * content :
0059      */
0060     default property alias content : _content.data
0061 
0062     /**
0063          * mouseArea :
0064          */
0065     property alias mouseArea : _mouseArea
0066 
0067     /**
0068          * draggable :
0069          */
0070     property bool draggable: false
0071 
0072     /**
0073          * isCurrentItem :
0074          */
0075     property alias isCurrentItem :  control.highlighted
0076 
0077     /**
0078          * containsPress :
0079          */
0080     property alias containsPress: _mouseArea.containsPress
0081 
0082     /**
0083          * highlighted :
0084          */
0085     property bool highlighted: control.isCurrentItem
0086 
0087     property int radius:  Maui.Style.radiusV
0088     
0089     property bool flat : !Maui.Handy.isMobile
0090 
0091     /**
0092          * pressed :
0093          */
0094     signal pressed(var mouse)
0095 
0096     /**
0097          * pressAndHold :
0098          */
0099     signal pressAndHold(var mouse)
0100 
0101     /**
0102          * clicked :
0103          */
0104     signal clicked(var mouse)
0105 
0106     /**
0107          * rightClicked :
0108          */
0109     signal rightClicked(var mouse)
0110 
0111     /**
0112          * doubleClicked :
0113          */
0114     signal doubleClicked(var mouse)
0115 
0116     Drag.active: mouseArea.drag.active && control.draggable
0117     Drag.dragType: Drag.Automatic
0118 //     Drag.supportedActions: Qt.MoveAction
0119     Drag.hotSpot.x: control.width / 2
0120     Drag.hotSpot.y: control.height / 2
0121 
0122     contentItem : MouseArea
0123     {
0124         id: _mouseArea
0125         
0126         propagateComposedEvents: false
0127         acceptedButtons: Qt.RightButton | Qt.LeftButton
0128         
0129         property bool pressAndHoldIgnored : false
0130 
0131         onClicked:
0132         {
0133             if(mouse.button === Qt.RightButton)
0134             {
0135                 control.rightClicked(mouse)
0136             }
0137             else
0138             {
0139                 control.clicked(mouse)
0140             }
0141         }
0142 
0143         onDoubleClicked:
0144         {
0145             control.doubleClicked(mouse)
0146         }
0147 
0148         onPressed:
0149         {
0150             if(control.draggable && mouse.source !== Qt.MouseEventSynthesizedByQt)
0151             {
0152                 drag.target = _content
0153                 control.grabToImage(function(result)
0154                 {
0155                     control.Drag.imageSource = result.url
0156                 })
0157             }else
0158             {
0159                 // drag.target = null
0160             }
0161             // 
0162             _mouseArea.pressAndHoldIgnored = false
0163             control.pressed(mouse)
0164         }
0165 
0166         onReleased :
0167         {
0168             _content.x = 0
0169             _content.y = 0
0170 //            if(control.draggable)
0171 //            {
0172 //                drag.target = null
0173 //            }
0174             console.log("DROPPING DRAG", _mouseArea.pressAndHoldIgnored)
0175 
0176             if(!mouseArea.drag.active && _mouseArea.pressAndHoldIgnored)
0177             {
0178                 control.pressAndHold(mouse)
0179                 _mouseArea.pressAndHoldIgnored = false
0180             }
0181         }
0182 
0183         onPressAndHold :
0184         {
0185             xAnim.running = control.draggable || mouse.source === Qt.MouseEventSynthesizedByQt
0186 
0187             _mouseArea.pressAndHoldIgnored = true
0188 
0189             if(control.draggable && mouse.source === Qt.MouseEventSynthesizedByQt)
0190             {
0191                 drag.target = _content
0192                 console.log("GETTING DRAG", _mouseArea.pressAndHoldIgnored)
0193                 control.grabToImage(function(result)
0194                 {
0195                     control.Drag.imageSource = result.url
0196                 })                
0197 
0198             }else
0199             {
0200                 // drag.target = null
0201                 control.pressAndHold(mouse)
0202             }
0203         }
0204 
0205         onPositionChanged:
0206         {
0207             if(control.draggable)
0208             {
0209                 console.log("MOVING DRAG", _mouseArea.pressAndHoldIgnored)
0210                 _mouseArea.pressAndHoldIgnored = false
0211                 mouse.accepted = true
0212             }
0213         }
0214 
0215         Item
0216         {
0217             id: _content
0218             
0219             height: parent.height
0220             width: parent.width
0221 
0222             SequentialAnimation on y
0223             {
0224                 id: xAnim
0225                 // Animations on properties start running by default
0226                 running: false
0227                 loops: 3
0228                 NumberAnimation { from: 0; to: -10; duration: 200; easing.type: Easing.InBack }
0229                 NumberAnimation { from: -10; to: 0; duration: 200; easing.type: Easing.OutBack }
0230                 PauseAnimation { duration: 50 } // This puts a bit of time between the loop
0231             }
0232         }
0233     }
0234 
0235     background: Rectangle
0236     {        
0237         color: control.isCurrentItem || control.containsPress ? Maui.Theme.highlightColor : ( control.hovered ? Maui.Theme.hoverColor : "transparent")
0238         
0239         radius: control.radius
0240     }
0241 }
0242