跳转至

cf::ui::components::material::CFMaterialFadeAnimation

Material Design 3 Fade Animation. More...

#include <cfmaterial_fade_animation.h>

Inherits from cf::ui::components::ICFTimingAnimation, cf::ui::components::ICFAbstractAnimation, QObject

Public Functions

Name
CFMaterialFadeAnimation(cf::ui::core::IMotionSpec * spec, QObject * parent =nullptr)
Constructor with motion spec.
~CFMaterialFadeAnimation() override
Destructor.
CFMaterialFadeAnimation(constCFMaterialFadeAnimation & ) =delete
CFMaterialFadeAnimation & operator=(constCFMaterialFadeAnimation & ) =delete
CFMaterialFadeAnimation(CFMaterialFadeAnimation && ) =delete
CFMaterialFadeAnimation & operator=(CFMaterialFadeAnimation && ) =delete
virtual void start(Direction dir =Direction::Forward) override
Start the fade animation.
virtual void pause() override
Pause the animation.
virtual void stop() override
Stop the animation and reset to initial state.
virtual void reverse() override
Reverse the animation direction.
virtual bool tick(int dt) override
Update animation state.
virtual float currentValue() const override
Get the current opacity value.
void setTargetWidget(QWidget * widget)
Set the target widget for the fade animation.
QWidget * targetWidget() const
Get the target widget.
virtual cf::WeakPtr< ICFAbstractAnimation > GetWeakPtr() override
Get a weak pointer to this animation.

Additional inherited members

Public Functions inherited from cf::ui::components::ICFTimingAnimation

Name
ICFTimingAnimation(cf::ui::core::IMotionSpec * spec, QObject * parent =nullptr)
Constructor with motion specification.
virtual void setRange(float from, float to)
Sets the value range for the animation.

Protected Attributes inherited from cf::ui::components::ICFTimingAnimation

Name
cf::ui::core::IMotionSpec * motion_spec_
float m_from
float m_to
int m_elapsed

Public Types inherited from cf::ui::components::ICFAbstractAnimation

Name
enum class State { Idle, Running, Paused, Finished}
Animation states.
enum class Direction { Forward, Backward}
Animation playback direction.

Public Signals inherited from cf::ui::components::ICFAbstractAnimation

Name
void started()
Signal emitted when animation starts.
void paused()
Signal emitted when animation is paused.
void stopped()
Signal emitted when animation stops.
void reversed()
Signal emitted when animation reverses direction.
void finished()
Signal emitted when animation finishes.
void progressChanged(float progress)
Signal emitted when animation progress changes.

Public Functions inherited from cf::ui::components::ICFAbstractAnimation

Name
ICFAbstractAnimation(QObject * parent =nullptr)
bool getEnabled() const
Gets the enabled state of the animation.
void setTargetFps(float fps)
Set the target FPS for this animation.
int calculateInterval() const
Calculate the timer interval based on target FPS.

Protected Functions inherited from cf::ui::components::ICFAbstractAnimation

Name
void setEnabled(bool enabled)
Sets the enabled state of the animation.

Protected Attributes inherited from cf::ui::components::ICFAbstractAnimation

Name
QTimer * driven_internal_timer
float m_progress
State m_state
float targetFps_
Target FPS for this animation (default 60.0f)

Friends inherited from cf::ui::components::ICFAbstractAnimation

Name
class ICFAnimationManagerFactory(ICFAnimationManagerFactory )

Detailed Description

class cf::ui::components::material::CFMaterialFadeAnimation;

Material Design 3 Fade Animation.

Since: 0.1

Note: The target widget must remain valid during animation.

Warning: Changing the target widget during animation may cause issues.

Animates the opacity of a widget from a start value to an end value following Material Design 3 motion specifications.

The animation uses:

  • Duration from the MotionSpec token
  • Easing curve from the MotionSpec token
  • Optional delay before starting

Opacity is applied via QGraphicsOpacityEffect for widgets that support it.

// Create a fade-in animation
auto& motionSpec = theme.motion_spec();
auto fadeAnim = std::make_unique<CFMaterialFadeAnimation>(
    cf::WeakPtr<cf::ui::core::IMotionSpec>(&motionSpec),
    this);
fadeAnim->setRange(0.0f, 1.0f);  // Fade from transparent to opaque
fadeAnim->setTargetWidget(myWidget);
fadeAnim->start();

// Connect to progress signal
connect(fadeAnim.get(), &ICFAbstractAnimation::progressChanged,
        this, [](float progress) {
    qDebug() << "Fade progress:" << progress;
});

Public Functions Documentation

function CFMaterialFadeAnimation

explicit CFMaterialFadeAnimation(
    cf::ui::core::IMotionSpec * spec,
    QObject * parent =nullptr
)

Constructor with motion spec.

Parameters:

  • spec Raw pointer to the motion spec for timing/easing. Must remain valid for the lifetime of this animation.
  • parent QObject parent.

Exceptions:

  • None

Since: 0.1

Note: None

Warning: None

function ~CFMaterialFadeAnimation

~CFMaterialFadeAnimation() override

Destructor.

Since: 0.1

function CFMaterialFadeAnimation

CFMaterialFadeAnimation(
    constCFMaterialFadeAnimation & 
) =delete

function operator=

CFMaterialFadeAnimation & operator=(
    constCFMaterialFadeAnimation & 
) =delete

function CFMaterialFadeAnimation

CFMaterialFadeAnimation(
    CFMaterialFadeAnimation && 
) =delete

function operator=

CFMaterialFadeAnimation & operator=(
    CFMaterialFadeAnimation && 
) =delete

function start

virtual void start(
    Direction dir =Direction::Forward
) override

Start the fade animation.

Parameters:

  • dir Direction to play (Forward = fade in, Backward = fade out).

Exceptions:

  • None

Since: 0.1

Note: None

Warning: None

Reimplements: cf::ui::components::ICFAbstractAnimation::start

function pause

virtual void pause() override

Pause the animation.

Since: 0.1

Reimplements: cf::ui::components::ICFAbstractAnimation::pause

function stop

virtual void stop() override

Stop the animation and reset to initial state.

Since: 0.1

Reimplements: cf::ui::components::ICFAbstractAnimation::stop

function reverse

virtual void reverse() override

Reverse the animation direction.

Since: 0.1

Reimplements: cf::ui::components::ICFAbstractAnimation::reverse

function tick

virtual bool tick(
    int dt
) override

Update animation state.

Parameters:

  • dt Time elapsed since last tick (milliseconds).

Exceptions:

  • None

Return: true if animation is still running, false if finished.

Since: 0.1

Note: None

Warning: None

Reimplements: cf::ui::components::ICFAbstractAnimation::tick

function currentValue

inline virtual float currentValue() const override

Get the current opacity value.

Return: Current opacity (0.0 = transparent, 1.0 = opaque).

Since: 0.1

Reimplements: cf::ui::components::ICFTimingAnimation::currentValue

function setTargetWidget

void setTargetWidget(
    QWidget * widget
)

Set the target widget for the fade animation.

Parameters:

  • widget Target widget (may be nullptr).

Exceptions:

  • None

Since: 0.1

Note: None

Warning: None

The widget's opacity is animated. The widget must remain valid for the duration of the animation.

fadeAnim->setTargetWidget(myLabel);

function targetWidget

inline QWidget * targetWidget() const

Get the target widget.

Return: Target widget, or nullptr if not set.

Since: 0.1

function GetWeakPtr

inline virtual cf::WeakPtr< ICFAbstractAnimation > GetWeakPtr() override

Get a weak pointer to this animation.

Return: WeakPtr that can be used to safely access this animation.

Since: 0.1

Reimplements: cf::ui::components::ICFAbstractAnimation::GetWeakPtr


Updated on 2026-03-09 at 10:14:00 +0000