Skip to content

Commit

Permalink
给自动 BP 卡片添加提示文本
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzaphkiel committed Jun 30, 2024
1 parent 2ea5e6f commit 458e9c9
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 229 deletions.
1 change: 1 addition & 0 deletions app/common/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Icon(FluentIconBase, Enum):
TEXTCHECK = 'TextCheck'
DOCUMENT = 'Document'
ARROWREPEAT = "ArrowRepeat"
QUESTION_CIRCLE = 'QuestionCircle'

def path(self, theme=Theme.AUTO):
return f'./app/resource/icons/{self.value}_{getIconColor(theme)}.svg'
119 changes: 5 additions & 114 deletions app/components/profile_level_icon_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from app.common.qfluentwidgets import (ProgressRing, ToolTipFilter, ToolTipPosition, isDarkTheme,
themeColor, FlyoutViewBase, TextWrap, FlyoutAnimationType)
from app.components.color_label import ColorLabel
from app.components.tool_tip import CustomToolTip
from app.common.style_sheet import StyleSheet


Expand Down Expand Up @@ -139,13 +140,15 @@ def updateAramInfo(self, info):
if not self.mFlyout or not info:
return

self.mFlyout.updateInfo(info)
self.mFlyout.view.updateInfo(info)

def enterEvent(self, a0):
if not self.aramInfo or self.mFlyout:
return

self.mFlyout = AramFlyout(self.aramInfo, self)
view = AramFlyoutView(self.aramInfo)

self.mFlyout = CustomToolTip(view, self)
self.mFlyout.show()

super().enterEvent(a0)
Expand All @@ -158,118 +161,6 @@ def leaveEvent(self, a0):
self.mFlyout = None


class AramFlyout(QWidget):
def __init__(self, info, target: QWidget, parent=None):
super().__init__(parent)
self.target = target

self.hBoxLayout = QHBoxLayout(self)
self.view = AramFlyoutView(info, parent)
self.setWindowFlags(Qt.ToolTip | Qt.FramelessWindowHint |
Qt.NoDropShadowWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)

self.hBoxLayout.addWidget(self.view)
self.hBoxLayout.setContentsMargins(15, 8, 15, 20)

self.__initShadowEffect()
self.__initAnimation()

def __initShadowEffect(self, blurRadius=35, offset=(0, 8)):
color = QColor(0, 0, 0, 80 if isDarkTheme() else 30)

self.shadowEffect = QGraphicsDropShadowEffect(self.view)
self.shadowEffect.setBlurRadius(blurRadius)
self.shadowEffect.setOffset(*offset)
self.shadowEffect.setColor(color)

self.view.setGraphicsEffect(None)
self.view.setGraphicsEffect(self.shadowEffect)

def __initAnimation(self):
self.inOpacityAni = QPropertyAnimation(
self, b'windowOpacity', self.parent())
self.inSlideAni = QPropertyAnimation(self, b'pos', self.parent())

self.inOpacityAni.setDuration(187)
self.inSlideAni.setDuration(187)

self.inOpacityAni.setEasingCurve(QEasingCurve.InOutQuad)
self.inSlideAni.setEasingCurve(QEasingCurve.InOutQuad)

self.inOpacityAni.setStartValue(0)
self.inOpacityAni.setEndValue(1)

self.inAniGroup = QParallelAnimationGroup(self)
self.inAniGroup.addAnimation(self.inOpacityAni)
self.inAniGroup.addAnimation(self.inSlideAni)

self.outAniGroup = QParallelAnimationGroup(self)

self.outOpacityAni = QPropertyAnimation(
self, b'windowOpacity', self.parent())
self.outOpacityAni.setEasingCurve(QEasingCurve.InOutQuad)
self.outOpacityAni.setStartValue(1)
self.outOpacityAni.setEndValue(0)
self.outOpacityAni.setDuration(120)

self.outSlideAni = QPropertyAnimation(self, b'pos', self.parent())
self.outSlideAni.setEasingCurve(QEasingCurve.InOutQuad)
self.outSlideAni.setDuration(120)

self.outAniGroup.addAnimation(self.outOpacityAni)
self.outAniGroup.addAnimation(self.outSlideAni)

self.outAniGroup.finished.connect(self.close)

def showEvent(self, e):
pos = self.getPosition()

if self.animationType == FlyoutAnimationType.SLIDE_LEFT:
self.inSlideAni.setStartValue(pos + QPoint(10, 0))
else:
self.inSlideAni.setStartValue(pos - QPoint(10, 0))

self.inSlideAni.setEndValue(pos)
self.inAniGroup.start()

return super().showEvent(e)

def fadeOut(self):
self.outSlideAni.setStartValue(self.pos())

if self.animationType == FlyoutAnimationType.SLIDE_LEFT:
self.outSlideAni.setEndValue(self.pos() + QPoint(10, 0))
else:
self.outSlideAni.setEndValue(self.pos() - QPoint(10, 0))

self.outAniGroup.finished.connect(self.close)
self.outAniGroup.start()

def getPosition(self):
pos = self.target.mapToGlobal(QPoint())
x, y = pos.x(), pos.y()

hintWidth = self.sizeHint().width()
hintHeight = self.sizeHint().height()

x += self.target.width() // 2 - hintWidth // 2
y += self.target.height() // 2 - hintHeight // 2

dx = -hintWidth // 2 - 45

self.animationType = FlyoutAnimationType.SLIDE_LEFT

if x + dx < -15:
self.animationType = FlyoutAnimationType.SLIDE_RIGHT
dx = -dx

return QPoint(x + dx, y)

def updateInfo(self, info):
self.view.updateInfo(info)


class AramFlyoutView(FlyoutViewBase):
def __init__(self, info, parent=None):
super().__init__(parent=parent)
Expand Down
147 changes: 147 additions & 0 deletions app/components/tool_tip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@

from PyQt5.QtCore import (
Qt, QPoint, QPropertyAnimation, QParallelAnimationGroup, QEasingCurve,
QSize)
from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import (QWidget, QHBoxLayout,
QGraphicsDropShadowEffect)

from app.common.qfluentwidgets import (isDarkTheme, TransparentToolButton,
FlyoutAnimationType, FluentIcon)
from app.common.icons import Icon


class CustomToolTip(QWidget):
def __init__(self, view: QWidget, target: QWidget, parent=None):
super().__init__(parent)
self.target = target

self.hBoxLayout = QHBoxLayout(self)
self.view = view
self.setWindowFlags(Qt.ToolTip | Qt.FramelessWindowHint |
Qt.NoDropShadowWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)

self.hBoxLayout.addWidget(self.view)
self.hBoxLayout.setContentsMargins(15, 8, 15, 20)

self.__initShadowEffect()
self.__initAnimation()

def __initShadowEffect(self, blurRadius=35, offset=(0, 8)):
color = QColor(0, 0, 0, 80 if isDarkTheme() else 30)

self.shadowEffect = QGraphicsDropShadowEffect(self.view)
self.shadowEffect.setBlurRadius(blurRadius)
self.shadowEffect.setOffset(*offset)
self.shadowEffect.setColor(color)

self.view.setGraphicsEffect(None)
self.view.setGraphicsEffect(self.shadowEffect)

def __initAnimation(self):
self.inOpacityAni = QPropertyAnimation(
self, b'windowOpacity', self.parent())
self.inSlideAni = QPropertyAnimation(self, b'pos', self.parent())

self.inOpacityAni.setDuration(187)
self.inSlideAni.setDuration(187)

self.inOpacityAni.setEasingCurve(QEasingCurve.InOutQuad)
self.inSlideAni.setEasingCurve(QEasingCurve.InOutQuad)

self.inOpacityAni.setStartValue(0)
self.inOpacityAni.setEndValue(1)

self.inAniGroup = QParallelAnimationGroup(self)
self.inAniGroup.addAnimation(self.inOpacityAni)
self.inAniGroup.addAnimation(self.inSlideAni)

self.outAniGroup = QParallelAnimationGroup(self)

self.outOpacityAni = QPropertyAnimation(
self, b'windowOpacity', self.parent())
self.outOpacityAni.setEasingCurve(QEasingCurve.InOutQuad)
self.outOpacityAni.setStartValue(1)
self.outOpacityAni.setEndValue(0)
self.outOpacityAni.setDuration(120)

self.outSlideAni = QPropertyAnimation(self, b'pos', self.parent())
self.outSlideAni.setEasingCurve(QEasingCurve.InOutQuad)
self.outSlideAni.setDuration(120)

self.outAniGroup.addAnimation(self.outOpacityAni)
self.outAniGroup.addAnimation(self.outSlideAni)

self.outAniGroup.finished.connect(self.close)

def showEvent(self, e):
pos = self.getPosition()

if self.animationType == FlyoutAnimationType.SLIDE_LEFT:
self.inSlideAni.setStartValue(pos + QPoint(10, 0))
else:
self.inSlideAni.setStartValue(pos - QPoint(10, 0))

self.inSlideAni.setEndValue(pos)
self.inAniGroup.start()

return super().showEvent(e)

def fadeOut(self):
self.outSlideAni.setStartValue(self.pos())

if self.animationType == FlyoutAnimationType.SLIDE_LEFT:
self.outSlideAni.setEndValue(self.pos() + QPoint(10, 0))
else:
self.outSlideAni.setEndValue(self.pos() - QPoint(10, 0))

self.outAniGroup.finished.connect(self.close)
self.outAniGroup.start()

def getPosition(self):
pos = self.target.mapToGlobal(QPoint())
x, y = pos.x(), pos.y()

hintWidth = self.sizeHint().width()
hintHeight = self.sizeHint().height()

x += self.target.width() // 2 - hintWidth // 2
y += self.target.height() // 2 - hintHeight // 2

dx = -hintWidth // 2 - 45

self.animationType = FlyoutAnimationType.SLIDE_LEFT

if x + dx < -15:
self.animationType = FlyoutAnimationType.SLIDE_RIGHT
dx = -dx

return QPoint(x + dx, y)


class HelpButton(TransparentToolButton):
def __init__(self, view: QWidget, parent: QWidget = None):
super().__init__(Icon.QUESTION_CIRCLE, parent=parent)

self.setFixedSize(QSize(26, 26))
self.setFixedSize(QSize(16, 16))

self.view = view
self.mToolTip = None

def enterEvent(self, e):
if self.mToolTip:
return

self.mToolTip = CustomToolTip(self.view, self)
self.mToolTip.show()

return super().enterEvent(e)

def leaveEvent(self, a0):
if not self.mToolTip:
return

self.mToolTip.fadeOut()
self.mToolTip = None
Binary file modified app/resource/i18n/Seraphine.zh_CN.qm
Binary file not shown.
Loading

0 comments on commit 458e9c9

Please sign in to comment.