Files
z-bar-qt/Components/Notifs/NotifSwipeArea.qml
T
zach 11e7aac195
C++ / fmt (pull_request) Failing after 5s
C++ / build (pull_request) Failing after 11s
C++ / clang-tidy (pull_request) Failing after 10s
JS/TS / fmt (pull_request) Successful in 12s
JS/TS / lint (pull_request) Successful in 10s
Python / static (pull_request) Failing after 27s
Rust / build (pull_request) Successful in 54s
Python / verify (pull_request) Failing after 1m26s
Rust / fmt (pull_request) Successful in 46s
Rust / clippy (pull_request) Successful in 1m6s
feat: better notification storage and image caching + blobs
2026-11-02 19:00:43 +01:00

71 lines
1.6 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
import ZShell.Config
import qs.Components
MouseArea {
id: root
required property bool expanded
property bool expandable: true
property bool dragExpand: expandable
property bool hoveringLink
property int startY
property real lastX
property real lastMoveTime
property real velocity
signal swiped
signal dismissed
signal requestExpand(expand: bool)
hoverEnabled: true
cursorShape: hoveringLink ? Qt.PointingHandCursor : pressedButtons === Qt.LeftButton ? Qt.ClosedHandCursor : undefined
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
preventStealing: dragExpand
drag.target: pressedButtons === Qt.LeftButton ? this : null
drag.axis: Drag.XAxis
onPressed: event => {
startY = event.y;
lastX = x;
lastMoveTime = Date.now();
velocity = 0;
if (event.button === Qt.RightButton && expandable)
requestExpand(!expanded);
else if (event.button === Qt.MiddleButton)
dismissed();
}
onPositionChanged: event => {
if (pressedButtons !== Qt.LeftButton)
return;
const now = Date.now();
const dt = now - lastMoveTime;
if (dt > 0) {
velocity = (velocity + (x - lastX) / dt * 1000) / 2;
lastX = x;
lastMoveTime = now;
}
if (dragExpand) {
const diffY = event.y - startY;
if (Math.abs(diffY) > Config.notifs.expandThreshold)
requestExpand(diffY > 0);
}
}
onReleased: {
const flung = Date.now() - lastMoveTime < 100 && Math.sign(velocity) === Math.sign(x) && Math.abs(velocity) > Config.notifs.clearVelocity;
if (!flung && Math.abs(x) < width * Config.notifs.clearThreshold)
x = 0;
else
swiped();
}
Behavior on x {
Anim {}
}
}