3 Commits

Author SHA1 Message Date
0b45ba963a chore(changelog): update
All checks were successful
Code and build check / Check code (push) Successful in 1m22s
Code and build check / Build with uv (push) Successful in 56s
Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
2025-06-14 11:51:04 +05:00
7becbf5de2 feat(input_manager): added change slider size to RT and LT
Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
2025-06-14 11:49:28 +05:00
66b4b82d49 feat: change game card size only on slider released
Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
2025-06-14 11:14:22 +05:00
5 changed files with 128 additions and 46 deletions

View File

@@ -47,6 +47,8 @@
- Кнопка добавления игры больше не фокусируется - Кнопка добавления игры больше не фокусируется
- Диалог добавления игры теперь открывается только в библиотеке - Диалог добавления игры теперь открывается только в библиотеке
- Удалены все упоминания PortProtonQT из кода и заменены на PortProtonQt - Удалены все упоминания PortProtonQT из кода и заменены на PortProtonQt
- Размер карточек теперь меняется только при отпускании слайдера
- Слайдер теперь управляется через тригеры на геймпаде
### Fixed ### Fixed
- Возврат к теме «standard» при выборе несуществующей темы - Возврат к теме «standard» при выборе несуществующей темы

View File

@@ -1,5 +1,5 @@
import numpy as np import numpy as np
from PySide6.QtWidgets import QLabel, QPushButton, QWidget, QLayout, QStyleOption, QLayoutItem from PySide6.QtWidgets import QLabel, QPushButton, QWidget, QLayout, QLayoutItem
from PySide6.QtCore import Qt, Signal, QRect, QPoint, QSize from PySide6.QtCore import Qt, Signal, QRect, QPoint, QSize
from PySide6.QtGui import QFont, QFontMetrics, QPainter from PySide6.QtGui import QFont, QFontMetrics, QPainter
@@ -133,18 +133,7 @@ class FlowLayout(QLayout):
class ClickableLabel(QLabel): class ClickableLabel(QLabel):
clicked = Signal() clicked = Signal()
def __init__(self, *args, icon=None, icon_size=16, icon_space=5, change_cursor=True, **kwargs): def __init__(self, *args, icon=None, icon_size=16, icon_space=5, change_cursor=True, font_scale_factor=0.06, **kwargs):
"""
Поддерживаются вызовы:
- ClickableLabel("текст", parent=...) первый аргумент строка,
- ClickableLabel(parent, text="...") если первым аргументом передается родитель.
Аргументы:
icon: QIcon или None иконка, которая будет отрисована вместе с текстом.
icon_size: int размер иконки (ширина и высота).
icon_space: int отступ между иконкой и текстом.
change_cursor: bool изменять ли курсор на PointingHandCursor при наведении (по умолчанию True).
"""
if args and isinstance(args[0], str): if args and isinstance(args[0], str):
text = args[0] text = args[0]
parent = kwargs.get("parent", None) parent = kwargs.get("parent", None)
@@ -162,20 +151,38 @@ class ClickableLabel(QLabel):
self._icon = icon self._icon = icon
self._icon_size = icon_size self._icon_size = icon_size
self._icon_space = icon_space self._icon_space = icon_space
self._font_scale_factor = font_scale_factor
self._card_width = 250 # Значение по умолчанию
if change_cursor: if change_cursor:
self.setCursor(Qt.CursorShape.PointingHandCursor) self.setCursor(Qt.CursorShape.PointingHandCursor)
self.updateFontSize()
def setIcon(self, icon): def setIcon(self, icon):
"""Устанавливает иконку и перерисовывает виджет."""
self._icon = icon self._icon = icon
self.update() self.update()
def icon(self): def icon(self):
"""Возвращает текущую иконку."""
return self._icon return self._icon
def setIconSize(self, icon_size: int, icon_space: int):
self._icon_size = icon_size
self._icon_space = icon_space
self.update()
def setCardWidth(self, card_width: int):
"""Обновляет ширину карточки и пересчитывает размер шрифта."""
self._card_width = card_width
self.updateFontSize()
def updateFontSize(self):
"""Обновляет размер шрифта на основе card_width и font_scale_factor."""
font = self.font()
font_size = int(self._card_width * self._font_scale_factor)
font.setPointSize(max(8, font_size)) # Минимальный размер шрифта 8
self.setFont(font)
self.update()
def paintEvent(self, event): def paintEvent(self, event):
"""Переопределяем отрисовку: рисуем иконку и текст в одном лейбле."""
painter = QPainter(self) painter = QPainter(self)
painter.setRenderHint(QPainter.RenderHint.Antialiasing) painter.setRenderHint(QPainter.RenderHint.Antialiasing)
@@ -190,7 +197,6 @@ class ClickableLabel(QLabel):
text = self.text() text = self.text()
if self._icon: if self._icon:
# Получаем QPixmap нужного размера
pixmap = self._icon.pixmap(icon_size, icon_size) pixmap = self._icon.pixmap(icon_size, icon_size)
icon_rect = QRect(0, 0, icon_size, icon_size) icon_rect = QRect(0, 0, icon_size, icon_size)
icon_rect.moveTop(rect.top() + (rect.height() - icon_size) // 2) icon_rect.moveTop(rect.top() + (rect.height() - icon_size) // 2)
@@ -214,13 +220,8 @@ class ClickableLabel(QLabel):
if pixmap: if pixmap:
icon_rect.moveLeft(x) icon_rect.moveLeft(x)
text_rect = QRect(x + icon_size + spacing, y, text_width, text_height) text_rect = QRect(x + icon_size + spacing, y, text_width, text_height)
else:
text_rect = QRect(x, y, text_width, text_height)
option = QStyleOption()
option.initFrom(self)
if pixmap:
painter.drawPixmap(icon_rect, pixmap) painter.drawPixmap(icon_rect, pixmap)
self.style().drawItemText( self.style().drawItemText(
painter, painter,
text_rect, text_rect,

View File

@@ -255,6 +255,42 @@ class GameCard(QFrame):
nameLabel.setStyleSheet(self.theme.GAME_CARD_NAME_LABEL_STYLE) nameLabel.setStyleSheet(self.theme.GAME_CARD_NAME_LABEL_STYLE)
layout.addWidget(nameLabel) layout.addWidget(nameLabel)
def update_card_size(self, new_width: int):
self.card_width = new_width
extra_margin = 20
self.setFixedSize(new_width + extra_margin, int(new_width * 1.6) + extra_margin)
if self.coverLabel is None:
return
coverWidget = self.coverLabel.parentWidget()
if coverWidget is None:
return
coverWidget.setFixedSize(new_width, int(new_width * 1.2))
self.coverLabel.setFixedSize(new_width, int(new_width * 1.2))
label_ref = weakref.ref(self.coverLabel)
def on_cover_loaded(pixmap):
label = label_ref()
if label:
scaled_pixmap = pixmap.scaled(new_width, int(new_width * 1.2), Qt.AspectRatioMode.KeepAspectRatioByExpanding, Qt.TransformationMode.SmoothTransformation)
rounded_pixmap = round_corners(scaled_pixmap, 15)
label.setPixmap(rounded_pixmap)
load_pixmap_async(self.cover_path or "", new_width, int(new_width * 1.2), on_cover_loaded)
badge_width = int(new_width * 2/3)
icon_size = int(new_width * 0.06)
icon_space = int(new_width * 0.012)
for label in [self.steamLabel, self.egsLabel, self.portprotonLabel, self.protondbLabel, self.anticheatLabel]:
if label is not None:
label.setFixedWidth(badge_width)
label.setIconSize(icon_size, icon_space)
label.setCardWidth(new_width)
self.update()
def update_badge_visibility(self, display_filter: str): def update_badge_visibility(self, display_filter: str):
"""Update badge visibility based on the provided display_filter.""" """Update badge visibility based on the provided display_filter."""
self.display_filter = display_filter self.display_filter = display_filter

View File

@@ -27,6 +27,8 @@ class MainWindowProtocol(Protocol):
... ...
def openSystemOverlay(self) -> None: def openSystemOverlay(self) -> None:
... ...
def on_slider_released(self) -> None:
...
stackedWidget: QStackedWidget stackedWidget: QStackedWidget
tabButtons: dict[int, QWidget] tabButtons: dict[int, QWidget]
gamesListWidget: QWidget gamesListWidget: QWidget
@@ -34,18 +36,20 @@ class MainWindowProtocol(Protocol):
current_exec_line: str | None current_exec_line: str | None
current_add_game_dialog: QDialog | None current_add_game_dialog: QDialog | None
# Mapping of actions to evdev button codes, includes Xbox and Playstation controllers # Mapping of actions to evdev button codes, includes Xbox and PlayStation controllers
# https://github.com/torvalds/linux/blob/master/drivers/hid/hid-playstation.c # https://github.com/torvalds/linux/blob/master/drivers/hid/hid-playstation.c
# https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c # https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c
BUTTONS = { BUTTONS = {
'confirm': {ecodes.BTN_A, ecodes.BTN_SOUTH}, # A / Cross 'confirm': {ecodes.BTN_A, ecodes.BTN_SOUTH}, # A (Xbox) / Cross (PS)
'back': {ecodes.BTN_B, ecodes.BTN_EAST}, # B / Circle 'back': {ecodes.BTN_B, ecodes.BTN_EAST}, # B (Xbox) / Circle (PS)
'add_game': {ecodes.BTN_Y, ecodes.BTN_NORTH}, # Y / Triangle 'add_game': {ecodes.BTN_Y, ecodes.BTN_NORTH}, # Y (Xbox) / Triangle (PS)
'prev_tab': {ecodes.BTN_TL}, # LB / L1 'prev_tab': {ecodes.BTN_TL}, # LB (Xbox) / L1 (PS)
'next_tab': {ecodes.BTN_TR}, # RB / R1 'next_tab': {ecodes.BTN_TR}, # RB (Xbox) / R1 (PS)
'context_menu': {ecodes.BTN_START}, # Start / Options 'context_menu': {ecodes.BTN_START}, # Start (Xbox) / Options (PS)
'menu': {ecodes.BTN_SELECT}, # Select / Share 'menu': {ecodes.BTN_SELECT}, # Select (Xbox) / Share (PS)
'guide': {ecodes.BTN_MODE}, # Xbox / PS Home 'guide': {ecodes.BTN_MODE}, # Xbox Button / PS Button
'increase_size': {ecodes.ABS_RZ}, # RT (Xbox) / R2 (PS)
'decrease_size': {ecodes.ABS_Z}, # LT (Xbox) / L2 (PS)
} }
class InputManager(QObject): class InputManager(QObject):
@@ -83,6 +87,10 @@ class InputManager(QObject):
self.running = True self.running = True
self._is_fullscreen = read_fullscreen_config() self._is_fullscreen = read_fullscreen_config()
self.rumble_effect_id: int | None = None # Store the rumble effect ID self.rumble_effect_id: int | None = None # Store the rumble effect ID
self.lt_pressed = False
self.rt_pressed = False
self.last_trigger_time = 0.0
self.trigger_cooldown = 0.2
# Add variables for continuous D-pad movement # Add variables for continuous D-pad movement
self.dpad_timer = QTimer(self) self.dpad_timer = QTimer(self)
@@ -169,7 +177,7 @@ class InputManager(QObject):
@Slot(int) @Slot(int)
def handle_button_slot(self, button_code: int) -> None: def handle_button_slot(self, button_code: int) -> None:
try: try:
# Игнорировать события геймпада, если игра запущена # Ignore gamepad events if a game is launched
if getattr(self._parent, '_gameLaunched', False): if getattr(self._parent, '_gameLaunched', False):
return return
@@ -235,7 +243,7 @@ class InputManager(QObject):
focused.clearSelection() focused.clearSelection()
focused.hide() focused.hide()
# Закрытие AddGameDialog на кнопку B # Close AddGameDialog on B button
if button_code in BUTTONS['back'] and isinstance(active, QDialog): if button_code in BUTTONS['back'] and isinstance(active, QDialog):
active.reject() active.reject()
return return
@@ -282,6 +290,20 @@ class InputManager(QObject):
idx = (self._parent.stackedWidget.currentIndex() + 1) % len(self._parent.tabButtons) idx = (self._parent.stackedWidget.currentIndex() + 1) % len(self._parent.tabButtons)
self._parent.switchTab(idx) self._parent.switchTab(idx)
self._parent.tabButtons[idx].setFocus(Qt.FocusReason.OtherFocusReason) self._parent.tabButtons[idx].setFocus(Qt.FocusReason.OtherFocusReason)
elif button_code in BUTTONS['increase_size'] and self._parent.stackedWidget.currentIndex() == 0:
# Increase card size with RT (Xbox) / R2 (PS)
size_slider = getattr(self._parent, 'sizeSlider', None)
if size_slider:
new_value = min(size_slider.value() + 10, size_slider.maximum())
size_slider.setValue(new_value)
self._parent.on_slider_released()
elif button_code in BUTTONS['decrease_size'] and self._parent.stackedWidget.currentIndex() == 0:
# Decrease card size with LT (Xbox) / L2 (PS)
size_slider = getattr(self._parent, 'sizeSlider', None)
if size_slider:
new_value = max(size_slider.value() - 10, size_slider.minimum())
size_slider.setValue(new_value)
self._parent.on_slider_released()
except Exception as e: except Exception as e:
logger.error(f"Error in handle_button_slot: {e}", exc_info=True) logger.error(f"Error in handle_button_slot: {e}", exc_info=True)
@@ -297,7 +319,7 @@ class InputManager(QObject):
@Slot(int, int, float) @Slot(int, int, float)
def handle_dpad_slot(self, code: int, value: int, current_time: float) -> None: def handle_dpad_slot(self, code: int, value: int, current_time: float) -> None:
try: try:
# Игнорировать события геймпада, если игра запущена # Ignore gamepad events if a game is launched
if getattr(self._parent, '_gameLaunched', False): if getattr(self._parent, '_gameLaunched', False):
return return
@@ -698,9 +720,9 @@ class InputManager(QObject):
self.gamepad_thread.join() self.gamepad_thread.join()
self.gamepad_thread = threading.Thread(target=self.monitor_gamepad, daemon=True) self.gamepad_thread = threading.Thread(target=self.monitor_gamepad, daemon=True)
self.gamepad_thread.start() self.gamepad_thread.start()
# Отправляем сигнал для полноэкранного режима только если: # Send signal for fullscreen mode only if:
# 1. auto_fullscreen_gamepad включено # 1. auto_fullscreen_gamepad is enabled
# 2. fullscreen выключено (чтобы не конфликтовать с основной настройкой) # 2. fullscreen is not already enabled (to avoid conflict)
if read_auto_fullscreen_gamepad() and not read_fullscreen_config(): if read_auto_fullscreen_gamepad() and not read_fullscreen_config():
self.toggle_fullscreen.emit(True) self.toggle_fullscreen.emit(True)
except Exception as e: except Exception as e:
@@ -734,6 +756,25 @@ class InputManager(QObject):
else: else:
self.button_pressed.emit(event.code) self.button_pressed.emit(event.code)
elif event.type == ecodes.EV_ABS: elif event.type == ecodes.EV_ABS:
if event.code in {ecodes.ABS_Z, ecodes.ABS_RZ}:
# Проверяем, достаточно ли времени прошло с последнего срабатывания
if now - self.last_trigger_time < self.trigger_cooldown:
continue
if event.code == ecodes.ABS_Z: # LT/L2
if event.value > 128 and not self.lt_pressed:
self.lt_pressed = True
self.button_pressed.emit(event.code)
self.last_trigger_time = now
elif event.value <= 128 and self.lt_pressed:
self.lt_pressed = False
elif event.code == ecodes.ABS_RZ: # RT/R2
if event.value > 128 and not self.rt_pressed:
self.rt_pressed = True
self.button_pressed.emit(event.code)
self.last_trigger_time = now
elif event.value <= 128 and self.rt_pressed:
self.rt_pressed = False
else:
self.dpad_moved.emit(event.code, event.value, now) self.dpad_moved.emit(event.code, event.value, now)
except OSError as e: except OSError as e:
if e.errno == 19: # ENODEV: No such device if e.errno == 19: # ENODEV: No such device

View File

@@ -535,10 +535,12 @@ class MainWindow(QMainWindow):
def startSearchDebounce(self, text): def startSearchDebounce(self, text):
self.searchDebounceTimer.start() self.searchDebounceTimer.start()
def on_slider_value_changed(self, value: int): def on_slider_released(self):
self.card_width = value self.card_width = self.sizeSlider.value()
self.sizeSlider.setToolTip(f"{value} px") self.sizeSlider.setToolTip(f"{self.card_width} px")
save_card_size(value) save_card_size(self.card_width)
for card in self.game_card_cache.values():
card.update_card_size(self.card_width)
self.updateGameGrid() self.updateGameGrid()
def filterGamesDelayed(self): def filterGamesDelayed(self):
@@ -581,7 +583,7 @@ class MainWindow(QMainWindow):
self.sizeSlider.setFixedWidth(150) self.sizeSlider.setFixedWidth(150)
self.sizeSlider.setToolTip(f"{self.card_width} px") self.sizeSlider.setToolTip(f"{self.card_width} px")
self.sizeSlider.setStyleSheet(self.theme.SLIDER_SIZE_STYLE) self.sizeSlider.setStyleSheet(self.theme.SLIDER_SIZE_STYLE)
self.sizeSlider.valueChanged.connect(self.on_slider_value_changed) self.sizeSlider.sliderReleased.connect(self.on_slider_released)
sliderLayout.addWidget(self.sizeSlider) sliderLayout.addWidget(self.sizeSlider)
layout.addLayout(sliderLayout) layout.addLayout(sliderLayout)