diagrams: simplify pan — native Flickable drag, MouseArea only for wheel+right-click
Remove manual pan logic. Let Flickable handle drag-to-pan natively. MouseArea only accepts RightButton (close) and wheel (zoom), so it no longer steals left-click events from the Flickable.
This commit is contained in:
parent
395f2890ae
commit
32c501a2c7
|
|
@ -1469,7 +1469,6 @@ Item {
|
||||||
contentWidth: diagramZoomImg.width
|
contentWidth: diagramZoomImg.width
|
||||||
contentHeight: diagramZoomImg.height
|
contentHeight: diagramZoomImg.height
|
||||||
boundsBehavior: Flickable.StopAtBounds
|
boundsBehavior: Flickable.StopAtBounds
|
||||||
interactive: false // disable default drag — we handle it via Ctrl+drag
|
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
id: diagramZoomImg
|
id: diagramZoomImg
|
||||||
|
|
@ -1485,37 +1484,11 @@ Item {
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
acceptedButtons: Qt.RightButton
|
||||||
property real startX: 0
|
|
||||||
property real startY: 0
|
|
||||||
property real startContentX: 0
|
|
||||||
property real startContentY: 0
|
|
||||||
property bool panning: false
|
|
||||||
|
|
||||||
onPressed: function(mouse) {
|
|
||||||
if (mouse.button === Qt.LeftButton && (mouse.modifiers & Qt.ControlModifier)) {
|
|
||||||
panning = true
|
|
||||||
startX = mouse.x
|
|
||||||
startY = mouse.y
|
|
||||||
startContentX = diagramFlick.contentX
|
|
||||||
startContentY = diagramFlick.contentY
|
|
||||||
mouse.accepted = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onPositionChanged: function(mouse) {
|
|
||||||
if (panning) {
|
|
||||||
diagramFlick.contentX = Math.max(0, Math.min(diagramFlick.contentWidth - diagramFlick.width, startContentX - (mouse.x - startX)))
|
|
||||||
diagramFlick.contentY = Math.max(0, Math.min(diagramFlick.contentHeight - diagramFlick.height, startContentY - (mouse.y - startY)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onReleased: function(mouse) {
|
|
||||||
panning = false
|
|
||||||
}
|
|
||||||
onClicked: function(mouse) {
|
onClicked: function(mouse) {
|
||||||
if (mouse.button === Qt.RightButton)
|
if (mouse.button === Qt.RightButton)
|
||||||
diagramFullscreen.close()
|
diagramFullscreen.close()
|
||||||
}
|
}
|
||||||
onDoubleClicked: diagramFullscreen.close()
|
|
||||||
onWheel: function(wheel) {
|
onWheel: function(wheel) {
|
||||||
let factor = wheel.angleDelta.y > 0 ? 1.15 : 0.87
|
let factor = wheel.angleDelta.y > 0 ? 1.15 : 0.87
|
||||||
let newZoom = Math.max(0.25, Math.min(10.0, diagramZoomImg.zoomFactor * factor))
|
let newZoom = Math.max(0.25, Math.min(10.0, diagramZoomImg.zoomFactor * factor))
|
||||||
|
|
|
||||||
|
|
@ -2279,7 +2279,6 @@ ApplicationWindow {
|
||||||
contentWidth: diagramZoomImg.width
|
contentWidth: diagramZoomImg.width
|
||||||
contentHeight: diagramZoomImg.height
|
contentHeight: diagramZoomImg.height
|
||||||
boundsBehavior: Flickable.StopAtBounds
|
boundsBehavior: Flickable.StopAtBounds
|
||||||
interactive: false // disable default drag — we handle it via Ctrl+drag
|
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
id: diagramZoomImg
|
id: diagramZoomImg
|
||||||
|
|
@ -2294,37 +2293,11 @@ ApplicationWindow {
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
acceptedButtons: Qt.RightButton
|
||||||
property real startX: 0
|
|
||||||
property real startY: 0
|
|
||||||
property real startContentX: 0
|
|
||||||
property real startContentY: 0
|
|
||||||
property bool panning: false
|
|
||||||
|
|
||||||
onPressed: function(mouse) {
|
|
||||||
if (mouse.button === Qt.LeftButton && (mouse.modifiers & Qt.ControlModifier)) {
|
|
||||||
panning = true
|
|
||||||
startX = mouse.x
|
|
||||||
startY = mouse.y
|
|
||||||
startContentX = diagramFlick.contentX
|
|
||||||
startContentY = diagramFlick.contentY
|
|
||||||
mouse.accepted = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onPositionChanged: function(mouse) {
|
|
||||||
if (panning) {
|
|
||||||
diagramFlick.contentX = Math.max(0, Math.min(diagramFlick.contentWidth - diagramFlick.width, startContentX - (mouse.x - startX)))
|
|
||||||
diagramFlick.contentY = Math.max(0, Math.min(diagramFlick.contentHeight - diagramFlick.height, startContentY - (mouse.y - startY)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onReleased: function(mouse) {
|
|
||||||
panning = false
|
|
||||||
}
|
|
||||||
onClicked: function(mouse) {
|
onClicked: function(mouse) {
|
||||||
if (mouse.button === Qt.RightButton)
|
if (mouse.button === Qt.RightButton)
|
||||||
diagramFullscreen.close()
|
diagramFullscreen.close()
|
||||||
}
|
}
|
||||||
onDoubleClicked: diagramFullscreen.close()
|
|
||||||
onWheel: function(wheel) {
|
onWheel: function(wheel) {
|
||||||
var factor = wheel.angleDelta.y > 0 ? 1.15 : 0.87
|
var factor = wheel.angleDelta.y > 0 ? 1.15 : 0.87
|
||||||
var newZoom = Math.max(0.25, Math.min(10.0, diagramZoomImg.zoomFactor * factor))
|
var newZoom = Math.max(0.25, Math.min(10.0, diagramZoomImg.zoomFactor * factor))
|
||||||
|
|
|
||||||
Reference in New Issue