跳转至

ui/base/color.h

Enhanced color representation with HCT color space support. More...

Namespaces

Name
cf
cf::ui
cf::ui::base

Classes

Name
class cf::ui::base::CFColor
Enhanced color class with HCT color space support.

Detailed Description

Enhanced color representation with HCT color space support.

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

Version: 0.1

Since: 0.1

Date: 2026-02-23

Provides the CFColor class which extends QColor with HCT (Hue-Chroma-Tone) color space for Material Design 3 color system compatibility.

Source code

#pragma once
#include <QColor>
#include <QString>

namespace cf::ui::base {

class CFColor {
  public:
    CFColor() : internal_color(Qt::black) {}

    CFColor(int r, int g, int b);

    CFColor(const QColor& native);

    explicit CFColor(const QString& hex);

    CFColor(const char* hex);

    CFColor(float hue, float chroma, float tone);

    float relativeLuminance() const;

    float hue() const;

    float chroma() const;

    float tone() const;

    QColor native_color() const { return internal_color; }

    CFColor(const CFColor& other) = default;

    CFColor& operator=(const CFColor& other) = default;

  private:
    QColor internal_color; 

    // Cached HCT values (computed from RGB in constructors)
    float m_hue = 0.0f;    
    float m_chroma = 0.0f; 
    float m_tone = 0.0f;   
};

} // namespace cf::ui::base

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