diff --git a/docs/v2_requirements_checklist.md b/docs/v2_requirements_checklist.md index 96f3dce..f653e8f 100644 --- a/docs/v2_requirements_checklist.md +++ b/docs/v2_requirements_checklist.md @@ -61,14 +61,14 @@ ## 交互体验 -- [ ] 当前模式在状态栏显示。 +- [x] 当前模式在状态栏显示。 - [ ] 阅读、编辑PDF、页面、工具、注释模式互斥。 - [ ] 鼠标光标随模式变化。 -- [ ] Esc 取消放置文本。 -- [ ] Esc 取消放置图片。 -- [ ] Esc 取消放置签名。 -- [ ] Esc 取消画笔。 -- [ ] Esc 取消当前选中对象。 +- [x] Esc 取消放置文本。 +- [x] Esc 取消放置图片。 +- [x] Esc 取消放置签名。 +- [x] Esc 取消画笔。 +- [x] Esc 取消当前选中对象。 - [ ] 顶部工具栏只保留模式和常用基础动作。 - [ ] 复杂设置放在右侧面板或右键菜单中。 diff --git a/pdfreaderlite/ui/main_window.py b/pdfreaderlite/ui/main_window.py index f16b5c9..829a745 100644 --- a/pdfreaderlite/ui/main_window.py +++ b/pdfreaderlite/ui/main_window.py @@ -92,6 +92,7 @@ class MainWindow(QMainWindow): self.search_box = QLineEdit() self.search_results = QListWidget() self.right_annotation_list = QListWidget() + self.mode_status_label = QLabel() self.right_tools = RightToolsPanel(self.search_box, self.search_results) self.main_splitter: QSplitter | None = None self.pending_placement: dict[str, object] | None = None @@ -1391,6 +1392,9 @@ class MainWindow(QMainWindow): self.zoom_slider.setFixedWidth(162) self.zoom_percent_input.setObjectName("statusZoomPercent") self.zoom_percent_input.setFixedWidth(58) + self.mode_status_label.setObjectName("statusModeLabel") + self.mode_status_label.setMinimumWidth(86) + self._sync_mode_status() controls = QWidget() controls.setObjectName("statusPageControls") @@ -1414,6 +1418,7 @@ class MainWindow(QMainWindow): controls_layout.addWidget(widget) widget.show() controls.setFixedWidth(800) + status.addPermanentWidget(self.mode_status_label, 0) status.addPermanentWidget(controls, 0) def _connect_signals(self) -> None: @@ -1677,7 +1682,29 @@ class MainWindow(QMainWindow): if chosen == delete_action: self.delete_selected_object() + def cancel_current_operation(self) -> bool: + had_pending = self.pending_placement is not None + had_selection = self.selected_annotation is not None or self.selected_raster_id is not None + had_tool = self.select_object_action.isChecked() or self.freehand_action.isChecked() + if not (had_pending or had_selection or had_tool): + return False + + self.pending_placement = None + self.selected_annotation = None + self.selected_raster_id = None + self.select_object_action.setChecked(False) + self.freehand_action.setChecked(False) + self.viewer.set_placement_enabled(False) + self.viewer.set_drawing_enabled(False) + self.viewer.set_object_edit_enabled(False) + self.viewer.clear_object_selection() + self.statusBar().showMessage("已取消当前操作", 3000) + return True + def keyPressEvent(self, event) -> None: + if event.key() == Qt.Key.Key_Escape and self.cancel_current_operation(): + event.accept() + return if event.key() == Qt.Key.Key_Delete and (self.selected_annotation or self.selected_raster_id is not None): self.delete_selected_object() return @@ -2068,6 +2095,25 @@ class MainWindow(QMainWindow): def _any_right_mode_checked(self) -> bool: return any(action.isChecked() for action in self._right_mode_actions()) + def _current_mode_text(self) -> str: + if not hasattr(self, "toggle_tools_action"): + return "模式:工具" + if self.toggle_read_action.isChecked(): + return "模式:阅读" + if self.toggle_annotations_action.isChecked(): + return "模式:注释" + if self.toggle_edit_pdf_action.isChecked(): + return "模式:编辑PDF" + if self.toggle_pages_action.isChecked(): + return "模式:页面" + if self.toggle_tools_action.isChecked(): + return "模式:工具" + return "模式:无" + + def _sync_mode_status(self) -> None: + if hasattr(self, "mode_status_label"): + self.mode_status_label.setText(self._current_mode_text()) + def _show_right_panel_mode(self, mode: str) -> None: with ( QSignalBlocker(self.toggle_edit_pdf_action), @@ -2096,6 +2142,7 @@ class MainWindow(QMainWindow): self.right_tools.set_title("工具") self.right_tools.show_sections(["sign", "export", "settings"]) self.set_right_tools_visible(True) + self._sync_mode_status() def _enter_read_mode(self) -> None: with ( @@ -2121,6 +2168,7 @@ class MainWindow(QMainWindow): self.viewer.set_object_edit_enabled(False) self.viewer.clear_object_selection() self.set_right_tools_visible(False) + self._sync_mode_status() self.statusBar().showMessage("阅读模式已开启", 3000) def close_right_tools_panel(self) -> None: @@ -2134,6 +2182,7 @@ class MainWindow(QMainWindow): for action in self._right_mode_actions(): action.setChecked(False) self.set_right_tools_visible(False) + self._sync_mode_status() def set_right_tools_visible(self, visible: bool) -> None: self.right_tools.setVisible(visible) @@ -2164,7 +2213,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; } + QLabel#statusPageLabel, QLabel#statusPageTotal, QLabel#statusModeLabel { color: #cfd3d8; padding: 0 4px; } QFrame#statusSeparator { color: #555a60; background: #555a60; } QToolButton#statusToolButton { color: #f1f1f1; background: transparent; border: 1px solid transparent; @@ -2241,7 +2290,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; } + QLabel#statusPageLabel, QLabel#statusPageTotal, QLabel#statusModeLabel { color: #5b6067; padding: 0 4px; } QFrame#statusSeparator { color: #c9cdd3; background: #c9cdd3; } QToolButton#statusToolButton { color: #25272a; background: transparent; border: 1px solid transparent; @@ -2378,6 +2427,7 @@ class MainWindow(QMainWindow): self._sync_zoom_controls(self.viewer.zoom) self._sync_page_controls() self._refresh_annotation_panel() + self._sync_mode_status() if not self.document.is_open: self.statusBar().showMessage("就绪") return