colordialog/picker/wheel: finished color picker UI

Dialog is still unmanaged, but that's the only remaining step.
This commit is contained in:
itsmattkc
2020-04-02 19:26:30 +11:00
parent a2ed1035da
commit 4d0b8f18e2
13 changed files with 366 additions and 236 deletions
+76 -2
View File
@@ -87,14 +87,14 @@ void Color::toHsv(float *hue, float *sat, float *val) const
}
}
float Color::hue() const
float Color::hsv_hue() const
{
float h, s, v;
toHsv(&h, &s, &v);
return h;
}
float Color::saturation() const
float Color::hsv_saturation() const
{
float h, s, v;
toHsv(&h, &s, &v);
@@ -107,3 +107,77 @@ float Color::value() const
toHsv(&h, &s, &v);
return v;
}
void Color::toHsl(float *hue, float *sat, float *lightness) const
{
float fCMin = qMin(red(), qMin(green(), blue()));
float fCMax = qMax(red(), qMax(green(), blue()));
*lightness = 0.5 * (fCMin + fCMax);
if (fCMin == fCMax)
{
*sat = 0;
*hue = 0;
return;
}
else if (*lightness < 0.5)
{
*sat = (fCMax - fCMin) / (fCMax + fCMin);
}
else
{
*sat = (fCMax - fCMin) / (2.0 - fCMax - fCMin);
}
if (fCMax == red())
{
*hue = 60 * (green() - blue()) / (fCMax - fCMin);
}
if (fCMax == green())
{
*hue = 60 * (blue() - red()) / (fCMax - fCMin) + 120;
}
if (fCMax == blue())
{
*hue = 60 * (red() - green()) / (fCMax - fCMin) + 240;
}
if (*hue < 0)
{
*hue = *hue + 360;
}
}
float Color::hsl_hue() const
{
float h, s, l;
toHsl(&h, &s, &l);
return h;
}
float Color::hsl_saturation() const
{
float h, s, l;
toHsl(&h, &s, &l);
return s;
}
float Color::lightness() const
{
float h, s, l;
toHsl(&h, &s, &l);
return l;
}
QColor Color::toQColor() const
{
QColor c;
c.setRedF(red());
c.setGreenF(green());
c.setBlueF(blue());
c.setAlphaF(alpha());
return c;
}