NTooltip: cleaned up

This commit is contained in:
quadbyte 2025-08-09 16:32:49 -04:00
parent 446bbe68d8
commit 0e037561f3

View file

@ -1,5 +1,4 @@
import QtQuick import QtQuick
import QtQuick.Window 2.15
import qs.Services import qs.Services
import qs.Theme import qs.Theme
@ -8,12 +7,10 @@ Window {
readonly property real scaling: Scaling.scale(screen) readonly property real scaling: Scaling.scale(screen)
property bool isVisible: false property bool isVisible: false
property string text: "" property string text: "Placeholder"
property Item target: null property Item target: null
property int delay: 300 property int delay: 300
property bool positionAbove: false property bool positionAbove: false
property var _timerObj: null
flags: Qt.ToolTip | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint flags: Qt.ToolTip | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
color: "transparent" color: "transparent"
@ -22,14 +19,7 @@ Window {
onIsVisibleChanged: { onIsVisibleChanged: {
if (isVisible) { if (isVisible) {
if (delay > 0) { if (delay > 0) {
if (_timerObj) { timerShow.running = true
_timerObj.destroy()
_timerObj = null
}
_timerObj = Qt.createQmlObject(
'import QtQuick 2.0; Timer { interval: ' + delay
+ '; running: true; repeat: false; onTriggered: root._showNow() }',
root)
} else { } else {
_showNow() _showNow()
} }
@ -39,10 +29,10 @@ Window {
} }
function show() { function show() {
isVisible = true; isVisible = true
} }
function hide() { function hide() {
isVisible = false; isVisible = false
} }
function _showNow() { function _showNow() {
@ -70,10 +60,6 @@ Window {
function _hideNow() { function _hideNow() {
visible = false visible = false
if (_timerObj) {
_timerObj.destroy()
_timerObj = null
}
} }
Connections { Connections {
@ -100,6 +86,17 @@ Window {
} }
} }
Timer {
id: timerShow
interval: delay
running: false
repeat: false
onTriggered: {
_showNow()
running = false
}
}
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
radius: Style.radiusMedium * scaling radius: Style.radiusMedium * scaling
@ -112,11 +109,11 @@ Window {
Text { Text {
id: tooltipText id: tooltipText
anchors.centerIn: parent
text: root.text text: root.text
color: Theme.textPrimary color: Theme.textPrimary
font.family: Theme.fontFamily font.family: Theme.fontFamily
font.pointSize: Theme.fontSizeMedium * scaling * 4 font.pointSize: Style.fontSmall * scaling
anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
wrapMode: Text.Wrap wrapMode: Text.Wrap