File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 11#include " colortheme.h"
2+ #include " colorutils.h"
23
34QString ColorTheme::getIcon (const QString& name) {
45 switch (m_group) {
Original file line number Diff line number Diff line change 44#include < QObject>
55#include < QQmlEngine>
66#include < QColor>
7+ #include < QRandomGenerator>
8+
79
810class ColorUtils : public QObject {
911 Q_OBJECT
@@ -58,6 +60,33 @@ class ColorUtils : public QObject {
5860 }
5961 // If used with light mode, this will make things lighter and vice versa.
6062 Q_INVOKABLE static QColor daytimeModeAdjust (QColor c, float ratio);
63+
64+
65+ Q_INVOKABLE static QColor brighten (QColor input, float factor = 0 .0F ) {
66+ // TODO this is probably not too useful
67+ factor = std::clamp (factor, -1 .0F , 1 .0F );
68+ HSLA hsla (input);
69+ float lightnessRange = qMin (hsla.l , (1 .0F - hsla.l ));
70+ hsla.l += factor * lightnessRange;
71+ return hsla.toColor ();
72+ }
73+
74+ Q_INVOKABLE static QColor setLightness (QColor input, float newL) {
75+ HSLA hsla (input);
76+ hsla.l = std::clamp (newL, 0 .0F , 1 .0F );
77+ return hsla.toColor ();
78+ }
79+
80+ Q_INVOKABLE static QColor setSaturation (QColor input, float newS) {
81+ HSLA hsla (input);
82+ hsla.s = std::clamp (newS, 0 .0F , 1 .0F );
83+ return hsla.toColor ();
84+ }
85+
86+ Q_INVOKABLE static QColor random () {
87+ auto * gen = QRandomGenerator::system ();
88+ return QColor::fromRgb (gen->bounded (256 ), gen->bounded (256 ), gen->bounded (256 ));
89+ }
6190};
6291
6392#endif // COLORUTILS_H
You can’t perform that action at this time.
0 commit comments