* Add main view menu

* Add browser view menu

* Use standard keys for zooming and full screen

* Capitalise menu item names

* Toggle Showing Cards/Notes -> Toggle Cards/Notes

* Explicitly set linux full screen key

on_toggle_fullscreen -> on_toggle_full_screen
This commit is contained in:
RumovZ 2022-02-17 07:31:46 +01:00 committed by GitHub
parent fd6a78e7cf
commit 700fc50f7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 149 additions and 23 deletions

View file

@ -91,7 +91,7 @@ browsing-suspended = Suspended
browsing-tag-duplicates = Tag Duplicates browsing-tag-duplicates = Tag Duplicates
browsing-tag-rename-warning-empty = You can't rename a tag that has no notes. browsing-tag-rename-warning-empty = You can't rename a tag that has no notes.
browsing-target-field = Target field: browsing-target-field = Target field:
browsing-toggle-showing-cards-notes = Toggle Showing Cards/Notes browsing-toggle-showing-cards-notes = Toggle Cards/Notes
browsing-toggle-mark = Toggle Mark browsing-toggle-mark = Toggle Mark
browsing-toggle-suspend = Toggle Suspend browsing-toggle-suspend = Toggle Suspend
browsing-treat-input-as-regular-expression = Treat input as regular expression browsing-treat-input-as-regular-expression = Treat input as regular expression

View file

@ -33,3 +33,10 @@ qt-accel-undo = &Undo
qt-accel-redo = &Redo qt-accel-redo = &Redo
qt-accel-set-due-date = Set &Due Date... qt-accel-set-due-date = Set &Due Date...
qt-accel-forget = &Forget qt-accel-forget = &Forget
qt-accel-view = &View
qt-accel-full-screen = Toggle &Full Screen
qt-accel-zoom-in = Zoom &In
qt-accel-zoom-out = Zoom &Out
qt-accel-reset-zoom = &Reset Zoom
qt-accel-zoom-editor-in = Zoom Editor &In
qt-accel-zoom-editor-out = Zoom Editor &Out

View file

@ -178,6 +178,7 @@ class Browser(QMainWindow):
def setupMenus(self) -> None: def setupMenus(self) -> None:
# actions # actions
f = self.form f = self.form
# edit # edit
qconnect(f.actionUndo.triggered, self.undo) qconnect(f.actionUndo.triggered, self.undo)
qconnect(f.actionRedo.triggered, self.redo) qconnect(f.actionRedo.triggered, self.redo)
@ -187,6 +188,24 @@ class Browser(QMainWindow):
f.actionClose.setVisible(False) f.actionClose.setVisible(False)
qconnect(f.actionCreateFilteredDeck.triggered, self.createFilteredDeck) qconnect(f.actionCreateFilteredDeck.triggered, self.createFilteredDeck)
f.actionCreateFilteredDeck.setShortcuts(["Ctrl+G", "Ctrl+Alt+G"]) f.actionCreateFilteredDeck.setShortcuts(["Ctrl+G", "Ctrl+Alt+G"])
# view
qconnect(f.actionFullScreen.triggered, self.mw.on_toggle_full_screen)
qconnect(
f.actionZoomIn.triggered,
lambda: self.editor.web.setZoomFactor(self.editor.web.zoomFactor() + 0.1),
)
f.actionZoomIn.setShortcut(QKeySequence.StandardKey.ZoomIn)
qconnect(
f.actionZoomOut.triggered,
lambda: self.editor.web.setZoomFactor(self.editor.web.zoomFactor() - 0.1),
)
f.actionZoomOut.setShortcut(QKeySequence.StandardKey.ZoomOut)
qconnect(
f.actionResetZoom.triggered,
lambda: self.editor.web.setZoomFactor(1),
)
# notes # notes
qconnect(f.actionAdd.triggered, self.mw.onAddCard) qconnect(f.actionAdd.triggered, self.mw.onAddCard)
qconnect(f.actionCopy.triggered, self.on_create_copy) qconnect(f.actionCopy.triggered, self.on_create_copy)
@ -199,6 +218,7 @@ class Browser(QMainWindow):
qconnect(f.actionFindReplace.triggered, self.onFindReplace) qconnect(f.actionFindReplace.triggered, self.onFindReplace)
qconnect(f.actionManage_Note_Types.triggered, self.mw.onNoteTypes) qconnect(f.actionManage_Note_Types.triggered, self.mw.onNoteTypes)
qconnect(f.actionDelete.triggered, self.delete_selected_notes) qconnect(f.actionDelete.triggered, self.delete_selected_notes)
# cards # cards
qconnect(f.actionChange_Deck.triggered, self.set_deck_of_selected_cards) qconnect(f.actionChange_Deck.triggered, self.set_deck_of_selected_cards)
qconnect(f.action_Info.triggered, self.showCardInfo) qconnect(f.action_Info.triggered, self.showCardInfo)
@ -216,6 +236,7 @@ class Browser(QMainWindow):
) )
self._update_flag_labels() self._update_flag_labels()
qconnect(f.actionExport.triggered, self._on_export_notes) qconnect(f.actionExport.triggered, self._on_export_notes)
# jumps # jumps
qconnect(f.actionPreviousCard.triggered, self.onPreviousCard) qconnect(f.actionPreviousCard.triggered, self.onPreviousCard)
qconnect(f.actionNextCard.triggered, self.onNextCard) qconnect(f.actionNextCard.triggered, self.onNextCard)
@ -225,13 +246,16 @@ class Browser(QMainWindow):
qconnect(f.actionNote.triggered, self.onNote) qconnect(f.actionNote.triggered, self.onNote)
qconnect(f.actionSidebar.triggered, self.focusSidebar) qconnect(f.actionSidebar.triggered, self.focusSidebar)
qconnect(f.actionCardList.triggered, self.onCardList) qconnect(f.actionCardList.triggered, self.onCardList)
# help # help
qconnect(f.actionGuide.triggered, self.onHelp) qconnect(f.actionGuide.triggered, self.onHelp)
# keyboard shortcut for shift+home/end # keyboard shortcut for shift+home/end
self.pgUpCut = QShortcut(QKeySequence("Shift+Home"), self) self.pgUpCut = QShortcut(QKeySequence("Shift+Home"), self)
qconnect(self.pgUpCut.activated, self.onFirstCard) qconnect(self.pgUpCut.activated, self.onFirstCard)
self.pgDownCut = QShortcut(QKeySequence("Shift+End"), self) self.pgDownCut = QShortcut(QKeySequence("Shift+End"), self)
qconnect(self.pgDownCut.activated, self.onLastCard) qconnect(self.pgDownCut.activated, self.onLastCard)
# add-on hook # add-on hook
gui_hooks.browser_menus_did_init(self) gui_hooks.browser_menus_did_init(self)
self.mw.maybeHideAccelerators(self) self.mw.maybeHideAccelerators(self)

View file

@ -219,8 +219,6 @@
<addaction name="actionUndo"/> <addaction name="actionUndo"/>
<addaction name="actionRedo"/> <addaction name="actionRedo"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="action_toggle_mode"/>
<addaction name="separator"/>
<addaction name="actionSelectAll"/> <addaction name="actionSelectAll"/>
<addaction name="actionSelectNotes"/> <addaction name="actionSelectNotes"/>
<addaction name="actionInvertSelection"/> <addaction name="actionInvertSelection"/>
@ -300,7 +298,20 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionDelete"/> <addaction name="actionDelete"/>
</widget> </widget>
<widget class="QMenu" name="menuqt_accel_view">
<property name="title">
<string>qt_accel_view</string>
</property>
<addaction name="action_toggle_mode"/>
<addaction name="separator"/>
<addaction name="actionFullScreen"/>
<addaction name="separator"/>
<addaction name="actionZoomIn"/>
<addaction name="actionZoomOut"/>
<addaction name="actionResetZoom"/>
</widget>
<addaction name="menuEdit"/> <addaction name="menuEdit"/>
<addaction name="menuqt_accel_view"/>
<addaction name="menu_Notes"/> <addaction name="menu_Notes"/>
<addaction name="menu_Cards"/> <addaction name="menu_Cards"/>
<addaction name="menuJump"/> <addaction name="menuJump"/>
@ -665,6 +676,34 @@
<string notr="true">Ctrl+Alt+E</string> <string notr="true">Ctrl+Alt+E</string>
</property> </property>
</action> </action>
<action name="actionFullScreen">
<property name="text">
<string>qt_accel_full_screen</string>
</property>
</action>
<action name="actionZoomIn">
<property name="text">
<string>qt_accel_zoom_editor_in</string>
</property>
</action>
<action name="actionZoomOut">
<property name="text">
<string>qt_accel_zoom_editor_out</string>
</property>
</action>
<action name="actionResetZoom">
<property name="text">
<string>qt_accel_reset_zoom</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+0</string>
</property>
</action>
<action name="actionbrowsing_toggle_showing_cards_notes">
<property name="text">
<string>browsing_toggle_showing_cards_notes</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="icons.qrc"/> <include location="icons.qrc"/>

View file

@ -92,8 +92,19 @@
<addaction name="actionNoteTypes"/> <addaction name="actionNoteTypes"/>
<addaction name="actionPreferences"/> <addaction name="actionPreferences"/>
</widget> </widget>
<widget class="QMenu" name="menuqt_accel_view">
<property name="title">
<string>qt_accel_view</string>
</property>
<addaction name="actionFullScreen"/>
<addaction name="separator"/>
<addaction name="actionZoomIn"/>
<addaction name="actionZoomOut"/>
<addaction name="actionResetZoom"/>
</widget>
<addaction name="menuCol"/> <addaction name="menuCol"/>
<addaction name="menuEdit"/> <addaction name="menuEdit"/>
<addaction name="menuqt_accel_view"/>
<addaction name="menuTools"/> <addaction name="menuTools"/>
<addaction name="menuHelp"/> <addaction name="menuHelp"/>
</widget> </widget>
@ -236,6 +247,29 @@
<string notr="true">Ctrl+Shift+Z</string> <string notr="true">Ctrl+Shift+Z</string>
</property> </property>
</action> </action>
<action name="actionFullScreen">
<property name="text">
<string>qt_accel_full_screen</string>
</property>
</action>
<action name="actionZoomIn">
<property name="text">
<string>qt_accel_zoom_in</string>
</property>
</action>
<action name="actionZoomOut">
<property name="text">
<string>qt_accel_zoom_out</string>
</property>
</action>
<action name="actionResetZoom">
<property name="text">
<string>qt_accel_reset_zoom</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+0</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="icons.qrc"/> <include location="icons.qrc"/>

View file

@ -209,7 +209,6 @@ class AnkiQt(QMainWindow):
self.setup_timers() self.setup_timers()
self.updateTitleBar() self.updateTitleBar()
self.setup_focus() self.setup_focus()
self.setup_shortcuts()
# screens # screens
self.setupDeckBrowser() self.setupDeckBrowser()
self.setupOverview() self.setupOverview()
@ -244,17 +243,6 @@ class AnkiQt(QMainWindow):
def on_focus_changed(self, old: QWidget, new: QWidget) -> None: def on_focus_changed(self, old: QWidget, new: QWidget) -> None:
gui_hooks.focus_did_change(new, old) gui_hooks.focus_did_change(new, old)
def setup_shortcuts(self) -> None:
QShortcut(
QKeySequence("Ctrl+Meta+F" if is_mac else "F11"),
self,
self.on_toggle_fullscreen,
).setContext(Qt.ShortcutContext.ApplicationShortcut)
def on_toggle_fullscreen(self) -> None:
window = self.app.activeWindow()
window.setWindowState(window.windowState() ^ Qt.WindowState.WindowFullScreen)
# Profiles # Profiles
########################################################################## ##########################################################################
@ -1277,28 +1265,62 @@ title="{}" {}>{}</button>""".format(
def setupMenus(self) -> None: def setupMenus(self) -> None:
m = self.form m = self.form
# File
qconnect( qconnect(
m.actionSwitchProfile.triggered, self.unloadProfileAndShowProfileManager m.actionSwitchProfile.triggered, self.unloadProfileAndShowProfileManager
) )
qconnect(m.actionImport.triggered, self.onImport) qconnect(m.actionImport.triggered, self.onImport)
qconnect(m.actionExport.triggered, self.onExport) qconnect(m.actionExport.triggered, self.onExport)
qconnect(m.actionExit.triggered, self.close) qconnect(m.actionExit.triggered, self.close)
qconnect(m.actionPreferences.triggered, self.onPrefs)
qconnect(m.actionAbout.triggered, self.onAbout) # Help
qconnect(m.actionUndo.triggered, self.undo)
qconnect(m.actionRedo.triggered, self.redo)
qconnect(m.actionFullDatabaseCheck.triggered, self.onCheckDB)
qconnect(m.actionCheckMediaDatabase.triggered, self.on_check_media_db)
qconnect(m.actionDocumentation.triggered, self.onDocumentation) qconnect(m.actionDocumentation.triggered, self.onDocumentation)
qconnect(m.actionDonate.triggered, self.onDonate) qconnect(m.actionDonate.triggered, self.onDonate)
qconnect(m.actionAbout.triggered, self.onAbout)
# Edit
qconnect(m.actionUndo.triggered, self.undo)
qconnect(m.actionRedo.triggered, self.redo)
# Tools
qconnect(m.actionFullDatabaseCheck.triggered, self.onCheckDB)
qconnect(m.actionCheckMediaDatabase.triggered, self.on_check_media_db)
qconnect(m.actionStudyDeck.triggered, self.onStudyDeck) qconnect(m.actionStudyDeck.triggered, self.onStudyDeck)
qconnect(m.actionCreateFiltered.triggered, self.onCram) qconnect(m.actionCreateFiltered.triggered, self.onCram)
qconnect(m.actionEmptyCards.triggered, self.onEmptyCards) qconnect(m.actionEmptyCards.triggered, self.onEmptyCards)
qconnect(m.actionNoteTypes.triggered, self.onNoteTypes) qconnect(m.actionNoteTypes.triggered, self.onNoteTypes)
qconnect(m.actionPreferences.triggered, self.onPrefs)
# View
qconnect(
m.actionZoomIn.triggered,
lambda: self.web.setZoomFactor(self.web.zoomFactor() + 0.1),
)
m.actionZoomIn.setShortcut(QKeySequence.StandardKey.ZoomIn)
qconnect(
m.actionZoomOut.triggered,
lambda: self.web.setZoomFactor(self.web.zoomFactor() - 0.1),
)
m.actionZoomOut.setShortcut(QKeySequence.StandardKey.ZoomOut)
qconnect(m.actionResetZoom.triggered, lambda: self.web.setZoomFactor(1))
# app-wide shortcut
qconnect(m.actionFullScreen.triggered, self.on_toggle_full_screen)
m.actionFullScreen.setShortcut(
QKeySequence("F11") if is_lin else QKeySequence.StandardKey.FullScreen
)
m.actionFullScreen.setShortcutContext(Qt.ShortcutContext.ApplicationShortcut)
def updateTitleBar(self) -> None: def updateTitleBar(self) -> None:
self.setWindowTitle("Anki") self.setWindowTitle("Anki")
# View
##########################################################################
def on_toggle_full_screen(self) -> None:
window = self.app.activeWindow()
window.setWindowState(window.windowState() ^ Qt.WindowState.WindowFullScreen)
# Auto update # Auto update
########################################################################## ##########################################################################

View file

@ -358,7 +358,7 @@ class AnkiWebView(QWebEngineView):
self._domDone = False self._domDone = False
super().load(url) super().load(url)
def zoomFactor(self) -> float: def app_zoom_factor(self) -> float:
# overridden scale factor? # overridden scale factor?
webscale = os.environ.get("ANKI_WEBSCALE") webscale = os.environ.get("ANKI_WEBSCALE")
if webscale: if webscale:
@ -448,7 +448,7 @@ div[contenteditable="true"]:focus {{
color_hl_txt=color_hl_txt, color_hl_txt=color_hl_txt,
) )
zoom = self.zoomFactor() zoom = self.app_zoom_factor()
window_bg_day = self.get_window_bg_color(False).name() window_bg_day = self.get_window_bg_color(False).name()
window_bg_night = self.get_window_bg_color(True).name() window_bg_night = self.get_window_bg_color(True).name()