Split edit and page tool panels

This commit is contained in:
2026-06-30 10:47:05 +08:00
parent 380653d58d
commit 200fe089cd
+59 -13
View File
@@ -1075,6 +1075,10 @@ class MainWindow(QMainWindow):
self.dark_mode_action = QAction("深色模式", self)
self.dark_mode_action.setCheckable(True)
self.dark_mode_action.setChecked(self.dark_mode)
self.toggle_edit_pdf_action = QAction("编辑PDF", self)
self.toggle_edit_pdf_action.setCheckable(True)
self.toggle_pages_action = QAction("页面", self)
self.toggle_pages_action.setCheckable(True)
self.toggle_tools_action = QAction("工具", self)
self.toggle_tools_action.setCheckable(True)
self.toggle_tools_action.setChecked(True)
@@ -1220,6 +1224,8 @@ class MainWindow(QMainWindow):
self.arrow_action: QStyle.StandardPixmap.SP_ArrowRight,
self.cover_action: QStyle.StandardPixmap.SP_DialogCloseButton,
self.dark_mode_action: QStyle.StandardPixmap.SP_ComputerIcon,
self.toggle_edit_pdf_action: QStyle.StandardPixmap.SP_FileDialogDetailedView,
self.toggle_pages_action: QStyle.StandardPixmap.SP_FileDialogInfoView,
self.toggle_tools_action: QStyle.StandardPixmap.SP_FileDialogDetailedView,
self.toggle_annotations_action: QStyle.StandardPixmap.SP_FileDialogListView,
}
@@ -1308,7 +1314,7 @@ class MainWindow(QMainWindow):
section_id="settings",
)
self.right_tools.finish()
self.right_tools.show_sections(["edit", "pages", "sign", "export", "settings"])
self.right_tools.show_sections(["sign", "export", "settings"])
def _build_toolbar(self) -> None:
toolbar = QToolBar("主工具栏")
@@ -1360,11 +1366,8 @@ class MainWindow(QMainWindow):
]:
toolbar.addAction(action)
toolbar.addSeparator()
for action in [
self.page_manager_action,
]:
toolbar.addAction(action)
toolbar.addSeparator()
toolbar.addAction(self.toggle_edit_pdf_action)
toolbar.addAction(self.toggle_pages_action)
toolbar.addAction(self.toggle_tools_action)
toolbar.addAction(self.toggle_annotations_action)
@@ -1495,6 +1498,8 @@ class MainWindow(QMainWindow):
self.arrow_action.triggered.connect(self.add_arrow)
self.cover_action.triggered.connect(self.add_cover_area)
self.dark_mode_action.triggered.connect(self.toggle_dark_mode)
self.toggle_edit_pdf_action.toggled.connect(self.toggle_edit_pdf_panel)
self.toggle_pages_action.toggled.connect(self.toggle_pages_panel)
self.toggle_tools_action.toggled.connect(self.toggle_tools_panel)
self.toggle_annotations_action.toggled.connect(self.toggle_annotations_panel)
self.right_tools.collapse_requested.connect(self.close_right_tools_panel)
@@ -2042,20 +2047,50 @@ class MainWindow(QMainWindow):
self.settings.setValue("darkMode", self.dark_mode)
self._apply_theme()
def toggle_edit_pdf_panel(self, checked: bool) -> None:
if checked:
self._show_right_panel_mode("edit")
elif not self._any_right_mode_checked():
self.set_right_tools_visible(False)
def toggle_pages_panel(self, checked: bool) -> None:
if checked:
self._show_right_panel_mode("pages")
elif not self._any_right_mode_checked():
self.set_right_tools_visible(False)
def toggle_tools_panel(self, checked: bool) -> None:
if checked:
self._show_right_panel_mode("tools")
elif not self.toggle_annotations_action.isChecked():
elif not self._any_right_mode_checked():
self.set_right_tools_visible(False)
def toggle_annotations_panel(self, checked: bool) -> None:
if checked:
self._show_right_panel_mode("annotations")
elif not self.toggle_tools_action.isChecked():
elif not self._any_right_mode_checked():
self.set_right_tools_visible(False)
def _right_mode_actions(self) -> list[QAction]:
return [
self.toggle_edit_pdf_action,
self.toggle_pages_action,
self.toggle_tools_action,
self.toggle_annotations_action,
]
def _any_right_mode_checked(self) -> bool:
return any(action.isChecked() for action in self._right_mode_actions())
def _show_right_panel_mode(self, mode: str) -> None:
with QSignalBlocker(self.toggle_tools_action), QSignalBlocker(self.toggle_annotations_action):
with (
QSignalBlocker(self.toggle_edit_pdf_action),
QSignalBlocker(self.toggle_pages_action),
QSignalBlocker(self.toggle_tools_action),
QSignalBlocker(self.toggle_annotations_action),
):
self.toggle_edit_pdf_action.setChecked(mode == "edit")
self.toggle_pages_action.setChecked(mode == "pages")
self.toggle_tools_action.setChecked(mode == "tools")
self.toggle_annotations_action.setChecked(mode == "annotations")
@@ -2063,15 +2098,26 @@ class MainWindow(QMainWindow):
self.right_tools.set_title("注释")
self.right_tools.show_sections(["annotations", "annotation_list"])
self._refresh_annotation_panel()
elif mode == "edit":
self.right_tools.set_title("编辑PDF")
self.right_tools.show_sections(["edit"])
elif mode == "pages":
self.right_tools.set_title("页面")
self.right_tools.show_sections(["pages"])
else:
self.right_tools.set_title("工具")
self.right_tools.show_sections(["edit", "pages", "sign", "export", "settings"])
self.right_tools.show_sections(["sign", "export", "settings"])
self.set_right_tools_visible(True)
def close_right_tools_panel(self) -> None:
with QSignalBlocker(self.toggle_tools_action), QSignalBlocker(self.toggle_annotations_action):
self.toggle_tools_action.setChecked(False)
self.toggle_annotations_action.setChecked(False)
with (
QSignalBlocker(self.toggle_edit_pdf_action),
QSignalBlocker(self.toggle_pages_action),
QSignalBlocker(self.toggle_tools_action),
QSignalBlocker(self.toggle_annotations_action),
):
for action in self._right_mode_actions():
action.setChecked(False)
self.set_right_tools_visible(False)
def set_right_tools_visible(self, visible: bool) -> None: