跳转至

ui/components/material/cfmaterial_animation_strategy.h

Animation Strategy Interface for Material Design 3. More...

Namespaces

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

Classes

Name
struct cf::ui::components::material::AnimationDescriptor
Animation descriptor structure.
class cf::ui::components::material::AnimationStrategy
Abstract strategy interface for animation customization.
class cf::ui::components::material::DefaultAnimationStrategy
Default animation strategy implementation.

Detailed Description

Animation Strategy Interface for Material Design 3.

Author: Charliechen114514 (chengh1922@mails.jlu.edu.cn)

Version: 0.1

Date: 2026-02-28

Copyright: Copyright © 2026

Defines the strategy interface for animation customization based on widget types. This allows different widget types to have specialized animation behaviors while maintaining a consistent factory interface.

The Animation Strategy pattern enables:

  • Widget-specific animation parameter adjustments
  • Runtime animation type overrides
  • Conditional animation enable/disable logic
  • Reusable customization logic across different widget types

Source code

#pragma once

#include "export.h"
#include <QWidget>

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

struct CF_UI_EXPORT AnimationDescriptor {
    const char* animationType;

    const char* motionToken;

    const char* property;

    float fromValue;

    float toValue;

    int delayMs = 0;

    AnimationDescriptor() = default;

    AnimationDescriptor(const char* type, const char* motion, const char* prop, float from,
                        float to, int delay = 0)
        : animationType(type), motionToken(motion), property(prop), fromValue(from), toValue(to),
          delayMs(delay) {}
};

class CF_UI_EXPORT AnimationStrategy {
  public:
    virtual ~AnimationStrategy() = default;

    virtual AnimationDescriptor adjust(const AnimationDescriptor& descriptor, QWidget* widget) = 0;

    virtual bool shouldEnable(QWidget* widget) const;

    void setGlobalEnabled(bool enabled);

    bool globalEnabled() const { return globalEnabled_; }

  protected:
    bool globalEnabled_ = true;
};

class CF_UI_EXPORT DefaultAnimationStrategy : public AnimationStrategy {
  public:
    AnimationDescriptor adjust(const AnimationDescriptor& descriptor, QWidget* widget) override;
};

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

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