colordialog/picker/wheel: finished color picker UI
Dialog is still unmanaged, but that's the only remaining step.
This commit is contained in:
+76
-2
@@ -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;
|
||||
}
|
||||
|
||||
+11
-2
@@ -1,6 +1,8 @@
|
||||
#ifndef COLOR_H
|
||||
#define COLOR_H
|
||||
|
||||
#include <QColor>
|
||||
|
||||
#include "common/define.h"
|
||||
#include "render/pixelformat.h"
|
||||
|
||||
@@ -40,10 +42,15 @@ public:
|
||||
const float& alpha() const {return data_[3];}
|
||||
|
||||
void toHsv(float* hue, float* sat, float* val) const;
|
||||
float hue() const;
|
||||
float saturation() const;
|
||||
float hsv_hue() const;
|
||||
float hsv_saturation() const;
|
||||
float value() const;
|
||||
|
||||
void toHsl(float* hue, float* sat, float* lightness) const;
|
||||
float hsl_hue() const;
|
||||
float hsl_saturation() const;
|
||||
float lightness() const;
|
||||
|
||||
void set_red(const float& red) {data_[0] = red;}
|
||||
void set_green(const float& green) {data_[1] = green;}
|
||||
void set_blue(const float& blue) {data_[2] = blue;}
|
||||
@@ -54,6 +61,8 @@ public:
|
||||
|
||||
static Color fromData(const char* data, const PixelFormat::Format& format);
|
||||
|
||||
QColor toQColor() const;
|
||||
|
||||
private:
|
||||
float data_[kRGBAChannels];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user