From 0d0916fc347a85dcc50a38c507a157d03316d04f Mon Sep 17 00:00:00 2001 From: hewenfei Date: Mon, 22 Apr 2024 15:13:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(tooltip):=20=E6=9B=BF=E6=8D=A2Tooltip?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=8F=8D=E5=A4=8D=E8=A7=A6=E5=8F=91?= =?UTF-8?q?tooltip=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qml/AppControls2/AppItem.qml | 12 ++++-- qml/AppControls2/FolderItem.qml | 15 ++++---- qml/AppUI/AppListActions.qml | 10 +++-- qml/AppUI/Sidebar.qml | 68 +++++++++++++-------------------- 4 files changed, 49 insertions(+), 56 deletions(-) diff --git a/qml/AppControls2/AppItem.qml b/qml/AppControls2/AppItem.qml index 49204e7..0058130 100644 --- a/qml/AppControls2/AppItem.qml +++ b/qml/AppControls2/AppItem.qml @@ -18,6 +18,15 @@ MouseArea { border.width: 2 } } + + UkuiItems.Tooltip { + anchors.fill: parent + mainText: name + posFollowCursor: true + margin: 6 + visible: content.textTruncated + } + UkuiItems.StyleBackground { id: controlBase anchors.fill: parent @@ -25,9 +34,6 @@ MouseArea { useStyleTransparency: false paletteRole: Platform.Theme.Text alpha: isSelect ? 1.00 : control.containsPress ? 0.16 : control.containsMouse ? 0.08 : 0.00 - ToolTip.visible: content.textTruncated && control.containsMouse - ToolTip.text: name - ToolTip.delay: 500 RowLayout { anchors.fill: parent diff --git a/qml/AppControls2/FolderItem.qml b/qml/AppControls2/FolderItem.qml index 8e6e9d6..21f0c5b 100644 --- a/qml/AppControls2/FolderItem.qml +++ b/qml/AppControls2/FolderItem.qml @@ -12,15 +12,14 @@ MouseArea { property bool isSelect: false hoverEnabled: true - ToolTip { - property bool isVisible: !editStatus && truncate && control.containsMouse - id: tip - x: mouseX + 15 - y: mouseY + 15 - text: name - visible: !editStatus && truncate && control.containsMouse - delay: 500 + UkuiItems.Tooltip { + anchors.fill: parent + mainText: name + posFollowCursor: true + margin: 6 + visible: !editStatus && truncate } + onPositionChanged: { if (tip.isVisible) { if (tip.visible) { diff --git a/qml/AppUI/AppListActions.qml b/qml/AppUI/AppListActions.qml index 94e5f0c..8b8515f 100644 --- a/qml/AppUI/AppListActions.qml +++ b/qml/AppUI/AppListActions.qml @@ -53,9 +53,13 @@ UkuiItems.StyleBackground { width: height height: parent.height - ToolTip.delay: 500 - ToolTip.text: modelData.toolTip - ToolTip.visible: modelData.toolTip !== "" && containsMouse + UkuiItems.Tooltip { + anchors.fill: parent + mainText: modelData.toolTip + posFollowCursor: true + margin: 6 + visible: modelData.toolTip !== "" + } background.radius: width / 2 background.paletteRole: Platform.Theme.Highlight diff --git a/qml/AppUI/Sidebar.qml b/qml/AppUI/Sidebar.qml index 73600f7..384e337 100644 --- a/qml/AppUI/Sidebar.qml +++ b/qml/AppUI/Sidebar.qml @@ -42,18 +42,14 @@ Item { Layout.preferredHeight: 36 Layout.alignment: Qt.AlignHCenter - UkuiItems.ToolTip.text: mainWindow.isFullScreen ? qsTr("Contract") : qsTr("Expand") - - onEntered: { - UkuiItems.ToolTip.show(fullScreenButton.mapToGlobal(0, fullScreenButton.height)); - } - - onExited: { - UkuiItems.ToolTip.hide(); + UkuiItems.Tooltip { + anchors.fill: parent + mainText: mainWindow.isFullScreen ? qsTr("Contract") : qsTr("Expand") + posFollowCursor: true + margin: 6 } onClicked: { - UkuiItems.ToolTip.hide(); if (mainWindow.isFullScreen) { mainWindow.exitFullScreen(); } else { @@ -93,14 +89,11 @@ Item { icon.width: 24 icon.height: 24 - UkuiItems.ToolTip.text: totalUtils.realName - - onEntered: { - UkuiItems.ToolTip.show(userInfoButton.mapToGlobal(0, userInfoButton.height)); - } - - onExited: { - UkuiItems.ToolTip.hide(); + UkuiItems.Tooltip { + anchors.fill: parent + mainText: totalUtils.realName + posFollowCursor: true + margin: 6 } onClicked: totalUtils.openUserCenter() @@ -122,14 +115,11 @@ Item { Layout.preferredHeight: 36 Layout.alignment: Qt.AlignHCenter - UkuiItems.ToolTip.text: qsTr("Computer") - - onEntered: { - UkuiItems.ToolTip.show(computerButton.mapToGlobal(0, computerButton.height)); - } - - onExited: { - UkuiItems.ToolTip.hide(); + UkuiItems.Tooltip { + anchors.fill: parent + mainText: qsTr("Computer") + posFollowCursor: true + margin: 6 } onClicked: { @@ -153,14 +143,11 @@ Item { Layout.preferredHeight: 36 Layout.alignment: Qt.AlignHCenter - UkuiItems.ToolTip.text: qsTr("Control center") - - onEntered: { - UkuiItems.ToolTip.show(setButton.mapToGlobal(0, setButton.height)); - } - - onExited: { - UkuiItems.ToolTip.hide(); + UkuiItems.Tooltip { + anchors.fill: parent + mainText: qsTr("Control center") + posFollowCursor: true + margin: 6 } onClicked: { @@ -184,7 +171,12 @@ Item { Layout.preferredHeight: 36 Layout.alignment: Qt.AlignHCenter - UkuiItems.ToolTip.text: powerButtonBase.toolTip + UkuiItems.Tooltip { + anchors.fill: parent + mainText: powerButtonBase.toolTip + posFollowCursor: true + margin: 6 + } PowerButton { id: powerButtonBase @@ -199,14 +191,6 @@ Item { } } - onEntered: { - UkuiItems.ToolTip.show(powerButton.mapToGlobal(0, powerButton.height)); - } - - onExited: { - UkuiItems.ToolTip.hide(); - } - onClicked: { var buttonPosition = mapToGlobal(width, height); powerButtonBase.clicked(mouse.button === Qt.LeftButton, buttonPosition.x + spacingFromMenu, buttonPosition.y + spacingFromMenu, mainWindow.isFullScreen);