95 lines
3.2 KiB
Python
95 lines
3.2 KiB
Python
# coding: utf-8
|
|
|
|
from PyQt6.QtCore import Qt, QTimer, pyqtSignal
|
|
from PyQt6.QtWidgets import QHBoxLayout, QVBoxLayout, QWidget
|
|
from qfluentwidgets import ComboBox, PushButton
|
|
from qfluentwidgets import FluentIcon as FIF
|
|
|
|
from app.view.components.linkage_switching import ShareLinkageSwitching
|
|
from app.view.widgets.page_flip_widget import PageFlipWidget
|
|
|
|
|
|
#
|
|
|
|
|
|
class ShareSearchScrollWidget(QWidget):
|
|
returnSignal = pyqtSignal()
|
|
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent=parent)
|
|
self.currentKeyword = ""
|
|
self.currentPage = 1
|
|
self.vBoxLayout = QVBoxLayout(self)
|
|
|
|
self.topLayout = QHBoxLayout()
|
|
self.returnButton = PushButton(
|
|
FIF.RETURN,
|
|
"返回",
|
|
self,
|
|
)
|
|
self.searchMethod = ComboBox(self)
|
|
self.searchMethod.addItems(["创建时间", "下载次数", "浏览次数"])
|
|
self.searchMethod.currentTextChanged.connect(
|
|
lambda: self.shareSearch(self.currentKeyword, self.currentPage)
|
|
)
|
|
self.sortMethod = ComboBox(self)
|
|
self.sortMethod.addItems(["从大到小", "从小到大"])
|
|
self.sortMethod.currentTextChanged.connect(
|
|
lambda: self.shareSearch(self.currentKeyword, self.currentPage)
|
|
)
|
|
|
|
self.returnButton.clicked.connect(self.clear)
|
|
|
|
self.searchScrolledArea = ShareLinkageSwitching(self)
|
|
self.searchScrolledArea.totalItemsSignal.connect(self.updatePageFlip)
|
|
|
|
self.pageFlipWidget = None
|
|
|
|
self.topLayout.addWidget(self.returnButton, 0, Qt.AlignmentFlag.AlignLeft)
|
|
self.topLayout.addWidget(self.searchMethod, 1, Qt.AlignmentFlag.AlignRight)
|
|
self.topLayout.addWidget(self.sortMethod, 0, Qt.AlignmentFlag.AlignRight)
|
|
self.vBoxLayout.addLayout(self.topLayout)
|
|
self.vBoxLayout.addWidget(self.searchScrolledArea)
|
|
self.vBoxLayout.setContentsMargins(0, 0, 0, 0)
|
|
|
|
QTimer.singleShot(1000, lambda: self.shareSearch("A", 1))
|
|
|
|
def updatePageFlip(self, total):
|
|
if not self.pageFlipWidget:
|
|
pages = total // 18 if total % 18 == 0 else total // 18 + 1
|
|
self.pageFlipWidget = PageFlipWidget(self, pages)
|
|
self.vBoxLayout.addWidget(
|
|
self.pageFlipWidget,
|
|
0,
|
|
Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignHCenter,
|
|
)
|
|
self.pageFlipWidget.pageChangeSignal.connect(
|
|
lambda page: self.shareSearch(self.currentKeyword, page)
|
|
)
|
|
|
|
def shareSearch(self, keyword, page):
|
|
if self.currentKeyword != keyword:
|
|
self.currentKeyword = keyword
|
|
if self.currentPage != page:
|
|
self.currentPage = page
|
|
|
|
orderByDict = {
|
|
"创建时间": "created_at",
|
|
"下载次数": "downloads",
|
|
"浏览次数": "views",
|
|
}
|
|
sortDict = {
|
|
"从大到小": "DESC",
|
|
"从小到大": "ASC",
|
|
}
|
|
self.searchScrolledArea.search(
|
|
keyword,
|
|
orderByDict[self.searchMethod.currentText()],
|
|
sortDict[self.sortMethod.currentText()],
|
|
page,
|
|
)
|
|
|
|
def clear(self):
|
|
self.searchScrolledArea.clearFileCards()
|
|
self.returnSignal.emit()
|