Holding a modifier while releasing a movement key no longer keeps moving
Button and key release events now ignore modifiers and notify all matching view actions of the release event
This commit is contained in:
parent
3b647c7f93
commit
3a00423552
@ -573,6 +573,8 @@ class CameraPanMouseAction(ViewAction):
|
|||||||
|
|
||||||
_stickyThreshold = 0.25
|
_stickyThreshold = 0.25
|
||||||
|
|
||||||
|
downTime = None
|
||||||
|
|
||||||
def __init__(self, stickyAction):
|
def __init__(self, stickyAction):
|
||||||
super(CameraPanMouseAction, self).__init__()
|
super(CameraPanMouseAction, self).__init__()
|
||||||
self._stickyAction = stickyAction
|
self._stickyAction = stickyAction
|
||||||
@ -585,10 +587,14 @@ class CameraPanMouseAction(ViewAction):
|
|||||||
self.mouseDragStart = x, y
|
self.mouseDragStart = x, y
|
||||||
|
|
||||||
def buttonReleaseEvent(self, event):
|
def buttonReleaseEvent(self, event):
|
||||||
|
if self.downTime is None:
|
||||||
|
return
|
||||||
|
|
||||||
if event.view.stickyMouselook and time.time() - self.downTime < self._stickyThreshold:
|
if event.view.stickyMouselook and time.time() - self.downTime < self._stickyThreshold:
|
||||||
self._stickyAction.toggleSticky(event)
|
self._stickyAction.toggleSticky(event)
|
||||||
|
|
||||||
self.mouseDragStart = None
|
self.mouseDragStart = None
|
||||||
|
self.downTime = None
|
||||||
|
|
||||||
sensitivity = .15
|
sensitivity = .15
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ from mcedit2.util.settings import Settings
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ViewAction(QtCore.QObject):
|
class ViewAction(QtCore.QObject):
|
||||||
button = Qt.NoButton
|
button = Qt.NoButton
|
||||||
modifiers = Qt.NoModifier
|
modifiers = Qt.NoModifier
|
||||||
@ -29,7 +30,8 @@ class ViewAction(QtCore.QObject):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
An action that can be bound to a keypress or mouse button click, drag, or movement with the bound key or button held.
|
An action that can be bound to a keypress or mouse button click, drag, or
|
||||||
|
movement with the bound key or button held.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
super(ViewAction, self).__init__()
|
super(ViewAction, self).__init__()
|
||||||
@ -68,12 +70,17 @@ class ViewAction(QtCore.QObject):
|
|||||||
if key in (Qt.Key_Shift, Qt.Key_Control, Qt.Key_Alt, Qt.Key_Meta):
|
if key in (Qt.Key_Shift, Qt.Key_Control, Qt.Key_Alt, Qt.Key_Meta):
|
||||||
modifiers = self.modifiers # pressing modifier key by itself has modifiers set, but releasing modifiers does not
|
modifiers = self.modifiers # pressing modifier key by itself has modifiers set, but releasing modifiers does not
|
||||||
|
|
||||||
return self.key == key and (self.modifiers & modifiers or self.modifiers == modifiers)
|
matched = self.key == key
|
||||||
|
|
||||||
|
if event.type == QtCore.QEvent.KeyPress:
|
||||||
|
# Only match modifiers on key press, ignore modifiers on release to handle
|
||||||
|
# input sequences like: S down, Shift down, S up, Shift up
|
||||||
|
matched &= (self.modifiers == modifiers)
|
||||||
|
return matched
|
||||||
|
|
||||||
def matchModifiers(self, event):
|
def matchModifiers(self, event):
|
||||||
return (self.modifiers is None or
|
return (self.modifiers is None or
|
||||||
(self.modifiers & event.modifiers() or
|
self.modifiers == event.modifiers())
|
||||||
self.modifiers == event.modifiers()))
|
|
||||||
|
|
||||||
def mouseMoveEvent(self, event):
|
def mouseMoveEvent(self, event):
|
||||||
"""
|
"""
|
||||||
@ -134,7 +141,6 @@ class ViewAction(QtCore.QObject):
|
|||||||
:type event: QtGui.QEvent
|
:type event: QtGui.QEvent
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def buttonName(self, buttons):
|
def buttonName(self, buttons):
|
||||||
if ViewAction._buttonNames is None:
|
if ViewAction._buttonNames is None:
|
||||||
ViewAction._buttonNames = [
|
ViewAction._buttonNames = [
|
||||||
@ -171,6 +177,7 @@ class ViewAction(QtCore.QObject):
|
|||||||
s += self.buttonName(self.button)
|
s += self.buttonName(self.button)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
class UseToolMouseAction(ViewAction):
|
class UseToolMouseAction(ViewAction):
|
||||||
button = Qt.LeftButton
|
button = Qt.LeftButton
|
||||||
labelText = "Use Tool (Don't change!)"
|
labelText = "Use Tool (Don't change!)"
|
||||||
|
@ -475,7 +475,6 @@ class WorldView(QGLWidget):
|
|||||||
for action in self.viewActions:
|
for action in self.viewActions:
|
||||||
if action.button & event.button():
|
if action.button & event.button():
|
||||||
if action.matchModifiers(event):
|
if action.matchModifiers(event):
|
||||||
if not action.key or action.key in self.pressedKeys:
|
|
||||||
action.mousePressEvent(event)
|
action.mousePressEvent(event)
|
||||||
|
|
||||||
def mouseMoveEvent(self, event):
|
def mouseMoveEvent(self, event):
|
||||||
@ -490,11 +489,12 @@ class WorldView(QGLWidget):
|
|||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def mouseReleaseEvent(self, event):
|
def mouseReleaseEvent(self, event):
|
||||||
|
# Ignore modifiers on mouse release event and send mouse release to any
|
||||||
|
# actions that are set to the given button. This handles this series of inputs,
|
||||||
|
# for example: Control Key down, Mouse1 down, Control Key up, Mouse1 up
|
||||||
self.augmentMouseEvent(event)
|
self.augmentMouseEvent(event)
|
||||||
for action in self.viewActions:
|
for action in self.viewActions:
|
||||||
if action.button & event.button():
|
if action.button & event.button():
|
||||||
if action.matchModifiers(event):
|
|
||||||
if not action.key or action.key in self.pressedKeys:
|
|
||||||
action.mouseReleaseEvent(event)
|
action.mouseReleaseEvent(event)
|
||||||
|
|
||||||
wheelPos = 0
|
wheelPos = 0
|
||||||
|
Reference in New Issue
Block a user