diff --git a/docs/v2_requirements_checklist.md b/docs/v2_requirements_checklist.md index f653e8f..c5b8462 100644 --- a/docs/v2_requirements_checklist.md +++ b/docs/v2_requirements_checklist.md @@ -11,8 +11,8 @@ - [ ] 注释线宽设置。 - [ ] 注释透明度设置。 - [ ] 便签/批注内容二次编辑。 -- [ ] 注释列表按类型筛选。 -- [ ] 注释列表搜索。 +- [x] 注释列表按类型筛选。 +- [x] 注释列表搜索。 - [ ] 注释列表右键删除。 - [ ] 注释列表双击编辑内容。 - [ ] 图章工具。 diff --git a/pdfreaderlite/ui/main_window.py b/pdfreaderlite/ui/main_window.py index 829a745..e700a62 100644 --- a/pdfreaderlite/ui/main_window.py +++ b/pdfreaderlite/ui/main_window.py @@ -91,6 +91,8 @@ class MainWindow(QMainWindow): self.sidebar = Sidebar() self.search_box = QLineEdit() self.search_results = QListWidget() + self.annotation_filter_combo = QComboBox() + self.annotation_search_box = QLineEdit() self.right_annotation_list = QListWidget() self.mode_status_label = QLabel() self.right_tools = RightToolsPanel(self.search_box, self.search_results) @@ -965,6 +967,8 @@ class MainWindow(QMainWindow): self.setAcceptDrops(True) self.search_box.setObjectName("searchBox") self.search_results.setObjectName("searchResults") + self.annotation_filter_combo.setObjectName("annotationFilterCombo") + self.annotation_search_box.setObjectName("annotationSearchBox") self.tab_widget.setObjectName("documentTabs") self.right_tools.setObjectName("rightToolsPanel") @@ -977,6 +981,13 @@ class MainWindow(QMainWindow): self.search_box.setPlaceholderText("搜索文本,按 Enter") self.search_results.setAlternatingRowColors(True) + self.annotation_filter_combo.addItem("全部注释", "all") + self.annotation_filter_combo.addItem("高亮", "highlight") + self.annotation_filter_combo.addItem("文本标记", "text_markup") + self.annotation_filter_combo.addItem("便签/批注", "note") + self.annotation_filter_combo.addItem("图形", "shape") + self.annotation_filter_combo.addItem("画笔", "ink") + self.annotation_search_box.setPlaceholderText("搜索注释内容") self.setStyleSheet( """ QMainWindow { background: #ededed; } @@ -1270,7 +1281,12 @@ class MainWindow(QMainWindow): ], section_id="annotations", ) - self.right_tools.add_annotation_list("注释列表", self.right_annotation_list, "annotation_list") + self.right_tools.add_annotation_list( + "注释列表", + self.right_annotation_list, + "annotation_list", + controls=[self.annotation_filter_combo, self.annotation_search_box], + ) self.right_tools.add_section( "页面", [ @@ -1492,6 +1508,8 @@ class MainWindow(QMainWindow): self.search_box.returnPressed.connect(self.search) self.search_results.itemClicked.connect(self._go_to_search_match) + self.annotation_filter_combo.currentIndexChanged.connect(self._refresh_annotation_panel) + self.annotation_search_box.textChanged.connect(self._refresh_annotation_panel) self.right_annotation_list.itemClicked.connect(self._go_to_annotation_item) def _go_to_search_match(self, item: QListWidgetItem) -> None: @@ -1505,6 +1523,34 @@ class MainWindow(QMainWindow): self.selected_annotation = annotation self.viewer.set_selected_object_rect(annotation.rect) + def _annotation_type_matches_filter(self, annotation: AnnotationInfo) -> bool: + filter_key = self.annotation_filter_combo.currentData() + if filter_key in (None, "all"): + return True + + annotation_type = annotation.annotation_type.lower() + type_groups = { + "highlight": {"highlight"}, + "text_markup": {"highlight", "underline", "strikeout", "squiggly"}, + "note": {"text", "freetext", "caret"}, + "shape": {"square", "circle", "line", "polygon", "polyline"}, + "ink": {"ink"}, + } + return annotation_type in type_groups.get(str(filter_key), set()) + + def _annotation_matches_search(self, annotation: AnnotationInfo) -> bool: + query = self.annotation_search_box.text().strip().lower() + if not query: + return True + haystack = " ".join( + [ + str(annotation.page_index + 1), + annotation.annotation_type, + annotation.content or "", + ] + ).lower() + return query in haystack + def _refresh_annotation_panel(self) -> None: if not hasattr(self, "right_annotation_list"): return @@ -1522,6 +1568,18 @@ class MainWindow(QMainWindow): self.right_annotation_list.addItem(item) return + annotations = [ + annotation + for annotation in annotations + if self._annotation_type_matches_filter(annotation) + and self._annotation_matches_search(annotation) + ] + if not annotations: + item = QListWidgetItem("?????????") + item.setFlags(item.flags() & ~Qt.ItemFlag.ItemIsEnabled) + self.right_annotation_list.addItem(item) + return + for annotation in annotations: content = annotation.content or annotation.annotation_type item = QListWidgetItem( @@ -2220,7 +2278,7 @@ class MainWindow(QMainWindow): border-radius: 4px; padding: 3px 7px; } QToolButton#statusToolButton:hover { background: #3c4045; border-color: #555a60; } - QLineEdit, QSpinBox { + QLineEdit, QSpinBox, QComboBox { padding: 6px 8px; background: #202225; color: #f1f1f1; border: 1px solid #555a60; border-radius: 4px; } @@ -2297,11 +2355,11 @@ class MainWindow(QMainWindow): border-radius: 4px; padding: 3px 7px; } QToolButton#statusToolButton:hover { background: #eceff3; border-color: #c9cdd3; } - QLineEdit, QSpinBox { + QLineEdit, QSpinBox, QComboBox { padding: 6px 8px; background: #ffffff; color: #202124; border: 1px solid #b9bec6; border-radius: 4px; } - QLineEdit:focus, QSpinBox:focus { border-color: #4f8bd3; } + QLineEdit:focus, QSpinBox:focus, QComboBox:focus { border-color: #4f8bd3; } QSlider::groove:horizontal { height: 4px; background: #c6cbd2; border-radius: 2px; } QSlider::handle:horizontal { background: #2d73c5; width: 14px; margin: -5px 0; border-radius: 7px; } QTabWidget::pane { background: #f1f2f4; border: 1px solid #cfd2d7; } diff --git a/pdfreaderlite/ui/right_tools.py b/pdfreaderlite/ui/right_tools.py index 6edc75f..4dfcfee 100644 --- a/pdfreaderlite/ui/right_tools.py +++ b/pdfreaderlite/ui/right_tools.py @@ -126,7 +126,13 @@ class RightToolsPanel(QWidget): self.sections[section_id] = section return section - def add_annotation_list(self, title: str, annotation_list: QListWidget, section_id: str) -> None: + def add_annotation_list( + self, + title: str, + annotation_list: QListWidget, + section_id: str, + controls: Iterable[QWidget] | None = None, + ) -> None: section = QFrame() section.setObjectName("toolSection") @@ -137,6 +143,8 @@ class RightToolsPanel(QWidget): label = QLabel(title) label.setObjectName("toolSectionLabel") layout.addWidget(label) + for control in controls or []: + layout.addWidget(control) layout.addWidget(annotation_list) annotation_list.setObjectName("rightAnnotationList")