Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick
- MouseArea {
- id: root
- // signal drag(real dx, real dy)
- signal anchorDrag(real dx, real dy)
- QtObject {
- id: priv
- property bool firstEvent: false
- property real firstx: 0
- property real firsty: 0
- }
- Rectangle {
- anchors.fill: parent
- color: "#20000000"
- }
- function fpos(p) {
- return `${p.x.toFixed(2)},${p.y.toFixed(2)}`
- }
- onPressed: (mouse) => {
- priv.firstEvent = true
- console.log(`${fpos(mouse)} press`)
- }
- onReleased: (mouse) => {
- priv.firstEvent = false
- console.log(`${fpos(mouse)} release`)
- }
- onPositionChanged: (mouse) => {
- if (priv.firstEvent) {
- priv.firstEvent = false
- priv.firstx = mouse.x
- priv.firsty = mouse.y
- let p = root.mapToGlobal(mouse.x, mouse.y)
- console.log(`${fpos(mouse)} pos change, first event, item ${fpos(mouse)}, global ${fpos(p)}`)
- return
- }
- let dx = mouse.x - priv.firstx
- let dy = mouse.y - priv.firsty
- root.anchorDrag(dx, dy)
- let d = { x: dx, y: dy }
- let p = root.mapToGlobal(priv.firstx, priv.firsty)
- mousePos.set(p.x, p.y)
- console.log(`${fpos(mouse)} pos change, d ${fpos(d)}, set to global ${fpos(p)}`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment