Move page zoom controls to status bar

This commit is contained in:
2026-06-30 08:34:58 +08:00
parent 33988a78ab
commit 6feedf58ef
4 changed files with 127 additions and 20 deletions
+3 -3
View File
@@ -8,7 +8,7 @@ PDFReaderLite 是一个面向 Windows 的轻量 PDF 阅读与编辑工具,目
- 阅读、翻页、缩放
- 连续阅读模式,页面上下自动衔接并保留页间缝隙
- 鼠标滚轮优先在文档内容窗口内上下滚动
- Acrobat 风格缩放滑条与百分比输入框
- 状态栏页面缩放区:缩小、放大、缩放滑条、百分比输入、适应宽度、适应页面、跳转
- 适应宽度、适应页面
- 页码跳转
- 左侧缩略图
@@ -68,8 +68,8 @@ PDFReaderLite 是一个面向 Windows 的轻量 PDF 阅读与编辑工具,目
- exe 版本资源
- 设置中注册 PDF 文件关联
- Acrobat 风格右侧工具面板(已完成可折叠分类、搜索结果默认收起、整栏收起/展开)
- 缩略图单列卡片式显示与克制选中态,左侧栏已压缩宽度
- 顶部与右侧常用工具图标化
- 缩略图单列卡片式显示与克制选中态,支持随左侧栏拖拽宽度自适应缩放
- 顶部与右侧常用工具图标化,另存为/缩放/适应宽度图标已区分
- 图片签名
- 多标签页打开、切换、关闭 PDF
- 未保存更改星号提示,关闭标签/窗口时保存确认
+3 -3
View File
@@ -7,7 +7,7 @@ PDFReaderLite 是 Windows 平台的轻量 PDF 阅读与编辑工具。功能重
## V1:基础可用版
- 打开 PDF
- 阅读、翻页、缩放(已支持连续阅读、页间缝隙、鼠标滚轮页内/文档内滚动、缩放滑条和百分比输入)
- 阅读、翻页、缩放(已支持连续阅读、页间缝隙、鼠标滚轮页内/文档内滚动、状态栏页面缩放控件)
- 适应宽度、适应页面
- 页码跳转
- 左侧缩略图
@@ -65,8 +65,8 @@ PDFReaderLite 是 Windows 平台的轻量 PDF 阅读与编辑工具。功能重
- 大文件性能优化(已完成缩略图可见区域懒加载与缩略图独立缓存)
- Acrobat 风格右侧工具面板(已完成可折叠分类、搜索结果默认收起、整栏收起/展开)
- 缩略图单列卡片式显示与克制选中态(已完成左侧栏宽度压缩)
- 顶部与右侧常用工具图标化(已完成)
- 缩略图单列卡片式显示与克制选中态(已完成随左侧栏拖拽宽度自适应缩放)
- 顶部与右侧常用工具图标化(已完成另存为、缩小、放大、适应宽度图标区分)
- 页面缓存(已完成基础缓存)
- 后台渲染(已完成缩略图分批加载)
- 快捷键(已完成常用快捷键与说明)
+97 -8
View File
@@ -4,7 +4,19 @@ from dataclasses import dataclass
from pathlib import Path
from PySide6.QtCore import QSize, QSignalBlocker, QSettings, QStandardPaths, Qt, QUrl
from PySide6.QtGui import QAction, QDesktopServices, QDragEnterEvent, QDropEvent, QIcon, QKeySequence, QPainter
from PySide6.QtGui import (
QAction,
QColor,
QDesktopServices,
QDragEnterEvent,
QDropEvent,
QFont,
QIcon,
QKeySequence,
QPainter,
QPen,
QPixmap,
)
from PySide6.QtPrintSupport import QPrintDialog, QPrinter
from PySide6.QtWidgets import (
QCheckBox,
@@ -28,6 +40,7 @@ from PySide6.QtWidgets import (
QStyle,
QTabWidget,
QToolBar,
QToolButton,
QVBoxLayout,
QWidget,
)
@@ -87,6 +100,7 @@ class MainWindow(QMainWindow):
self._build_window()
self._build_actions()
self._build_toolbar()
self._build_status_controls()
self._connect_signals()
self._apply_theme()
self._restore_window_state()
@@ -1077,19 +1091,33 @@ class MainWindow(QMainWindow):
help_menu.addAction(self.about_action)
self._build_right_tools_panel()
def _text_icon(self, text: str, color: QColor | None = None) -> QIcon:
pixmap = QPixmap(24, 24)
pixmap.fill(Qt.GlobalColor.transparent)
painter = QPainter(pixmap)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
pen_color = color or QColor("#2d73c5")
painter.setPen(QPen(pen_color, 2))
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.drawRoundedRect(3, 3, 18, 18, 4, 4)
font = QFont()
font.setBold(True)
font.setPixelSize(12 if len(text) <= 1 else 9)
painter.setFont(font)
painter.setPen(pen_color)
painter.drawText(pixmap.rect(), Qt.AlignmentFlag.AlignCenter, text)
painter.end()
return QIcon(pixmap)
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,
@@ -1130,6 +1158,10 @@ class MainWindow(QMainWindow):
}
for action, standard_icon in icon_map.items():
action.setIcon(self.style().standardIcon(standard_icon))
self.save_as_action.setIcon(self._text_icon("另", QColor("#365f91")))
self.zoom_out_action.setIcon(self._text_icon("-", QColor("#2f5f9f")))
self.zoom_in_action.setIcon(self._text_icon("+", QColor("#2f5f9f")))
self.fit_width_action.setIcon(self._text_icon("<>", QColor("#2f5f9f")))
def _build_right_tools_panel(self) -> None:
self.right_tools.add_section(
@@ -1206,6 +1238,8 @@ class MainWindow(QMainWindow):
def _build_toolbar(self) -> None:
toolbar = QToolBar("主工具栏")
self.main_toolbar = toolbar
self._toolbar_page_size_actions = []
toolbar.setObjectName("mainToolBar")
toolbar.setMovable(False)
toolbar.setFloatable(False)
@@ -1234,9 +1268,9 @@ class MainWindow(QMainWindow):
toolbar.addAction(action)
zoom_label = QLabel("缩放")
zoom_label.setObjectName("toolbarLabel")
toolbar.addWidget(zoom_label)
toolbar.addWidget(self.zoom_slider)
toolbar.addWidget(self.zoom_percent_input)
self._toolbar_page_size_actions.append(toolbar.addWidget(zoom_label))
self._toolbar_page_size_actions.append(toolbar.addWidget(self.zoom_slider))
self._toolbar_page_size_actions.append(toolbar.addWidget(self.zoom_percent_input))
toolbar.addSeparator()
for action in [
self.fit_width_action,
@@ -1259,6 +1293,49 @@ class MainWindow(QMainWindow):
toolbar.addSeparator()
toolbar.addAction(self.toggle_tools_action)
def _status_action_button(self, action: QAction) -> QToolButton:
button = QToolButton()
button.setObjectName("statusToolButton")
button.setDefaultAction(action)
button.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonIconOnly)
button.setIconSize(QSize(16, 16))
button.setAutoRaise(True)
return button
def _build_status_controls(self) -> None:
status = self.statusBar()
toolbar = getattr(self, "main_toolbar", None)
if toolbar:
for action in [
self.zoom_out_action,
self.zoom_in_action,
self.fit_width_action,
self.fit_page_action,
self.go_to_page_action,
]:
toolbar.removeAction(action)
for action in getattr(self, "_toolbar_page_size_actions", []):
toolbar.removeAction(action)
zoom_label = QLabel("页面")
zoom_label.setObjectName("statusZoomLabel")
self.zoom_slider.setObjectName("statusZoomSlider")
self.zoom_slider.setFixedWidth(132)
self.zoom_percent_input.setObjectName("statusZoomPercent")
self.zoom_percent_input.setFixedWidth(72)
for widget in [
zoom_label,
self._status_action_button(self.zoom_out_action),
self._status_action_button(self.zoom_in_action),
self.zoom_slider,
self.zoom_percent_input,
self._status_action_button(self.fit_width_action),
self._status_action_button(self.fit_page_action),
self._status_action_button(self.go_to_page_action),
]:
status.addPermanentWidget(widget)
def _connect_signals(self) -> None:
self.open_action.triggered.connect(lambda: self.open_file())
self.save_action.triggered.connect(self.save_file)
@@ -1832,6 +1909,12 @@ class MainWindow(QMainWindow):
QToolButton:hover, QPushButton#rightToolButton:hover { background: #3c4045; border-color: #555a60; }
QToolButton:checked, QPushButton#rightToolButton:checked { background: #244a78; border-color: #4f89c8; }
QLabel#toolbarLabel { color: #cfd3d8; padding-left: 4px; }
QLabel#statusZoomLabel { color: #cfd3d8; padding: 0 4px 0 10px; }
QToolButton#statusToolButton {
color: #f1f1f1; background: transparent; border: 1px solid transparent;
border-radius: 4px; padding: 3px;
}
QToolButton#statusToolButton:hover { background: #3c4045; border-color: #555a60; }
QLineEdit, QSpinBox {
padding: 6px 8px; background: #202225; color: #f1f1f1;
border: 1px solid #555a60; border-radius: 4px;
@@ -1899,6 +1982,12 @@ class MainWindow(QMainWindow):
QToolButton:pressed, QPushButton#rightToolButton:pressed { background: #dfe6f1; }
QToolButton:checked, QPushButton#rightToolButton:checked { background: #dbeafe; border-color: #6aa3dc; color: #0f3f7a; }
QLabel#toolbarLabel { color: #5b6067; padding-left: 4px; }
QLabel#statusZoomLabel { color: #5b6067; padding: 0 4px 0 10px; }
QToolButton#statusToolButton {
color: #25272a; background: transparent; border: 1px solid transparent;
border-radius: 4px; padding: 3px;
}
QToolButton#statusToolButton:hover { background: #eceff3; border-color: #c9cdd3; }
QLineEdit, QSpinBox {
padding: 6px 8px; background: #ffffff; color: #202124;
border: 1px solid #b9bec6; border-radius: 4px;
+24 -6
View File
@@ -23,15 +23,33 @@ class ThumbnailList(QListWidget):
self._thumbnail_timer.timeout.connect(self._render_next_thumbnail)
self.verticalScrollBar().valueChanged.connect(lambda _: self.schedule_visible_thumbnails())
self.setIconSize(QSize(118, 158))
self._last_thumbnail_width = 0
self._update_thumbnail_metrics()
self.setViewMode(QListWidget.ViewMode.IconMode)
self.setFlow(QListWidget.Flow.TopToBottom)
self.setWrapping(False)
self.setResizeMode(QListWidget.ResizeMode.Adjust)
self.setGridSize(QSize(164, 204))
self.setSpacing(6)
self.itemClicked.connect(self._emit_page)
def resizeEvent(self, event) -> None:
super().resizeEvent(event)
self._update_thumbnail_metrics()
self.schedule_visible_thumbnails()
def _update_thumbnail_metrics(self) -> None:
viewport_width = max(120, self.viewport().width())
thumbnail_width = max(92, min(170, viewport_width - 34))
thumbnail_height = int(thumbnail_width * 1.34)
gap = max(2, round(self.fontMetrics().height() * 0.5))
label_height = self.fontMetrics().height() + 8
grid_size = QSize(thumbnail_width + 26, thumbnail_height + label_height + gap)
if thumbnail_width != self._last_thumbnail_width:
self._rendered_keys.clear()
self._last_thumbnail_width = thumbnail_width
self.setIconSize(QSize(thumbnail_width, thumbnail_height))
self.setGridSize(grid_size)
self.setSpacing(gap)
def load_document(self, document: PdfDocument) -> None:
self._thumbnail_timer.stop()
same_document = self.document is document
@@ -91,7 +109,7 @@ class ThumbnailList(QListWidget):
return
item = self.item(page_index)
image = self.document.render_thumbnail(page_index)
image = self.document.render_thumbnail(page_index, self.iconSize().width())
item.setIcon(QIcon(QPixmap.fromImage(image)))
self._rendered_keys.add(render_key)
@@ -124,8 +142,8 @@ class Sidebar(QTabWidget):
layout.addWidget(self.thumbnails)
self.addTab(thumb_page, "缩略图")
self.setMinimumWidth(176)
self.setMaximumWidth(220)
self.setMinimumWidth(150)
self.setMaximumWidth(340)
def load_document(self, document: PdfDocument) -> None:
self.thumbnails.load_document(document)