Libplasma

ToolTip.qml
1/*
2 SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2016 The Qt Company Ltd.
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8import QtQuick
9import QtQuick.Templates as T
10import org.kde.ksvg as KSvg
11//NOTE: importing PlasmaCore is necessary in order to make KSvg load the current Plasma Theme
12import org.kde.plasma.core as PlasmaCore
13import org.kde.kirigami as Kirigami
14
15T.ToolTip {
16 id: control
17
18 property alias textFormat: label.textFormat
19
20 x: parent ? Math.round((parent.width - implicitWidth) / 2) : 0
21 y: -implicitHeight - 3
22
23 visible: parent instanceof T.AbstractButton && (Kirigami.Settings.tabletMode ? parent.pressed : parent.hovered) && text.length > 0
24 delay: Kirigami.Settings.tabletMode ? Qt.styleHints.mousePressAndHoldInterval : Kirigami.Units.toolTipDelay
25 // Never time out while being hovered; it's annoying
26 timeout: -1
27
28 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, contentHeight + topPadding + bottomPadding)
29 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, contentWidth + leftPadding + rightPadding)
30
31 margins: Kirigami.Units.smallSpacing
32
33 topPadding: backgroundItem.margins.top
34 leftPadding: backgroundItem.margins.left
35 rightPadding: backgroundItem.margins.right
36 bottomPadding: backgroundItem.margins.bottom
37
38 enter: Transition {
39 NumberAnimation {
40 property: "opacity"
41 from: 0.0
42 to: 1.0
43 duration: Kirigami.Units.longDuration
44 easing.type: Easing.OutCubic
45 }
46 }
47
48 exit: Transition {
49 NumberAnimation {
50 property: "opacity"
51 from: 1.0
52 to: 0.0
53 duration: Kirigami.Units.longDuration
54 easing.type: Easing.OutCubic
55 }
56 }
57
58 closePolicy: T.Popup.CloseOnEscape | T.Popup.CloseOnPressOutsideParent | T.Popup.CloseOnReleaseOutsideParent
59
60 contentItem: Item {
61 implicitWidth: Math.min(label.maxTextLength, label.contentWidth)
62 implicitHeight: label.implicitHeight
63
64 Label {
65 id: label
66
67 // This value is basically arbitrary. It just looks nice.
68 readonly property double maxTextLength: Kirigami.Units.gridUnit * 14
69
70 // Strip out ampersands right before non-whitespace characters, i.e.
71 // those used to determine the alt key shortcut
72 text: control.text.replace(/&(?=\S)/g, "")
73 wrapMode: Text.WordWrap
74 font: control.font
75
76 Kirigami.Theme.colorGroup: Kirigami.Theme.Tooltip
77 Kirigami.Theme.inherit: false
78
79 // ensure that long text actually gets wrapped
80 onLineLaidOut: (line) => {
81 if (line.implicitWidth > maxTextLength) {
82 line.width = maxTextLength
83 }
84 }
85 }
86 }
87
88 background: Item {
89 implicitHeight: Kirigami.Units.gridUnit + backgroundItem.margins.top + backgroundItem.margins.bottom
90 implicitWidth: Kirigami.Units.gridUnit + backgroundItem.margins.left + backgroundItem.margins.right
91
93 anchors {
94 fill: parent
95 topMargin: -margins.top
96 leftMargin: -margins.left
97 rightMargin: -margins.right
98 bottomMargin: -margins.bottom
99 }
100 imagePath: "solid/widgets/tooltip"
101 prefix: "shadow"
102 Kirigami.Theme.colorGroup: Kirigami.Theme.Tooltip
103 Kirigami.Theme.inherit: false
104 }
105
107 id: backgroundItem
108 anchors.fill: parent
109 // Because the transparent one doesn't match the appearance of all
110 // other ones
111 imagePath: "solid/widgets/tooltip"
112 Kirigami.Theme.colorGroup: Kirigami.Theme.Tooltip
113 Kirigami.Theme.inherit: false
114 }
115 }
116}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 11:50:52 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.