Warning, /plasma/latte-dock/declarativeimports/abilities/host/ThinTooltip.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 import QtQuick 2.7
0007 import QtQuick.Layouts 1.1
0008 import QtQuick.Window 2.2
0009 
0010 import org.kde.plasma.plasmoid 2.0
0011 import org.kde.plasma.components 2.0 as PlasmaComponents
0012 import org.kde.plasma.core 2.0 as PlasmaCore
0013 
0014 import org.kde.latte.core 0.2 as LatteCore
0015 import org.kde.latte.abilities.definition 0.1 as AbilityDefinition
0016 
0017 AbilityDefinition.ThinTooltip {
0018     id: _thinTooltip
0019     property Item debug: null
0020 
0021     readonly property int maxCharacters: 80
0022 
0023     property Item lastHidingVisualParent: null
0024 
0025     //! Public API
0026     readonly property Item publicApi: Item {
0027         readonly property alias isEnabled: _thinTooltip.isEnabled
0028         readonly property alias currentText: _thinTooltip.currentText
0029         readonly property alias currentVisualParent: _thinTooltip.currentVisualParent
0030 
0031         function show(visualParent, text) {
0032             _thinTooltip.show(visualParent, text);
0033         }
0034 
0035         function hide(visualParent) {
0036             _thinTooltip.hide(visualParent);
0037         }
0038     }
0039 
0040     //! Private Implementation
0041 
0042     onShowIsBlockedChanged: {       
0043         if (isEnabled && !showIsBlocked && !_tooltipDialog.visible && _thinTooltip.currentVisualParent) {
0044             _hideTimer.stop();
0045             _tooltipDialog.visible = true;
0046         } else if (showIsBlocked && _tooltipDialog.visible) {
0047             _tooltipDialog.visible = false;
0048         }
0049     }
0050 
0051     function show(visualParent, text) {
0052         if (!isEnabled || showIsBlocked) {
0053             _hideTimer.stop();
0054             _showTimer.stop();
0055             _tooltipDialog.visible = false;
0056             //disabling because we need to updated currentvisualparent even when tooltip is blocked
0057             //for example when triggering a different applet popup
0058             //return;
0059         }
0060 
0061         _hideTimer.stop();
0062         _thinTooltip.currentVisualParent = visualParent;
0063         _tooltipDialog.visualParent = visualParent;
0064 
0065         var fixedDisplayText = text.length>maxCharacters ? text.substring(0,maxCharacters-1) + "..." : text;
0066         _thinTooltip.currentText = fixedDisplayText;
0067 
0068         if (!_tooltipDialog.visible && !showIsBlocked) {
0069             _showTimer.start();
0070         }
0071     }
0072 
0073     function hide(visualParent) {
0074         if (_thinTooltip.currentVisualParent === visualParent) {
0075             _thinTooltip.lastHidingVisualParent = visualParent;
0076             _showTimer.stop();
0077             _hideTimer.start();
0078         }
0079     }
0080 
0081     //! Show Delayer Timer
0082     Timer {
0083         id: _showTimer
0084         interval: 100
0085         onTriggered: {
0086             if (_thinTooltip.currentVisualParent) {
0087                 _tooltipDialog.visible = true;
0088             }
0089 
0090             if (debug && debug.timersEnabled) {
0091                 console.log("ThinTooltip host timer: show() called...");
0092             }
0093         }
0094     }
0095 
0096     //! Hide Delayer Timer
0097     Timer {
0098         id: _hideTimer
0099         interval: 100
0100         onTriggered: {
0101             if (_thinTooltip.lastHidingVisualParent === _thinTooltip.currentVisualParent) {
0102                 _tooltipDialog.visible = false;
0103                 _thinTooltip.lastHidingVisualParent = null;
0104                 _thinTooltip.currentVisualParent = null;
0105                 _thinTooltip.currentText = "";
0106             }
0107 
0108             if (debug && debug.timersEnabled) {
0109                 console.log("ThinTooltip host timer: hide() called...");
0110             }
0111         }
0112     }
0113 
0114     LatteCore.Dialog{
0115         id: _tooltipDialog
0116         type: PlasmaCore.Dialog.Tooltip
0117         flags: Qt.WindowStaysOnTopHint | Qt.WindowDoesNotAcceptFocus | Qt.ToolTip
0118 
0119         location: plasmoid.location
0120         edge: plasmoid.location
0121         mainItem: RowLayout{
0122             Layout.fillWidth: true
0123             Layout.fillHeight: true
0124             PlasmaComponents.Label{
0125                 Layout.leftMargin: 4
0126                 Layout.rightMargin: 4
0127                 Layout.topMargin: 2
0128                 Layout.bottomMargin: 2
0129                 text: _thinTooltip.currentText
0130             }
0131         }
0132 
0133         visible: false
0134     }
0135 }