From 9048a1ff3c86728d835e874e597238eaf0e7d208 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 9 Feb 2021 11:39:47 +1000 Subject: [PATCH] experiment with using right click for AND/OR/NOT This frees up Ctrl/Shift+left click to behave like in a typical GUI app. On a Mac users can either two finger click, or Command+click in conjunction with one of the other modifiers. https://github.com/ankitects/anki/issues/1011 --- qt/aqt/sidebar.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index 7a0606e0a..7c90cce2f 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -274,8 +274,7 @@ class SidebarTreeView(QTreeView): self.col = self.mw.col self.current_search: Optional[str] = None - self.setContextMenuPolicy(Qt.CustomContextMenu) - self.customContextMenuRequested.connect(self.onContextMenu) # type: ignore + self.setContextMenuPolicy(Qt.PreventContextMenu) self.context_menus: Dict[SidebarItemType, Sequence[Tuple[str, Callable]]] = { SidebarItemType.DECK: ( (tr(TR.ACTIONS_RENAME), self.rename_deck), @@ -407,7 +406,13 @@ class SidebarTreeView(QTreeView): def mouseReleaseEvent(self, event: QMouseEvent) -> None: super().mouseReleaseEvent(event) if event.button() == Qt.LeftButton: - self._on_click_current() + if not self._keyboard_modified_pressed(): + self._on_click_current() + elif event.button() == Qt.RightButton: + if self._keyboard_modified_pressed(): + self._on_click_current() + else: + self.onContextMenu(event.pos()) def keyPressEvent(self, event: QKeyEvent) -> None: if event.key() in (Qt.Key_Return, Qt.Key_Enter): @@ -415,6 +420,10 @@ class SidebarTreeView(QTreeView): else: super().keyPressEvent(event) + def _keyboard_modified_pressed(self) -> bool: + mods = self.mw.app.keyboardModifiers() + return bool(mods & (Qt.ShiftModifier | Qt.AltModifier | Qt.ControlModifier)) + ########### def handle_drag_drop(self, sources: List[SidebarItem], target: SidebarItem) -> bool: