mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-06-09 22:32:19 +02:00
Keyboard Actions are never deactivated when focus is lost, leading to picking being enabled on a single click when Control was pressed in the 3D viewer and focus was lost to another Item. * keep track of focus loss inside the DefaultCameraController * use it to disable picking while Keyboard has not been pressed back in the 3D viewer * do the same for 'moving' state with Alt modifier
164 lines
5.5 KiB
QML
164 lines
5.5 KiB
QML
import QtQuick 2.7
|
|
import Qt3D.Core 2.1
|
|
import Qt3D.Render 2.1
|
|
import Qt3D.Input 2.1
|
|
import Qt3D.Logic 2.0
|
|
import QtQml 2.2
|
|
|
|
Entity {
|
|
id: root
|
|
|
|
property Camera camera
|
|
property real translateSpeed: 75.0
|
|
property real tiltSpeed: 500.0
|
|
property real panSpeed: 500.0
|
|
property bool moving: pressed || (actionAlt.active && keyboardHandler._pressed)
|
|
property alias focus: keyboardHandler.focus
|
|
readonly property bool pickingActive: actionControl.active && keyboardHandler._pressed
|
|
|
|
readonly property alias pressed: mouseHandler._pressed
|
|
signal mousePressed(var mouse)
|
|
signal mouseReleased(var mouse)
|
|
signal mouseClicked(var mouse)
|
|
signal mouseWheeled(var wheel)
|
|
signal mouseDoubleClicked(var mouse)
|
|
|
|
KeyboardDevice { id: keyboardSourceDevice }
|
|
MouseDevice { id: mouseSourceDevice }
|
|
|
|
MouseHandler {
|
|
id: mouseHandler
|
|
property bool _pressed
|
|
sourceDevice: mouseSourceDevice
|
|
onPressed: { _pressed = true; mousePressed(mouse) }
|
|
onReleased: { _pressed = false; mouseReleased(mouse) }
|
|
onClicked: mouseClicked(mouse)
|
|
onDoubleClicked: mouseDoubleClicked(mouse)
|
|
onWheel: {
|
|
var d = (root.camera.viewCenter.minus(root.camera.position)).length() * 0.2;
|
|
var tz = (wheel.angleDelta.y / 120) * d;
|
|
root.camera.translate(Qt.vector3d(0, 0, tz), Camera.DontTranslateViewCenter)
|
|
}
|
|
}
|
|
|
|
KeyboardHandler {
|
|
id: keyboardHandler
|
|
sourceDevice: keyboardSourceDevice
|
|
property bool _pressed
|
|
|
|
// When focus is lost while pressing a key, the corresponding action
|
|
// stays active, even when it's released.
|
|
// Handle this issue manually by keeping an additional _pressed state
|
|
// which is cleared when focus changes (used for 'pickingActive' property).
|
|
onFocusChanged: if(!focus) _pressed = false
|
|
onPressed: _pressed = true
|
|
onReleased: _pressed = false
|
|
}
|
|
|
|
LogicalDevice {
|
|
id: cameraControlDevice
|
|
actions: [
|
|
Action {
|
|
id: actionLMB
|
|
inputs: [
|
|
ActionInput {
|
|
sourceDevice: mouseSourceDevice
|
|
buttons: [MouseEvent.LeftButton]
|
|
}
|
|
]
|
|
},
|
|
Action {
|
|
id: actionRMB
|
|
inputs: [
|
|
ActionInput {
|
|
sourceDevice: mouseSourceDevice
|
|
buttons: [MouseEvent.RightButton]
|
|
}
|
|
]
|
|
},
|
|
Action {
|
|
id: actionMMB
|
|
inputs: [
|
|
ActionInput {
|
|
sourceDevice: mouseSourceDevice
|
|
buttons: [MouseEvent.MiddleButton]
|
|
}
|
|
]
|
|
},
|
|
Action {
|
|
id: actionShift
|
|
inputs: [
|
|
ActionInput {
|
|
sourceDevice: keyboardSourceDevice
|
|
buttons: [Qt.Key_Shift]
|
|
}
|
|
]
|
|
},
|
|
Action {
|
|
id: actionControl
|
|
inputs: [
|
|
ActionInput {
|
|
sourceDevice: keyboardSourceDevice
|
|
buttons: [Qt.Key_Control]
|
|
}
|
|
]
|
|
},
|
|
Action {
|
|
id: actionAlt
|
|
inputs: [
|
|
ActionInput {
|
|
sourceDevice: keyboardSourceDevice
|
|
buttons: [Qt.Key_Alt]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
axes: [
|
|
Axis {
|
|
id: axisMX
|
|
inputs: [
|
|
AnalogAxisInput {
|
|
sourceDevice: mouseSourceDevice
|
|
axis: MouseDevice.X
|
|
}
|
|
]
|
|
},
|
|
Axis {
|
|
id: axisMY
|
|
inputs: [
|
|
AnalogAxisInput {
|
|
sourceDevice: mouseSourceDevice
|
|
axis: MouseDevice.Y
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
|
|
components: [
|
|
FrameAction {
|
|
onTriggered: {
|
|
if(actionMMB.active || (actionLMB.active && actionShift.active)) { // translate
|
|
var d = (root.camera.viewCenter.minus(root.camera.position)).length() * 0.03;
|
|
var tx = axisMX.value * root.translateSpeed * d;
|
|
var ty = axisMY.value * root.translateSpeed * d;
|
|
root.camera.translate(Qt.vector3d(-tx, -ty, 0).times(dt))
|
|
return;
|
|
}
|
|
if(actionLMB.active) { // rotate
|
|
var rx = -axisMX.value;
|
|
var ry = -axisMY.value;
|
|
root.camera.panAboutViewCenter(root.panSpeed * rx * dt, Qt.vector3d(0,1,0))
|
|
root.camera.tiltAboutViewCenter(root.tiltSpeed * ry * dt)
|
|
return;
|
|
}
|
|
if(actionAlt.active && actionRMB.active) { // zoom with alt + RMD
|
|
var d = (root.camera.viewCenter.minus(root.camera.position)).length() * 0.1;
|
|
var tz = axisMX.value * root.translateSpeed * d;
|
|
root.camera.translate(Qt.vector3d(0, 0, tz).times(dt), Camera.DontTranslateViewCenter)
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|