diff --git a/src/mcedit2/worldview/camera.py b/src/mcedit2/worldview/camera.py index ab18297..962bda7 100644 --- a/src/mcedit2/worldview/camera.py +++ b/src/mcedit2/worldview/camera.py @@ -573,6 +573,8 @@ class CameraPanMouseAction(ViewAction): _stickyThreshold = 0.25 + downTime = None + def __init__(self, stickyAction): super(CameraPanMouseAction, self).__init__() self._stickyAction = stickyAction @@ -585,10 +587,14 @@ class CameraPanMouseAction(ViewAction): self.mouseDragStart = x, y def buttonReleaseEvent(self, event): + if self.downTime is None: + return + if event.view.stickyMouselook and time.time() - self.downTime < self._stickyThreshold: self._stickyAction.toggleSticky(event) self.mouseDragStart = None + self.downTime = None sensitivity = .15 diff --git a/src/mcedit2/worldview/viewaction.py b/src/mcedit2/worldview/viewaction.py index 824afcc..1e3963d 100644 --- a/src/mcedit2/worldview/viewaction.py +++ b/src/mcedit2/worldview/viewaction.py @@ -13,6 +13,7 @@ from mcedit2.util.settings import Settings log = logging.getLogger(__name__) + class ViewAction(QtCore.QObject): button = Qt.NoButton modifiers = Qt.NoModifier @@ -29,7 +30,8 @@ class ViewAction(QtCore.QObject): 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__() @@ -68,12 +70,17 @@ class ViewAction(QtCore.QObject): 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 - 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): return (self.modifiers is None or - (self.modifiers & event.modifiers() or - self.modifiers == event.modifiers())) + self.modifiers == event.modifiers()) def mouseMoveEvent(self, event): """ @@ -134,7 +141,6 @@ class ViewAction(QtCore.QObject): :type event: QtGui.QEvent """ - def buttonName(self, buttons): if ViewAction._buttonNames is None: ViewAction._buttonNames = [ @@ -171,6 +177,7 @@ class ViewAction(QtCore.QObject): s += self.buttonName(self.button) return s + class UseToolMouseAction(ViewAction): button = Qt.LeftButton labelText = "Use Tool (Don't change!)" diff --git a/src/mcedit2/worldview/worldview.py b/src/mcedit2/worldview/worldview.py index 8ff5cfa..023f485 100644 --- a/src/mcedit2/worldview/worldview.py +++ b/src/mcedit2/worldview/worldview.py @@ -475,8 +475,7 @@ class WorldView(QGLWidget): for action in self.viewActions: if action.button & event.button(): if action.matchModifiers(event): - if not action.key or action.key in self.pressedKeys: - action.mousePressEvent(event) + action.mousePressEvent(event) def mouseMoveEvent(self, event): self.augmentMouseEvent(event) @@ -490,12 +489,13 @@ class WorldView(QGLWidget): self.update() 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) for action in self.viewActions: 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