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

KDE's Doxygen guidelines are available online.