diff --git a/docs/v2_requirements_checklist.md b/docs/v2_requirements_checklist.md index e161a58..5e91b06 100644 --- a/docs/v2_requirements_checklist.md +++ b/docs/v2_requirements_checklist.md @@ -50,7 +50,7 @@ - [x] 方向键微调对象。 - [x] Shift+方向键大步移动对象。 - [ ] 对象图层顺序:置顶、置底、上移、下移。 -- [ ] 页面内对象列表。 +- [x] 页面内对象列表。 ## 编辑:旧功能完善 diff --git a/pdfreaderlite/ui/main_window.py b/pdfreaderlite/ui/main_window.py index 9494c27..3ccbe56 100644 --- a/pdfreaderlite/ui/main_window.py +++ b/pdfreaderlite/ui/main_window.py @@ -105,6 +105,7 @@ class MainWindow(QMainWindow): self.annotation_filter_combo = QComboBox() self.annotation_search_box = QLineEdit() self.right_annotation_list = QListWidget() + self.right_object_list = QListWidget() self.mode_status_label = QLabel() self.right_tools = RightToolsPanel(self.search_box, self.search_results) self.main_splitter: QSplitter | None = None @@ -1295,6 +1296,11 @@ class MainWindow(QMainWindow): ], section_id="edit", ) + self.right_tools.add_annotation_list( + "页面对象", + self.right_object_list, + "object_list", + ) self.right_tools.add_section( "注释", [ @@ -1554,6 +1560,7 @@ class MainWindow(QMainWindow): self.right_annotation_list.customContextMenuRequested.connect( self.show_annotation_list_context_menu ) + self.right_object_list.itemClicked.connect(self.select_object_from_panel_item) def _go_to_search_match(self, item: QListWidgetItem) -> None: match: SearchMatch = item.data(Qt.ItemDataRole.UserRole) @@ -1673,6 +1680,7 @@ class MainWindow(QMainWindow): item = QListWidgetItem("打开 PDF 后显示注释列表") item.setFlags(item.flags() & ~Qt.ItemFlag.ItemIsEnabled) self.right_annotation_list.addItem(item) + self._refresh_page_object_list() return annotations = self.document.annotations() @@ -1680,6 +1688,7 @@ class MainWindow(QMainWindow): item = QListWidgetItem("当前 PDF 没有注释") item.setFlags(item.flags() & ~Qt.ItemFlag.ItemIsEnabled) self.right_annotation_list.addItem(item) + self._refresh_page_object_list() return annotations = [ @@ -1692,6 +1701,7 @@ class MainWindow(QMainWindow): item = QListWidgetItem("?????????") item.setFlags(item.flags() & ~Qt.ItemFlag.ItemIsEnabled) self.right_annotation_list.addItem(item) + self._refresh_page_object_list() return for annotation in annotations: @@ -1701,6 +1711,66 @@ class MainWindow(QMainWindow): ) item.setData(Qt.ItemDataRole.UserRole, annotation) self.right_annotation_list.addItem(item) + self._refresh_page_object_list() + + def _refresh_page_object_list(self) -> None: + if not hasattr(self, "right_object_list"): + return + self.right_object_list.clear() + if not self.document.is_open: + item = QListWidgetItem("打开 PDF 后显示页面对象") + item.setFlags(item.flags() & ~Qt.ItemFlag.ItemIsEnabled) + self.right_object_list.addItem(item) + return + + page_index = self.viewer.page_index + count = 0 + for raster in self.session_raster_objects: + if int(raster["page_index"]) != page_index: + continue + label = {"image": "图片", "signature": "签名", "stamp": "图片图章"}.get( + str(raster["type"]), + str(raster["type"]), + ) + item = QListWidgetItem(f"{label} #{raster['id']}") + item.setData(Qt.ItemDataRole.UserRole, ("raster", int(raster["id"]))) + self.right_object_list.addItem(item) + count += 1 + + for annotation in self.document.annotations(): + if annotation.page_index != page_index: + continue + content = annotation.content or annotation.annotation_type + item = QListWidgetItem(f"注释 {annotation.annotation_type} {content}") + item.setData(Qt.ItemDataRole.UserRole, ("annotation", annotation)) + self.right_object_list.addItem(item) + count += 1 + + if count == 0: + item = QListWidgetItem("当前页没有对象") + item.setFlags(item.flags() & ~Qt.ItemFlag.ItemIsEnabled) + self.right_object_list.addItem(item) + + def select_object_from_panel_item(self, item: QListWidgetItem) -> None: + payload = item.data(Qt.ItemDataRole.UserRole) + if not payload: + return + kind, value = payload + self.select_object_action.setChecked(True) + if kind == "raster": + raster = self._session_raster_by_id(int(value)) + if not raster: + return + self.viewer.go_to_page(int(raster["page_index"])) + self.selected_raster_id = int(raster["id"]) + self.selected_annotation = None + self.viewer.set_selected_object_rect(raster["rect"]) + return + if kind == "annotation" and isinstance(value, AnnotationInfo): + self.viewer.go_to_page(value.page_index) + self.selected_annotation = value + self.selected_raster_id = None + self.viewer.set_selected_object_rect(value.rect) def highlight_current_page(self) -> None: if not self._ensure_document(): @@ -2286,6 +2356,7 @@ class MainWindow(QMainWindow): def _refresh_session_raster_overlays(self) -> None: self.viewer.set_overlay_images(self.session_raster_objects) + self._refresh_page_object_list() self._update_current_tab_title() def _clear_session_raster_objects(self) -> None: @@ -2669,7 +2740,8 @@ class MainWindow(QMainWindow): self._refresh_annotation_panel() elif mode == "edit": self.right_tools.set_title("编辑PDF") - self.right_tools.show_sections(["edit"]) + self.right_tools.show_sections(["edit", "object_list"]) + self._refresh_page_object_list() elif mode == "pages": self.right_tools.set_title("页面") self.right_tools.show_sections(["pages"])