跳转至

ui/widget/material/widget/radiobutton/radiobutton.h

Material Design 3 RadioButton widget. 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::RadioButton
Material Design 3 RadioButton widget.

Types

Name
using cf::ui::base::CFColor CFColor

Detailed Description

Material Design 3 RadioButton widget.

Author: CFDesktop Team

Version: 0.1

Since: 0.1

Date: 2026-03-01

Implements Material Design 3 radio button with circular selection area, inner circle scale animation, ripple effects, and focus indicators. Supports mutual exclusion through QButtonGroup integration.

Types Documentation

using CFColor

using CFColor =  cf::ui::base::CFColor;

Source code

#pragma once

#include "base/include/base/weak_ptr/weak_ptr.h"
#include "cfmaterial_animation_factory.h"
#include "color.h"
#include "export.h"
#include <QRadioButton>
#include <QWidget>

using CFColor = cf::ui::base::CFColor;

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

// Forward declarations
namespace base {
class StateMachine;
class RippleHelper;
class MdFocusIndicator;
} // namespace base

class CF_UI_EXPORT RadioButton : public QRadioButton {
    Q_OBJECT
    Q_PROPERTY(bool error READ hasError WRITE setError DESIGNABLE true SCRIPTABLE true)
    Q_PROPERTY(bool pressEffectEnabled READ pressEffectEnabled WRITE setPressEffectEnabled)

  public:
    explicit RadioButton(QWidget* parent = nullptr);

    explicit RadioButton(const QString& text, QWidget* parent = nullptr);

    ~RadioButton() override;

    bool hasError() const;

    void setError(bool error);

    bool pressEffectEnabled() const;

    void setPressEffectEnabled(bool enabled);

    void setChecked(bool checked);

    QSize sizeHint() const override;

    QSize minimumSizeHint() const override;

    bool hitButton(const QPoint& pos) const override;

  protected:
    void paintEvent(QPaintEvent* event) override;

    void enterEvent(QEnterEvent* event) override;

    void leaveEvent(QEvent* event) override;

    void mousePressEvent(QMouseEvent* event) override;

    void mouseReleaseEvent(QMouseEvent* event) override;

    void focusInEvent(QFocusEvent* event) override;

    void focusOutEvent(QFocusEvent* event) override;

    void changeEvent(QEvent* event) override;

    void nextCheckState() override;

  private:
    // Drawing helpers - Material Design paint pipeline
    void drawStateLayer(QPainter& p, const QRectF& radioRect);
    void drawRipple(QPainter& p, const QRectF& radioRect);
    void drawOuterRing(QPainter& p, const QRectF& radioRect);
    void drawInnerCircle(QPainter& p, const QRectF& radioRect);
    void drawText(QPainter& p, const QRectF& textRect);
    void drawFocusIndicator(QPainter& p, const QRectF& radioRect);

    // Color access methods
    CFColor radioColor() const;
    CFColor onRadioColor() const;
    CFColor stateLayerColor() const;
    CFColor errorColor() const;
    QFont labelFont() const;

    // Layout calculations
    QRectF calculateRadioRect() const;
    QRectF calculateTextRect(const QRectF& radioRect) const;

    // Animation helpers
    void startInnerCircleAnimation(bool checked);

    // Behavior components
    cf::WeakPtr<components::material::CFMaterialAnimationFactory> m_animationFactory;
    base::StateMachine* m_stateMachine;
    base::RippleHelper* m_ripple;
    base::MdFocusIndicator* m_focusIndicator;

    // Animation state
    float m_innerCircleScale = 0.0f;

    // Properties
    bool m_hasError = false;
    bool m_pressEffectEnabled = true;
};

} // namespace cf::ui::widget::material

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