diff --git a/ui/main_window.py b/ui/main_window.py index fac1846..8163117 100644 --- a/ui/main_window.py +++ b/ui/main_window.py @@ -76,21 +76,45 @@ class MainWindow(QMainWindow): model_layout.addWidget(self.change_model_btn) # 高级辅助面板(可折叠) - self.advanced_group = QGroupBox("高级辅助 (背景与术语)") - self.advanced_group.setCheckable(True) - self.advanced_group.setChecked(False) - self.advanced_group.setStyleSheet( - "QGroupBox { border: 1px solid #e2e8f0; border-radius: 8px; margin-top: 10px; }" - "QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 5px 0 5px; }" - ) + advanced_panel = QWidget() + advanced_layout = QVBoxLayout(advanced_panel) + advanced_layout.setSpacing(10) + advanced_layout.setContentsMargins(0, 0, 0, 0) - advanced_layout = QVBoxLayout(self.advanced_group) - advanced_layout.setSpacing(15) - advanced_layout.setContentsMargins(15, 15, 15, 15) + # 高级辅助标题和折叠按钮 + advanced_header = QWidget() + header_layout = QHBoxLayout(advanced_header) + header_layout.setContentsMargins(0, 0, 0, 0) + header_layout.setSpacing(10) + + advanced_title = QLabel("高级辅助 (背景与术语)") + advanced_title.setStyleSheet("color: #4a5568; font-weight: bold;") + + self.advanced_toggle = QToolButton() + self.advanced_toggle.setText("▼") + self.advanced_toggle.setCheckable(True) + self.advanced_toggle.setChecked(False) + self.advanced_toggle.setFixedSize(20, 20) + self.advanced_toggle.setStyleSheet( + "border: none; background: none; color: #4a5568;" + ) + self.advanced_toggle.clicked.connect(self.toggle_advanced_panel) + + header_layout.addWidget(advanced_title) + header_layout.addStretch() + header_layout.addWidget(self.advanced_toggle) + + advanced_layout.addWidget(advanced_header) + + # 高级辅助内容区域 + self.advanced_content = QWidget() + content_layout = QVBoxLayout(self.advanced_content) + content_layout.setSpacing(15) + content_layout.setContentsMargins(0, 0, 0, 0) # 文本背景/场景介绍 context_label = QLabel("文本背景 / 场景介绍") - context_label.setStyleSheet("color: #4a5568; font-weight: bold;") + context_label.setStyleSheet("color: #4a5568;") self.context_edit = QTextEdit() self.context_edit.setPlaceholderText("例如:这是一份关于建筑工程的合同...") @@ -101,7 +125,7 @@ class MainWindow(QMainWindow): # 术语定义 terms_label = QLabel("术语簿 (定义 A=B)") - terms_label.setStyleSheet("color: #4a5568; font-weight: bold;") + terms_label.setStyleSheet("color: #4a5568;") self.terms_list = QListWidget() self.terms_list.setStyleSheet( @@ -112,7 +136,7 @@ class MainWindow(QMainWindow): self.term_input = QLineEdit() self.term_input.setPlaceholderText("你好 = what's up") self.term_input.setStyleSheet( - "border: 1px solid #e2e8f0; border-radius: 6px; padding: 8px; flex: 1;" + "border: 1px solid #e2e8f0; border-radius: 6px; padding: 8px;" ) add_term_btn = QPushButton("+") @@ -129,11 +153,21 @@ class MainWindow(QMainWindow): self.terms_list.setContextMenuPolicy(Qt.CustomContextMenu) self.terms_list.customContextMenuRequested.connect(self.show_term_context_menu) - advanced_layout.addWidget(context_label) - advanced_layout.addWidget(self.context_edit) - advanced_layout.addWidget(terms_label) - advanced_layout.addWidget(self.terms_list) - advanced_layout.addLayout(terms_input_layout) + content_layout.addWidget(context_label) + content_layout.addWidget(self.context_edit) + content_layout.addWidget(terms_label) + content_layout.addWidget(self.terms_list) + content_layout.addLayout(terms_input_layout) + + advanced_layout.addWidget(self.advanced_content) + + # 默认隐藏高级辅助内容 + self.advanced_content.setVisible(False) + + # 将高级辅助面板添加到主布局 + advanced_panel.setStyleSheet( + "border: 1px solid #e2e8f0; border-radius: 8px; padding: 15px; margin-top: 10px;" + ) # 原文输入区域 input_layout = QVBoxLayout() @@ -210,7 +244,7 @@ class MainWindow(QMainWindow): # 将所有组件添加到主布局 main_layout.addWidget(title_label) main_layout.addLayout(model_layout) - main_layout.addWidget(self.advanced_group) + main_layout.addWidget(advanced_panel) main_layout.addLayout(input_layout) main_layout.addWidget(self.translate_btn) main_layout.addLayout(output_layout) @@ -276,6 +310,12 @@ class MainWindow(QMainWindow): else: QMessageBox.warning(self, "警告", "术语格式不正确,请使用 'A = B' 格式") + def toggle_advanced_panel(self): + """切换高级辅助面板的显示/隐藏状态""" + is_visible = not self.advanced_content.isVisible() + self.advanced_content.setVisible(is_visible) + self.advanced_toggle.setText("▲" if is_visible else "▼") + def show_term_context_menu(self, pos): """显示术语项右键菜单""" from PySide6.QtWidgets import QMenu