优化触控,支持拖拽文件到本地漫画
This commit is contained in:
tonquer 2023-02-24 21:40:38 +08:00
parent 7369bfa264
commit ef2ab2b431
8 changed files with 155 additions and 82 deletions

View File

@ -1,6 +1,6 @@
from PySide6.QtCore import Qt
from PySide6.QtGui import QMouseEvent
from PySide6.QtWidgets import QListWidget, QAbstractItemView, QScroller
from PySide6.QtWidgets import QListWidget, QAbstractItemView, QScroller, QScrollerProperties
from component.scroll.smooth_scroll_bar import SmoothScrollBar
from config.setting import Setting
@ -22,18 +22,25 @@ class BaseListWidget(QListWidget, QtTaskBase):
self.LikeBack = None
self.KillBack = None
self.parentId = -1
self.vScrollBar = SmoothScrollBar()
self.vScrollBar.setOrientation(Qt.Vertical)
self.setVerticalScrollBar(self.vScrollBar)
self.vScrollBar.MoveEvent.connect(self.OnActionTriggered)
self.vScrollBar = None
if Setting.IsGrabGesture.value:
QScroller.grabGesture(self.viewport(), QScroller.LeftMouseButtonGesture)
QScroller.grabGesture(self, QScroller.LeftMouseButtonGesture)
propertiesOne = QScroller.scroller(self).scrollerProperties()
print(propertiesOne.scrollMetric(propertiesOne.MousePressEventDelay))
propertiesOne.setScrollMetric(QScrollerProperties.MousePressEventDelay, 1)
propertiesOne.setScrollMetric(QScrollerProperties.VerticalOvershootPolicy, QScrollerProperties.OvershootAlwaysOff)
propertiesOne.setScrollMetric(QScrollerProperties.HorizontalOvershootPolicy, QScrollerProperties.OvershootAlwaysOff)
propertiesOne.setScrollMetric(QScrollerProperties.AcceleratingFlickMaximumTime , 0)
QScroller.scroller(self).setScrollerProperties(propertiesOne)
self.verticalScrollBar().valueChanged.connect(self.ValueChange)
else:
self.vScrollBar = SmoothScrollBar()
self.vScrollBar.setOrientation(Qt.Vertical)
self.setVerticalScrollBar(self.vScrollBar)
self.vScrollBar.MoveEvent.connect(self.OnActionTriggered)
self.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
self.verticalScrollBar().setSingleStep(30)
# self.timer = QTimer()
# self.timer.setInterval(1000)
# self.timer.timeout.connect(self.TimeOut)
@ -43,6 +50,19 @@ class BaseListWidget(QListWidget, QtTaskBase):
self.lastIndex = -1
self.doubleClickType = 0
def ValueChange(self, v):
if v >= self.verticalScrollBar().maximum():
if Setting.IsGrabGesture.value:
QScroller.ungrabGesture(self)
self.ClearWheelEvent()
self.isLoadingPage = True
if self.LoadCallBack:
self.LoadCallBack()
if Setting.IsGrabGesture.value:
QScroller.grabGesture(self, QScroller.LeftMouseButtonGesture)
# def event(self, e) -> bool:
# print(e)
# return QListWidget.event(self, e)
@ -57,7 +77,12 @@ class BaseListWidget(QListWidget, QtTaskBase):
def wheelEvent(self, arg__1) -> None:
if not self.wheelStatus:
return
self.vScrollBar.ScrollValue(-arg__1.angleDelta().y())
if self.vScrollBar:
self.vScrollBar.ScrollValue(-arg__1.angleDelta().y())
else:
print(self.verticalScrollMode())
print(self.verticalScrollBar().singleStep())
return QListWidget.wheelEvent(self, arg__1)
def OnActionTriggered(self):
if self.isLoadingPage:
@ -89,7 +114,8 @@ class BaseListWidget(QListWidget, QtTaskBase):
# 防止异步加载时,信息错乱
self.ClearTask()
self.vScrollBar.ResetValue(0)
if self.vScrollBar:
self.vScrollBar.ResetValue(0)
def mousePressEvent(self, event: QMouseEvent):
if event.button() == Qt.ForwardButton:

View File

@ -1,6 +1,6 @@
from PySide6.QtCore import QPropertyAnimation, QRect, QEasingCurve, QFile, QEvent, QSize
from PySide6.QtGui import QPixmap, Qt, QIcon
from PySide6.QtWidgets import QWidget, QScroller
from PySide6.QtWidgets import QWidget, QScroller, QScrollerProperties
from config import config
from config.setting import Setting
@ -37,6 +37,14 @@ class NavigationWidget(QWidget, Ui_Navigation, QtTaskBase):
self.offlineButton.SetState(False)
self.offlineButton.Switch.connect(self.SwitchOffline)
if Setting.IsGrabGesture.value:
QScroller.grabGesture(self.scrollArea, QScroller.LeftMouseButtonGesture)
propertiesOne = QScroller.scroller(self).scrollerProperties()
propertiesOne.setScrollMetric(QScrollerProperties.MousePressEventDelay, 0)
propertiesOne.setScrollMetric(QScrollerProperties.VerticalOvershootPolicy, QScrollerProperties.OvershootAlwaysOff)
propertiesOne.setScrollMetric(QScrollerProperties.HorizontalOvershootPolicy, QScrollerProperties.OvershootAlwaysOff)
QScroller.scroller(self.scrollArea).setScrollerProperties(propertiesOne)
def SwitchOffline(self, state):
QtOwner().isOfflineModel = state
return

View File

@ -15,9 +15,9 @@ from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QHBoxLayout, QListWidgetItem, QPushButton,
QSizePolicy, QSpacerItem, QTabWidget, QToolButton,
QVBoxLayout, QWidget)
from PySide6.QtWidgets import (QApplication, QHBoxLayout, QListWidgetItem, QSizePolicy,
QSpacerItem, QTabWidget, QToolButton, QVBoxLayout,
QWidget)
from component.list.comic_list_widget import ComicListWidget
@ -42,6 +42,20 @@ class Ui_Index(object):
self.verticalLayout.addWidget(self.randomList)
self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
self.horizontalLayout.addItem(self.horizontalSpacer)
self.toolButton = QToolButton(self.tab_1)
self.toolButton.setObjectName(u"toolButton")
self.horizontalLayout.addWidget(self.toolButton)
self.verticalLayout.addLayout(self.horizontalLayout)
self.tabWidget.addTab(self.tab_1, "")
self.tab_3 = QWidget()
self.tab_3.setObjectName(u"tab_3")
@ -66,25 +80,6 @@ class Ui_Index(object):
self.verticalLayout_2.addWidget(self.tabWidget)
self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
self.horizontalLayout.addItem(self.horizontalSpacer)
self.pushButton = QPushButton(Index)
self.pushButton.setObjectName(u"pushButton")
self.horizontalLayout.addWidget(self.pushButton)
self.toolButton = QToolButton(Index)
self.toolButton.setObjectName(u"toolButton")
self.horizontalLayout.addWidget(self.toolButton)
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.retranslateUi(Index)
@ -96,13 +91,12 @@ class Ui_Index(object):
def retranslateUi(self, Index):
Index.setWindowTitle(QCoreApplication.translate("Index", u"\u9996\u9875", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_1), QCoreApplication.translate("Index", u"\u968f\u673a\u63a8\u8350", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), QCoreApplication.translate("Index", u"\u672c\u5b50\u795e\u63a8\u8350", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QCoreApplication.translate("Index", u"\u672c\u5b50\u9b54\u63a8\u8350", None))
self.pushButton.setText(QCoreApplication.translate("Index", u"\u6279\u91cf\u4e0b\u8f7d", None))
self.toolButton.setText(QCoreApplication.translate("Index", u"\u5237\u65b0(F5)", None))
#if QT_CONFIG(shortcut)
self.toolButton.setShortcut(QCoreApplication.translate("Index", u"F5", None))
#endif // QT_CONFIG(shortcut)
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_1), QCoreApplication.translate("Index", u"\u968f\u673a\u63a8\u8350", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), QCoreApplication.translate("Index", u"\u672c\u5b50\u795e\u63a8\u8350", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QCoreApplication.translate("Index", u"\u672c\u5b50\u9b54\u63a8\u8350", None))
# retranslateUi

View File

@ -34,10 +34,11 @@ class QLocalTask(object):
class LocalData(object):
Type1 = 1
Type2 = 2
Type3 = 3
Type4 = 4
Type1 = 1 # 加载目录
Type2 = 2 # 加载文件
Type3 = 3 #
Type4 = 4 #
Type5 = 5 # 批量加载
AllPictureFormat = ["jpg", "jpeg", "webp", "gif", "apng", "png"]
@ -193,6 +194,8 @@ class TaskLocal(TaskBase, QtTaskBase):
st, datas = self.ParseBookInfoByFile(dir)
elif type == 4:
st, datas = self.ParseBookInfoByFile(dir)
elif type == 5:
st, datas = self.ParseBookInfoByFileAll(dir)
self.taskObj.localBack.emit(taskId, st, datas)
@ -367,6 +370,19 @@ class TaskLocal(TaskBase, QtTaskBase):
return Str.ErrorPath, ""
return Status.Ok, l
def ParseBookInfoByFileAll(self, fileNames):
allBooks = []
for url in fileNames:
if os.path.isfile(url):
st, v = self.ParseBookInfoByFile(url)
elif os.path.isdir(url):
st, v = self.ParseBookInfoByDir(url)
else:
st = Status.Error
if st == Status.Ok:
allBooks.append(v)
return Status.Ok, allBooks
def GetBookCover(self, v):
return self.GetBookPicture(v, 0, 1)

View File

@ -236,6 +236,7 @@ class SearchView(QWidget, Ui_Search, QtTaskBase):
for v in info.get("docs", []):
self.bookList.AddBookByDict(v)
self.CheckCategoryShowItem()
self.bookList.setFocus()
else:
# QtWidgets.QMessageBox.information(self, '未搜索到结果', "未搜索到结果", QtWidgets.QMessageBox.Yes)
QtOwner().ShowError(Str.GetStr(st))

View File

@ -5,9 +5,9 @@ import sys
from functools import partial
from PySide6 import QtWidgets
from PySide6.QtCore import QSettings, Qt, QSize, QUrl, QFile, QTranslator, QLocale
from PySide6.QtCore import QSettings, Qt, QSize, QUrl, QFile, QTranslator, QLocale, QEvent
from PySide6.QtGui import QDesktopServices, QFont, QFontDatabase
from PySide6.QtWidgets import QFileDialog, QScroller
from PySide6.QtWidgets import QFileDialog, QScroller, QScrollerProperties
from config import config
from config.setting import Setting, SettingValue
@ -104,8 +104,23 @@ class SettingView(QtWidgets.QWidget, Ui_SettingNew):
self.msgLabel.setVisible(False)
# if Setting.IsGrabGesture.value:
if Setting.IsGrabGesture.value:
QScroller.grabGesture(self.scrollArea, QScroller.LeftMouseButtonGesture)
propertiesOne = QScroller.scroller(self).scrollerProperties()
propertiesOne.setScrollMetric(QScrollerProperties.MousePressEventDelay, 0)
propertiesOne.setScrollMetric(QScrollerProperties.VerticalOvershootPolicy, QScrollerProperties.OvershootAlwaysOff)
propertiesOne.setScrollMetric(QScrollerProperties.HorizontalOvershootPolicy, QScrollerProperties.OvershootAlwaysOff)
QScroller.scroller(self.scrollArea).setScrollerProperties(propertiesOne)
# QScroller.grabGesture(self.scrollArea, QScroller.LeftMouseButtonGesture)
# self.grabGestureBox.installEventFilter(self)
#
# def eventFilter(self, watched, event) -> bool:
# if (watched == self.grabGestureBox and event.type() == QEvent.Enter):
# QScroller.ungrabGesture(self.scrollArea)
# elif (watched == self.grabGestureBox and event.type() == QEvent.Leave):
# QScroller.grabGesture(self.scrollArea, QScroller.LeftMouseButtonGesture)
# return super(self.__class__, self).eventFilter(watched, event)
def MoveToLabel(self, label):
p = label.pos()
@ -437,7 +452,7 @@ class SettingView(QtWidgets.QWidget, Ui_SettingNew):
index += 1
self.encodeSelect.addItem("CPU")
if config.EncodeGpu == "CPU":
config.Encode = -1
self.encodeSelect.setCurrentIndex(index)

View File

@ -1,5 +1,6 @@
import json
import os
from this import d
from PySide6.QtCore import Signal
from PySide6.QtGui import QAction
@ -57,6 +58,7 @@ class LocalReadView(QWidget, Ui_Local, QtTaskBase):
self.sortIdCombox.currentIndexChanged.connect(self.Init)
self.sortKeyCombox.currentIndexChanged.connect(self.Init)
self.setAcceptDrops(True)
def Init(self):
self.bookList.clear()
@ -183,7 +185,8 @@ class LocalReadView(QWidget, Ui_Local, QtTaskBase):
return
alreadyNum = 0
addNum = 0
self.lastPath = url
if url:
self.lastPath = url
for v in books:
if v.id in self.allBookInfos:
alreadyNum += 1
@ -218,4 +221,21 @@ class LocalReadView(QWidget, Ui_Local, QtTaskBase):
return
def JumpPage(self):
return
return
def dragEnterEvent(self, event):
if(event.mimeData().hasUrls()):
event.acceptProposedAction()
else:
event.ignore()
def dragMoveEvent(self, evemt):
return
def dropEvent(self, event):
mimeData = event.mimeData()
if(mimeData.hasUrls()):
urls = mimeData.urls()
QtOwner().ShowLoading()
fileNames = [str(i.toLocalFile()) for i in urls]
self.AddLocalTaskLoad(LocalData.Type5, fileNames, "", self.CheckAction1LoadBack)

View File

@ -37,6 +37,33 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string>刷新(F5)</string>
</property>
<property name="shortcut">
<string>F5</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
@ -61,40 +88,6 @@
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>批量下载</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string>刷新(F5)</string>
</property>
<property name="shortcut">
<string>F5</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>