ui/components/material/cfmaterial_slide_animation.h¶
Material Design 3 Slide Animation. More...
Namespaces¶
| Name |
|---|
| cf |
| cf::ui |
| cf::ui::components |
| cf::ui::components::material |
Classes¶
| Name | |
|---|---|
| class | cf::ui::components::material::CFMaterialSlideAnimation Material Design 3 Slide Animation. |
Detailed Description¶
Material Design 3 Slide Animation.
Author: Charliechen114514 (chengh1922@mails.jlu.edu.cn)
Version: 0.1
Date: 2026-02-28
Copyright: Copyright © 2026
Implements a slide animation that follows Material Design 3 motion specifications. Animates the position of a widget from a start offset to an end offset using the specified timing and easing curve.
This animation integrates with the MaterialMotionScheme to obtain duration and easing values based on the motion token (e.g., "md.motion.mediumEnter").
Source code¶
#pragma once
#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 <QPoint>
#include <QWidget>
namespace cf::ui::components::material {
enum class SlideDirection {
Up,
Down,
Left,
Right
};
class CF_UI_EXPORT CFMaterialSlideAnimation : public ICFTimingAnimation {
Q_OBJECT
public:
explicit CFMaterialSlideAnimation(cf::ui::core::IMotionSpec* spec, SlideDirection direction,
QObject* parent = nullptr);
~CFMaterialSlideAnimation() override;
// Non-copyable, non-movable
CFMaterialSlideAnimation(const CFMaterialSlideAnimation&) = delete;
CFMaterialSlideAnimation& operator=(const CFMaterialSlideAnimation&) = delete;
CFMaterialSlideAnimation(CFMaterialSlideAnimation&&) = delete;
CFMaterialSlideAnimation& operator=(CFMaterialSlideAnimation&&) = delete;
// =========================================================================
// ICFAbstractAnimation Interface
// =========================================================================
void start(Direction dir = Direction::Forward) override;
void pause() override;
void stop() override;
void reverse() override;
bool tick(int dt) override;
// =========================================================================
// ICFTimingAnimation Interface
// =========================================================================
float currentValue() const override { return currentOffset_; }
// =========================================================================
// Slide-Specific Methods
// =========================================================================
void setTargetWidget(QWidget* widget);
QWidget* targetWidget() const { return targetWidget_; }
void setDistance(float distance) { distance_ = distance; }
float distance() const { return distance_; }
void setDirection(SlideDirection direction) { direction_ = direction; }
SlideDirection direction() const { return direction_; }
cf::WeakPtr<ICFAbstractAnimation> GetWeakPtr() override { return weak_factory_.GetWeakPtr(); }
private:
float currentOffset_ = 0.0f;
QWidget* targetWidget_ = nullptr;
QPoint originalPosition_;
SlideDirection direction_ = SlideDirection::Up;
float distance_ = 100.0f;
int durationMs_ = 300;
int delayMs_ = 0;
int elapsedTime_ = 0;
void applyOffset(float offset);
QPoint calculateOffsetPoint(float offset) const;
float calculateEasedProgress(float linearProgress) const;
cf::WeakPtrFactory<ICFAbstractAnimation> weak_factory_{this};
};
} // namespace cf::ui::components::material
Updated on 2026-03-09 at 10:14:01 +0000