14
14
15
15
#include " color.h"
16
16
17
- /* !
18
- \qmltype Color
19
- \instantiates Color
20
- \inqmlmodule Fluid
21
-
22
- \brief Utility functions for colors.
23
-
24
- Utility functions to manipulate colors.
25
- */
26
-
27
17
Color::Color (QObject *parent)
28
18
: QObject(parent)
29
19
{
30
20
}
31
21
32
- /* !
33
- \qmlmethod color Fluid.Controls::Color::transparent(color color, real alpha)
34
-
35
- A utility method for changing the \a alpha on \a color.
36
- Returns a new object, and does not modify the original color at all.
37
- */
38
22
QColor Color::transparent (const QColor &color, qreal alpha)
39
23
{
40
24
return QColor (color.red (), color.green (), color.blue (), int (qBound<qreal>(0.0 , alpha, 1.0 ) * 255 ));
41
25
}
42
26
43
- /* !
44
- \qmlmethod color Fluid.Controls::Color::blend(color color1, color color2, real alpha)
45
-
46
- Blend \a color1 and \a color2 together and set alpha to \a alpha.
47
- */
48
27
QColor Color::blend (const QColor &color1, const QColor &color2, qreal alpha)
49
28
{
50
29
QColor color;
@@ -54,34 +33,17 @@ QColor Color::blend(const QColor &color1, const QColor &color2, qreal alpha)
54
33
return transparent (color, alpha);
55
34
}
56
35
57
- /* !
58
- \qmlmethod real Fluid.Controls::Color::luminance(color color)
59
-
60
- Calculate luminance of \a color.
61
- */
62
36
qreal Color::luminance (const QColor &color)
63
37
{
64
38
return (color.redF () * 0.2126 ) + (color.greenF () * 0.7152 ) + (color.blueF () * 0.0722 );
65
39
}
66
40
67
- /* !
68
- \qmlmethod bool Fluid.Controls::Color::isDarkColor(color color)
69
-
70
- Returns \c true if \a color is dark and should have light content on top.
71
- */
72
41
bool Color::isDarkColor (const QColor &color)
73
42
{
74
43
auto a = 1.0 - (0.299 * color.redF () + 0.587 * color.greenF () + 0.114 * color.blueF ());
75
44
return color.alphaF () > 0.0 && a >= 0.3 ;
76
45
}
77
46
78
- /* !
79
- \qmlmethod color Fluid.Controls::Color::lightDark(color background, color lightColor, color darkColor)
80
-
81
- Select a color depending on whether \a background color is light or dark.
82
- Returns \a lightColor if \a background is a light color, otherwise
83
- returns \a darkColor.
84
- */
85
47
QColor Color::lightDark (const QColor &background, const QColor &lightColor, const QColor &darkColor)
86
48
{
87
49
return isDarkColor (background) ? darkColor : lightColor;
0 commit comments