Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
color_math.h
Go to the documentation of this file.
1
9
10#ifndef COLOR_MATH_H
11#define COLOR_MATH_H
12
14
15#include <QColor>
16
29{
30public:
31 // ---------------------------------------------------------------
32 // Luminance & contrast
33 // ---------------------------------------------------------------
34
36 static double relativeLuminance(const QColor &color);
37
40 static qreal contrastRatio(const QColor &color1, const QColor &color2);
41
52 static QColor ensureContrast(const QColor &c, const QColor &bg, qreal minRatio);
53
57 static bool isDark(const QColor &color);
58
62 static constexpr qreal DistinctSurfaceRatio = 1.5;
63
66 static constexpr qreal ReadableTextRatio = 4.5;
67
75 static QColor selectionHoverFill(const QColor &base, const QColor &selection);
76
79 static QColor readableText(const QColor &text, const QColor &surface);
80
83 static bool isReadable(const QColor &text, const QColor &surface);
84
85 // ---------------------------------------------------------------
86 // Mix / shade
87 // ---------------------------------------------------------------
88
91 static QColor mix(const QColor &a, const QColor &b, qreal ratio = 0.5);
92 static ThemeColorPair mix(const ThemeColorPair &a, const ThemeColorPair &b, qreal ratio = 0.5);
93
96 static QColor darken(const QColor &c, int percent);
97 static ThemeColorPair darken(const ThemeColorPair &p, int percent);
98
101 static QColor lighten(const QColor &c, int percent);
102 static ThemeColorPair lighten(const ThemeColorPair &p, int percent);
103
104 // ---------------------------------------------------------------
105 // Alpha
106 // ---------------------------------------------------------------
107
109 static QColor withAlpha(const QColor &c, int alpha);
110 static ThemeColorPair withAlpha(const ThemeColorPair &p, int alpha);
111
113 static QColor withAlphaF(const QColor &c, qreal alpha);
114 static ThemeColorPair withAlphaF(const ThemeColorPair &p, qreal alpha);
115
116 // ---------------------------------------------------------------
117 // Contrast & state
118 // ---------------------------------------------------------------
119
123 static QColor contrastingText(const QColor &surface);
125
130 static QColor contrastingTextOver(const QColor &surface, const QColor &backdrop);
131
133 static QColor disabled(const QColor &c, const QColor &background);
134 static ThemeColorPair disabled(const ThemeColorPair &p, const QColor &background);
135
137 static QColor hoverBg(const QColor &c, const QColor &background);
138 static ThemeColorPair hoverBg(const ThemeColorPair &p, const QColor &background);
139};
140
141#endif /* COLOR_MATH_H */
Definition color_math.h:29
static bool isDark(const QColor &color)
Definition color_math.cpp:89
static constexpr qreal DistinctSurfaceRatio
Definition color_math.h:62
static QColor withAlpha(const QColor &c, int alpha)
Definition color_math.cpp:151
static bool isReadable(const QColor &text, const QColor &surface)
Definition color_math.cpp:84
static QColor selectionHoverFill(const QColor &base, const QColor &selection)
Definition color_math.cpp:71
static QColor contrastingTextOver(const QColor &surface, const QColor &backdrop)
Definition color_math.cpp:202
static QColor ensureContrast(const QColor &c, const QColor &bg, qreal minRatio)
Definition color_math.cpp:51
static QColor lighten(const QColor &c, int percent)
Definition color_math.cpp:133
static QColor disabled(const QColor &c, const QColor &background)
Definition color_math.cpp:220
static QColor mix(const QColor &a, const QColor &b, qreal ratio=0.5)
Definition color_math.cpp:98
static QColor darken(const QColor &c, int percent)
Definition color_math.cpp:119
static constexpr qreal ReadableTextRatio
Definition color_math.h:66
static qreal contrastRatio(const QColor &color1, const QColor &color2)
Definition color_math.cpp:42
static QColor withAlphaF(const QColor &c, qreal alpha)
Definition color_math.cpp:163
static QColor contrastingText(const QColor &surface)
Definition color_math.cpp:179
static QColor readableText(const QColor &text, const QColor &surface)
Definition color_math.cpp:79
static double relativeLuminance(const QColor &color)
Definition color_math.cpp:34
static QColor hoverBg(const QColor &c, const QColor &background)
Definition color_math.cpp:230
Definition theme_manager.h:38