Commit 2e3bcccb authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Anti-wiggly measure for Color Slider docker.

Some anti-wiggly measure for the color slider docker. This is not as
effective as actually increasing the precision of the algorithms
involved, but it sorta helps decreasing the noise up to 2 colour models
at once.
For all 12 sliders at once the algorithms need to become mre precise,
but that has been more complex than I anticipated. For now, a stopgap
solution.
parent 493fdae5
......@@ -86,6 +86,8 @@ void KisColorSliderInput::init()
m_hsvSlider->setMaximumHeight(60);
m_hsvSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_layout->addWidget(m_hsvSlider, 0, 1);
connect (m_hsvSlider, SIGNAL(sliderPressed()), SLOT(sliderIn()));
connect (m_hsvSlider, SIGNAL(sliderReleased()), SLOT(sliderOut()));
QWidget* m_input = createInput();
m_input->setMaximumHeight(60);
......@@ -172,6 +174,12 @@ void KisHSXColorSliderInput::setValue(double v)
s=m_sat/100.0f;
l=m_val/100.0f;
*m_color = this->converter()->fromHsvF(h, s, l);
if (m_satupdating==false) {
emit(satUpdated(static_cast<int>(m_sat), m_type));
}
else {
m_satupdating=false;
}
break;
case 2:
m_val = v;
......@@ -186,6 +194,12 @@ void KisHSXColorSliderInput::setValue(double v)
s=m_sat/100.0f;
l=m_val/100.0f;
*m_color = this->converter()->fromHslF(h, s, l);
if (m_satupdating==false) {
emit(satUpdated(static_cast<int>(m_sat), m_type));
}
else {
m_satupdating=false;
}
break;
case 5:
m_val = v;
......@@ -200,6 +214,12 @@ void KisHSXColorSliderInput::setValue(double v)
s=m_sat/100.0f;
l=m_val/100.0f;
*m_color = this->converter()->fromHsiF(h, s, l);
if (m_satupdating==false) {
emit(satUpdated(static_cast<int>(m_sat), m_type));
}
else {
m_satupdating=false;
}
break;
case 8:
m_val = v;
......@@ -214,6 +234,12 @@ void KisHSXColorSliderInput::setValue(double v)
s=m_sat/100.0f;
l=m_val/100.0f;
*m_color = this->converter()->fromHsyF(h, s, l, R, G, B);
if (m_satupdating==false) {
emit(satUpdated(static_cast<int>(m_sat), m_type));
}
else {
m_satupdating=false;
}
break;
case 11:
m_val = v;
......@@ -230,36 +256,244 @@ void KisHSXColorSliderInput::setValue(double v)
//update
void KisHSXColorSliderInput::update()
{
KoColor min = *m_color;
KoColor max = *m_color;
qreal hue, sat, val, hue_backup, sat_backup;
qreal hue, sat, val, hue_backup, sat_backup, val_backup;
//gets the hsv for the appropriate type//
hue_backup = m_hue;
sat_backup = m_sat;
val_backup = m_val;
switch (m_type) {
case 0:
this->converter()->getHsvF(*m_color, &hue, &sat, &val);
if (m_sliderisupdating==true)
{
if((sat*100.0)<m_sat+1 && (sat*100.0)>m_sat-1) {
sat = (sat_backup*0.01);
}
if((val*100.0)<m_val+1 && (val*100.0)>m_val-1) {
val = (val_backup*0.01);
}
}
else{
if((hue*360.0)<m_hue+1 && (hue*360.0)>m_hue-1) {
hue = (hue_backup/360.0);
}
}
break;
case 1:
this->converter()->getHsvF(*m_color, &hue, &sat, &val);
if (m_sliderisupdating==true)
{
if( (hue*360.0)<m_hue+1 && (hue*360.0)>m_hue-1 ) {
hue = (hue_backup/360.0);
}
if((val*100.0)<m_val+1 && (val*100.0)>m_val-1) {
val = (val_backup*0.01);
}
}
else{
if((sat*100.0)<m_sat+1 && (sat*100.0)>m_sat-1) {
sat = (sat_backup*0.01);
}
}
break;
case 2:
this->converter()->getHsvF(*m_color, &hue, &sat, &val);
if (m_sliderisupdating==true)
{
if((sat*100.0)<m_sat+1 && (sat*100.0)>m_sat-1) {
sat = (sat_backup*0.01);
}
if((hue*360.0)<m_hue+1 && (hue*360.0)>m_hue-1) {
hue = (hue_backup/360.0);
}
}
else{
if((val*100.0)<m_val+1 && (val*100.0)>m_val-1) {
val = (val_backup*0.01);
}
}
break;
case 3:
this->converter()->getHslF(*m_color, &hue, &sat, &val);
if (m_sliderisupdating==true)
{
if((sat*100.0)<m_sat+1 && (sat*100.0)>m_sat-1) {
sat = (sat_backup*0.01);
}
if((val*100.0)<m_val+1 && (val*100.0)>m_val-1) {
val = (val_backup*0.01);
}
}
else{
if((hue*360.0)<m_hue+1 && (hue*360.0)>m_hue-1) {
hue = (hue_backup/360.0);
}
}
break;
case 4:
this->converter()->getHslF(*m_color, &hue, &sat, &val);
if (m_sliderisupdating==true)
{
if((hue*360.0)<m_hue+1 && (hue*360.0)>m_hue-1) {
hue = (hue_backup/360.0);
}
if((val*100.0)<m_val+1 && (val*100.0)>m_val-1) {
val = (val_backup*0.01);
}
}
else{
if((sat*100.0)<m_sat+1 && (sat*100.0)>m_sat-1) {
sat = (sat_backup*0.01);
}
}
break;
case 5:
this->converter()->getHslF(*m_color, &hue, &sat, &val);
if (m_sliderisupdating==true)
{
if((sat*100.0)<m_sat+1 && (sat*100.0)>m_sat-1) {
sat = (sat_backup*0.01);
}
if((hue*360.0)<m_hue+1 && (hue*360.0)>m_hue-1) {
hue = (hue_backup/360.0);
}
}
else{
if((val*100.0)<m_val+1 && (val*100.0)>m_val-1) {
val = (val_backup*0.01);
}
}
break;
case 6:
this->converter()->getHsiF(*m_color, &hue, &sat, &val);
if (m_sliderisupdating==true)
{
if((sat*100.0)<m_sat+1 && (sat*100.0)>m_sat-1) {
sat = (sat_backup*0.01);
}
if((val*100.0)<m_val+1 && (val*100.0)>m_val-1) {
val = (val_backup*0.01);
}
}
else{
if((hue*360.0)<m_hue+1 && (hue*360.0)>m_hue-1) {
hue = (hue_backup/360.0);
}
}
break;
case 7:
this->converter()->getHsiF(*m_color, &hue, &sat, &val);
if (m_sliderisupdating==true)
{
if((hue*360.0)<m_hue+1 && (hue*360.0)>m_hue-1) {
hue = (hue_backup/360.0);
}
if((val*100.0)<m_val+1 && (val*100.0)>m_val-1) {
val = (val_backup*0.01);
}
}
else{
if((sat*100.0)<m_sat+1 && (sat*100.0)>m_sat-1) {
sat = (sat_backup*0.01);
}
}
break;
case 8:
this->converter()->getHsiF(*m_color, &hue, &sat, &val);
if (m_sliderisupdating==true)
{
if((sat*100.0)<m_sat+1 && (sat*100.0)>m_sat-1) {
sat = (sat_backup*0.01);
}
if((hue*360.0)<m_hue+1 && (hue*360.0)>m_hue-1) {
hue = (hue_backup/360.0);
}
}
else{
if((val*100.0)<m_val+1 && (val*100.0)>m_val-1) {
val = (val_backup*0.01);
}
}
break;
case 9:
this->converter()->getHsyF(*m_color, &hue, &sat, &val, R, G, B);
if (m_sliderisupdating==true)
{
if((sat*100.0)<m_sat+1 && (sat*100.0)>m_sat-1) {
sat = (sat_backup*0.01);
}
if((val*100.0)<m_val+1 && (val*100.0)>m_val-1) {
val = (val_backup*0.01);
}
}
else{
if((hue*360.0)<m_hue+1 && (hue*360.0)>m_hue-1) {
hue = (hue_backup/360.0);
}
}
break;
case 10:
this->converter()->getHsyF(*m_color, &hue, &sat, &val, R, G, B);
if (m_sliderisupdating==true)
{
if((hue*360.0)<m_hue+1 && (hue*360.0)>m_hue-1) {
hue = (hue_backup/360.0);
}
if((val*100.0)<m_val+1 && (val*100.0)>m_val-1) {
val = (val_backup*0.01);
}
}
else{
if((sat*100.0)<m_sat+1 && (sat*100.0)>m_sat-1) {
sat = (sat_backup*0.01);
}
}
break;
case 11:
this->converter()->getHsyF(*m_color, &hue, &sat, &val, R, G, B);
if (m_sliderisupdating==true)
{
if((sat*100.0)<m_sat+1 && (sat*100.0)>m_sat-1) {
sat = (sat_backup*0.01);
}
if((hue*360.0)<m_hue+1 && (hue*360.0)>m_hue-1) {
hue = (hue_backup/360.0);
}
}
else{
if((val*100.0)<m_val+1 && (val*100.0)>m_val-1) {
val = (val_backup*0.01);
}
}
break;
}
//this prevents the hue going to 0 when used with grey//
if (sat<=0.0) {
m_hue = hue_backup;
}
......@@ -276,6 +510,7 @@ void KisHSXColorSliderInput::update()
m_val=(val*100.0);
//sets slider and num-input according to type//
switch (m_type) {
case 0:
......@@ -363,6 +598,13 @@ void KisHSXColorSliderInput::sliderChanged(int i)
m_NumInput->setValue(i*1.0);
}
void KisHSXColorSliderInput::sliderIn(){
m_sliderisupdating=true;
}
void KisHSXColorSliderInput::sliderOut(){
m_sliderisupdating=false;
}
//this connects to the display converter. Important for OCIO, breaks on missing of m_canvas somehow.
KisDisplayColorConverter* KisHSXColorSliderInput::converter() const
{
......@@ -380,4 +622,17 @@ void KisHSXColorSliderInput::hueUpdate(int h)
}
}
void KisHSXColorSliderInput::satUpdate(int s, int type)
{
if (m_type==type+1 || m_type==type-1)
{
if (s<=m_sat-1 || s>=m_sat+1) {
m_sat=s;
m_satupdating=true;
update();
}
}
}
#include "kis_color_slider_input.moc"
......@@ -68,9 +68,13 @@ public slots:
void setValue(double);
void update();
void hueUpdate(int h);
void satUpdate(int s, int type);
void sliderChanged(int i);
void sliderIn();
void sliderOut();
signals:
void hueUpdated(int);
void satUpdated(int, int);
private:
QDoubleSpinBox* m_NumInput;
qreal m_hue;
......@@ -78,6 +82,8 @@ private:
qreal m_val;
qreal R, G, B;
bool m_hueupdating;
bool m_satupdating;
bool m_sliderisupdating;
};
#endif
......@@ -172,6 +172,7 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
connect(this, SIGNAL(updated()), hsvH, SLOT(update()));
connect(hsvH, SIGNAL(hueUpdated(int)), this, SLOT(hueUpdate(int)));
connect(this, SIGNAL(hueUpdated(int)), hsvH, SLOT(hueUpdate(int)));
connect(this, SIGNAL(satUpdated(int, int)), hsvH, SLOT(satUpdate(int, int)));
}
else {
hsvH->setVisible(false);
......@@ -179,6 +180,7 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
disconnect(this, SIGNAL(updated()), hsvH, SLOT(update()));
disconnect(hsvH, SIGNAL(hueUpdated(int)), this, SLOT(hueUpdate(int)));
disconnect(this, SIGNAL(hueUpdated(int)), hsvH, SLOT(hueUpdate(int)));
disconnect(this, SIGNAL(satUpdated(int, int)), hsvH, SLOT(satUpdate(int, int)));
}
if (SlidersConfigArray[1]==true) {
......@@ -186,12 +188,16 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
connect(hsvS, SIGNAL(updated()), this, SLOT(update()));
connect(this, SIGNAL(updated()), hsvS, SLOT(update()));
connect(this, SIGNAL(hueUpdated(int)), hsvS, SLOT(hueUpdate(int)));
connect(hsvS, SIGNAL(satUpdated(int, int)), this, SLOT(satUpdate(int, int)));
connect(this, SIGNAL(satUpdated(int, int)), hsvS, SLOT(satUpdate(int, int)));
}
else {
hsvS->setVisible(false);
disconnect(hsvS, SIGNAL(updated()), this, SLOT(update()));
disconnect(this, SIGNAL(updated()), hsvS, SLOT(update()));
disconnect(this, SIGNAL(hueUpdated(int)), hsvS, SLOT(hueUpdate(int)));
disconnect(hsvS, SIGNAL(satUpdated(int, int)), this, SLOT(satUpdate(int, int)));
disconnect(this, SIGNAL(satUpdated(int, int)), hsvS, SLOT(satUpdate(int, int)));
}
if (SlidersConfigArray[2]==true) {
......@@ -199,12 +205,14 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
connect(hsvV, SIGNAL(updated()), this, SLOT(update()));
connect(this, SIGNAL(updated()), hsvV, SLOT(update()));
connect(this, SIGNAL(hueUpdated(int)), hsvV, SLOT(hueUpdate(int)));
connect(this, SIGNAL(satUpdated(int, int)), hsvV, SLOT(satUpdate(int, int)));
}
else {
hsvV->setVisible(false);
disconnect(hsvV, SIGNAL(updated()), this, SLOT(update()));
disconnect(this, SIGNAL(updated()), hsvV, SLOT(update()));
disconnect(this, SIGNAL(hueUpdated(int)), hsvV, SLOT(hueUpdate(int)));
connect(this, SIGNAL(satUpdated(int, int)), hsvV, SLOT(satUpdate(int, int)));
}
if (SlidersConfigArray[3]==true) {
......@@ -213,6 +221,7 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
connect(this, SIGNAL(updated()), hslH, SLOT(update()));
connect(hslH, SIGNAL(hueUpdated(int)), this, SLOT(hueUpdate(int)));
connect(this, SIGNAL(hueUpdated(int)), hslH, SLOT(hueUpdate(int)));
connect(this, SIGNAL(satUpdated(int, int)), hslH, SLOT(satUpdate(int, int)));
}
else {
hslH->setVisible(false);
......@@ -220,6 +229,7 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
disconnect(this, SIGNAL(updated()), hslH, SLOT(update()));
disconnect(hslH, SIGNAL(hueUpdated(int)), this, SLOT(hueUpdate(int)));
disconnect(this, SIGNAL(hueUpdated(int)), hslH, SLOT(hueUpdate(int)));
disconnect(this, SIGNAL(satUpdated(int, int)), hslH, SLOT(satUpdate(int, int)));
}
if (SlidersConfigArray[4]==true) {
......@@ -227,12 +237,16 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
connect(hslS, SIGNAL(updated()), this, SLOT(update()));
connect(this, SIGNAL(updated()), hslS, SLOT(update()));
connect(this, SIGNAL(hueUpdated(int)), hslS, SLOT(hueUpdate(int)));
connect(hslS, SIGNAL(satUpdated(int, int)), this, SLOT(satUpdate(int, int)));
connect(this, SIGNAL(satUpdated(int, int)), hslS, SLOT(satUpdate(int, int)));
}
else {
hslS->setVisible(false);
disconnect(hslS, SIGNAL(updated()), this, SLOT(update()));
disconnect(this, SIGNAL(updated()), hslS, SLOT(update()));
disconnect(this, SIGNAL(hueUpdated(int)), hslS, SLOT(hueUpdate(int)));
disconnect(hslS, SIGNAL(satUpdated(int, int)), this, SLOT(satUpdate(int, int)));
disconnect(this, SIGNAL(satUpdated(int, int)), hslS, SLOT(satUpdate(int, int)));
}
if (SlidersConfigArray[5]==true) {
......@@ -240,12 +254,14 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
connect(hslL, SIGNAL(updated()), this, SLOT(update()));
connect(this, SIGNAL(updated()), hslL, SLOT(update()));
connect(this, SIGNAL(hueUpdated(int)), hslL, SLOT(hueUpdate(int)));
connect(this, SIGNAL(satUpdated(int, int)), hslL, SLOT(satUpdate(int, int)));
}
else {
hslL->setVisible(false);
disconnect(hslL, SIGNAL(updated()), this, SLOT(update()));
disconnect(this, SIGNAL(updated()), hslL, SLOT(update()));
disconnect(this, SIGNAL(hueUpdated(int)), hslL, SLOT(hueUpdate(int)));
disconnect(this, SIGNAL(satUpdated(int, int)), hslL, SLOT(satUpdate(int, int)));
}
if (SlidersConfigArray[6]==true) {
......@@ -254,6 +270,7 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
connect(this, SIGNAL(updated()), hsiH, SLOT(update()));
connect(hsiH, SIGNAL(hueUpdated(int)), this, SLOT(hueUpdate(int)));
connect(this, SIGNAL(hueUpdated(int)), hsiH, SLOT(hueUpdate(int)));
connect(this, SIGNAL(satUpdated(int, int)), hsiH, SLOT(satUpdate(int, int)));
}
else {
hsiH->setVisible(false);
......@@ -261,6 +278,7 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
disconnect(this, SIGNAL(updated()), hsiH, SLOT(update()));
disconnect(hsiH, SIGNAL(hueUpdated(int)), this, SLOT(hueUpdate(int)));
disconnect(this, SIGNAL(hueUpdated(int)), hsiH, SLOT(hueUpdate(int)));
disconnect(this, SIGNAL(satUpdated(int, int)), hsiH, SLOT(satUpdate(int, int)));
}
if (SlidersConfigArray[7]==true) {
......@@ -268,12 +286,16 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
connect(hsiS, SIGNAL(updated()), this, SLOT(update()));
connect(this, SIGNAL(updated()), hsiS, SLOT(update()));
connect(this, SIGNAL(hueUpdated(int)), hsiS, SLOT(hueUpdate(int)));
connect(hsiS, SIGNAL(satUpdated(int, int)), this, SLOT(satUpdate(int, int)));
connect(this, SIGNAL(satUpdated(int, int)), hsiS, SLOT(satUpdate(int, int)));
}
else {
hsiS->setVisible(false);
disconnect(hsiS, SIGNAL(updated()), this, SLOT(update()));
disconnect(this, SIGNAL(updated()), hsiS, SLOT(update()));
disconnect(this, SIGNAL(hueUpdated(int)), hsiS, SLOT(hueUpdate(int)));
disconnect(hsiS, SIGNAL(satUpdated(int, int)), this, SLOT(satUpdate(int, int)));
disconnect(this, SIGNAL(satUpdated(int, int)), hsiS, SLOT(satUpdate(int, int)));
}
if (SlidersConfigArray[8]==true) {
......@@ -281,12 +303,14 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
connect(hsiI, SIGNAL(updated()), this, SLOT(update()));
connect(this, SIGNAL(updated()), hsiI, SLOT(update()));
connect(this, SIGNAL(hueUpdated(int)), hsiI, SLOT(hueUpdate(int)));
connect(this, SIGNAL(satUpdated(int, int)), hsiI, SLOT(satUpdate(int, int)));
}
else {
hsiI->setVisible(false);
disconnect(hsiI, SIGNAL(updated()), this, SLOT(update()));
disconnect(this, SIGNAL(updated()), hsiI, SLOT(update()));
disconnect(this, SIGNAL(hueUpdated(int)), hsiI, SLOT(hueUpdate(int)));
disconnect(this, SIGNAL(satUpdated(int, int)), hsiI, SLOT(satUpdate(int, int)));
}
if (SlidersConfigArray[9]==true) {
......@@ -295,6 +319,7 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
connect(this, SIGNAL(updated()), hsyH, SLOT(update()));
connect(hsyH, SIGNAL(hueUpdated(int)), this, SLOT(hueUpdate(int)));
connect(this, SIGNAL(hueUpdated(int)), hsyH, SLOT(hueUpdate(int)));
connect(this, SIGNAL(satUpdated(int, int)), hsyH, SLOT(satUpdate(int, int)));
}
else {
hsyH->setVisible(false);
......@@ -302,6 +327,7 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
disconnect(this, SIGNAL(updated()), hsyH, SLOT(update()));
disconnect(hsyH, SIGNAL(hueUpdated(int)), this, SLOT(hueUpdate(int)));
disconnect(this, SIGNAL(hueUpdated(int)), hsyH, SLOT(hueUpdate(int)));
disconnect(this, SIGNAL(satUpdated(int, int)), hsyH, SLOT(satUpdate(int, int)));
}
if (SlidersConfigArray[10]==true) {
......@@ -309,12 +335,16 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
connect(hsyS, SIGNAL(updated()), this, SLOT(update()));
connect(this, SIGNAL(updated()), hsyS, SLOT(update()));
connect(this, SIGNAL(hueUpdated(int)), hsyS, SLOT(hueUpdate(int)));
connect(hsyS, SIGNAL(satUpdated(int, int)), this, SLOT(satUpdate(int, int)));
connect(this, SIGNAL(satUpdated(int, int)), hsyS, SLOT(satUpdate(int, int)));
}
else {
hsyS->setVisible(false);
disconnect(hsyS, SIGNAL(updated()), this, SLOT(update()));
disconnect(this, SIGNAL(updated()), hsyS, SLOT(update()));
disconnect(this, SIGNAL(hueUpdated(int)), hsyS, SLOT(hueUpdate(int)));
disconnect(hsyS, SIGNAL(satUpdated(int, int)), this, SLOT(satUpdate(int, int)));
disconnect(this, SIGNAL(satUpdated(int, int)), hsyS, SLOT(satUpdate(int, int)));
}
if (SlidersConfigArray[11]==true) {
......@@ -322,12 +352,14 @@ void KisColorSliderWidget::setSlidersVisible(QBitArray SlidersConfigArray)
connect(hsyY, SIGNAL(updated()), this, SLOT(update()));
connect(this, SIGNAL(updated()), hsyY, SLOT(update()));
connect(this, SIGNAL(hueUpdated(int)), hsyY, SLOT(hueUpdate(int)));
connect(this, SIGNAL(satUpdated(int, int)), hsyY, SLOT(satUpdate(int, int)));
}
else {
hsyY->setVisible(false);
disconnect(hsyY, SIGNAL(updated()), this, SLOT(update()));
disconnect(this, SIGNAL(updated()), hsyY, SLOT(update()));
disconnect(this, SIGNAL(hueUpdated(int)), hsyY, SLOT(hueUpdate(int)));
disconnect(this, SIGNAL(satUpdated(int, int)), hsyY, SLOT(satUpdate(int, int)));
}
updateTimeout();
......@@ -372,4 +404,8 @@ void KisColorSliderWidget::hueUpdate(int h)
emit(hueUpdated(h));
}
void KisColorSliderWidget::satUpdate(int s, int type)
{
emit(satUpdated(s, type));
}
#include "kis_color_slider_widget.moc"
......@@ -47,6 +47,7 @@ private slots:
void update();
void updateTimeout();
void hueUpdate(int h);