diff --git a/docs/v2_requirements_checklist.md b/docs/v2_requirements_checklist.md index 7f4c17a..5c9902a 100644 --- a/docs/v2_requirements_checklist.md +++ b/docs/v2_requirements_checklist.md @@ -10,11 +10,11 @@ - [ ] 注释颜色设置。 - [ ] 注释线宽设置。 - [ ] 注释透明度设置。 -- [ ] 便签/批注内容二次编辑。 +- [x] 便签/批注内容二次编辑。 - [x] 注释列表按类型筛选。 - [x] 注释列表搜索。 - [x] 注释列表右键删除。 -- [ ] 注释列表双击编辑内容。 +- [x] 注释列表双击编辑内容。 - [ ] 图章工具。 - [ ] 常用中文图章预设。 - [ ] 自定义图片图章。 diff --git a/pdfreaderlite/core/document.py b/pdfreaderlite/core/document.py index e776d28..735d782 100644 --- a/pdfreaderlite/core/document.py +++ b/pdfreaderlite/core/document.py @@ -565,6 +565,21 @@ class PdfDocument: rect = annot.rect + (dx, dy, dx, dy) return self.update_annotation_rect(page_index, xref, self._rect_tuple(rect)) + def update_annotation_content(self, page_index: int, xref: int, content: str) -> bool: + if not self._annotation(page_index, xref): + return False + self.snapshot() + page = self._page(page_index) + annot = page.first_annot + while annot: + if annot.xref == xref: + annot.set_info(content=content) + annot.update() + self.mark_changed() + return True + annot = annot.next + return False + def delete_annotation(self, page_index: int, xref: int) -> bool: page = self._page(page_index) annot = page.first_annot diff --git a/pdfreaderlite/ui/main_window.py b/pdfreaderlite/ui/main_window.py index c1d7a23..4fc7529 100644 --- a/pdfreaderlite/ui/main_window.py +++ b/pdfreaderlite/ui/main_window.py @@ -1513,6 +1513,7 @@ class MainWindow(QMainWindow): self.annotation_search_box.textChanged.connect(self._refresh_annotation_panel) self.right_annotation_list.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) self.right_annotation_list.itemClicked.connect(self._go_to_annotation_item) + self.right_annotation_list.itemDoubleClicked.connect(self.edit_annotation_from_panel_item) self.right_annotation_list.customContextMenuRequested.connect( self.show_annotation_list_context_menu ) @@ -1537,11 +1538,46 @@ class MainWindow(QMainWindow): return menu = QMenu(self) + edit_action = menu.addAction("编辑内容") delete_action = menu.addAction("删除注释") chosen = menu.exec(self.right_annotation_list.mapToGlobal(position)) - if chosen == delete_action: + if chosen == edit_action: + self.edit_annotation_from_panel(annotation) + elif chosen == delete_action: self.delete_annotation_from_panel(annotation) + def edit_annotation_from_panel_item(self, item: QListWidgetItem) -> None: + annotation = item.data(Qt.ItemDataRole.UserRole) + if isinstance(annotation, AnnotationInfo): + self.edit_annotation_from_panel(annotation) + + def edit_annotation_from_panel(self, annotation: AnnotationInfo) -> None: + text, ok = QInputDialog.getMultiLineText( + self, + "编辑注释内容", + "注释内容:", + annotation.content or "", + ) + if not ok: + return + try: + if not self.document.update_annotation_content(annotation.page_index, annotation.xref, text): + QMessageBox.warning(self, "编辑失败", "没有找到对应的注释。") + return + if self.selected_annotation and self.selected_annotation.xref == annotation.xref: + self.selected_annotation = AnnotationInfo( + page_index=annotation.page_index, + xref=annotation.xref, + annotation_type=annotation.annotation_type, + content=text, + rect=annotation.rect, + ) + self.viewer.render() + self._refresh_annotation_panel() + self.statusBar().showMessage("注释内容已更新,记得保存", 3000) + except Exception as exc: + QMessageBox.critical(self, "编辑失败", f"无法更新注释内容:\n{exc}") + def delete_annotation_from_panel(self, annotation: AnnotationInfo) -> None: reply = QMessageBox.question( self,