Skip to content

Commit

Permalink
fix: correctly uses key mod for custom del obj
Browse files Browse the repository at this point in the history
  • Loading branch information
ElpadoCan committed Oct 5, 2024
1 parent 00fb4d0 commit a001b7c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 23 deletions.
5 changes: 3 additions & 2 deletions cellacdc/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12223,9 +12223,10 @@ def __init__(
entriesLayout = QGridLayout()

self.delObjShortcutLineEdit = widgets.ShortcutLineEdit(
allowModifiers=True
allowModifiers=True, notAllowedModifier=Qt.AltModifier
)
self.delObjShortcutLineEdit.setText(delObjectKey)
if delObjectKey is not None:
self.delObjShortcutLineEdit.setText(delObjectKey)
self.delObjButtonCombobox = QComboBox()
self.delObjButtonCombobox.addItems(['Middle click', 'Left click'])
self.delObjButtonCombobox.setCurrentText(delObjectButton)
Expand Down
69 changes: 49 additions & 20 deletions cellacdc/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1427,26 +1427,9 @@ def isMiddleClick(self, mouseEvent, modifiers):
return self.isDefaultMiddleClick(mouseEvent, modifiers)

delObjKeySequence, delObjQtButton = self.delObjAction

isMatchKey = self.delObjToolAction.isChecked()

if not isMatchKey:
isAltKeySequence = delObjKeySequence == QKeySequence(Qt.Key_Alt)
isAltModifier = modifiers == Qt.AltModifier
isMatchKey = isAltKeySequence and isAltModifier

if not isMatchKey:
isCtrlKeySequence = delObjKeySequence == QKeySequence(Qt.Key_Control)
isCtrlModifier = modifiers == Qt.ControlModifier
isMatchKey = isCtrlKeySequence and isCtrlModifier

if not isMatchKey:
isShiftKeySequence = delObjKeySequence == QKeySequence(Qt.Key_Shift)
isShiftModifier = modifiers == Qt.ShiftModifier
isMatchKey = isShiftKeySequence and isShiftModifier

middle_click = (
mouseEvent.button() == delObjQtButton and isMatchKey
mouseEvent.button() == delObjQtButton
and self.delObjToolAction.isChecked()
)

return middle_click
Expand Down Expand Up @@ -13225,7 +13208,27 @@ def _resizeLeaveSpaceTerminalBelow(self):
width = geometry.width()
height = geometry.height()
self.setGeometry(left, top+10, width, height-200)

def checkSetDelObjActionActive(self, isCtrlModifier, isShiftModifier):
if self.delObjAction is None:
return

isModifier = isCtrlModifier or isShiftModifier
if not isModifier:
return

delObjKeySequence, delObjQtButton = self.delObjAction

isCtrlKeySequence = delObjKeySequence == QKeySequence(Qt.Key_Control)
if isCtrlKeySequence and isCtrlModifier:
self.delObjToolAction.setChecked(True)
return

isShiftKeySequence = delObjKeySequence == QKeySequence(Qt.Key_Shift)
if isShiftKeySequence and isShiftModifier:
self.delObjToolAction.setChecked(True)
return

@exception_handler
def keyPressEvent(self, ev):
ctrl = ev.modifiers() == Qt.ControlModifier
Expand Down Expand Up @@ -13264,6 +13267,9 @@ def keyPressEvent(self, ev):
isAltModifier = modifiers == Qt.AltModifier
isCtrlModifier = modifiers == Qt.ControlModifier
isShiftModifier = modifiers == Qt.ShiftModifier

self.checkSetDelObjActionActive(isCtrlModifier, isShiftModifier)

self.isZmodifier = (
ev.key()== Qt.Key_Z and not isAltModifier
and not isCtrlModifier and not isShiftModifier
Expand Down Expand Up @@ -13508,6 +13514,7 @@ def doubleKeySpacebarTimerCallback(self):
# self.drawIDsContComboBox.setCurrentIndex(0)

def keyReleaseEvent(self, ev):
self.delObjToolAction.setChecked(False)
if self.app.overrideCursor() == Qt.SizeAllCursor:
self.app.restoreOverrideCursor()
if ev.key() == Qt.Key_Control:
Expand Down Expand Up @@ -22003,7 +22010,29 @@ def setShortcuts(self, shortcuts: dict, save=True):
cp.write(ini)

def editShortcuts_cb(self):
win = apps.ShortcutEditorDialog(self.widgetsWithShortcut, parent=self)
if sys.platform == 'darwin':
delObjKeySequenceText = 'Ctrl'
delObjButtonText = 'Left click'
else:
delObjKeySequenceText = ''
delObjButtonText = 'Middle click'

if self.delObjAction is not None:
delObjKeySequence, delObjQtButton = self.delObjAction
delObjKeySequenceText = delObjKeySequence.toString()
delObjKeySequenceText = (
delObjKeySequenceText.encode('ascii', 'ignore').decode('utf-8')
)
delObjButtonText = (
'Left click' if delObjQtButton == Qt.MouseButton.LeftButton
else 'Middle click'
)
win = apps.ShortcutEditorDialog(
self.widgetsWithShortcut,
delObjectKey=delObjKeySequenceText,
delObjectButton=delObjButtonText,
parent=self
)
win.exec_()
if win.cancel:
return
Expand Down
13 changes: 12 additions & 1 deletion cellacdc/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3331,10 +3331,13 @@ def paintEvent(self, e):
p.end()

class ShortcutLineEdit(QLineEdit):
def __init__(self, parent=None, allowModifiers=False):
def __init__(
self, parent=None, allowModifiers=False, notAllowedModifier=None
):
self.keySequence = None
super().__init__(parent)
self._allowModifiers = allowModifiers
self._notAllowedModifier = notAllowedModifier
self.setAlignment(Qt.AlignCenter)

def setText(self, text):
Expand All @@ -3358,6 +3361,14 @@ def keyPressEvent(self, event: QKeyEvent):
isModifierKey = isAltKey or isCtrlKey or isShiftKey

modifiers = event.modifiers()
isNotAllowedMod = (
self._notAllowedModifier is not None
and modifiers == self._notAllowedModifier
)
if isNotAllowedMod:
self.setText('')
return

modifers_value = modifiers.value if PYQT6 else modifiers
if isModifierKey:
keySequence = QKeySequence(modifers_value).toString()
Expand Down

0 comments on commit a001b7c

Please sign in to comment.