Preserve right panel width and improve annotation list

This commit is contained in:
2026-06-30 13:59:37 +08:00
parent b388d21215
commit e61d078ca3
2 changed files with 68 additions and 5 deletions
+2 -2
View File
@@ -13,7 +13,7 @@
- [ ] 便签/批注内容二次编辑。
- [x] 注释列表按类型筛选。
- [x] 注释列表搜索。
- [ ] 注释列表右键删除。
- [x] 注释列表右键删除。
- [ ] 注释列表双击编辑内容。
- [ ] 图章工具。
- [ ] 常用中文图章预设。
@@ -26,7 +26,7 @@
- [ ] 图形注释支持修改颜色、线宽、透明度。
- [ ] 自由画笔支持颜色、线宽、透明度。
- [ ] 注释创建后自动刷新右侧注释列表。
- [ ] 注释删除后自动刷新右侧注释列表。
- [x] 注释删除后自动刷新右侧注释列表。
- [ ] 阅读模式下禁止选中注释对象。
## 编辑:新增功能
+66 -3
View File
@@ -97,6 +97,7 @@ class MainWindow(QMainWindow):
self.mode_status_label = QLabel()
self.right_tools = RightToolsPanel(self.search_box, self.search_results)
self.main_splitter: QSplitter | None = None
self._last_right_tools_width = 280
self.pending_placement: dict[str, object] | None = None
self.selected_annotation: AnnotationInfo | None = None
self.session_raster_objects: list[dict[str, object]] = []
@@ -1510,7 +1511,11 @@ class MainWindow(QMainWindow):
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.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
self.right_annotation_list.itemClicked.connect(self._go_to_annotation_item)
self.right_annotation_list.customContextMenuRequested.connect(
self.show_annotation_list_context_menu
)
def _go_to_search_match(self, item: QListWidgetItem) -> None:
match: SearchMatch = item.data(Qt.ItemDataRole.UserRole)
@@ -1523,6 +1528,42 @@ class MainWindow(QMainWindow):
self.selected_annotation = annotation
self.viewer.set_selected_object_rect(annotation.rect)
def show_annotation_list_context_menu(self, position) -> None:
item = self.right_annotation_list.itemAt(position)
if not item:
return
annotation = item.data(Qt.ItemDataRole.UserRole)
if not isinstance(annotation, AnnotationInfo):
return
menu = QMenu(self)
delete_action = menu.addAction("删除注释")
chosen = menu.exec(self.right_annotation_list.mapToGlobal(position))
if chosen == delete_action:
self.delete_annotation_from_panel(annotation)
def delete_annotation_from_panel(self, annotation: AnnotationInfo) -> None:
reply = QMessageBox.question(
self,
"删除注释",
"确定删除选中的注释吗?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
)
if reply != QMessageBox.StandardButton.Yes:
return
try:
if not self.document.delete_annotation(annotation.page_index, annotation.xref):
QMessageBox.warning(self, "删除失败", "没有找到对应的注释。")
return
if self.selected_annotation and self.selected_annotation.xref == annotation.xref:
self.selected_annotation = None
self.viewer.clear_object_selection()
self.viewer.render()
self._refresh_annotation_panel()
self.statusBar().showMessage("注释已删除,记得保存", 3000)
except Exception as exc:
QMessageBox.critical(self, "删除失败", f"无法删除注释:\n{exc}")
def _annotation_type_matches_filter(self, annotation: AnnotationInfo) -> bool:
filter_key = self.annotation_filter_combo.currentData()
if filter_key in (None, "all"):
@@ -2243,9 +2284,31 @@ class MainWindow(QMainWindow):
self._sync_mode_status()
def set_right_tools_visible(self, visible: bool) -> None:
self.right_tools.setVisible(visible)
if self.main_splitter:
self.main_splitter.setSizes([self.width() - (280 if visible else 0), 280 if visible else 0])
if not self.main_splitter:
self.right_tools.setVisible(visible)
return
sizes = self.main_splitter.sizes()
total_width = sum(sizes) or self.width()
if visible:
if self.right_tools.isVisible():
return
right_width = self._clamp_right_tools_width(self._last_right_tools_width)
self.right_tools.setVisible(True)
self.main_splitter.setSizes([max(1, total_width - right_width), right_width])
return
if self.right_tools.isVisible() and len(sizes) > 1 and sizes[1] > 0:
self._last_right_tools_width = self._clamp_right_tools_width(sizes[1])
self.right_tools.setVisible(False)
self.main_splitter.setSizes([total_width, 0])
def _clamp_right_tools_width(self, width: int) -> int:
minimum = self.right_tools.minimumWidth()
maximum = self.right_tools.maximumWidth()
if maximum <= 0:
maximum = 300
return max(minimum, min(int(width), maximum))
def _apply_theme(self) -> None:
if self.dark_mode: