T-572 修复封面画廊方向键焦点
This commit is contained in:
+28
-10
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtCore import QEvent
|
||||
|
||||
from ..models import GenerateTaskTableModel
|
||||
from ..widgets import *
|
||||
from ..workers import GenerateWorker as _RealGenerateWorker
|
||||
@@ -148,6 +150,7 @@ class CoverGalleryDialog(QDialog):
|
||||
self._update_navigation_buttons()
|
||||
self._update_regenerate_button_state()
|
||||
self._fit_to_screen()
|
||||
self._install_navigation_event_filters()
|
||||
|
||||
def _old_cover_panel(self):
|
||||
panel = QWidget()
|
||||
@@ -458,24 +461,34 @@ class CoverGalleryDialog(QDialog):
|
||||
event.ignore()
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if event.key() == Qt.Key_Up and self._should_consume_navigation_key():
|
||||
self.switch_task(-1)
|
||||
event.accept()
|
||||
return
|
||||
if event.key() == Qt.Key_Down and self._should_consume_navigation_key():
|
||||
self.switch_task(1)
|
||||
event.accept()
|
||||
if self._handle_navigation_key(event, QApplication.focusWidget()):
|
||||
return
|
||||
super().keyPressEvent(event)
|
||||
|
||||
def _should_consume_navigation_key(self):
|
||||
focus = QApplication.focusWidget()
|
||||
def eventFilter(self, watched, event):
|
||||
focus = QApplication.focusWidget() if watched is self else watched
|
||||
if event.type() == QEvent.KeyPress and self._handle_navigation_key(event, focus):
|
||||
return True
|
||||
return super().eventFilter(watched, event)
|
||||
|
||||
def _handle_navigation_key(self, event, focus):
|
||||
if event.key() == Qt.Key_Up and self._should_consume_navigation_key(focus):
|
||||
self.switch_task(-1)
|
||||
event.accept()
|
||||
return True
|
||||
if event.key() == Qt.Key_Down and self._should_consume_navigation_key(focus):
|
||||
self.switch_task(1)
|
||||
event.accept()
|
||||
return True
|
||||
return False
|
||||
|
||||
def _should_consume_navigation_key(self, focus=None):
|
||||
focus = focus or QApplication.focusWidget()
|
||||
if focus is None or focus is self:
|
||||
return True
|
||||
return not isinstance(
|
||||
focus,
|
||||
(
|
||||
QPushButton,
|
||||
QLineEdit,
|
||||
QPlainTextEdit,
|
||||
QComboBox,
|
||||
@@ -483,6 +496,10 @@ class CoverGalleryDialog(QDialog):
|
||||
),
|
||||
)
|
||||
|
||||
def _install_navigation_event_filters(self):
|
||||
for widget in [self] + self.findChildren(QWidget):
|
||||
widget.installEventFilter(self)
|
||||
|
||||
def open_original_image(self, image_path):
|
||||
dialog = OriginalImageDialog(image_path, self)
|
||||
dialog.exec()
|
||||
@@ -543,6 +560,7 @@ class CoverGalleryDialog(QDialog):
|
||||
empty_label.setMinimumSize(320, self.THUMBNAIL_SIZE)
|
||||
empty_label.setAlignment(Qt.AlignCenter)
|
||||
self.candidate_layout.addWidget(empty_label)
|
||||
self._install_navigation_event_filters()
|
||||
|
||||
def _on_regenerate_progress(self, payload):
|
||||
if payload.get("failed"):
|
||||
|
||||
Reference in New Issue
Block a user