跳转至

ui/components/material/cfmaterial_property_animation.h

Material Design 3 Property Animation. More...

Namespaces

Name
cf
cf::ui
cf::ui::components
cf::ui::components::material

Classes

Name
class cf::ui::components::material::CFMaterialPropertyAnimation
Material Design 3 Property Animation.

Detailed Description

Material Design 3 Property Animation.

Version: 0.1

Date: 2026-03-01

Copyright: Copyright © 2026

Implements a property animation that follows Material Design 3 motion specifications. Animates a float property from a start value to an end value using the specified duration and easing curve.

This animation is designed for simple property animations like:

  • Floating label progress (0.0 to 1.0)
  • Scale animations
  • Opacity transitions
  • Any float property animation

Source code

#pragma once

#include "base/easing.h"
#include "base/weak_ptr/weak_ptr.h"
#include "base/weak_ptr/weak_ptr_factory.h"
#include "components/timing_animation.h"
#include "core/motion_spec.h"
#include "export.h"
#include <QObject>

namespace cf::ui::components::material {

class CF_UI_EXPORT CFMaterialPropertyAnimation : public ICFAbstractAnimation {
    Q_OBJECT

  public:
    CFMaterialPropertyAnimation(float* value, float from, float to, int durationMs,
                                base::Easing::Type easing =
                                    base::Easing::Type::EmphasizedDecelerate,
                                QObject* parent = nullptr);

    ~CFMaterialPropertyAnimation() override;

    // Non-copyable, non-movable
    CFMaterialPropertyAnimation(const CFMaterialPropertyAnimation&) = delete;
    CFMaterialPropertyAnimation& operator=(const CFMaterialPropertyAnimation&) = delete;
    CFMaterialPropertyAnimation(CFMaterialPropertyAnimation&&) = delete;
    CFMaterialPropertyAnimation& operator=(CFMaterialPropertyAnimation&&) = delete;

    // =========================================================================
    // ICFAbstractAnimation Interface
    // =========================================================================

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

    void pause() override;

    void stop() override;

    void reverse() override;

    bool tick(int dt) override;
    cf::WeakPtr<ICFAbstractAnimation> GetWeakPtr() override {
        return weak_factory_.GetWeakPtr();
    }

    // =========================================================================
    // Property-Specific Methods
    // =========================================================================

    void setTargetWidget(QWidget* widget);

    float currentValue() const { return m_value ? *m_value : 0.0f; }

  private slots:
    void onTimerTick();

  private:
    float* m_value;

    float m_from;

    float m_to;

    int m_durationMs;

    base::Easing::Type m_easing;

    int m_elapsed;

    QWidget* m_targetWidget;

    QTimer* m_timer;

    float m_targetFps = 60.0f;

    int calculateInterval() const { return static_cast<int>(1000.0f / m_targetFps); }

    cf::WeakPtrFactory<ICFAbstractAnimation> weak_factory_{this};
};

} // namespace cf::ui::components::material

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