diff --git a/portprotonqt/config/ui.py b/portprotonqt/config/ui.py index 44b374d1..3358c974 100644 --- a/portprotonqt/config/ui.py +++ b/portprotonqt/config/ui.py @@ -537,6 +537,14 @@ class UIConfig(BaseConfig): validate_bool(enabled, "disable_alt_i586_dependency_check") self._save_value("disable_alt_i586_dependency_check", enabled, "bool") + def get_show_wine_prefix_cards(self) -> bool: + """Get whether to display Wine version and Prefix name on game cards.""" + return self._get_bool("show_wine_prefix_cards", True) + + def set_show_wine_prefix_cards(self, enabled: bool) -> None: + """Set whether to display Wine version and Prefix name on game cards.""" + validate_bool(enabled, "show_wine_prefix_cards") + self._save_value("show_wine_prefix_cards", enabled, "bool") def load_theme_metainfo(theme_name: str) -> dict: """Load theme metadata from metainfo.ini.""" diff --git a/portprotonqt/game_card.py b/portprotonqt/game_card.py index 81d0bf96..95a3b738 100644 --- a/portprotonqt/game_card.py +++ b/portprotonqt/game_card.py @@ -19,7 +19,10 @@ from PySide6.QtGui import ( QKeyEvent, QPaintEvent, ) -from PySide6.QtCore import QEvent, Signal, Property, Qt, QUrl, QTimer, QSize +from PySide6.QtCore import QEvent, Signal, Property, Qt, QUrl, QTimer, QSize, QRunnable, QObject, Slot, QThreadPool + +from portprotonqt.logger import get_logger + from PySide6.QtWidgets import ( QApplication, QFrame, @@ -59,6 +62,137 @@ def is_valid_protondb_tier(tier: str | None) -> bool: """Check if ProtonDB tier is supported.""" return bool(tier) and tier.lower() in PROTONDB_TIERS +def show_wine_prefix_check_card( + wp_exec_line: str, + wp_game_source: str, + wp_is_missing_exe: bool, + wp_games: list[tuple] | None = None, +) -> bool: + """Collects data and checks rules for showing WinePrefix.""" + if not getattr(ui_config, "get_show_wine_prefix_cards", lambda: True)(): + return False + if wp_games is not None: + # Header mode: game[5] = exec_line, game[12] = game_source. + for game in wp_games: + wp_exec = str(game[5] or "") + wp_source = str(game[12] or "") + wp_missing = False + # to not change this code extract_executable_path + if wp_source.lower() == "portproton": + wp_path = GameCard._extract_executable_path(wp_exec) + if wp_path and wp_path.lower().endswith(WINDOWS_LAUNCH_EXTENSIONS): + wp_missing = not os.path.exists(wp_path) + if show_wine_prefix_check_card(wp_exec, wp_source, wp_missing): + return True + return False + # Hidden for: + if wp_exec_line.startswith("autoinstall:"): + return False + wp_source_lower = str(wp_game_source).lower() + if wp_source_lower in ("steam", "gog", "egs"): + return False + if wp_is_missing_exe: + return False + if wp_source_lower == "portproton" and not GameCard._extract_executable_path(wp_exec_line): + return False + return True + +def show_wine_prefix_columns( + theme, + wp_games: list[tuple] | None = None, + wp_exec_line: str | None = None, + wp_game_source: str | None = None, + wp_is_missing_exe: bool | None = None, +) -> bool: + """Theme: passes only when the theme has all required attributes.""" + required = ( + "WINE_PREFIX_CARD_HEIGHT", + "wine_prefix_margin", + "wine_prefix_spacing", + "GAME_CARD_WINE_PREFIX_CONTAINER_STYLE", + "GAME_CARD_WINE_PREFIX_LOADING_STYLE", + ) + if not all(hasattr(theme, attr) for attr in required): + return False + return show_wine_prefix_check_card( + wp_exec_line=wp_exec_line or "", + wp_game_source=wp_game_source or "", + wp_is_missing_exe=bool(wp_is_missing_exe), + wp_games=wp_games, + ) + +class TaskSignals(QObject): + """Transmitter class for signals from QRunnable.""" + result_ready = Signal(str, str) + +class WinePrefixTask(QRunnable, QObject): + """Task to extract Wine version and Prefix name from game files.""" + def __init__(self, wp_exec_line: str, callback): + super().__init__() + self.logger = get_logger(__name__) + self.wp_exec_line = wp_exec_line + self.signals = TaskSignals() + self.signals.result_ready.connect(callback) + self.setAutoDelete(True) + self._is_cancelled = False + + def cancel(self): + self._is_cancelled = True + + def run(self) -> None: + if self._is_cancelled: + return + + wp_wine = _("Not found") + wp_prefix = _("Not found") + + wp_exe = GameCard._extract_executable_path(self.wp_exec_line) + if not wp_exe: + self.signals.result_ready.emit(wp_wine, wp_prefix) + return + + try: + with open(f"{wp_exe}.ppdb", encoding="utf-8", errors="ignore") as file: + has_wp_wine = has_wp_prefix = False + + for line in file: + if self._is_cancelled: + return + + if not has_wp_wine and (wp_wine_match := re.search( + r'export\s+PW_WINE_USE=["\']?(.*?)["\']?(?:\s|$)', line + )): + wp_wine = wp_wine_match.group(1).strip() + has_wp_wine = True + + if not has_wp_prefix and (wp_prefix_match := re.search( + r'export\s+PW_PREFIX_NAME=["\']?(.*?)["\']?(?:\s|$)', line + )): + wp_prefix = wp_prefix_match.group(1).strip() + has_wp_prefix = True + + if has_wp_wine and has_wp_prefix: + break + except FileNotFoundError: + pass # no .ppdb file → "Not found" is the expected result + except OSError as e: + self.logger.error(f"Error reading wine-prefix .ppdb file: {wp_exe}", exc_info=e) + if self._is_cancelled: + return + + # Reference to the user's PortProton defaults + if re.fullmatch(r"\$?\{?PW_DEFAULT_WINE_USE\}?", wp_wine): + wp_wine = _("Default (settings)") + if not wp_wine.strip(): + wp_wine = _("Not found") + if re.fullmatch(r"\$?\{?PW_DEFAULT_PREFIX_NAME\}?", wp_prefix): + wp_prefix = _("Default (settings)") + elif wp_prefix in ("default", "") or not wp_prefix.strip(): + # WINEPREFIX is the prefix the game will actually run in + wp_prefix = os.environ.get("WINEPREFIX") or _("Not found") + + if not self._is_cancelled: + self.signals.result_ready.emit(wp_wine, wp_prefix) class SourceCorner(QWidget): @@ -354,6 +488,7 @@ class GameCard(AnimatedCard): card_width=250, parent=None, context_menu_manager=None ): super().__init__(parent) + self.logger = get_logger(__name__) self.coverReady.connect(self.on_cover_loaded, Qt.ConnectionType.QueuedConnection) self.name = name self.description = description @@ -394,6 +529,7 @@ class GameCard(AnimatedCard): parent_mode or getattr(self.theme, "LIBRARY_LAYOUT_MODE", "grid") ).lower() self.list_layout = self.layout_mode in {"list", "vertical"} + self.wp_enabled = False self.vertical_layout = self.layout_mode == "vertical" self.horizontal_layout = self.layout_mode in {"horizontal", "horizontal_top"} self.economy_mode = ui_config.get_economy_mode() @@ -586,7 +722,7 @@ class GameCard(AnimatedCard): self.layout_.addWidget(self.nameLabel, stretches[0]) for text, stretch in zip( (self.last_launch, self.formatted_playtime, str(self.game_source)), - stretches[1:], + stretches[1:4], strict=True, ): label = QLabel(text) @@ -603,7 +739,7 @@ class GameCard(AnimatedCard): font_size = self.nameLabel.font().pointSizeF() self.base_font_size = font_size if font_size > 0 else 10.0 - + self._initialize_wp_widgets() self.update_scale() # Force initial layout update to ensure correct geometry @@ -615,6 +751,144 @@ class GameCard(AnimatedCard): layout.invalidate() parent.updateGeometry() + def _initialize_wp_widgets(self) -> None: + """Initialize Wine version and Prefix name widgets based on UI configuration.""" + try: + self._reset_wp_widgets() + self._check_wp_conditions() + + if not self.wp_enabled: + if self.vertical_layout: + # Empty Wine/Prefix columns keep + self._setup_wp_vertical_layout() + # Excessive, but protected + self._sync_wp_columns_alignment() + return + + self._setup_wp_layout() + + def safe_callback(wp_wine, wp_prefix): + try: + if hasattr(self, "_wp_task"): + self._wp_task = None + + if not self.wp_enabled: + return + + if hasattr(self, "nameLabel") and self.nameLabel is not None: + self._update_wp(wp_wine, wp_prefix) + except Exception as e: + self.logger.error("Error processing callback information Wine Prefix", exc_info=e) + + self._wp_task = WinePrefixTask( + wp_exec_line=self.exec_line, + callback=safe_callback, + ) + QThreadPool.globalInstance().start(self._wp_task) + + except Exception as e: + self.logger.error("Error initializing widgets Wine Prefix", exc_info=e) + + def _reset_wp_widgets(self): + self.wp_container_card = None + self.wp_wine_label_card = None + self.wp_prefix_label_card = None + self.wp_wine_column_label = None + self.wp_prefix_column_label = None + self._wp_columns_visible = False + + def _check_wp_conditions(self): + if self.list_layout and not self.vertical_layout: + self.wp_enabled = False + return + + self.wp_enabled = show_wine_prefix_columns( + self.theme, + wp_exec_line=self.exec_line, + wp_game_source=self.game_source, + wp_is_missing_exe=bool(self.missing_executable_path), + ) + + def _setup_wp_layout(self): + self.update_scale() + + if self.vertical_layout: + self._setup_wp_vertical_layout() + else: + self._setup_wp_horizontal_layout() + + def _setup_wp_vertical_layout(self): + stretches = self.theme.GAME_CARD_VERTICAL["column_stretches"] + + wp_wine_text = _("Loading...") if self.wp_enabled else "" + self.wp_wine_column_label = QLabel(wp_wine_text) + self.wp_wine_column_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + self.wp_wine_column_label.setProperty("theme_style_name", "GAME_CARD_COLUMN_LABEL_STYLE") + self.wp_wine_column_label.setStyleSheet(self.theme.GAME_CARD_COLUMN_LABEL_STYLE) + self.wp_wine_column_label.setWordWrap(True) + self.layout_.addWidget(self.wp_wine_column_label, stretches[4] if len(stretches) > 4 else 2) + + wp_prefix_text = _("Loading...") if self.wp_enabled else "" + self.wp_prefix_column_label = QLabel(wp_prefix_text) + self.wp_prefix_column_label.setAlignment(Qt.AlignmentFlag.AlignCenter) + self.wp_prefix_column_label.setProperty("theme_style_name", "GAME_CARD_COLUMN_LABEL_STYLE") + self.wp_prefix_column_label.setStyleSheet(self.theme.GAME_CARD_COLUMN_LABEL_STYLE) + self.wp_prefix_column_label.setWordWrap(True) + self.layout_.addWidget(self.wp_prefix_column_label, stretches[5] if len(stretches) > 5 else 2) + + def _setup_wp_horizontal_layout(self): + self.wp_container_card = QFrame() + self.wp_container_card.setStyleSheet(self.theme.GAME_CARD_WINE_PREFIX_CONTAINER_STYLE) + self.wp_container_card.setSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Maximum) + + wp_layout = QVBoxLayout(self.wp_container_card) + wp_layout.setContentsMargins(*self.theme.wine_prefix_margin) + wp_layout.setSpacing(self.theme.wine_prefix_spacing) + + self.wp_wine_label_card = QLabel(f"Wine: {_('Loading...')}") + self.wp_wine_label_card.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter) + self.wp_wine_label_card.setStyleSheet(self.theme.GAME_CARD_WINE_PREFIX_LOADING_STYLE) + + self.wp_prefix_label_card = QLabel(f"Prefix: {_('Loading...')}") + self.wp_prefix_label_card.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter) + self.wp_prefix_label_card.setStyleSheet(self.theme.GAME_CARD_WINE_PREFIX_LOADING_STYLE) + + wp_layout.addWidget(self.wp_wine_label_card) + wp_layout.addWidget(self.wp_prefix_label_card) + self.layout_.addWidget(self.wp_container_card) + + def update_wp_columns_alignment(self, wp_columns_visible: bool) -> None: + """Show or hide empty WinePrefix. Excluded cards only.""" + wp_visible = bool(wp_columns_visible) + height_changed = wp_visible != self._wp_columns_visible + self._wp_columns_visible = wp_visible + if self.wp_enabled or not self.vertical_layout: + if height_changed and not self.wp_enabled and not self.horizontal_layout: + self.update_scale() + return + try: + if self.wp_wine_column_label is not None: + self.wp_wine_column_label.setVisible(wp_visible) + if self.wp_prefix_column_label is not None: + self.wp_prefix_column_label.setVisible(wp_visible) + except RuntimeError: + pass + + def _sync_wp_columns_alignment(self) -> None: + """Immediately following its creation.""" + try: + parent = self.parent() + while parent is not None: + manager = getattr(parent, "game_library_manager", None) + if manager is not None: + self.update_wp_columns_alignment( + bool(getattr(manager, "_wp_header_columns_visible", False)) + ) + return + parent = parent.parent() + except RuntimeError: + pass + def refresh_theme(self, theme: Any) -> None: """Refresh cached card visuals after a live theme change.""" old_theme = self.theme @@ -675,6 +949,21 @@ class GameCard(AnimatedCard): else: self.animations.theme = theme self.update_favorite_icon() + + try: + if self.vertical_layout: + if self.wp_wine_column_label is not None: + self.wp_wine_column_label.setStyleSheet(theme.GAME_CARD_COLUMN_LABEL_STYLE) + if self.wp_prefix_column_label is not None: + self.wp_prefix_column_label.setStyleSheet(theme.GAME_CARD_COLUMN_LABEL_STYLE) + else: + if self.wp_wine_label_card is not None: + self.wp_wine_label_card.setStyleSheet(theme.GAME_CARD_WINE_PREFIX_LOADING_STYLE) + if self.wp_prefix_label_card is not None: + self.wp_prefix_label_card.setStyleSheet(theme.GAME_CARD_WINE_PREFIX_LOADING_STYLE) + except Exception as e: + self.logger.error("Error Update theme", exc_info=e) + layout_changed = ( old_layout_cfg != self.card_layout_cfg or old_theme.COMPACT_CARD != theme.COMPACT_CARD @@ -945,6 +1234,9 @@ class GameCard(AnimatedCard): self.theme.COMPACT_CARD["height_ratio"] if small_card_mode else self.card_geometry_cfg.get("card_height_ratio", 1.8) ) + if not self.horizontal_layout and (self.wp_enabled or self._wp_columns_visible): + height_ratio += self.theme.WINE_PREFIX_CARD_HEIGHT + scaled_height = int(self.base_card_width * height_ratio * self._scale) self.setFixedSize(scaled_width + scaled_extra, scaled_height + scaled_extra) cover_ratio = self.card_geometry_cfg.get("cover_aspect_ratio", 1.5) @@ -1043,6 +1335,17 @@ class GameCard(AnimatedCard): self.display_filter = display_filter self.economy_mode = ui_config.get_economy_mode() + + if self.wp_container_card is not None: + self.wp_container_card.setVisible(self.wp_enabled and not self.list_layout) + if self.vertical_layout: + if self.wp_wine_column_label is not None: + self.wp_wine_column_label.setVisible(self.wp_enabled or self._wp_columns_visible) + if self.wp_prefix_column_label is not None: + self.wp_prefix_column_label.setVisible(self.wp_enabled or self._wp_columns_visible) + + self.update_scale() + self.steam_visible = str(self.game_source).lower() == "steam" self.gog_visible = str(self.game_source).lower() == "gog" self.egs_visible = str(self.game_source).lower() == "egs" @@ -1195,6 +1498,33 @@ class GameCard(AnimatedCard): url = QUrl(f"https://www.protondb.com/app/{self.protondb_appid}") QDesktopServices.openUrl(url) + @Slot(str, str) + def _update_wp(self, wp_wine: str, wp_prefix: str) -> None: + """Update UI fields with formatting compatible with text wraps.""" + try: + if not hasattr(self, "coverLabel") or self.coverLabel is None: + return + + if not self.wp_enabled: + return + + formatted_wine = wp_wine.replace("-", "-\u200b").replace("_", "_\u200b") + formatted_prefix = wp_prefix.replace("-", "-\u200b").replace("_", "_\u200b") + + if self.vertical_layout: + if self.wp_wine_column_label is not None: + self.wp_wine_column_label.setText(formatted_wine) + if self.wp_prefix_column_label is not None: + self.wp_prefix_column_label.setText(formatted_prefix) + else: + if self.wp_wine_label_card is not None: + self.wp_wine_label_card.setText(f"Wine: {formatted_wine}") + if self.wp_prefix_label_card is not None: + self.wp_prefix_label_card.setText(f"Prefix: {formatted_prefix}") + + except RuntimeError: + pass + def open_weanticheatyet_page(self): if self.anticheat_slug: url = QUrl(f"https://areweanticheatyet.com/game/{self.anticheat_slug}") @@ -1305,6 +1635,13 @@ class GameCard(AnimatedCard): def cleanup(self): """Clean up animations to prevent memory leaks when the card is destroyed.""" + if (task := getattr(self, "_wp_task", None)) is not None: + try: + task.cancel() + self._wp_task = None + except (RuntimeError, TypeError): + pass + if hasattr(self, 'coverLabel') and self.coverLabel is not None: cleanup_animated_cover(self.coverLabel) if hasattr(self, 'animations') and self.animations: diff --git a/portprotonqt/game_library_manager.py b/portprotonqt/game_library_manager.py index 424d0cdc..b723ee17 100644 --- a/portprotonqt/game_library_manager.py +++ b/portprotonqt/game_library_manager.py @@ -8,7 +8,7 @@ from portprotonqt.search_utils import ( search_index, ) from PySide6.QtWidgets import QAbstractButton -from PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel, QFrame, QScrollArea, QSlider, QScroller, QStackedWidget +from PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel, QFrame, QScrollArea, QSlider, QScroller, QStackedWidget, QSizePolicy from PySide6.QtCore import QElapsedTimer, QRect, QRectF, Qt, QTimer from PySide6.QtGui import QPaintEvent, QPainter, QPainterPath, QPixmap, QRegion from portprotonqt.custom_widgets import FlowLayout, AutoHideScrollArea @@ -18,7 +18,7 @@ from portprotonqt.localization import _ from portprotonqt.detail_pages.utils import remove_cover_background, setup_cover_background from portprotonqt.context_menu_manager import ContextMenuManager, CustomLineEdit from collections import deque - +from portprotonqt.game_card import show_wine_prefix_columns class FullLibraryTile(AnimatedCard): def __init__(self, theme: Any): @@ -101,6 +101,7 @@ class GameLibraryManager: self._incremental_scroll_delay_ms: int = 250 self._focus_first_card_after_update = False self._pending_update = False + self._wp_header_columns_visible: bool | None = None self.pending_deletions = deque() self.is_filtering = False self.dirty = False @@ -170,6 +171,9 @@ class GameLibraryManager: self.libraryHeaderWidget = self._create_library_header() layout.addWidget(self.libraryHeaderWidget) layout.addWidget(scrollArea) + if self.layout_mode == "vertical": + self._sync_header_width() + scrollArea.viewportResized.connect(self._sync_header_width) # Slider for card size sliderLayout = QHBoxLayout() @@ -222,20 +226,54 @@ class GameLibraryManager: header_layout.setContentsMargins(*config["header_margins"]) header_layout.setSpacing(config["header_spacing"]) header_layout.addSpacing(config["header_cover_width"] + config["header_spacing"]) - labels = (_("Game Title"), _("LAST LAUNCH"), _("TIME SPENT"), _("Library")) - for text, stretch in zip(labels, config["column_stretches"], strict=True): + + base_labels = (_("Game Title"), _("LAST LAUNCH"), _("TIME SPENT"), _("Library")) + base_stretches = list(config.get("column_stretches", (4, 2, 2, 2))) + + wp_visible = show_wine_prefix_columns(self.theme, self.filtered_games) + self._wp_header_columns_visible = wp_visible + for card in self.game_card_cache.values(): + card.update_wp_columns_alignment(wp_visible) + if wp_visible: + labels = base_labels + (_("WINE"), _("PREFIX")) + stretches = list(base_stretches) + while len(stretches) < len(labels): + stretches.append(2) + stretches = stretches[:len(labels)] + else: + labels = base_labels + stretches = base_stretches[:4] + + # Check WinePrefix for equality of list + if len(labels) != len(stretches): + raise ValueError("Number of marks is not equal to number of stretches") + for text, stretch in zip(labels, stretches, strict=True): label = QLabel(text.upper()) label.setAlignment( Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignLeft - if text == labels[0] else Qt.AlignmentFlag.AlignCenter + if text == base_labels[0] else Qt.AlignmentFlag.AlignCenter ) label.setProperty("theme_style_name", "LIBRARY_HEADER_LABEL_STYLE") label.setStyleSheet(self.theme.LIBRARY_HEADER_LABEL_STYLE) + label.setMinimumWidth(0) + label.setSizePolicy(QSizePolicy.Policy.Ignored, QSizePolicy.Policy.Preferred) header_layout.addWidget(label, stretch) if self.gamesScrollArea is not None: header_layout.addSpacing(self.gamesScrollArea.verticalScrollBar().sizeHint().width()) return header + def _sync_header_width(self) -> None: + """Keeps header width equal to the card area width (scrollbar included).""" + if self.libraryHeaderWidget is None or self.gamesListWidget is None: + return + width = self.gamesListWidget.width() + if self.gamesScrollArea is not None: + scrollbar = self.gamesScrollArea.verticalScrollBar() + if scrollbar.isVisible(): + width += scrollbar.sizeHint().width() + if width > 50: + self.libraryHeaderWidget.setFixedWidth(width) + def rebuild_library_layout(self, layout_mode: str) -> None: """Replace the card layout when a theme changes its library mode.""" if self.gamesListWidget is None or self.gamesListLayout is None: @@ -284,13 +322,14 @@ class GameLibraryManager: if self.full_library_open and self.libraryBackgroundLabel is not None: remove_cover_background(self.libraryBackgroundLabel) self.layout_mode = layout_mode - if ( - layout_mode == "vertical" - and self.libraryHeaderWidget is None - and self.libraryContentLayout is not None - ): + if layout_mode == "vertical" and self.libraryContentLayout is not None: + if self.libraryHeaderWidget is not None: + self.libraryHeaderWidget.setParent(None) + self.libraryHeaderWidget.deleteLater() + self.libraryHeaderWidget = None self.libraryHeaderWidget = self._create_library_header() self.libraryContentLayout.insertWidget(1, self.libraryHeaderWidget) + self._sync_header_width() if self.libraryHeaderWidget is not None: self.libraryHeaderWidget.setVisible(layout_mode == "vertical") self.gamesListWidget.setProperty("library_layout_mode", layout_mode) @@ -506,7 +545,25 @@ class GameLibraryManager: if not self._pending_update: return self._pending_update = False + old_wp_visible = self._wp_header_columns_visible + wp_visible = show_wine_prefix_columns(self.theme, self.filtered_games) + self._wp_header_columns_visible = wp_visible self._update_game_grid_immediate() + # Sync newly created cards with the current header state + for card in self.game_card_cache.values(): + card.update_wp_columns_alignment(wp_visible) + # The vertical header only when WinePrefix visibility changes + if self.layout_mode != "vertical" or self.libraryContentLayout is None: + return + if self.libraryHeaderWidget is not None and wp_visible == old_wp_visible: + return + if self.libraryHeaderWidget is not None: + self.libraryHeaderWidget.setParent(None) + self.libraryHeaderWidget.deleteLater() + self.libraryHeaderWidget = None + self.libraryHeaderWidget = self._create_library_header() + self.libraryContentLayout.insertWidget(1, self.libraryHeaderWidget) + self._sync_header_width() def update_game_grid( self, @@ -565,6 +622,7 @@ class GameLibraryManager: self.gamesListLayout.invalidate() if self.gamesListWidget: self.gamesListWidget.updateGeometry() + self._sync_header_width() def _fit_horizontal_cards(self, card: GameCard | None = None) -> None: if self.layout_mode not in {"horizontal", "horizontal_top"}: @@ -929,6 +987,7 @@ class GameLibraryManager: parent=self.gamesListWidget, context_menu_manager=self.context_menu_manager ) + card.update_wp_columns_alignment(bool(self._wp_header_columns_visible)) card.hoverChanged.connect(self._on_card_hovered) card.focusChanged.connect(self._on_card_focused) diff --git a/portprotonqt/tabs/settings_tab.py b/portprotonqt/tabs/settings_tab.py index 72d03bcd..ba7d5904 100644 --- a/portprotonqt/tabs/settings_tab.py +++ b/portprotonqt/tabs/settings_tab.py @@ -345,6 +345,24 @@ class MainWindowSettingsTabMixin(_MainWindowTypingBase): hide_cursor_layout.addStretch() uiForm.addRow(hide_cursor_layout) + self.showWinePrefixCheckBox = QCheckBox() + self.showWinePrefixCheckBox.setStyleSheet(self.theme.CHECKBOX_STYLE) + self.showWinePrefixCheckBox.setFocusPolicy(Qt.FocusPolicy.StrongFocus) + self.showWinePrefixTitle = QLabel(_("On game card wine and prefix")) + self.showWinePrefixTitle.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) + self.showWinePrefixTitle.setStyleSheet(self.theme.SETTINGS_TITLE_CHECKBOX_STYLE) + self.showWinePrefixTitle.setFocusPolicy(Qt.FocusPolicy.NoFocus) + current_show_wine_prefix = ui_config.get_show_wine_prefix_cards() + self.showWinePrefixCheckBox.setChecked(current_show_wine_prefix) + self.showWinePrefixCheckBox.clicked.connect(self._on_show_wine_prefix_changed) + + show_wine_prefix_layout = QHBoxLayout() + show_wine_prefix_layout.setContentsMargins(0, 0, 0, 0) + show_wine_prefix_layout.addWidget(self.showWinePrefixCheckBox) + show_wine_prefix_layout.addWidget(self.showWinePrefixTitle) + show_wine_prefix_layout.addStretch() + uiForm.addRow(show_wine_prefix_layout) + self.autoFullscreenGamepadCheckBox = QCheckBox() self.autoFullscreenGamepadCheckBox.setStyleSheet(self.theme.CHECKBOX_STYLE) self.autoFullscreenGamepadCheckBox.setFocusPolicy(Qt.FocusPolicy.StrongFocus) @@ -907,6 +925,10 @@ class MainWindowSettingsTabMixin(_MainWindowTypingBase): layout.addLayout(actionsLayout) self.stackedWidget.addWidget(self.portProtonWidget) + def _on_show_wine_prefix_changed(self, checked: bool) -> None: + """Handle show wine/prefix checkbox toggle.""" + pass + def openGlobalGameSettings(self) -> None: from portprotonqt.dialogs.settings_dialog import ExeSettingsDialog @@ -1093,6 +1115,13 @@ class MainWindowSettingsTabMixin(_MainWindowTypingBase): display_config.set_auto_fullscreen_gamepad(auto_fullscreen_gamepad) display_config.set_boot_animation_enabled(not self.disableBootAnimationCheckBox.isChecked()) + # Save show WinePrefix setting from checkbox state + show_wine_prefix = self.showWinePrefixCheckBox.isChecked() + ui_config.set_show_wine_prefix_cards(show_wine_prefix) + + if hasattr(self, "game_library_manager") and self.game_library_manager is not None: + self.game_library_manager.rebuild_library_layout(self.game_library_manager.layout_mode) + hide_control_hints = self.hideControlHintsCheckBox.isChecked() ui_config.set_hide_control_hints(hide_control_hints) force_english = self.forceEnglishCheckBox.isChecked() @@ -1164,9 +1193,9 @@ class MainWindowSettingsTabMixin(_MainWindowTypingBase): self.keyboard.update_keyboard() if economy_mode_changed: - if self.game_library_manager.gamesListLayout is not None: + if self.game_library_manager is not None and self.game_library_manager.gamesListLayout is not None: self.game_library_manager.clear_layout(self.game_library_manager.gamesListLayout) - else: + elif self.game_library_manager is not None: display_filter = game_config.get_display_filter() for card in self.game_library_manager.game_card_cache.values(): card.update_badge_visibility(display_filter) diff --git a/portprotonqt/themes/standart-light/styles.py b/portprotonqt/themes/standart-light/styles.py index 2a865ff9..7a13077c 100644 --- a/portprotonqt/themes/standart-light/styles.py +++ b/portprotonqt/themes/standart-light/styles.py @@ -397,7 +397,25 @@ MAIN_WINDOW_STYLE = f""" background-color: {color_accent}; }} """ - +# GAME CARD STYLE WinePrefix Badge Container +GAME_CARD_WINE_PREFIX_CONTAINER_STYLE = f""" + QFrame {{ + background: {color_surface_elevated}; + border-radius: {border_radius_small}; + border: {border_none} {color_transparent}; + }} +""" +# GAME CARD STYLE WinePrefix +GAME_CARD_WINE_PREFIX_LOADING_STYLE = f""" + QLabel {{ + color: {color_text_dark}; + font-family: '{font_family}'; + font-size: 13px; + background: {color_transparent}; + qproperty-alignment: 'AlignLeft | AlignVCenter'; + qproperty-wordWrap: false; + }} +""" # Favorite Star FAVORITE_LABEL_STYLE = f"color: {color_favorite_star}; font-size: 32px; background: {color_transparent};" @@ -799,8 +817,12 @@ GAME_CARD_NAME_LABEL_STYLE = f""" }} """ -GAME_CARD_VERTICAL_NAME_STYLE = GAME_CARD_NAME_LABEL_STYLE - +GAME_CARD_VERTICAL_NAME_STYLE = f""" + {GAME_CARD_NAME_LABEL_STYLE} + QLabel {{ + background-color: {color_transparent}; + }} +""" GAME_CARD_COLUMN_LABEL_STYLE = f""" QLabel {{ color: {color_text_dark}; diff --git a/portprotonqt/themes/standart/styles/constants.py b/portprotonqt/themes/standart/styles/constants.py index 2b8ff901..4b4605e9 100644 --- a/portprotonqt/themes/standart/styles/constants.py +++ b/portprotonqt/themes/standart/styles/constants.py @@ -32,6 +32,10 @@ fullLibraryTileSize = (180, 180) fullLibraryTileColumns = 2 fullLibraryTileRows = 2 fullLibraryTileRadius = 10 +# WinePrefix constants +wine_prefix_margin = (8, 4, 6, 4) +wine_prefix_spacing = 1 +WINE_PREFIX_CARD_HEIGHT = 0.10 GAME_CARD_LIST = { "extra_margin": 8, "spacing": 12, @@ -71,7 +75,7 @@ GAME_CARD_VERTICAL = { "header_margins": (4, 0, 4, 0), "header_spacing": 12, "header_cover_width": 66, - "column_stretches": (4, 2, 2, 2), + "column_stretches": (4, 2, 2, 2, 2, 2), } downloadsSummaryHeight = 96 downloadsTableHeaderHeight = 38 diff --git a/portprotonqt/themes/standart/styles/game_card.py b/portprotonqt/themes/standart/styles/game_card.py index a547d21d..d0f99d96 100644 --- a/portprotonqt/themes/standart/styles/game_card.py +++ b/portprotonqt/themes/standart/styles/game_card.py @@ -1,5 +1,25 @@ from .constants import * - +# GAME CARD STYLE WinePrefix Badge Container +GAME_CARD_WINE_PREFIX_CONTAINER_STYLE = f""" + QFrame {{ + background: {color_detail_overlay}; + border-radius: {border_radius_small}; + border: {border_none} {color_transparent}; + margin-top: 4px; + margin-bottom: 2px; + }} +""" +# GAME CARD STYLE WinePrefix +GAME_CARD_WINE_PREFIX_LOADING_STYLE = f""" + QLabel {{ + color: {color_text_muted}; + font-family: '{font_family}'; + font-size: 12px; + background: {color_transparent}; + qproperty-alignment: 'AlignLeft | AlignVCenter'; + qproperty-wordWrap: false; + }} +""" # GAME CARD STYLE (GAMECARD) GAME_CARD_WINDOW_STYLE = f""" QFrame {{ @@ -28,7 +48,12 @@ GAME_CARD_NAME_LABEL_STYLE = f""" }} """ -GAME_CARD_VERTICAL_NAME_STYLE = GAME_CARD_NAME_LABEL_STYLE +GAME_CARD_VERTICAL_NAME_STYLE = f""" + {GAME_CARD_NAME_LABEL_STYLE} + QLabel {{ + background-color: {color_transparent}; + }} +""" GAME_CARD_COLUMN_LABEL_STYLE = f""" QLabel {{