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

KDE's Doxygen guidelines are available online.