Separate annotation tools panel
This commit is contained in:
@@ -20,8 +20,9 @@ from PySide6.QtWidgets import (
|
||||
|
||||
|
||||
class ToolSection(QFrame):
|
||||
def __init__(self, title: str, actions: Iterable[QAction]) -> None:
|
||||
def __init__(self, title: str, actions: Iterable[QAction], section_id: str | None = None) -> None:
|
||||
super().__init__()
|
||||
self.section_id = section_id
|
||||
self.setObjectName("toolSection")
|
||||
self.actions_container = QWidget()
|
||||
self.actions_container.setObjectName("toolSectionActions")
|
||||
@@ -74,6 +75,8 @@ class RightToolsPanel(QWidget):
|
||||
super().__init__()
|
||||
self.search_box = search_box
|
||||
self.search_results = search_results
|
||||
self.sections: dict[str, QWidget] = {}
|
||||
self.annotation_list: QListWidget | None = None
|
||||
self.setObjectName("rightToolsPanel")
|
||||
self.sections_container = QWidget()
|
||||
self.sections_container.setObjectName("rightToolsSections")
|
||||
@@ -94,6 +97,7 @@ class RightToolsPanel(QWidget):
|
||||
header_layout.setSpacing(6)
|
||||
title = QLabel("工具")
|
||||
title.setObjectName("rightToolsTitle")
|
||||
self.title_label = title
|
||||
collapse_button = QToolButton()
|
||||
collapse_button.setObjectName("rightToolsCollapseButton")
|
||||
collapse_button.setText("‹")
|
||||
@@ -115,11 +119,42 @@ class RightToolsPanel(QWidget):
|
||||
self.setMinimumWidth(260)
|
||||
self.setMaximumWidth(300)
|
||||
|
||||
def add_section(self, title: str, actions: Iterable[QAction]) -> None:
|
||||
self.sections_layout.addWidget(ToolSection(title, actions))
|
||||
def add_section(self, title: str, actions: Iterable[QAction], section_id: str | None = None) -> ToolSection:
|
||||
section = ToolSection(title, actions, section_id)
|
||||
self.sections_layout.addWidget(section)
|
||||
if section_id:
|
||||
self.sections[section_id] = section
|
||||
return section
|
||||
|
||||
def add_annotation_list(self, title: str, annotation_list: QListWidget, section_id: str) -> None:
|
||||
section = QFrame()
|
||||
section.setObjectName("toolSection")
|
||||
|
||||
layout = QVBoxLayout(section)
|
||||
layout.setContentsMargins(8, 8, 8, 8)
|
||||
layout.setSpacing(6)
|
||||
|
||||
label = QLabel(title)
|
||||
label.setObjectName("toolSectionLabel")
|
||||
layout.addWidget(label)
|
||||
layout.addWidget(annotation_list)
|
||||
|
||||
annotation_list.setObjectName("rightAnnotationList")
|
||||
annotation_list.setMinimumHeight(180)
|
||||
self.annotation_list = annotation_list
|
||||
self.sections[section_id] = section
|
||||
self.sections_layout.addWidget(section)
|
||||
|
||||
def finish(self) -> None:
|
||||
self.sections_layout.addStretch(1)
|
||||
|
||||
def set_search_results_visible(self, visible: bool) -> None:
|
||||
self.search_results.setVisible(visible)
|
||||
|
||||
def set_title(self, title: str) -> None:
|
||||
self.title_label.setText(title)
|
||||
|
||||
def show_sections(self, section_ids: Iterable[str]) -> None:
|
||||
visible_ids = set(section_ids)
|
||||
for section_id, section in self.sections.items():
|
||||
section.setVisible(section_id in visible_ids)
|
||||
|
||||
Reference in New Issue
Block a user