diff --git a/portprotonqt/game_library_manager.py b/portprotonqt/game_library_manager.py index 3668f92..e10d502 100644 --- a/portprotonqt/game_library_manager.py +++ b/portprotonqt/game_library_manager.py @@ -56,6 +56,16 @@ class GameLibraryManager: self.is_filtering = False self.dirty = False + def force_update_cards_library(self): + if self.gamesListWidget and self.gamesListLayout: + self.gamesListLayout.invalidate() + self.gamesListWidget.updateGeometry() + widget = self.gamesListWidget + QTimer.singleShot(0, lambda: ( + widget.adjustSize(), + widget.updateGeometry() + )) + def create_games_library_widget(self): """Creates the games library widget with search, grid, and slider.""" self.gamesLibraryWidget = QWidget() @@ -346,6 +356,8 @@ class GameLibraryManager: self.gamesListWidget.updateGeometry() self.main_window._last_card_width = self.card_width + self.force_update_cards_library() + self.is_filtering = False # Reset flag in any case def _apply_filter_visibility(self, search_text: str): @@ -453,11 +465,3 @@ class GameLibraryManager: def filter_games_delayed(self): """Filters games based on search text and updates the grid.""" self.update_game_grid(is_filter=True) - - def calculate_columns(self, card_width: int) -> int: - """Calculate the number of columns based on card width and assumed container width.""" - # Assuming a typical container width; adjust as needed - available_width = 1200 # Example width, can be dynamic if widget access is added - spacing = 15 # Assumed spacing between cards - columns = max(1, (available_width - spacing) // (card_width + spacing)) - return min(columns, 8) # Cap at reasonable max diff --git a/portprotonqt/main_window.py b/portprotonqt/main_window.py index 3e8da83..7b48fca 100644 --- a/portprotonqt/main_window.py +++ b/portprotonqt/main_window.py @@ -100,6 +100,7 @@ class MainWindow(QMainWindow): self.games_load_timer.timeout.connect(self.finalize_game_loading) self.games_loaded.connect(self.on_games_loaded) self.current_add_game_dialog = None + self.current_display_filter = read_display_filter() self.settingsDebounceTimer = QTimer(self) self.settingsDebounceTimer.setSingleShot(True) @@ -820,6 +821,24 @@ class MainWindow(QMainWindow): for i, btn in self.tabButtons.items(): btn.setChecked(i == index) self.stackedWidget.setCurrentIndex(index) + if hasattr(self, "game_library_manager"): + mgr = self.game_library_manager + if mgr.gamesListWidget and mgr.gamesListLayout: + layout = mgr.gamesListLayout + widget = mgr.gamesListWidget + QTimer.singleShot(0, lambda: ( + layout.invalidate(), + widget.adjustSize(), + widget.updateGeometry() + )) + if hasattr(self, "autoInstallContainer") and hasattr(self, "autoInstallContainerLayout"): + layout = self.autoInstallContainerLayout + widget = self.autoInstallContainer + QTimer.singleShot(0, lambda: ( + layout.invalidate(), + widget.adjustSize(), + widget.updateGeometry() + )) def openSystemOverlay(self): """Opens the system overlay dialog.""" @@ -1978,9 +1997,12 @@ class MainWindow(QMainWindow): def applySettingsDelayed(self): read_time_config() - self.games = [] - self.loadGames() display_filter = read_display_filter() + reload_needed = display_filter != self.current_display_filter + if reload_needed: + self.games = [] + self.loadGames() + self.current_display_filter = display_filter for card in self.game_library_manager.game_card_cache.values(): card.update_badge_visibility(display_filter) @@ -1995,6 +2017,10 @@ class MainWindow(QMainWindow): filter_idx = self.gamesDisplayCombo.currentIndex() filter_key = self.filter_keys[filter_idx] + + old_filter = self.current_display_filter + save_display_filter(filter_key) + save_display_filter(filter_key) proxy_url = self.proxyUrlEdit.text().strip() @@ -2011,17 +2037,19 @@ class MainWindow(QMainWindow): rumble_enabled = self.gamepadRumbleCheckBox.isChecked() save_rumble_config(rumble_enabled) - for card in self.game_library_manager.game_card_cache.values(): - card.update_badge_visibility(filter_key) + if filter_key != old_filter: + for card in self.game_library_manager.game_card_cache.values(): + card.update_badge_visibility(filter_key) - if self.currentDetailPage and self.current_exec_line: - current_game = next((game for game in self.games if game[4] == self.current_exec_line), None) - if current_game: - self.stackedWidget.removeWidget(self.currentDetailPage) - self.currentDetailPage.deleteLater() - self.currentDetailPage = None - self.openGameDetailPage(*current_game) + if self.currentDetailPage and self.current_exec_line: + current_game = next((game for game in self.games if game[4] == self.current_exec_line), None) + if current_game: + self.stackedWidget.removeWidget(self.currentDetailPage) + self.currentDetailPage.deleteLater() + self.currentDetailPage = None + self.openGameDetailPage(*current_game) + self.current_display_filter = filter_key self.settingsDebounceTimer.start() gamepad_connected = self.input_manager.find_gamepad() is not None