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 2.6 9import QtQuick.Templates @QQC2_VERSION@ as T 10import org.kde.plasma.core 2.0 as PlasmaCore 11import org.kde.kirigami 2.5 as Kirigami 12 13T.ToolTip { 14 id: control 15 16 x: parent ? Math.round((parent.width - implicitWidth) / 2) : 0 17 y: -implicitHeight - 3 18 19 visible: parent instanceof T.AbstractButton && (Kirigami.Settings.tabletMode ? parent.pressed : parent.hovered) 20 delay: Kirigami.Units.toolTipDelay 21 timeout: 5000 22 23 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, contentHeight + topPadding + bottomPadding) 24 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, contentWidth + leftPadding + rightPadding) 25 26 margins: PlasmaCore.Units.smallSpacing 27 leftPadding: backgroundItem.margins.left 28 topPadding: backgroundItem.margins.top 29 rightPadding: backgroundItem.margins.right 30 bottomPadding: backgroundItem.margins.bottom 31 32 closePolicy: T.Popup.CloseOnEscape | T.Popup.CloseOnPressOutsideParent | T.Popup.CloseOnReleaseOutsideParent 33 34 contentItem: Item { 35 implicitHeight: Math.ceil(label.implicitHeight) 36 implicitWidth: Math.ceil(label.implicitWidth) 37 Label { 38 id: label 39 // Strip out ampersands right before non-whitespace characters, i.e. 40 // those used to determine the alt key shortcut 41 text: control.text.replace(/&(?=\S)/g, "") 42 font: control.font 43 PlasmaCore.ColorScope.colorGroup: PlasmaCore.Theme.ToolTipColorGroup 44 PlasmaCore.ColorScope.inherit: false 45 } 46 } 47 48 background: Item { 49 implicitHeight: PlasmaCore.Units.gridUnit + backgroundItem.margins.top + backgroundItem.margins.bottom 50 implicitWidth: PlasmaCore.Units.gridUnit + backgroundItem.margins.left + backgroundItem.margins.right 51 52 PlasmaCore.FrameSvgItem { 53 anchors.fill: parent 54 anchors.leftMargin: -margins.left 55 anchors.rightMargin: -margins.right 56 anchors.topMargin: -margins.top 57 anchors.bottomMargin: -margins.bottom 58 imagePath: "widgets/tooltip" 59 prefix: "shadow" 60 colorGroup: PlasmaCore.Theme.ToolTipColorGroup 61 PlasmaCore.ColorScope.inherit: false 62 } 63 64 PlasmaCore.FrameSvgItem { 65 id: backgroundItem 66 anchors.fill: parent 67 // Because the transparent one doesn't match the appearance of all 68 // other ones 69 imagePath: "solid/widgets/tooltip" 70 colorGroup: PlasmaCore.Theme.ToolTipColorGroup 71 PlasmaCore.ColorScope.inherit: false 72 } 73 } 74} 75