105 Zeilen
3.7 KiB
Python
105 Zeilen
3.7 KiB
Python
"""
|
|
Platform Grid View - Zeigt die Plattform-Kacheln in einem Grid
|
|
"""
|
|
|
|
import os
|
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QGridLayout, QLabel
|
|
from PyQt5.QtCore import pyqtSignal, Qt
|
|
from PyQt5.QtGui import QFont
|
|
|
|
from views.widgets.platform_button import PlatformButton
|
|
from application.services.platform_service import PlatformService
|
|
|
|
|
|
class PlatformGridView(QWidget):
|
|
"""
|
|
Grid-Ansicht der Plattform-Kacheln
|
|
Wiederverwendung der existierenden PlatformButton-Komponente
|
|
"""
|
|
|
|
# Signal wird ausgelöst, wenn eine Plattform ausgewählt wird
|
|
platform_selected = pyqtSignal(str)
|
|
|
|
def __init__(self, language_manager=None, db_manager=None):
|
|
super().__init__()
|
|
self.language_manager = language_manager
|
|
self.db_manager = db_manager
|
|
self.platform_service = PlatformService(db_manager)
|
|
self.init_ui()
|
|
|
|
if self.language_manager:
|
|
self.language_manager.language_changed.connect(self.update_texts)
|
|
self.update_texts()
|
|
|
|
def init_ui(self):
|
|
"""Initialisiert die UI nach Styleguide"""
|
|
# Hauptlayout mit Container-Padding
|
|
layout = QVBoxLayout(self)
|
|
layout.setContentsMargins(40, 40, 40, 40)
|
|
layout.setSpacing(32)
|
|
|
|
# Titel
|
|
self.title_label = QLabel("AccountForger")
|
|
self.title_label.setAlignment(Qt.AlignCenter)
|
|
self.title_label.setObjectName("platform_title")
|
|
|
|
# Poppins Font für Titel
|
|
title_font = QFont("Poppins", 32)
|
|
title_font.setBold(True)
|
|
self.title_label.setFont(title_font)
|
|
|
|
layout.addWidget(self.title_label)
|
|
|
|
# Container für Plattform-Grid
|
|
platforms_container = QWidget()
|
|
platforms_container.setObjectName("platforms_container") # For QSS targeting
|
|
grid_layout = QGridLayout(platforms_container)
|
|
grid_layout.setSpacing(24) # Styleguide Grid-Gap
|
|
|
|
# Lade nur aktive Plattformen aus dem Service
|
|
active_platforms = self.platform_service.get_active_platforms()
|
|
|
|
# Icon-Pfade
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
parent_dir = os.path.dirname(os.path.dirname(current_dir))
|
|
icons_dir = os.path.join(parent_dir, "resources", "icons")
|
|
|
|
# Platziere Buttons in einem 2x2 Grid (nur 4 Plattformen)
|
|
for i, platform in enumerate(active_platforms):
|
|
row = i // 2 # 2 Spalten
|
|
col = i % 2
|
|
|
|
# Icon-Pfad erstellen
|
|
icon_path = os.path.join(icons_dir, platform.icon)
|
|
if not os.path.exists(icon_path):
|
|
# Fallback für X/Twitter
|
|
if platform.id == "x":
|
|
icon_path = os.path.join(icons_dir, "twitter.svg")
|
|
if not os.path.exists(icon_path):
|
|
icon_path = None
|
|
|
|
# Platform Button erstellen
|
|
button = PlatformButton(
|
|
platform.display_name,
|
|
icon_path,
|
|
True # Alle aktiven Plattformen sind enabled
|
|
)
|
|
|
|
# Signal verbinden
|
|
button.clicked.connect(
|
|
lambda checked=False, p=platform.id: self.platform_selected.emit(p)
|
|
)
|
|
|
|
grid_layout.addWidget(button, row, col, Qt.AlignCenter)
|
|
|
|
layout.addWidget(platforms_container)
|
|
layout.addStretch()
|
|
|
|
def update_texts(self):
|
|
"""Aktualisiert die Texte gemäß der aktuellen Sprache"""
|
|
if not self.language_manager:
|
|
return
|
|
|
|
self.title_label.setText(
|
|
self.language_manager.get_text("main.title", "AccountForger")
|
|
) |