QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskHctColor.h
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_HCT_COLOR_H
7#define QSK_HCT_COLOR_H
8
9#include "QskGlobal.h"
10#include <qcolor.h>
11
12/*
13 For M(aterial)3 the new HTC color system has been created, that
14 is based on H(ue), (C)hroma, (T)one:
15
16 https://material.io/blog/science-of-color-design
17
18 This system allows to create color palettes by varying the tone
19 for given hue/chroma values.
20
21 https://material-foundation.github.io/material-theme-builder/#/custom
22 shows how to create a tonal palette from a given RGB color.
23 */
24
25class QSK_EXPORT QskHctColor
26{
27 public:
28 constexpr QskHctColor() noexcept = default;
29 constexpr QskHctColor( qreal hue, qreal chrome, qreal tone = 40 ) noexcept;
30
31 QskHctColor( QRgb );
32
33 void setHue( qreal hue );
34 constexpr qreal hue() const noexcept;
35
36 void setChroma( qreal chroma ) noexcept;
37 constexpr qreal chroma() const noexcept;
38
39 void setTone( qreal tone ) noexcept;
40 constexpr qreal tone() const noexcept;
41
42 constexpr QskHctColor toned( qreal tone ) const noexcept;
43
44 void setRgb( QRgb );
45 QRgb rgb() const;
46
47 private:
48 qreal m_hue = 0; // [0.0, 360.0[
49 qreal m_chroma = 0;
50 qreal m_tone = 0; // [0.0, 100.0]
51};
52
53Q_DECLARE_TYPEINFO( QskHctColor, Q_MOVABLE_TYPE );
54
55inline constexpr QskHctColor::QskHctColor( qreal hue, qreal chroma, qreal tone ) noexcept
56 : m_hue( hue )
57 , m_chroma( chroma )
58 , m_tone( tone )
59{
60}
61
62inline constexpr qreal QskHctColor::hue() const noexcept
63{
64 return m_hue;
65}
66
67inline constexpr qreal QskHctColor::chroma() const noexcept
68{
69 return m_chroma;
70}
71
72inline constexpr qreal QskHctColor::tone() const noexcept
73{
74 return m_tone;
75}
76
77inline constexpr QskHctColor QskHctColor::toned( qreal tone ) const noexcept
78{
79 return QskHctColor( m_hue, m_chroma, tone );
80}
81
82#ifndef QT_NO_DEBUG_STREAM
83
84 class QDebug;
85 QSK_EXPORT QDebug operator<<( QDebug, const QskHctColor& );
86
87#endif
88
89#endif