Refine status page controls

This commit is contained in:
2026-06-30 09:02:24 +08:00
parent 5f1848b26a
commit 9c0d47eae8
5 changed files with 59 additions and 21 deletions
+49 -11
View File
@@ -296,11 +296,36 @@ class MainWindow(QMainWindow):
return
if watched is not None and watched is not self._current_session():
return
percent = max(25, min(400, round(zoom * 100)))
percent = max(10, min(1000, round(zoom * 100)))
with QSignalBlocker(self.zoom_slider), QSignalBlocker(self.zoom_percent_input):
self.zoom_slider.setValue(percent)
self.zoom_percent_input.setValue(percent)
def _sync_page_controls(self) -> None:
if not hasattr(self, "page_number_input"):
return
if not self.document.is_open:
with QSignalBlocker(self.page_number_input):
self.page_number_input.setRange(1, 1)
self.page_number_input.setValue(1)
self.page_number_input.setEnabled(False)
self.page_total_label.setText("/ 0 页")
return
with QSignalBlocker(self.page_number_input):
self.page_number_input.setEnabled(True)
self.page_number_input.setRange(1, self.document.page_count)
self.page_number_input.setValue(self.viewer.page_index + 1)
self.page_total_label.setText(f"/ {self.document.page_count} 页")
def apply_page_number_input(self) -> None:
if not self.document.is_open:
self._sync_page_controls()
return
page = self.page_number_input.value()
if 1 <= page <= self.document.page_count:
self.viewer.go_to_page(page - 1)
self._sync_page_controls()
def offer_restore_last_file(self) -> None:
last_file = self.settings.value("lastOpenFile", "", str)
if not last_file or self.document.is_open or not Path(last_file).exists():
@@ -952,17 +977,25 @@ class MainWindow(QMainWindow):
self.zoom_in_action = QAction("放大", self)
self.zoom_in_action.setShortcut(QKeySequence.StandardKey.ZoomIn)
self.zoom_slider = QSlider(Qt.Orientation.Horizontal)
self.zoom_slider.setRange(25, 400)
self.zoom_slider.setRange(10, 1000)
self.zoom_slider.setSingleStep(5)
self.zoom_slider.setPageStep(25)
self.zoom_slider.setFixedWidth(150)
self.zoom_slider.setToolTip("缩放")
self.zoom_percent_input = QSpinBox()
self.zoom_percent_input.setRange(25, 400)
self.zoom_percent_input.setRange(10, 1000)
self.zoom_percent_input.setSingleStep(5)
self.zoom_percent_input.setSuffix("%")
self.zoom_percent_input.setFixedWidth(78)
self.zoom_percent_input.setToolTip("缩放百分比")
self.page_number_input = QSpinBox()
self.page_number_input.setRange(1, 1)
self.page_number_input.setKeyboardTracking(False)
self.page_number_input.setFixedWidth(64)
self.page_number_input.setToolTip("当前页码")
self.page_number_input.setEnabled(False)
self.page_total_label = QLabel("/ 0 页")
self.page_total_label.setObjectName("statusPageTotal")
self.fit_width_action = QAction("适应宽度", self)
self.fit_page_action = QAction("适应页面", self)
self.go_to_page_action = QAction("跳转", self)
@@ -1316,7 +1349,9 @@ class MainWindow(QMainWindow):
for action in getattr(self, "_toolbar_page_size_actions", []):
toolbar.removeAction(action)
zoom_label = QLabel("页面")
page_label = QLabel("第")
page_label.setObjectName("statusPageLabel")
zoom_label = QLabel("缩放")
zoom_label.setObjectName("statusZoomLabel")
self.zoom_slider.setObjectName("statusZoomSlider")
self.zoom_slider.setFixedWidth(132)
@@ -1324,14 +1359,16 @@ class MainWindow(QMainWindow):
self.zoom_percent_input.setFixedWidth(72)
for widget in [
zoom_label,
self._status_action_button(self.zoom_out_action, 66),
self._status_action_button(self.zoom_in_action, 66),
self.zoom_slider,
zoom_label,
self.zoom_percent_input,
self.zoom_slider,
self._status_action_button(self.fit_width_action, 92),
self._status_action_button(self.fit_page_action, 92),
self._status_action_button(self.go_to_page_action, 66),
page_label,
self.page_number_input,
self.page_total_label,
]:
status.addPermanentWidget(widget)
@@ -1354,6 +1391,7 @@ class MainWindow(QMainWindow):
self.zoom_in_action.triggered.connect(self.zoom_in)
self.zoom_slider.valueChanged.connect(self.set_zoom_percent)
self.zoom_percent_input.valueChanged.connect(self.set_zoom_percent)
self.page_number_input.editingFinished.connect(self.apply_page_number_input)
self.fit_width_action.triggered.connect(self.fit_width)
self.fit_page_action.triggered.connect(self.fit_page)
self.go_to_page_action.triggered.connect(self.go_to_page_dialog)
@@ -1909,6 +1947,7 @@ class MainWindow(QMainWindow):
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; }
QLabel#statusPageLabel, QLabel#statusPageTotal { color: #cfd3d8; padding: 0 4px; }
QToolButton#statusToolButton {
color: #f1f1f1; background: transparent; border: 1px solid transparent;
border-radius: 4px; padding: 3px 7px;
@@ -1982,6 +2021,7 @@ class MainWindow(QMainWindow):
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; }
QLabel#statusPageLabel, QLabel#statusPageTotal { color: #5b6067; padding: 0 4px; }
QToolButton#statusToolButton {
color: #25272a; background: transparent; border: 1px solid transparent;
border-radius: 4px; padding: 3px 7px;
@@ -2112,10 +2152,8 @@ class MainWindow(QMainWindow):
def _update_status(self) -> None:
self._update_current_tab_title()
self._sync_page_controls()
if not self.document.is_open:
self.statusBar().showMessage("就绪")
return
self.statusBar().showMessage(
f"第 {self.viewer.page_index + 1} / {self.document.page_count} 页 "
f"缩放 {int(self.viewer.zoom * 100)}%"
)
self.statusBar().showMessage("就绪")
+3 -3
View File
@@ -222,13 +222,13 @@ class PdfViewer(QScrollArea):
self.page_changed.emit(self.page_index)
def zoom_in(self) -> None:
self.set_zoom(min(4.0, self.zoom + 0.15))
self.set_zoom(min(10.0, self.zoom + 0.15))
def zoom_out(self) -> None:
self.set_zoom(max(0.25, self.zoom - 0.15))
self.set_zoom(max(0.1, self.zoom - 0.15))
def set_zoom(self, zoom: float) -> None:
self.zoom = max(0.25, min(4.0, zoom))
self.zoom = max(0.1, min(10.0, zoom))
self.render()
def wheelEvent(self, event: QWheelEvent) -> None:
+1 -1
View File
@@ -41,7 +41,7 @@ class ThumbnailList(QListWidget):
viewport_width = max(120, self.viewport().width())
thumbnail_width = max(92, min(self.MAX_THUMBNAIL_WIDTH, viewport_width - 34))
thumbnail_height = int(thumbnail_width * 1.34)
gap = max(2, round(self.fontMetrics().height() * 0.5))
gap = max(1, round(self.fontMetrics().height() * 0.25))
label_height = self.fontMetrics().height() + 8
grid_size = QSize(thumbnail_width + 26, thumbnail_height + label_height + gap)
if thumbnail_width != self._last_thumbnail_width: