The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
feat(task): 点名称打开文件,点信息行看详情
XiaoYouChR950c08cc7609
diff --git a/app/view/cards/task_cards.py b/app/view/cards/task_cards.pyindex 9c16f210..f44d15ee 100644--- a/app/view/cards/task_cards.py+++ b/app/view/cards/task_cards.py@@ -5,9 +5,9 @@ from datetime import datetimefrom collections.abc import Callablefrom typing import TYPE_CHECKING-from PySide6.QtCore import QFileInfo, QPoint, QRectF, Signal, Qt, QT_TRANSLATE_NOOP as N+from PySide6.QtCore import QFileInfo, QPoint, QRect, QRectF, Signal, Qt, QT_TRANSLATE_NOOP as Nfrom PySide6.QtGui import QColor, QIcon, QPainter, QPen-from PySide6.QtWidgets import QFileIconProvider, QHBoxLayout, QVBoxLayout, QApplication, QWidget, QSizePolicy+from PySide6.QtWidgets import QFileIconProvider, QHBoxLayout, QLabel, QVBoxLayout, QApplication, QWidget, QSizePolicyfrom qfluentwidgets import (Action, CardWidget, CheckBox, FluentIcon, ImageLabel,IndeterminateProgressBar, PrimaryToolButton, ProgressBar, ProgressRing,@@ -211,6 +211,8 @@ class TaskCard(CardWidget):return bardef _initWidget(self) -> None:+ for widget in (self, self.nameLabel, self.statusLabel, *(getattr(self, f"{f.name}Label") for f in self.infoFields)):+ widget.setMouseTracking(True)self.iconLabel.setFixedSize(48, 48)self.checkBox.setFixedSize(23, 23)self.checkBox.setVisible(False)@@ -472,7 +474,24 @@ class TaskCard(CardWidget):self._isDragPending = Trueself._dragStartPos = e.position().toPoint()+ def _matchNameText(self, pos: QPoint) -> bool:+ if self._isSelectionMode or not self.openFileButton.isEnabled():+ return False+ label = self.nameLabel+ textWidth = label.fontMetrics().horizontalAdvance(QLabel.text(label))+ return QRect(label.x() + label.indent(), label.y(), textWidth, label.height()).contains(pos)++ def _matchInfoText(self, pos: QPoint) -> bool:+ if self._isSelectionMode:+ return False+ labels = [getattr(self, f"{f.name}Label") for f in self.infoFields] + [self.statusLabel]+ return any(label.isVisible() and label.geometry().contains(pos) for label in labels)+def mouseMoveEvent(self, e) -> None:+ if not e.buttons():+ pos = e.position().toPoint()+ isLink = self._matchNameText(pos) or self._matchInfoText(pos)+ self.setCursor(Qt.CursorShape.PointingHandCursor if isLink else Qt.CursorShape.ArrowCursor)if self._isDragPending:if (e.position().toPoint() - self._dragStartPos).manhattanLength() >= QApplication.startDragDistance():self._isDragPending = False@@ -484,8 +503,15 @@ class TaskCard(CardWidget):def mouseReleaseEvent(self, e) -> None:self._isDragPending = Falsesuper().mouseReleaseEvent(e)- if e.button() == Qt.MouseButton.LeftButton and not self._hasDragged:- extend = bool(e.modifiers() & Qt.KeyboardModifier.ShiftModifier)+ if e.button() != Qt.MouseButton.LeftButton or self._hasDragged:+ return+ pos = e.position().toPoint()+ extend = bool(e.modifiers() & Qt.KeyboardModifier.ShiftModifier)+ if not extend and self._matchNameText(pos):+ openFile(self._task.outputPath)+ elif not extend and self._matchInfoText(pos):+ self._openDrawer()+ else:checked = True if extend or not self._isSelectionMode else not self.isChecked()self.selectionChanged.emit(checked, extend)diff --git a/tests/test_task_card_links.py b/tests/test_task_card_links.pynew file mode 100644index 00000000..d7b5d005--- /dev/null+++ b/tests/test_task_card_links.py@@ -0,0 +1,117 @@+"""TaskCard 的名称和信息行热区。++Seam: TaskCard 鼠标事件(qtbot 真实点击)+"""+from __future__ import annotations++import pytest+from PySide6.QtCore import QPoint, Qt++from app.models.task import TaskStatus+from app.signal import Signal+from tests.test_task_service import makeTask+++class FakeTaskService:+ def checksumProgress(self, task):+ return None+++class FakeCategoryService:+ categoriesChanged = Signal()++ def categoryById(self, categoryId):+ return None+++def card(qtbot, monkeypatch, tmp_path):+ from app.view.cards import task_cards+ opened: list[str] = []+ monkeypatch.setattr(task_cards, "openFile", opened.append)+ task = makeTask(name="movie.mp4")+ task.outputFolder = tmp_path+ (tmp_path / "movie.mp4").write_bytes(b"x")+ task.steps[0].progress = 100+ task.setStatus(TaskStatus.COMPLETED)+ widget = task_cards.TaskCard(task, FakeTaskService(), None, FakeCategoryService())+ widget.drawers = []+ monkeypatch.setattr(widget, "_openDrawer", lambda: widget.drawers.append(task.taskId))+ widget.opened = opened+ qtbot.addWidget(widget)+ widget.resize(800, widget.ROW_HEIGHT)+ widget.show()+ widget.refresh(force=True)+ qtbot.waitExposed(widget)+ return widget+++def namePos(card) -> QPoint:+ return card.nameLabel.geometry().topLeft() + QPoint(card.nameLabel.indent() + 5, card.nameLabel.height() // 2)+++def blankNamePos(card) -> QPoint:+ return card.nameLabel.geometry().topRight() + QPoint(-5, card.nameLabel.height() // 2)+++def infoPos(card) -> QPoint:+ return card.statusLabel.geometry().center()+++def test_click_name_text_opens_file(card, qtbot):+ qtbot.mouseClick(card, Qt.MouseButton.LeftButton, pos=namePos(card))++ assert card.opened == [card.task.outputPath]+++def test_click_blank_after_name_selects_instead(card, qtbot):+ with qtbot.waitSignal(card.selectionChanged, timeout=1000):+ qtbot.mouseClick(card, Qt.MouseButton.LeftButton, pos=blankNamePos(card))++ assert card.opened == []+++def test_click_info_opens_drawer_without_selecting(card, qtbot):+ with qtbot.assertNotEmitted(card.selectionChanged):+ qtbot.mouseClick(card, Qt.MouseButton.LeftButton, pos=infoPos(card))++ assert card.drawers == [card.task.taskId]+++def test_shift_click_on_name_extends_selection(card, qtbot):+ with qtbot.waitSignal(card.selectionChanged, timeout=1000) as blocker:+ qtbot.mouseClick(card, Qt.MouseButton.LeftButton, Qt.KeyboardModifier.ShiftModifier, pos=namePos(card))++ assert blocker.args == [True, True]+ assert card.opened == []+++def test_selection_mode_turns_links_into_plain_area(card, qtbot):+ card.setSelectionMode(True)++ with qtbot.waitSignal(card.selectionChanged, timeout=1000):+ qtbot.mouseClick(card, Qt.MouseButton.LeftButton, pos=namePos(card))+ with qtbot.waitSignal(card.selectionChanged, timeout=1000):+ qtbot.mouseClick(card, Qt.MouseButton.LeftButton, pos=infoPos(card))++ assert card.opened == []+ assert card.drawers == []+++def test_name_of_unfinished_task_is_not_a_link(card, qtbot):+ card.task.steps[0].status = TaskStatus.PAUSED+ card.task.updateStatus()+ card.refresh(force=True)++ with qtbot.waitSignal(card.selectionChanged, timeout=1000):+ qtbot.mouseClick(card, Qt.MouseButton.LeftButton, pos=namePos(card))++ assert card.opened == []+++def test_hover_shows_hand_only_over_links(card, qtbot):+ qtbot.mouseMove(card, namePos(card))+ assert card.cursor().shape() == Qt.CursorShape.PointingHandCursor++ qtbot.mouseMove(card, blankNamePos(card))+ assert card.cursor().shape() == Qt.CursorShape.ArrowCursor