feat: Enhance branding management with editable fields and save functionality in settings dialog
This commit is contained in:
parent
fe341163e8
commit
e52c09857f
9 changed files with 178 additions and 8 deletions
|
|
@ -10,6 +10,7 @@ from PySide6.QtWidgets import (
|
|||
QDialogButtonBox,
|
||||
QFileDialog,
|
||||
QHBoxLayout,
|
||||
QInputDialog,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
QListWidget,
|
||||
|
|
@ -184,16 +185,42 @@ class SettingsDialog(QDialog):
|
|||
|
||||
self.branding_combo = QComboBox()
|
||||
self.branding_combo.setToolTip(tr("settings.branding.select_tooltip"))
|
||||
for template in self.branding_manager.list_templates():
|
||||
self.branding_combo.addItem(template.display_name, template.template_id)
|
||||
|
||||
idx = self.branding_combo.findData(self.config.active_branding_id)
|
||||
if idx < 0:
|
||||
idx = self.branding_combo.findData("default")
|
||||
if idx >= 0:
|
||||
self.branding_combo.setCurrentIndex(idx)
|
||||
self._refresh_branding_combo()
|
||||
self.branding_combo.currentIndexChanged.connect(self._on_branding_selection_changed)
|
||||
layout.addWidget(self.branding_combo)
|
||||
|
||||
self.branding_display_name_input = QLineEdit()
|
||||
self.branding_display_name_input.setPlaceholderText(
|
||||
tr("settings.branding.display_name_label")
|
||||
)
|
||||
layout.addWidget(QLabel(tr("settings.branding.display_name_label")))
|
||||
layout.addWidget(self.branding_display_name_input)
|
||||
|
||||
self.branding_app_name_input = QLineEdit()
|
||||
self.branding_app_name_input.setPlaceholderText(tr("settings.branding.app_name_label"))
|
||||
layout.addWidget(QLabel(tr("settings.branding.app_name_label")))
|
||||
layout.addWidget(self.branding_app_name_input)
|
||||
|
||||
self.branding_window_title_input = QLineEdit()
|
||||
self.branding_window_title_input.setPlaceholderText(
|
||||
tr("settings.branding.window_title_label")
|
||||
)
|
||||
layout.addWidget(QLabel(tr("settings.branding.window_title_label")))
|
||||
layout.addWidget(self.branding_window_title_input)
|
||||
|
||||
self.branding_logo_path_input = QLineEdit()
|
||||
self.branding_logo_path_input.setPlaceholderText(tr("settings.branding.logo_path_label"))
|
||||
layout.addWidget(QLabel(tr("settings.branding.logo_path_label")))
|
||||
layout.addWidget(self.branding_logo_path_input)
|
||||
|
||||
branding_button_layout = QHBoxLayout()
|
||||
self.save_branding_as_btn = QPushButton(tr("settings.branding.save_as_btn"))
|
||||
self.save_branding_as_btn.clicked.connect(self._save_branding_as)
|
||||
branding_button_layout.addWidget(self.save_branding_as_btn)
|
||||
layout.addLayout(branding_button_layout)
|
||||
|
||||
self._load_branding_into_editor(self.branding_combo.currentData() or "default")
|
||||
|
||||
note = QLabel(tr("settings.branding.restart_note"))
|
||||
note.setWordWrap(True)
|
||||
note.setStyleSheet("color: gray; font-size: 11px;")
|
||||
|
|
@ -203,6 +230,60 @@ class SettingsDialog(QDialog):
|
|||
widget.setLayout(layout)
|
||||
return widget
|
||||
|
||||
def _refresh_branding_combo(self, selected_template_id: Optional[str] = None) -> None:
|
||||
"""Refresh the branding template selector."""
|
||||
current = selected_template_id or self.config.active_branding_id or "default"
|
||||
self.branding_combo.blockSignals(True)
|
||||
self.branding_combo.clear()
|
||||
for template in self.branding_manager.list_templates():
|
||||
self.branding_combo.addItem(template.display_name, template.template_id)
|
||||
|
||||
idx = self.branding_combo.findData(current)
|
||||
if idx < 0:
|
||||
idx = self.branding_combo.findData("default")
|
||||
if idx >= 0:
|
||||
self.branding_combo.setCurrentIndex(idx)
|
||||
self.branding_combo.blockSignals(False)
|
||||
|
||||
def _load_branding_into_editor(self, template_id: str) -> None:
|
||||
"""Load the selected branding template into the editable fields."""
|
||||
template = self.branding_manager.load_template(template_id)
|
||||
self.branding_display_name_input.setText(template.display_name)
|
||||
self.branding_app_name_input.setText(template.app_name)
|
||||
self.branding_window_title_input.setText(template.window_title)
|
||||
self.branding_logo_path_input.setText(template.logo_path)
|
||||
|
||||
def _on_branding_selection_changed(self) -> None:
|
||||
"""Update editable branding fields when a different template is selected."""
|
||||
template_id = self.branding_combo.currentData()
|
||||
if template_id:
|
||||
self._load_branding_into_editor(template_id)
|
||||
|
||||
def _save_branding_as(self) -> None:
|
||||
"""Save the edited branding as a new reusable template."""
|
||||
template_id, ok = QInputDialog.getText(
|
||||
self,
|
||||
tr("settings.branding.save_as_title"),
|
||||
tr("settings.branding.save_as_prompt"),
|
||||
)
|
||||
|
||||
if not ok or not template_id:
|
||||
return
|
||||
|
||||
try:
|
||||
template = self.branding_manager.build_template(
|
||||
template_id=template_id,
|
||||
display_name=self.branding_display_name_input.text(),
|
||||
app_name=self.branding_app_name_input.text(),
|
||||
window_title=self.branding_window_title_input.text(),
|
||||
logo_path=self.branding_logo_path_input.text(),
|
||||
)
|
||||
self.branding_manager.save_template(template)
|
||||
self._refresh_branding_combo(template.template_id)
|
||||
self._load_branding_into_editor(template.template_id)
|
||||
except ConfigurationError as e:
|
||||
self._show_error(f"Failed to save branding: {e}")
|
||||
|
||||
def _create_web_source_tab(self) -> QWidget:
|
||||
"""Create web source configuration tab."""
|
||||
widget = QWidget()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue