Skip to content

Commit

Permalink
修復滾動錯誤
Browse files Browse the repository at this point in the history
  • Loading branch information
tonquer committed Nov 28, 2021
1 parent a64173f commit b8f16a1
Show file tree
Hide file tree
Showing 15 changed files with 709 additions and 599 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install pyinstaller==4.5.1
pip install https://github.com/tonquer/waifu2x-vulkan/releases/download/v1.0.8/waifu2x_vulkan-1.0.8-cp37-cp37m-macosx_10_14_x86_64.whl
pip install -r src/requirements.txt
brew install create-dmg
- name: Build
Expand Down
4 changes: 3 additions & 1 deletion src/component/list/user_list_widget.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from functools import partial

from PySide6.QtCore import Qt
from PySide6.QtWidgets import QListWidgetItem

Expand Down Expand Up @@ -88,7 +90,7 @@ def AddUserItem(self, info, floor, hideKillButton=False, likeCallBack=None):
iwidget.SetLike()

if likeCallBack:
iwidget.starButton.clicked.connect(likeCallBack)
iwidget.starButton.clicked.connect(partial(likeCallBack, commnetId))

if commentsCount == "":
iwidget.commentButton.hide()
Expand Down
13 changes: 11 additions & 2 deletions src/component/scroll/read_scroll.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from PySide6.QtCore import QPropertyAnimation, QEasingCurve, QAbstractAnimation
from PySide6.QtWidgets import QScrollBar

from qt_owner import QtOwner


class ReadScroll(QScrollBar):
def __init__(self):
Expand All @@ -15,17 +17,24 @@ def __init__(self):
self.backTick = 0
self.laveValue = 0
self.lastV = 0
self.animation.finished.connect(self.Finished)

def Finished(self):
QtOwner().owner.readView.frame.scrollArea.OnValueChange(self.value())

def StopScroll(self):
self.backTick = 0
self.animation.stop()

def Scroll(self, value):
def Scroll(self, value, time=0):
if self.animation.state() == QAbstractAnimation.State.Running:
self.animation.stop()
oldValue = self.value()
self.animation.setStartValue(oldValue)
self.animation.setDuration(self.scrollTime)
if not time:
self.animation.setDuration(self.scrollTime)
else:
self.animation.setDuration(time)
self.animation.setEndValue(oldValue + value)
self.animation.start()

22 changes: 12 additions & 10 deletions src/component/widget/comment_item_widget.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from PySide6 import QtWidgets
from PySide6.QtCore import QEvent, Qt, QSize
from PySide6.QtGui import QPixmap, QIcon
Expand Down Expand Up @@ -52,16 +54,16 @@ def __init__(self, parent):
self.killButton.setCursor(Qt.PointingHandCursor)

def SetLike(self, isLike=True):
# p = QPixmap()
# if isLike:
# p.loadFromData(DataMgr.GetData("icon_comment_liked"))
# else:
# p.loadFromData(DataMgr.GetData("icon_comment_like"))
# nums = re.findall("\d+", self.starButton.text())
# if nums:
# num = int(nums[0]) + 1 if isLike else int(nums[0]) - 1
# self.starButton.setText("({})".format(str(num)))
# self.starButton.setIcon(QIcon(p.scaled(50, 50, Qt.KeepAspectRatio, Qt.SmoothTransformation)))
p = QPixmap()
if isLike:
p.load(":/png/icon/icon_comment_liked.png")
else:
p.load(":/png/icon/icon_comment_like.png")
nums = re.findall("\d+", self.starButton.text())
if nums:
num = int(nums[0]) + 1 if isLike else int(nums[0]) - 1
self.starButton.setText("({})".format(str(num)))
self.starButton.setIcon(QIcon(p.scaled(50, 50, Qt.KeepAspectRatio, Qt.SmoothTransformation)))
self.starButton.setChecked(isLike)

def SetPicture(self, data):
Expand Down
34 changes: 33 additions & 1 deletion src/component/widget/navigation_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from PySide6.QtCore import QPropertyAnimation, QRect, QEasingCurve, QFile
from PySide6.QtCore import QPropertyAnimation, QRect, QEasingCurve, QFile, QEvent
from PySide6.QtGui import QPixmap, Qt
from PySide6.QtWidgets import QWidget

from config import config
Expand Down Expand Up @@ -26,6 +27,8 @@ def __init__(self, parent=None):
self.picLabel.SetPicture(f.readAll())
f.close()
self.pushButton.clicked.connect(self.OpenLoginView)
self.picLabel.installEventFilter(self)
self.picData = None

def OpenLoginView(self):
if User().isLogin:
Expand Down Expand Up @@ -61,6 +64,7 @@ def UpdateUserBack(self, raw):

def ShowUserImg(self, data, st):
if st == Status.Ok:
self.picData = data
self.SetPicture(data)
return

Expand All @@ -83,6 +87,22 @@ def SignBack(self, raw):
def SetPicture(self, data):
self.pictureData = data
self.picLabel.SetPicture(data)
return

def UpdatePictureData(self, data):
if not data:
return
self.picLabel.setPixmap(QPixmap())
self.picLabel.setText(self.tr("头像上传中......"))
self.AddHttpTask(req.SetAvatarInfoReq(data), self.UpdatePictureDataBack)
return

def UpdatePictureDataBack(self, data):
st = data["st"]
if st == Status.Ok:
self.AddHttpTask(req.GetUserInfo(), self.UpdateUserBack)
else:
QtOwner().ShowError(Str.GetStr(st))

def aniShow(self):
""" 动画显示 """
Expand All @@ -109,3 +129,15 @@ def __hideAniFinishedSlot(self):
if self.__connect:
self.__ani.disconnect(self.__connect)
self.__connect = None

def eventFilter(self, obj, event):
if event.type() == QEvent.MouseButtonPress:
if event.button() == Qt.LeftButton:
if self.picData and (obj == self.picLabel):
QtOwner().OpenWaifu2xTool(self.picData)
return True
return False
else:
return False
else:
return super(self.__class__, self).eventFilter(obj, event)
20 changes: 17 additions & 3 deletions src/interface/ui_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,34 @@
from PySide6.QtWidgets import (QApplication, QGridLayout, QHBoxLayout, QLabel,
QPushButton, QSizePolicy, QSpacerItem, QVBoxLayout,
QWidget)

from component.scroll_area.smooth_scroll_area import SmoothScrollArea
import images_rc

class Ui_Help(object):
def setupUi(self, Help):
if not Help.objectName():
Help.setObjectName(u"Help")
Help.resize(545, 582)
Help.resize(545, 586)
Help.setStyleSheet(u"QListWidget {background-color:transparent;}\n"
"QScrollArea {background-color:transparent;}")
self.verticalLayout = QVBoxLayout(Help)
self.verticalLayout.setObjectName(u"verticalLayout")
self.scrollArea = SmoothScrollArea(Help)
self.scrollArea.setObjectName(u"scrollArea")
self.scrollArea.setWidgetResizable(True)
self.scrollAreaWidgetContents = QWidget()
self.scrollAreaWidgetContents.setObjectName(u"scrollAreaWidgetContents")
self.scrollAreaWidgetContents.setGeometry(QRect(0, 0, 508, 586))
self.verticalLayout_3 = QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_3.setObjectName(u"verticalLayout_3")
self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

self.horizontalLayout.addItem(self.horizontalSpacer_2)

self.widget = QWidget(Help)
self.widget = QWidget(self.scrollAreaWidgetContents)
self.widget.setObjectName(u"widget")
self.verticalLayout_2 = QVBoxLayout(self.widget)
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
Expand Down Expand Up @@ -172,7 +182,11 @@ def setupUi(self, Help):
self.horizontalLayout.addItem(self.horizontalSpacer)


self.verticalLayout.addLayout(self.horizontalLayout)
self.verticalLayout_3.addLayout(self.horizontalLayout)

self.scrollArea.setWidget(self.scrollAreaWidgetContents)

self.verticalLayout.addWidget(self.scrollArea)


self.retranslateUi(Help)
Expand Down
2 changes: 1 addition & 1 deletion src/server/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def __init__(self, gameId, page=1):
# 游戏区评论爱心
class GameCommentsLikeReq(ServerReq):
def __init__(self, gameId):
url = config.Url + "games/{}/like".format(gameId)
url = config.Url + "comments/{}/like".format(gameId)
method = "POST"
super(self.__class__, self).__init__(url, ToolUtil.GetHeader(url, method),
{}, method)
Expand Down
2 changes: 1 addition & 1 deletion src/view/info/book_info_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def LoadHistory(self):
if self.lastEpsId >= 0:
item = self.epsListWidget.item(self.lastEpsId)
if item:
downloadIds = QtOwner().owner.downloadForm.GetDownloadCompleteEpsId(self.bookId)
downloadIds = QtOwner().downloadView.GetDownloadCompleteEpsId(self.bookId)
if self.lastEpsId in downloadIds:
item.setBackground(QColor(18, 161, 130))
else:
Expand Down
8 changes: 4 additions & 4 deletions src/view/read/read_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def GetReadScale(stripModel, scaleCnt, maxWidth, maxHeight):
return toScaleW, toScaleH

@staticmethod
def GetReadToPos(stripModel, maxWidth, maxHeight, toWidth, toHeight, index, curIndex):
def GetReadToPos(stripModel, maxWidth, maxHeight, toWidth, toHeight, index, curIndex, oldPos):
if stripModel == ReadMode.LeftRight:
return QPoint(maxWidth//2 - toWidth//2, max(0, maxHeight//2-toHeight//2))
elif stripModel in [ReadMode.RightLeftDouble]:
Expand All @@ -142,12 +142,12 @@ def GetReadToPos(stripModel, maxWidth, maxHeight, toWidth, toHeight, index, curI
else:
return QPoint(maxWidth//2-toWidth, maxHeight//2 - toHeight//2)
elif stripModel in [ReadMode.LeftRightScroll]:
return QPoint(0, max(0, maxHeight // 2 - toHeight // 2))
return QPoint(oldPos.x(), max(0, maxHeight // 2 - toHeight // 2))

elif stripModel in [ReadMode.RightLeftScroll]:
return QPoint(0, max(0, maxHeight // 2 - toHeight // 2))
return QPoint(oldPos.x(), max(0, maxHeight // 2 - toHeight // 2))

elif stripModel in [ReadMode.UpDown]:
return QPoint(maxWidth//2 - toWidth//2, 0)
return QPoint(maxWidth//2 - toWidth//2, oldPos.y())
else:
return QPoint(0, 0)
2 changes: 1 addition & 1 deletion src/view/read/read_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def ScaleFrame(self):
self.scrollArea.setGeometry(0, 0, w, h)
# h2 = min(800, h)
# self.qtTool.adjustSize()
self.qtTool.setGeometry(w - 300, 0, 300, h)
self.qtTool.setGeometry(w - 400, 0, 400, h)

# w = max((w - 150)//2, 0)
# h = max((h - 150)//2, 0)
Expand Down
46 changes: 26 additions & 20 deletions src/view/read/read_graphics.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import time

from PySide6.QtCore import Qt, QEvent, QPoint, Signal, QRect, QFile
from PySide6.QtGui import QPainter, QFont, QPixmap, QFontMetrics
from PySide6.QtGui import QPainter, QFont, QPixmap, QFontMetrics, QWheelEvent
from PySide6.QtWidgets import QGraphicsView, QFrame, QGraphicsItem, QGraphicsScene, \
QGraphicsPixmapItem, QGraphicsProxyWidget, QScroller, QAbstractSlider
QGraphicsPixmapItem, QGraphicsProxyWidget, QScroller, QAbstractSlider, QApplication

from component.label.msg_label import MsgLabel
from component.scroll.read_scroll import ReadScroll
Expand Down Expand Up @@ -95,6 +95,7 @@ def __init__(self, parent=None):
self.verticalScrollBar().actionTriggered.connect(self.OnActionTriggered)

self.horizontalScrollBar().actionTriggered.connect(self.OnActionTriggered)
self.verticalScrollBar()
self.startPos = QPoint()
self.labelWaifu2xState = {}
# self.setSceneRect(-self.width()//2, -self.height()//2, self.width(), self.height())
Expand Down Expand Up @@ -166,9 +167,11 @@ def ScrollValue(self, value):
if self.initReadMode == ReadMode.LeftRight:
return
if self.initReadMode in [ReadMode.UpDown, ReadMode.LeftRight]:
QScroller.scroller(self).scrollTo(QPoint(0, self.verticalScrollBar().value() + value), 500)
self.vScrollBar.Scroll(value, 500)
# QScroller.scroller(self).scrollTo(QPoint(0, self.verticalScrollBar().value() + value), 500)
else:
QScroller.scroller(self).scrollTo(QPoint(self.horizontalScrollBar().value() + value, 0), 500)
self.hScrollBar.Scroll(value, 500)
# QScroller.scroller(self).scrollTo(QPoint(self.horizontalScrollBar().value() + value, 0), 500)
return

def eventFilter(self, obj, ev) -> bool:
Expand Down Expand Up @@ -369,8 +372,8 @@ def InitAllQLabel(self, maxNum, curIndex):
value = self.labelSize.get(curIndex)
self.oldValue = value
self.GetScrollBar().setValue(value)
print(value)
print(self.labelSize)
# print(value)
# print(self.labelSize)
elif self.initReadMode in [ReadMode.LeftRight]:

self.graphicsItem1.setPos(0, 0)
Expand Down Expand Up @@ -402,8 +405,8 @@ def ResetMaxNum(self):
self.GetScrollBar().setMaximum(self.labelSize.get(maxNum - 1, 0))
self.GetOtherScrollBar().setMaximum(0)
else:
self.graphicsScene.setSceneRect(0, 0, self.width(), max(self.height(), self.graphicsItem1.pixmap().height()))
self.verticalScrollBar().setMaximum(max(0, self.graphicsItem1.pixmap().height()- self.height()))
self.graphicsScene.setSceneRect(0, 0, self.width(), max(self.height(), self.graphicsItem1.pixmap().height()//self.graphicsItem1.pixmap().devicePixelRatio()))
self.verticalScrollBar().setMaximum(max(0, self.graphicsItem1.pixmap().height()//self.graphicsItem1.pixmap().devicePixelRatio()- self.height()))
self.horizontalScrollBar().setMaximum(0)

def ResetLabelSize(self, size):
Expand All @@ -421,12 +424,12 @@ def ResetLabelSize(self, size):
if isinstance(proxy, QGraphicsProxyWidget):
height += proxy.widget().height()
else:
height += proxy.pixmap().height()
height += proxy.pixmap().height()//proxy.pixmap().devicePixelRatio()
else:
if isinstance(proxy, QGraphicsProxyWidget):
height += proxy.widget().width()
else:
height += proxy.pixmap().width()
height += proxy.pixmap().width()//proxy.pixmap().devicePixelRatio()

self.ResetMaxNum()

Expand Down Expand Up @@ -484,9 +487,9 @@ def PixmapToLabel(self, index):
label.setAlignment(Qt.AlignCenter)
label.setFont(font)
label.setText(text)
label.resize(proxy.pixmap().width(), proxy.pixmap().height())
newProxy.widget().setMinimumSize(proxy.pixmap().width(), proxy.pixmap().height())
newProxy.widget().setMaximumSize(proxy.pixmap().width(), proxy.pixmap().height())
label.resize(proxy.pixmap().width()//proxy.pixmap().devicePixelRatio(), proxy.pixmap().height()//proxy.pixmap().devicePixelRatio())
newProxy.widget().setMinimumSize(proxy.pixmap().width()//proxy.pixmap().devicePixelRatio(), proxy.pixmap().height()//proxy.pixmap().devicePixelRatio())
newProxy.widget().setMaximumSize(proxy.pixmap().width()//proxy.pixmap().devicePixelRatio(), proxy.pixmap().height()//proxy.pixmap().devicePixelRatio())
newProxy.setPos(oldPox)
# print(index, newProxy.widget().width(), newProxy.widget().height())
self.graphicsScene.addItem(newProxy)
Expand All @@ -511,7 +514,7 @@ def LabelToPixmap(self, index):
QtReadImgPoolManager().AddProxyItem(proxy)
return oldHeight, oldWidth
else:
return proxy.pixmap().height()//self.devicePixelRatio(), proxy.pixmap().width()//self.devicePixelRatio()
return proxy.pixmap().height()//proxy.pixmap().devicePixelRatio(), proxy.pixmap().width()//proxy.pixmap().devicePixelRatio()
elif (self.initReadMode == ReadMode.RightLeftDouble and index == self.readImg.curIndex) or (self.initReadMode == ReadMode.LeftRightDouble and index != self.readImg.curIndex):
self.graphicsItem2.pixmap().height(), self.graphicsItem2.pixmap().width()
return self.graphicsItem1.pixmap().height(), self.graphicsItem1.pixmap().width()
Expand All @@ -537,14 +540,14 @@ def SetPixIem(self, index, data, isWaifu2x=False):
if label.pixmap() and waifu2x == isWaifu2x and not self.resetImg:
return
self.labelWaifu2xState[index] = isWaifu2x

radio = self.devicePixelRatio()
oldPos = label.pos()
radio = data.devicePixelRatio()
toW, toH = QtFileData.GetReadScale(self.qtTool.stripModel, self.scaleCnt, self.width(), self.height())
newData = data.scaled(toW*radio, toH*radio, Qt.KeepAspectRatio, Qt.SmoothTransformation)
pos = QtFileData.GetReadToPos(self.qtTool.stripModel, self.width(), self.height(), newData.width()/radio, newData.height()//radio, index, self.readImg.curIndex)
pos = QtFileData.GetReadToPos(self.qtTool.stripModel, self.width(), self.height(), newData.width()/radio, newData.height()//radio, index, self.readImg.curIndex, oldPos)
# print(index, pos, radio, newData.size(), self.size())
label.setPos(pos)
label.setPixmap(newData)

if self.initReadMode == ReadMode.UpDown:
self.UpdateOtherHeight(index, oldHeight, label.pixmap().height()//radio)
else:
Expand Down Expand Up @@ -582,14 +585,17 @@ def UpdateOtherHeight(self, index, oldHeight, height):
for i in indexList:
proxy = self.allItems[i]
oldPos = proxy.pos()

if self.initReadMode == ReadMode.UpDown:
if isinstance(proxy, QGraphicsPixmapItem):
proxy.setPos(max(0, self.width()//2 - proxy.pixmap().width()//2), oldPos.y() + addHeight)
radio = proxy.pixmap().devicePixelRatio()
proxy.setPos(max(0, self.width()//2 - proxy.pixmap().width()//radio//2), oldPos.y() + addHeight)
else:
proxy.setPos(oldPos.x(), oldPos.y() + addHeight)
else:
if isinstance(proxy, QGraphicsPixmapItem):
proxy.setPos(oldPos.x() + addHeight, max(0, self.height()//2 - proxy.pixmap().height()//2))
radio = proxy.pixmap().devicePixelRatio()
proxy.setPos(oldPos.x() + addHeight, max(0, self.height()//2 - proxy.pixmap().height()//radio//2))
else:
proxy.setPos(oldPos.x() + addHeight, oldPos.y())
self.labelSize[i] += addHeight
Expand Down
Loading

0 comments on commit b8f16a1

Please sign in to comment.