From 33988a78abc1aea0a1b9496c7e2880b64b9d8a70 Mon Sep 17 00:00:00 2001 From: shen Date: Tue, 30 Jun 2026 00:27:58 +0800 Subject: [PATCH] Enhance reader layout polish --- README.md | 7 ++- docs/development_plan.md | 7 ++- pdfreaderlite/ui/main_window.py | 107 ++++++++++++++++++++++++++++---- pdfreaderlite/ui/right_tools.py | 29 ++++++++- pdfreaderlite/ui/sidebar.py | 7 ++- 5 files changed, 134 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 6d0ed2b..4cb0627 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ PDFReaderLite 是一个面向 Windows 的轻量 PDF 阅读与编辑工具,目 - 最近打开文件 - 拖拽 PDF 文件到软件窗口打开 - 中文界面 -- Acrobat 风格布局(已完成界面精简:高频顶部工具栏、灰色阅读画布、可折叠右侧工具面板) +- Acrobat 风格布局(已完成第二轮界面优化:图标化顶部工具栏、加深阅读画布、可收起右侧工具面板) ## 已加入的增强功能 @@ -67,8 +67,9 @@ PDFReaderLite 是一个面向 Windows 的轻量 PDF 阅读与编辑工具,目 - 打开日志目录 - exe 版本资源 - 设置中注册 PDF 文件关联 -- Acrobat 风格右侧工具面板(已完成可折叠分类、搜索结果默认收起) -- 缩略图单列卡片式显示与克制选中态 +- Acrobat 风格右侧工具面板(已完成可折叠分类、搜索结果默认收起、整栏收起/展开) +- 缩略图单列卡片式显示与克制选中态,左侧栏已压缩宽度 +- 顶部与右侧常用工具图标化 - 图片签名 - 多标签页打开、切换、关闭 PDF - 未保存更改星号提示,关闭标签/窗口时保存确认 diff --git a/docs/development_plan.md b/docs/development_plan.md index 46ca366..05c7698 100644 --- a/docs/development_plan.md +++ b/docs/development_plan.md @@ -23,7 +23,7 @@ PDFReaderLite 是 Windows 平台的轻量 PDF 阅读与编辑工具。功能重 - 最近打开文件 - 拖拽 PDF 文件到软件窗口打开(已完成) - 中文界面 -- Acrobat 风格布局(已完成界面精简:高频顶部工具栏、灰色阅读画布、可折叠右侧工具面板) +- Acrobat 风格布局(已完成第二轮界面优化:图标化顶部工具栏、加深阅读画布、可收起右侧工具面板) ## V2:编辑增强版 @@ -64,8 +64,9 @@ PDFReaderLite 是 Windows 平台的轻量 PDF 阅读与编辑工具。功能重 ## V4:打包与体验优化 - 大文件性能优化(已完成缩略图可见区域懒加载与缩略图独立缓存) -- Acrobat 风格右侧工具面板(已完成可折叠分类、搜索结果默认收起) -- 缩略图单列卡片式显示与克制选中态(已完成) +- Acrobat 风格右侧工具面板(已完成可折叠分类、搜索结果默认收起、整栏收起/展开) +- 缩略图单列卡片式显示与克制选中态(已完成左侧栏宽度压缩) +- 顶部与右侧常用工具图标化(已完成) - 页面缓存(已完成基础缓存) - 后台渲染(已完成缩略图分批加载) - 快捷键(已完成常用快捷键与说明) diff --git a/pdfreaderlite/ui/main_window.py b/pdfreaderlite/ui/main_window.py index b80dc87..6665648 100644 --- a/pdfreaderlite/ui/main_window.py +++ b/pdfreaderlite/ui/main_window.py @@ -25,6 +25,7 @@ from PySide6.QtWidgets import ( QSlider, QSpinBox, QStatusBar, + QStyle, QTabWidget, QToolBar, QVBoxLayout, @@ -75,6 +76,7 @@ class MainWindow(QMainWindow): self.search_box = QLineEdit() self.search_results = QListWidget() self.right_tools = RightToolsPanel(self.search_box, self.search_results) + self.main_splitter: QSplitter | None = None self.pending_placement: dict[str, object] | None = None self.selected_annotation: AnnotationInfo | None = None self.session_raster_objects: list[dict[str, object]] = [] @@ -133,7 +135,7 @@ class MainWindow(QMainWindow): splitter = QSplitter() splitter.addWidget(sidebar) splitter.addWidget(viewer) - splitter.setSizes([220, 820]) + splitter.setSizes([188, 872]) session = DocumentSession( document=document, @@ -889,12 +891,12 @@ class MainWindow(QMainWindow): self.tab_widget.setObjectName("documentTabs") self.right_tools.setObjectName("rightToolsPanel") - splitter = QSplitter() - splitter.setObjectName("mainSplitter") - splitter.addWidget(self.tab_widget) - splitter.addWidget(self.right_tools) - splitter.setSizes([1040, 320]) - self.setCentralWidget(splitter) + self.main_splitter = QSplitter() + self.main_splitter.setObjectName("mainSplitter") + self.main_splitter.addWidget(self.tab_widget) + self.main_splitter.addWidget(self.right_tools) + self.main_splitter.setSizes([1060, 280]) + self.setCentralWidget(self.main_splitter) self.search_box.setPlaceholderText("搜索文本,按 Enter") self.search_results.setAlternatingRowColors(True) @@ -992,6 +994,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_tools_action = QAction("工具", self) + self.toggle_tools_action.setCheckable(True) + self.toggle_tools_action.setChecked(True) + self._apply_action_icons() file_menu = self.menuBar().addMenu("文件") file_menu.addAction(self.open_action) @@ -1071,6 +1077,60 @@ class MainWindow(QMainWindow): help_menu.addAction(self.about_action) self._build_right_tools_panel() + def _apply_action_icons(self) -> None: + icon_map = { + self.open_action: QStyle.StandardPixmap.SP_DialogOpenButton, + self.save_action: QStyle.StandardPixmap.SP_DialogSaveButton, + self.save_as_action: QStyle.StandardPixmap.SP_DialogSaveButton, + self.print_action: QStyle.StandardPixmap.SP_FileDialogDetailedView, + self.undo_action: QStyle.StandardPixmap.SP_ArrowBack, + self.redo_action: QStyle.StandardPixmap.SP_ArrowForward, + self.previous_action: QStyle.StandardPixmap.SP_ArrowUp, + self.next_action: QStyle.StandardPixmap.SP_ArrowDown, + self.zoom_out_action: QStyle.StandardPixmap.SP_TitleBarMinButton, + self.zoom_in_action: QStyle.StandardPixmap.SP_TitleBarMaxButton, + self.fit_width_action: QStyle.StandardPixmap.SP_ArrowLeft, + self.fit_page_action: QStyle.StandardPixmap.SP_FileDialogContentsView, + self.go_to_page_action: QStyle.StandardPixmap.SP_ArrowRight, + self.rotate_action: QStyle.StandardPixmap.SP_BrowserReload, + self.delete_action: QStyle.StandardPixmap.SP_TrashIcon, + self.move_page_action: QStyle.StandardPixmap.SP_FileDialogListView, + self.page_manager_action: QStyle.StandardPixmap.SP_FileDialogInfoView, + self.insert_blank_action: QStyle.StandardPixmap.SP_FileIcon, + self.insert_pdf_action: QStyle.StandardPixmap.SP_FileLinkIcon, + self.extract_pages_action: QStyle.StandardPixmap.SP_DialogSaveButton, + self.split_pdf_action: QStyle.StandardPixmap.SP_DialogResetButton, + self.merge_pdfs_action: QStyle.StandardPixmap.SP_DirIcon, + self.export_current_image_action: QStyle.StandardPixmap.SP_DialogSaveButton, + self.export_pages_images_action: QStyle.StandardPixmap.SP_DirOpenIcon, + self.images_to_pdf_action: QStyle.StandardPixmap.SP_FileIcon, + self.metadata_action: QStyle.StandardPixmap.SP_MessageBoxInformation, + self.form_fill_action: QStyle.StandardPixmap.SP_FileDialogDetailedView, + self.annotation_list_action: QStyle.StandardPixmap.SP_FileDialogListView, + self.highlight_action: QStyle.StandardPixmap.SP_DialogApplyButton, + self.underline_action: QStyle.StandardPixmap.SP_DialogApplyButton, + self.strikeout_action: QStyle.StandardPixmap.SP_DialogCancelButton, + self.note_action: QStyle.StandardPixmap.SP_MessageBoxInformation, + self.select_object_action: QStyle.StandardPixmap.SP_ArrowRight, + self.freehand_action: QStyle.StandardPixmap.SP_DialogApplyButton, + self.add_text_action: QStyle.StandardPixmap.SP_FileDialogDetailedView, + self.place_text_action: QStyle.StandardPixmap.SP_FileDialogDetailedView, + self.insert_image_action: QStyle.StandardPixmap.SP_FileIcon, + self.place_image_action: QStyle.StandardPixmap.SP_FileIcon, + self.signature_action: QStyle.StandardPixmap.SP_DialogApplyButton, + self.place_signature_action: QStyle.StandardPixmap.SP_DialogApplyButton, + self.draw_signature_action: QStyle.StandardPixmap.SP_DialogApplyButton, + self.rectangle_action: QStyle.StandardPixmap.SP_FileDialogContentsView, + self.circle_action: QStyle.StandardPixmap.SP_FileDialogContentsView, + self.line_action: QStyle.StandardPixmap.SP_ArrowRight, + self.arrow_action: QStyle.StandardPixmap.SP_ArrowRight, + self.cover_action: QStyle.StandardPixmap.SP_DialogCloseButton, + self.dark_mode_action: QStyle.StandardPixmap.SP_ComputerIcon, + self.toggle_tools_action: QStyle.StandardPixmap.SP_FileDialogDetailedView, + } + for action, standard_icon in icon_map.items(): + action.setIcon(self.style().standardIcon(standard_icon)) + def _build_right_tools_panel(self) -> None: self.right_tools.add_section( "编辑 PDF", @@ -1151,7 +1211,7 @@ class MainWindow(QMainWindow): toolbar.setFloatable(False) toolbar.setAllowedAreas(Qt.ToolBarArea.TopToolBarArea) toolbar.setIconSize(QSize(18, 18)) - toolbar.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextOnly) + toolbar.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) self.addToolBar(Qt.ToolBarArea.TopToolBarArea, toolbar) for action in [ @@ -1196,6 +1256,8 @@ class MainWindow(QMainWindow): self.page_manager_action, ]: toolbar.addAction(action) + toolbar.addSeparator() + toolbar.addAction(self.toggle_tools_action) def _connect_signals(self) -> None: self.open_action.triggered.connect(lambda: self.open_file()) @@ -1256,6 +1318,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_tools_action.toggled.connect(self.set_right_tools_visible) + self.right_tools.collapse_requested.connect(lambda: self.toggle_tools_action.setChecked(False)) self.tab_widget.currentChanged.connect(self._on_tab_changed) self.tab_widget.tabCloseRequested.connect(self._close_tab) @@ -1740,6 +1804,11 @@ class MainWindow(QMainWindow): self.settings.setValue("darkMode", self.dark_mode) self._apply_theme() + def set_right_tools_visible(self, visible: bool) -> None: + self.right_tools.setVisible(visible) + if self.main_splitter: + self.main_splitter.setSizes([self.width() - (280 if visible else 0), 280 if visible else 0]) + def _apply_theme(self) -> None: if self.dark_mode: self.setStyleSheet( @@ -1777,6 +1846,13 @@ class MainWindow(QMainWindow): QTabBar::tab:selected { background: #26282b; border-bottom-color: #26282b; } QSplitter::handle { background: #34373b; } QWidget#rightToolsPanel { background: #2b2e31; border-left: 1px solid #44484d; } + QLabel#rightToolsTitle { color: #f1f1f1; font-weight: 600; padding-left: 4px; } + QToolButton#rightToolsCollapseButton { + color: #dfe3e7; background: transparent; border: 1px solid #555a60; + border-radius: 4px; padding: 2px 7px; + } + QToolButton#rightToolsCollapseButton:hover { background: #3c4045; } + QScrollArea#rightToolsScroll { background: transparent; border: none; } QFrame#toolSection { background: #313438; border: 1px solid #44484d; border-radius: 6px; } QToolButton#toolSectionTitle { color: #f1f1f1; font-weight: 600; text-align: left; @@ -1784,7 +1860,7 @@ class MainWindow(QMainWindow): } QToolButton#toolSectionTitle:hover { background: #3c4045; border-radius: 4px; } QPushButton#rightToolButton { - color: #f1f1f1; text-align: left; padding: 6px 8px 6px 20px; + color: #f1f1f1; text-align: left; padding: 6px 8px 6px 14px; border: 1px solid transparent; border-radius: 4px; background: transparent; } QListWidget, QListWidget#searchResults, QListWidget#thumbnailList { @@ -1794,7 +1870,7 @@ class MainWindow(QMainWindow): QListWidget::item:selected { background: #27384d; color: #ffffff; border: 2px solid #4f89c8; } QListWidget#thumbnailList::item { margin: 4px 6px; padding: 8px; } QListWidget#thumbnailList::item:selected { background: #26384d; border: 2px solid #5b9be3; } - QScrollArea#pdfCanvas { background: #1f2022; border: none; } + QScrollArea#pdfCanvas, QWidget#pdfContinuousContent { background: #181a1c; border: none; } QLabel#emptyPage { background: #2d3034; color: #cfd3d8; padding: 28px; border: 1px solid #464a4f; } QLabel#pdfPage { background: #ffffff; color: #202020; padding: 0; border: 1px solid #53575c; } QStatusBar { background: #303235; color: #dfe3e7; border-top: 1px solid #45494d; } @@ -1838,6 +1914,13 @@ class MainWindow(QMainWindow): QTabBar::tab:selected { background: #f8f9fb; border-bottom-color: #f8f9fb; } QSplitter::handle { background: #d2d5da; } QWidget#rightToolsPanel { background: #f4f5f7; border-left: 1px solid #cfd2d7; } + QLabel#rightToolsTitle { color: #25272a; font-weight: 600; padding-left: 4px; } + QToolButton#rightToolsCollapseButton { + color: #4b5563; background: transparent; border: 1px solid #c9cdd3; + border-radius: 4px; padding: 2px 7px; + } + QToolButton#rightToolsCollapseButton:hover { background: #eceff3; } + QScrollArea#rightToolsScroll { background: transparent; border: none; } QFrame#toolSection { background: #ffffff; border: 1px solid #d8dbe0; border-radius: 6px; } QToolButton#toolSectionTitle { color: #25272a; font-weight: 600; text-align: left; @@ -1845,7 +1928,7 @@ class MainWindow(QMainWindow): } QToolButton#toolSectionTitle:hover { background: #f0f3f8; border-radius: 4px; } QPushButton#rightToolButton { - color: #25272a; text-align: left; padding: 6px 8px 6px 20px; + color: #25272a; text-align: left; padding: 6px 8px 6px 14px; border: 1px solid transparent; border-radius: 4px; background: transparent; } QListWidget, QListWidget#searchResults, QListWidget#thumbnailList { @@ -1856,7 +1939,7 @@ class MainWindow(QMainWindow): QListWidget::item:selected { background: #f8fbff; color: #0f3f7a; border: 2px solid #6aa3dc; } QListWidget#thumbnailList::item { margin: 4px 6px; padding: 8px; } QListWidget#thumbnailList::item:selected { background: #f8fbff; border: 2px solid #2d73c5; } - QScrollArea#pdfCanvas { background: #cfd2d7; border: none; } + QScrollArea#pdfCanvas, QWidget#pdfContinuousContent { background: #bfc4cb; border: none; } QLabel#emptyPage { background: #f8f9fb; color: #5f6368; padding: 28px; border: 1px solid #d3d6dc; } QLabel#pdfPage { background: #ffffff; color: #202020; padding: 0; border: 1px solid #b7bbc2; } QStatusBar { background: #f7f8fa; color: #44484f; border-top: 1px solid #cfd2d7; } diff --git a/pdfreaderlite/ui/right_tools.py b/pdfreaderlite/ui/right_tools.py index afad62f..3919651 100644 --- a/pdfreaderlite/ui/right_tools.py +++ b/pdfreaderlite/ui/right_tools.py @@ -2,10 +2,12 @@ from __future__ import annotations from collections.abc import Iterable -from PySide6.QtCore import Qt +from PySide6.QtCore import QSize, Qt, Signal from PySide6.QtGui import QAction from PySide6.QtWidgets import ( QFrame, + QHBoxLayout, + QLabel, QLineEdit, QListWidget, QPushButton, @@ -45,6 +47,9 @@ class ToolSection(QFrame): for action in actions: button = QPushButton(action.text()) button.setObjectName("rightToolButton") + if not action.icon().isNull(): + button.setIcon(action.icon()) + button.setIconSize(QSize(16, 16)) button.setToolTip(action.toolTip() or action.text()) button.setFlat(True) button.setCheckable(action.isCheckable()) @@ -63,6 +68,8 @@ class ToolSection(QFrame): class RightToolsPanel(QWidget): + collapse_requested = Signal() + def __init__(self, search_box: QLineEdit, search_results: QListWidget) -> None: super().__init__() self.search_box = search_box @@ -80,15 +87,33 @@ class RightToolsPanel(QWidget): scroll.setFrameShape(QFrame.Shape.NoFrame) scroll.setWidget(self.sections_container) + header = QWidget() + header.setObjectName("rightToolsHeader") + header_layout = QHBoxLayout(header) + header_layout.setContentsMargins(0, 0, 0, 0) + header_layout.setSpacing(6) + title = QLabel("工具") + title.setObjectName("rightToolsTitle") + collapse_button = QToolButton() + collapse_button.setObjectName("rightToolsCollapseButton") + collapse_button.setText("‹") + collapse_button.setToolTip("收起工具面板") + collapse_button.clicked.connect(self.collapse_requested.emit) + header_layout.addWidget(title) + header_layout.addStretch(1) + header_layout.addWidget(collapse_button) + layout = QVBoxLayout(self) layout.setContentsMargins(8, 8, 8, 8) layout.setSpacing(8) + layout.addWidget(header) layout.addWidget(search_box) layout.addWidget(search_results) layout.addWidget(scroll, 1) search_results.setVisible(False) search_results.setMaximumHeight(170) - self.setMinimumWidth(300) + self.setMinimumWidth(260) + self.setMaximumWidth(300) def add_section(self, title: str, actions: Iterable[QAction]) -> None: self.sections_layout.addWidget(ToolSection(title, actions)) diff --git a/pdfreaderlite/ui/sidebar.py b/pdfreaderlite/ui/sidebar.py index c166580..b96802b 100644 --- a/pdfreaderlite/ui/sidebar.py +++ b/pdfreaderlite/ui/sidebar.py @@ -23,12 +23,12 @@ class ThumbnailList(QListWidget): self._thumbnail_timer.timeout.connect(self._render_next_thumbnail) self.verticalScrollBar().valueChanged.connect(lambda _: self.schedule_visible_thumbnails()) - self.setIconSize(QSize(132, 176)) + self.setIconSize(QSize(118, 158)) self.setViewMode(QListWidget.ViewMode.IconMode) self.setFlow(QListWidget.Flow.TopToBottom) self.setWrapping(False) self.setResizeMode(QListWidget.ResizeMode.Adjust) - self.setGridSize(QSize(188, 222)) + self.setGridSize(QSize(164, 204)) self.setSpacing(6) self.itemClicked.connect(self._emit_page) @@ -124,7 +124,8 @@ class Sidebar(QTabWidget): layout.addWidget(self.thumbnails) self.addTab(thumb_page, "缩略图") - self.setMinimumWidth(210) + self.setMinimumWidth(176) + self.setMaximumWidth(220) def load_document(self, document: PdfDocument) -> None: self.thumbnails.load_document(document)