跳转至

ui/widget/material/widget/groupbox/groupbox.h

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

Detailed Description

Material Design 3 GroupBox widget.

Author: CFDesktop Team

Version: 0.1

Since: 0.1

Date: 2026-03-01

Implements Material Design 3 group box with rounded corners, optional elevation shadows, and theme-aware colors. Provides a container for grouping related widgets with a title.

Source code

#pragma once

#include <QMarginsF>

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

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

// Forward declarations
namespace base {
class MdElevationController;
} // namespace base

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

class CF_UI_EXPORT GroupBox : public QGroupBox {
    Q_OBJECT
    Q_PROPERTY(int elevation READ elevation WRITE setElevation)
    Q_PROPERTY(float cornerRadius READ cornerRadius WRITE setCornerRadius)
    Q_PROPERTY(bool hasBorder READ hasBorder WRITE setHasBorder)

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

    explicit GroupBox(const QString& title, QWidget* parent = nullptr);

    ~GroupBox() override;

    int elevation() const;

    void setElevation(int level);

    float cornerRadius() const;

    void setCornerRadius(float radius);

    bool hasBorder() const;

    void setHasBorder(bool hasBorder);

    QSize sizeHint() const override;

    QSize minimumSizeHint() const override;

  protected:
    void paintEvent(QPaintEvent* event) override;

    void childEvent(QChildEvent* event) override;

    void changeEvent(QEvent* event) override;

    void resizeEvent(QResizeEvent* event) override;

  private:
    // Layout helpers
    void updateContentMargins();

    // Drawing helpers
    QMarginsF shadowMargin() const;
    void drawShadow(QPainter& p, const QRectF& contentRect, const QPainterPath& shape);
    void drawBackground(QPainter& p, const QPainterPath& shape);
    void drawBorder(QPainter& p, const QRectF& contentRect, const QPainterPath& shape);
    void drawTitle(QPainter& p, const QRectF& contentRect);

    // Color access methods
    CFColor surfaceColor() const;
    CFColor outlineColor() const;
    CFColor titleColor() const;
    QFont titleFont() const;

    // Calculate title area for background masking
    QRectF titleArea() const;

    // Behavior components
    cf::WeakPtr<components::material::CFMaterialAnimationFactory> m_animationFactory;
    base::MdElevationController* m_elevation;

    // Properties
    float m_cornerRadius;
    bool m_hasBorder;
    bool m_hasTitle;
};

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

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