From d5f54be8d71734c9c59f5275c47b02fdec8c3cdf Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 1 Sep 2026 22:27:24 +0800 Subject: fix(App): mouse selected unintentionally --- components/IMouseArea.qml | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 components/IMouseArea.qml (limited to 'components') diff --git a/components/IMouseArea.qml b/components/IMouseArea.qml new file mode 100644 index 0000000..4c360ed --- /dev/null +++ b/components/IMouseArea.qml @@ -0,0 +1,45 @@ +/// NOTE: This is not zero cost, there's performance penalty, only use this instead of mousearea if hover is strictly required to be still +/// Such as when the component may appear where the mouse is already is + +import QtQuick + +MouseArea { + hoverEnabled: true + + property real gx: Number.MAX_VALUE + property real gy: Number.MAX_VALUE + + property bool hovered: false + + signal entered_ + signal positionChanged_(var mouse) + + onPositionChanged: mouse => { + let gpos = mapToItem(null, mouse.x, mouse.y); + + if (gx === Number.MAX_VALUE && gy === Number.MAX_VALUE) { + gx = gpos.x; + gy = gpos.y; + return; + } + + if (gpos.x === gx && gpos.y === gy) + return; + + gx = gpos.x; + gy = gpos.y; + + if (!hovered) { + hovered = true; + entered_(); + } + + positionChanged_(mouse); + } + + onExited: { + hovered = false; + gx = Number.MAX_VALUE; + gy = Number.MAX_VALUE; + } +} -- cgit v1.2.3