跳转至

ui/widget/material/base/state_machine.h

Material Design state machine for widget interaction states. More...

Namespaces

Name
cf
cf::ui
cf::ui::widget
cf::ui::widget::material
cf::ui::widget::material::base

Classes

Name
class cf::ui::widget::material::base::StateMachine
Material Design state machine.

Detailed Description

Material Design state machine for widget interaction states.

Author: N/A

Version: N/A

Since: N/A

Date: N/A

Manages Material Design widget states including hover, pressed, focused, disabled, and checked states with animated state layer transitions.

Source code

#pragma once
#include "base/include/base/weak_ptr/weak_ptr.h"
#include "components/material/cfmaterial_animation_factory.h"
#include "export.h"
#include <QObject>

namespace cf::ui::widget::material::base {

class CF_UI_EXPORT StateMachine : public QObject {
    Q_OBJECT
  public:
    enum class State {
        StateNormal = 0x00,   
        StateHovered = 0x01,  
        StatePressed = 0x02,  
        StateFocused = 0x04,  
        StateDisabled = 0x08, 
        StateChecked = 0x10,  
        StateDragged = 0x20   
    };
    Q_DECLARE_FLAGS(States, State)


    explicit StateMachine(cf::WeakPtr<components::material::CFMaterialAnimationFactory> factory,
                          QObject* parent);

    void onHoverEnter();

    void onHoverLeave();

    void onPress(const QPoint& pos);

    void onRelease();

    void onFocusIn();

    void onFocusOut();

    void onEnable();

    void onDisable();

    void onCheckedChanged(bool checked);

    ~StateMachine();

    States currentState() const;

    bool hasState(State s) const;

    float stateLayerOpacity() const;

  signals:
    void stateChanged(States newState, States oldState);

    void stateLayerOpacityChanged(float opacity);

  private:
    void animateOpacityTo(float to);

    void cancelCurrentAnimation();

    void onAnimationFinished();

    float targetOpacityForState(States s) const;

    States m_state = State::StateNormal;
    float m_opacity = 0.0f;
    cf::WeakPtr<components::material::CFMaterialAnimationFactory> m_animator;

    cf::WeakPtr<components::ICFAbstractAnimation> m_currentAnimation;
};
} // namespace cf::ui::widget::material::base

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