Refine logarithmic zoom status layout

This commit is contained in:
2026-06-30 09:32:06 +08:00
parent 2ffe910c8f
commit d5796be29d
3 changed files with 41 additions and 18 deletions
+39 -16
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
import math
from dataclasses import dataclass
from pathlib import Path
@@ -26,6 +27,7 @@ from PySide6.QtWidgets import (
QDialogButtonBox,
QFormLayout,
QFileDialog,
QFrame,
QHBoxLayout,
QInputDialog,
QLabel,
@@ -286,7 +288,15 @@ class MainWindow(QMainWindow):
if not self.document.is_open:
self._sync_zoom_controls(self.viewer.zoom)
return
self.viewer.set_zoom(value / 100)
self.viewer.set_zoom(self._zoom_from_slider_value(value))
def _slider_value_from_zoom(self, zoom: float) -> int:
clamped_zoom = max(0.1, min(10.0, zoom))
return round((math.log10(clamped_zoom) + 1.0) * 1000)
def _zoom_from_slider_value(self, value: int) -> float:
exponent = (value / 1000) - 1.0
return 10**exponent
def apply_zoom_percent_input(self) -> None:
if not self.document.is_open:
@@ -313,7 +323,7 @@ class MainWindow(QMainWindow):
return
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_slider.setValue(self._slider_value_from_zoom(zoom))
self.zoom_percent_input.setText(str(percent))
def _sync_page_controls(self) -> None:
@@ -996,9 +1006,9 @@ 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(10, 1000)
self.zoom_slider.setSingleStep(5)
self.zoom_slider.setPageStep(25)
self.zoom_slider.setRange(0, 2000)
self.zoom_slider.setSingleStep(25)
self.zoom_slider.setPageStep(100)
self.zoom_slider.setFixedWidth(150)
self.zoom_slider.setToolTip("缩放")
self.zoom_percent_input = QLineEdit()
@@ -1350,6 +1360,14 @@ class MainWindow(QMainWindow):
button.setAutoRaise(True)
return button
def _status_separator(self) -> QFrame:
separator = QFrame()
separator.setObjectName("statusSeparator")
separator.setFrameShape(QFrame.Shape.VLine)
separator.setFrameShadow(QFrame.Shadow.Plain)
separator.setFixedHeight(18)
return separator
def _build_status_controls(self) -> None:
status = self.statusBar()
toolbar = getattr(self, "main_toolbar", None)
@@ -1370,30 +1388,33 @@ class MainWindow(QMainWindow):
zoom_label = QLabel("缩放")
zoom_label.setObjectName("statusZoomLabel")
self.zoom_slider.setObjectName("statusZoomSlider")
self.zoom_slider.setFixedWidth(132)
self.zoom_slider.setFixedWidth(170)
self.zoom_percent_input.setObjectName("statusZoomPercent")
self.zoom_percent_input.setFixedWidth(72)
self.zoom_percent_input.setFixedWidth(58)
controls = QWidget()
controls.setObjectName("statusPageControls")
controls_layout = QHBoxLayout(controls)
controls_layout.setContentsMargins(0, 0, 0, 0)
controls_layout.setSpacing(6)
controls_layout.setSpacing(8)
for widget in [
self._status_action_button(self.zoom_out_action, 66),
self._status_action_button(self.zoom_in_action, 66),
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),
page_label,
self.page_number_input,
self.page_total_label,
self._status_separator(),
self._status_action_button(self.zoom_out_action, 64),
self._status_action_button(self.zoom_in_action, 64),
zoom_label,
self.zoom_percent_input,
self.zoom_slider,
self._status_separator(),
self._status_action_button(self.fit_width_action, 92),
self._status_action_button(self.fit_page_action, 92),
]:
controls_layout.addWidget(widget)
widget.show()
status.addPermanentWidget(controls, 1)
controls.setFixedWidth(760)
status.addPermanentWidget(controls, 0)
def _connect_signals(self) -> None:
self.open_action.triggered.connect(lambda: self.open_file())
@@ -1987,6 +2008,7 @@ class MainWindow(QMainWindow):
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; }
QFrame#statusSeparator { color: #555a60; background: #555a60; }
QToolButton#statusToolButton {
color: #f1f1f1; background: transparent; border: 1px solid transparent;
border-radius: 4px; padding: 3px 7px;
@@ -2061,6 +2083,7 @@ class MainWindow(QMainWindow):
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; }
QFrame#statusSeparator { color: #c9cdd3; background: #c9cdd3; }
QToolButton#statusToolButton {
color: #25272a; background: transparent; border: 1px solid transparent;
border-radius: 4px; padding: 3px 7px;