From abcfd5cd86d578a98bfc22377b02f214c963658e Mon Sep 17 00:00:00 2001 From: shen Date: Mon, 29 Jun 2026 16:23:33 +0800 Subject: [PATCH] Add Acrobat style right tools panel --- README.md | 1 + docs/development_plan.md | 1 + pdfreaderlite/ui/main_window.py | 82 +++++++++++++++++++++++++++++---- pdfreaderlite/ui/right_tools.py | 67 +++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 pdfreaderlite/ui/right_tools.py diff --git a/README.md b/README.md index aa4a57d..53ab869 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ PDFReaderLite 是一个面向 Windows 的轻量 PDF 阅读与编辑工具,目 - 打开日志目录 - exe 版本资源 - 设置中注册 PDF 文件关联 +- Acrobat 风格右侧工具面板 - 图片签名 - 深色模式 - 常用快捷键 diff --git a/docs/development_plan.md b/docs/development_plan.md index 30910bb..1190014 100644 --- a/docs/development_plan.md +++ b/docs/development_plan.md @@ -63,6 +63,7 @@ PDFReaderLite 是 Windows 平台的轻量 PDF 阅读与编辑工具。功能重 ## V4:打包与体验优化 - 大文件性能优化 +- Acrobat 风格右侧工具面板(已完成) - 页面缓存(已完成基础缓存) - 后台渲染(已完成缩略图分批加载) - 快捷键(已完成常用快捷键与说明) diff --git a/pdfreaderlite/ui/main_window.py b/pdfreaderlite/ui/main_window.py index 69163b0..3db4716 100644 --- a/pdfreaderlite/ui/main_window.py +++ b/pdfreaderlite/ui/main_window.py @@ -22,7 +22,6 @@ from PySide6.QtWidgets import ( QSplitter, QStatusBar, QToolBar, - QWidget, QVBoxLayout, ) @@ -34,6 +33,7 @@ from pdfreaderlite.core.file_association import ( from pdfreaderlite.core.document import EncryptedPdfError, FormField, PdfDocument, SearchMatch from pdfreaderlite.resources import pdf_icon_path, software_icon_path from pdfreaderlite.ui.pdf_viewer import PdfViewer +from pdfreaderlite.ui.right_tools import RightToolsPanel from pdfreaderlite.ui.sidebar import Sidebar from pdfreaderlite.ui.signature_dialog import SignatureDialog @@ -50,6 +50,7 @@ class MainWindow(QMainWindow): self.sidebar = Sidebar() self.search_box = QLineEdit() self.search_results = QListWidget() + self.right_tools = RightToolsPanel(self.search_box, self.search_results) self._build_window() self._build_actions() @@ -618,18 +619,11 @@ class MainWindow(QMainWindow): self.resize(1320, 860) self.setStatusBar(QStatusBar()) - right_panel = QWidget() - right_layout = QVBoxLayout(right_panel) - right_layout.setContentsMargins(8, 8, 8, 8) - right_layout.addWidget(self.search_box) - right_layout.addWidget(self.search_results) - right_panel.setMinimumWidth(260) - splitter = QSplitter() splitter.addWidget(self.sidebar) splitter.addWidget(self.viewer) - splitter.addWidget(right_panel) - splitter.setSizes([220, 830, 270]) + splitter.addWidget(self.right_tools) + splitter.setSizes([220, 820, 320]) self.setCentralWidget(splitter) self.search_box.setPlaceholderText("搜索文本,按 Enter") @@ -778,6 +772,74 @@ class MainWindow(QMainWindow): help_menu.addAction(self.shortcuts_action) help_menu.addAction(self.open_log_dir_action) help_menu.addAction(self.about_action) + self._build_right_tools_panel() + + def _build_right_tools_panel(self) -> None: + self.right_tools.add_section( + "编辑 PDF", + [ + self.add_text_action, + self.insert_image_action, + self.cover_action, + self.undo_action, + self.redo_action, + ], + ) + self.right_tools.add_section( + "注释", + [ + self.highlight_action, + self.underline_action, + self.strikeout_action, + self.note_action, + self.rectangle_action, + self.circle_action, + self.line_action, + self.arrow_action, + self.annotation_list_action, + ], + ) + self.right_tools.add_section( + "页面", + [ + self.rotate_action, + self.delete_action, + self.move_page_action, + self.insert_blank_action, + self.insert_pdf_action, + self.extract_pages_action, + self.split_pdf_action, + self.merge_pdfs_action, + ], + ) + self.right_tools.add_section( + "签名与表单", + [ + self.signature_action, + self.draw_signature_action, + self.form_fill_action, + ], + ) + self.right_tools.add_section( + "导出与安全", + [ + self.export_current_image_action, + self.export_pages_images_action, + self.images_to_pdf_action, + self.metadata_action, + self.save_encrypted_action, + self.remove_password_action, + ], + ) + self.right_tools.add_section( + "设置", + [ + self.register_pdf_action, + self.default_apps_action, + self.open_log_dir_action, + ], + ) + self.right_tools.finish() def _build_toolbar(self) -> None: toolbar = QToolBar("主工具栏") diff --git a/pdfreaderlite/ui/right_tools.py b/pdfreaderlite/ui/right_tools.py new file mode 100644 index 0000000..7c6832a --- /dev/null +++ b/pdfreaderlite/ui/right_tools.py @@ -0,0 +1,67 @@ +from __future__ import annotations + +from collections.abc import Iterable + +from PySide6.QtGui import QAction +from PySide6.QtWidgets import ( + QFrame, + QLineEdit, + QListWidget, + QPushButton, + QScrollArea, + QSizePolicy, + QVBoxLayout, + QWidget, +) + + +class ToolSection(QFrame): + def __init__(self, title: str, actions: Iterable[QAction]) -> None: + super().__init__() + self.setObjectName("toolSection") + + layout = QVBoxLayout(self) + layout.setContentsMargins(8, 8, 8, 8) + layout.setSpacing(6) + + title_button = QPushButton(title) + title_button.setObjectName("toolSectionTitle") + title_button.setEnabled(False) + layout.addWidget(title_button) + + for action in actions: + button = QPushButton(action.text()) + button.setToolTip(action.toolTip() or action.text()) + button.clicked.connect(action.trigger) + button.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed) + layout.addWidget(button) + + +class RightToolsPanel(QWidget): + def __init__(self, search_box: QLineEdit, search_results: QListWidget) -> None: + super().__init__() + self.search_box = search_box + self.search_results = search_results + self.sections_container = QWidget() + self.sections_layout = QVBoxLayout(self.sections_container) + self.sections_layout.setContentsMargins(0, 0, 0, 0) + self.sections_layout.setSpacing(8) + + scroll = QScrollArea() + scroll.setWidgetResizable(True) + scroll.setFrameShape(QFrame.Shape.NoFrame) + scroll.setWidget(self.sections_container) + + layout = QVBoxLayout(self) + layout.setContentsMargins(8, 8, 8, 8) + layout.setSpacing(8) + layout.addWidget(search_box) + layout.addWidget(search_results, 1) + layout.addWidget(scroll, 2) + self.setMinimumWidth(300) + + def add_section(self, title: str, actions: Iterable[QAction]) -> None: + self.sections_layout.addWidget(ToolSection(title, actions)) + + def finish(self) -> None: + self.sections_layout.addStretch(1)