2 # SPDX-FileCopyrightText: 2011-2024 Filipe Coelho <falktx@falktx.com>
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # ------------------------------------------------------------------------------------------------------------
8 from qt_compat
import qt_config
11 from PyQt5
.QtCore
import QAbstractAnimation
12 from PyQt5
.QtWidgets
import QGraphicsObject
14 from PyQt6
.QtCore
import QAbstractAnimation
15 from PyQt6
.QtWidgets
import QGraphicsObject
17 # ------------------------------------------------------------------------------------------------------------
20 from . import canvas
, CanvasBoxType
22 # ------------------------------------------------------------------------------------------------------------
24 class CanvasFadeAnimation(QAbstractAnimation
):
25 def __init__(self
, item
, show
):
26 QAbstractAnimation
.__init
__(self
)
31 self
.m_item_is_object
= isinstance(item
, QGraphicsObject
)
37 self
.blockSignals(True)
39 self
.blockSignals(False)
41 def setDuration(self
, time
):
42 if self
.m_item
.opacity() == 0 and not self
.m_show
:
45 if self
.m_item_is_object
:
46 self
.m_item
.blockSignals(True)
48 self
.m_item
.blockSignals(False)
51 self
.m_duration
= time
54 return self
.m_duration
56 def updateCurrentTime(self
, time
):
57 if self
.m_duration
== 0:
61 value
= float(time
) / self
.m_duration
63 value
= 1.0 - (float(time
) / self
.m_duration
)
66 self
.m_item
.setOpacity(value
)
68 print("CanvasFadeAnimation::updateCurrentTime() - failed to animate canvas item, already destroyed?")
70 canvas
.animation_list
.remove(self
)
73 if self
.m_item
.type() == CanvasBoxType
:
74 self
.m_item
.setShadowOpacity(value
)
76 def updateDirection(self
, direction
):
79 def updateState(self
, oldState
, newState
):
82 # ------------------------------------------------------------------------------------------------------------