feat: Add delete and preview functionality for branding in settings dialog and update translations
This commit is contained in:
parent
e1dbc2ee84
commit
b826bd9b20
10 changed files with 143 additions and 17 deletions
|
|
@ -4,6 +4,7 @@ import logging
|
|||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from PySide6.QtGui import QIcon, QPixmap
|
||||
from PySide6.QtWidgets import (
|
||||
QComboBox,
|
||||
QDialog,
|
||||
|
|
@ -193,6 +194,7 @@ class SettingsDialog(QDialog):
|
|||
self.branding_display_name_input.setPlaceholderText(
|
||||
tr("settings.branding.display_name_label")
|
||||
)
|
||||
self.branding_display_name_input.textChanged.connect(self._update_branding_preview)
|
||||
layout.addWidget(QLabel(tr("settings.branding.display_name_label")))
|
||||
layout.addWidget(self.branding_display_name_input)
|
||||
|
||||
|
|
@ -200,6 +202,7 @@ class SettingsDialog(QDialog):
|
|||
logo_layout = QHBoxLayout()
|
||||
self.branding_logo_path_input = QLineEdit()
|
||||
self.branding_logo_path_input.setPlaceholderText(tr("settings.branding.logo_path_label"))
|
||||
self.branding_logo_path_input.textChanged.connect(self._update_branding_preview)
|
||||
logo_layout.addWidget(self.branding_logo_path_input)
|
||||
|
||||
self.browse_branding_logo_btn = QPushButton(tr("settings.log_file.browse_btn"))
|
||||
|
|
@ -207,10 +210,26 @@ class SettingsDialog(QDialog):
|
|||
logo_layout.addWidget(self.browse_branding_logo_btn)
|
||||
layout.addLayout(logo_layout)
|
||||
|
||||
layout.addWidget(QLabel(tr("settings.branding.preview_label")))
|
||||
self.branding_preview_name_label = QLabel()
|
||||
self.branding_preview_name_label.setStyleSheet("font-weight: bold;")
|
||||
layout.addWidget(self.branding_preview_name_label)
|
||||
|
||||
self.branding_preview_icon_label = QLabel(tr("settings.branding.no_icon_selected"))
|
||||
self.branding_preview_icon_label.setFixedSize(72, 72)
|
||||
self.branding_preview_icon_label.setStyleSheet(
|
||||
"border: 1px solid #ccc; padding: 4px; background: #fafafa;"
|
||||
)
|
||||
layout.addWidget(self.branding_preview_icon_label)
|
||||
|
||||
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)
|
||||
|
||||
self.delete_branding_btn = QPushButton(tr("settings.branding.delete_btn"))
|
||||
self.delete_branding_btn.clicked.connect(self._delete_branding)
|
||||
branding_button_layout.addWidget(self.delete_branding_btn)
|
||||
layout.addLayout(branding_button_layout)
|
||||
|
||||
self._load_branding_into_editor(self.branding_combo.currentData() or "default")
|
||||
|
|
@ -240,10 +259,33 @@ class SettingsDialog(QDialog):
|
|||
self.branding_combo.blockSignals(False)
|
||||
|
||||
def _load_branding_into_editor(self, template_id: str) -> None:
|
||||
"""Load the selected branding template into the editable fields."""
|
||||
"""Load the selected branding into the editable fields."""
|
||||
template = self.branding_manager.load_template(template_id)
|
||||
self.branding_display_name_input.setText(template.display_name)
|
||||
self.branding_logo_path_input.setText(template.logo_path)
|
||||
self._update_branding_preview()
|
||||
|
||||
def _update_branding_preview(self) -> None:
|
||||
"""Refresh the small branding preview for name and icon."""
|
||||
display_name = self.branding_display_name_input.text().strip() or tr(
|
||||
"settings.branding.preview_default_name"
|
||||
)
|
||||
self.branding_preview_name_label.setText(display_name)
|
||||
|
||||
logo_path = self.branding_logo_path_input.text().strip()
|
||||
if logo_path and Path(logo_path).exists():
|
||||
pixmap = QPixmap(logo_path)
|
||||
if pixmap.isNull():
|
||||
icon = QIcon(logo_path)
|
||||
pixmap = icon.pixmap(64, 64)
|
||||
|
||||
if not pixmap.isNull():
|
||||
self.branding_preview_icon_label.setPixmap(pixmap.scaled(64, 64))
|
||||
self.branding_preview_icon_label.setText("")
|
||||
return
|
||||
|
||||
self.branding_preview_icon_label.setPixmap(QPixmap())
|
||||
self.branding_preview_icon_label.setText(tr("settings.branding.no_icon_selected"))
|
||||
|
||||
def _on_branding_selection_changed(self) -> None:
|
||||
"""Update editable branding fields when a different template is selected."""
|
||||
|
|
@ -275,10 +317,11 @@ class SettingsDialog(QDialog):
|
|||
return
|
||||
|
||||
try:
|
||||
display_name = self.branding_display_name_input.text().strip() or branding_name
|
||||
template = self.branding_manager.build_template(
|
||||
template_id=branding_name,
|
||||
display_name=branding_name,
|
||||
app_name=branding_name,
|
||||
display_name=display_name,
|
||||
app_name=display_name,
|
||||
logo_path=self.branding_logo_path_input.text(),
|
||||
)
|
||||
self.branding_manager.save_template(template)
|
||||
|
|
@ -287,6 +330,19 @@ class SettingsDialog(QDialog):
|
|||
except ConfigurationError as e:
|
||||
self._show_error(f"Failed to save branding: {e}")
|
||||
|
||||
def _delete_branding(self) -> None:
|
||||
"""Delete the currently selected custom branding."""
|
||||
template_id = self.branding_combo.currentData()
|
||||
if not template_id:
|
||||
return
|
||||
|
||||
try:
|
||||
self.branding_manager.delete_template(template_id)
|
||||
self._refresh_branding_combo("default")
|
||||
self._load_branding_into_editor("default")
|
||||
except ConfigurationError as e:
|
||||
self._show_error(f"Failed to delete 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