Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/ToolTip.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org>
0003     SPDX-FileCopyrightText: 2017 The Qt Company Ltd.
0004 
0005     SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later
0006 */
0007 
0008 
0009 import QtQuick
0010 import QtQuick.Controls as Controls
0011 import QtQuick.Templates as T
0012 import org.kde.kirigami as Kirigami
0013 
0014 T.ToolTip {
0015     id: control
0016 
0017     Kirigami.Theme.colorSet: parent && parent.Kirigami.Theme.colorSet === Kirigami.Theme.Complementary
0018         ? Kirigami.Theme.Complementary : Kirigami.Theme.Tooltip
0019     Kirigami.Theme.inherit: false
0020 
0021     x: parent ? Math.round((parent.width - implicitWidth) / 2) : 0
0022     y: -implicitHeight - 3
0023 
0024     z: Kirigami.OverlayZStacking.z
0025 
0026     // Math.ceil() prevents blurry edges and prevents unnecessary text wrapping
0027     // (vs using floor or sometimes round).
0028     implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
0029                             Math.ceil(contentWidth) + leftPadding + rightPadding)
0030     implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
0031                              Math.ceil(contentHeight) + topPadding + bottomPadding)
0032 
0033     margins: 6
0034     padding: 6
0035 
0036     visible: {
0037         if (!parent || text.length === 0) {
0038             return false;
0039         }
0040         if (Kirigami.Settings.tabletMode) {
0041             return parent.pressed ?? false;
0042         }
0043         return parent.hovered ?? parent.containsMouse ?? false;
0044     }
0045     delay: Kirigami.Settings.tabletMode ? Qt.styleHints.mousePressAndHoldInterval : Kirigami.Units.toolTipDelay
0046     // Never time out while being hovered; it's annoying
0047     timeout: -1
0048 
0049     closePolicy: T.Popup.CloseOnEscape | T.Popup.CloseOnPressOutsideParent | T.Popup.CloseOnReleaseOutsideParent
0050 
0051     enter: Transition {
0052         NumberAnimation {
0053             property: "opacity"
0054             from: 0.0
0055             to: 1.0
0056             duration: Kirigami.Units.longDuration
0057             easing.type: Easing.OutCubic
0058         }
0059     }
0060 
0061     exit: Transition {
0062         NumberAnimation {
0063             property: "opacity"
0064             from: 1.0
0065             to: 0.0
0066             duration: Kirigami.Units.longDuration
0067             easing.type: Easing.OutCubic
0068         }
0069     }
0070 
0071     contentItem: Item {
0072         implicitWidth: Math.min(label.maxTextLength, label.contentWidth)
0073         implicitHeight: label.implicitHeight
0074 
0075         Controls.Label {
0076             id: label
0077 
0078             // This value is basically arbitrary. It just looks nice.
0079             readonly property double maxTextLength: Kirigami.Units.gridUnit * 14
0080 
0081             // Strip out ampersands right before non-whitespace characters, i.e.
0082             // those used to determine the alt key shortcut
0083             // (except when the word ends in ; (HTML entities))
0084             text: control.text.replace(/(&)(?!;)\S+(?>\s)/g, "")
0085             // Using Wrap instead of WordWrap to prevent tooltips with long URLs
0086             // from overflowing
0087             wrapMode: Text.Wrap
0088             font: control.font
0089             color: Kirigami.Theme.textColor
0090 
0091             Kirigami.Theme.colorSet: control.Kirigami.Theme.colorSet
0092             // ensure that long text actually gets wrapped
0093             onLineLaidOut: (line) => {
0094                 if (line.implicitWidth > maxTextLength)
0095                     line.width = maxTextLength
0096             }
0097         }
0098     }
0099 
0100     // TODO: Consider replacing this with a StyleItem
0101     background: Kirigami.ShadowedRectangle {
0102         radius: 3
0103         color: Kirigami.Theme.backgroundColor
0104         Kirigami.Theme.colorSet: control.Kirigami.Theme.colorSet
0105 
0106         // Roughly but doesn't exactly match the medium shadow setting for Breeze menus/tooltips.
0107         // TODO: Find a way to more closely match the user's Breeze settings.
0108         shadow.xOffset: 0
0109         shadow.yOffset: 4
0110         shadow.size: 16
0111         shadow.color: Qt.rgba(0, 0, 0, 0.2)
0112 
0113         border.width: 1
0114         // TODO: Replace this with a frame or separator color role if that becomes a thing.
0115         // Matches the color used by Breeze::Style::drawPanelTipLabelPrimitive()
0116         border.color: Kirigami.ColorUtils.linearInterpolation(background.color, Kirigami.Theme.textColor, Kirigami.Theme.frameContrast)
0117     }
0118 }