This is a stripped down version of customizable demo available at my invent repo[1]. It is optimized for this particular use-case. Animation honors right-to-left application layout and "instant animation speed" preference. [1]: https://invent.kde.org/ratijas/reject-input-animation/wilder-5.25
parent
2918bc2134
commit
6688c4a513
4 changed files with 109 additions and 0 deletions
@ -0,0 +1,42 @@ |
||||
/* |
||||
SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk> |
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later |
||||
*/ |
||||
|
||||
import QtQuick 2.15 |
||||
import QtQml 2.15 |
||||
|
||||
QtObject { |
||||
id: root |
||||
|
||||
property Item target |
||||
|
||||
readonly property Animation __animation: RejectPasswordPathAnimation { |
||||
id: animation |
||||
target: Item { id: fakeTarget } |
||||
} |
||||
|
||||
property Binding __bindEnabled: Binding { |
||||
target: root.target |
||||
property: "enabled" |
||||
value: false |
||||
when: animation.running |
||||
restoreMode: Binding.RestoreBindingOrValue |
||||
} |
||||
|
||||
// real target is getting a Translate object which pulls coordinates from |
||||
// a fake Item object |
||||
property Binding __bindTransform: Binding { |
||||
target: root.target |
||||
property: "transform" |
||||
value: Translate { |
||||
x: fakeTarget.x |
||||
} |
||||
restoreMode: Binding.RestoreBindingOrValue |
||||
} |
||||
|
||||
function start() { |
||||
animation.start(); |
||||
} |
||||
} |
||||
@ -0,0 +1,53 @@ |
||||
/* |
||||
SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk> |
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later |
||||
*/ |
||||
|
||||
import QtQuick 2.15 |
||||
import QtQml 2.15 |
||||
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore |
||||
|
||||
PathAnimation { |
||||
id: root |
||||
|
||||
/** The magnitude/distance/offset of the animation, in the usual device-independent pixels. */ |
||||
property real swing: 15 |
||||
|
||||
/** |
||||
* In which direction the target starts moving first. |
||||
* Must be either Qt.LeftToRight or Qt.RightToLeft. |
||||
* |
||||
* By default it is opposite to the application's layout direction, to |
||||
* make an animation feel more "disturbing". |
||||
*/ |
||||
property int initialDirection: Qt.application.layoutDirection === Qt.RightToLeft ? Qt.LeftToRight : Qt.RightToLeft |
||||
|
||||
alwaysRunToEnd: true |
||||
|
||||
// This animation's speed does not depend on user preferences, except when |
||||
// we honor the "reduced animations" special case. |
||||
// Animators with a duration of 0 do not fire reliably, which is why duration is at least 1. |
||||
// see Bug 357532 and QTBUG-39766 |
||||
duration: PlasmaCore.Units.longDuration <= 1 ? 1 : 600 |
||||
easing.type: Easing.OutCubic |
||||
|
||||
path: Path { |
||||
PathPolyline { |
||||
path: { |
||||
const directionFactor = root.initialDirection === Qt.RightToLeft ? -1 : 1; |
||||
const extreme = root.swing * directionFactor; |
||||
const here = Qt.point(extreme, 0); |
||||
const there = Qt.point(-extreme, 0); |
||||
return [ |
||||
Qt.point(0, 0), |
||||
here, there, |
||||
here, there, |
||||
here, there, |
||||
Qt.point(0, 0), |
||||
]; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue