Files
FRAISEMOE2-Installer/animations.py
2025-07-03 18:38:03 +08:00

72 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from PySide6.QtCore import (QPropertyAnimation, QSequentialAnimationGroup,
QParallelAnimationGroup, QPoint, QEasingCurve)
from PySide6.QtWidgets import QGraphicsOpacityEffect
class LogoAnimations:
def __init__(self, ui):
self.ui = ui
self.logos = [
ui.vol1bg, ui.vol2bg, ui.vol3bg,
ui.vol4bg, ui.afterbg
]
self.animation_group = None
def initialize(self):
"""初始化所有logo的状态透明且位于屏幕外"""
for logo in self.logos:
# 保存原始位置
logo.original_pos = logo.pos()
# 设置透明度效果
opacity_effect = QGraphicsOpacityEffect(logo)
logo.setGraphicsEffect(opacity_effect)
opacity_effect.setOpacity(0)
# 移动到屏幕左侧外
logo.move(-logo.width(), logo.y())
def create_animation_sequence(self):
"""创建顺序动画序列"""
self.animation_group = QSequentialAnimationGroup()
# 为每个logo创建动画延迟递增
delays = [0, 50, 100, 150, 200] # 每个动画的延迟时间(ms)
for i, logo in enumerate(self.logos):
# 创建并行动画组(位置+透明度)
parallel_group = QParallelAnimationGroup()
# 位置动画(从左侧滑入)
pos_anim = QPropertyAnimation(logo, b"pos")
pos_anim.setDuration(800)
pos_anim.setStartValue(QPoint(-logo.width(), logo.y()))
pos_anim.setEndValue(logo.original_pos)
pos_anim.setEasingCurve(QEasingCurve.OutBack)
# 透明度动画(淡入)
opacity_anim = QPropertyAnimation(logo.graphicsEffect(), b"opacity")
opacity_anim.setDuration(800)
opacity_anim.setStartValue(0)
opacity_anim.setEndValue(1)
parallel_group.addAnimation(pos_anim)
parallel_group.addAnimation(opacity_anim)
# 添加延迟(使动画按顺序触发)
if delays[i] > 0:
delay_anim = QPropertyAnimation(logo, b"pos")
delay_anim.setDuration(delays[i])
self.animation_group.addAnimation(delay_anim)
self.animation_group.addAnimation(parallel_group)
return self.animation_group
def start_animation(self):
"""启动动画序列"""
self.initialize()
self.create_animation_sequence()
self.animation_group.start()
def stop_animation(self):
"""停止动画"""
if self.animation_group:
self.animation_group.stop()