Krita Source Code Documentation
Loading...
Searching...
No Matches
KisHsvColorInput Class Reference

#include <kis_color_input.h>

+ Inheritance diagram for KisHsvColorInput:

Public Slots

void hueSliderChanged (int)
 
void saturationSliderChanged (int)
 
void setHue (double)
 
void setSaturation (double)
 
void setValue (double)
 
void update ()
 
void valueSliderChanged (int)
 

Signals

void updated ()
 

Public Member Functions

 KisHsvColorInput (QWidget *parent, KoColor *color)
 
void setMixMode (KisHsvColorSlider::MIX_MODE mixMode)
 

Private Member Functions

void fillColor (QColor &color)
 
void fillColor (QColor &color, const qreal &h, const qreal &s, const qreal &x)
 
void getHsxF (const QColor &color, qreal *h, qreal *s, qreal *x)
 
void recolorSliders ()
 
void sendUpdate ()
 

Private Attributes

KoColor * m_color
 
qreal m_h
 
KisDoubleParseSpinBox * m_hInput
 
KisHsvColorSlider * m_hSlider
 
KisHsvColorSlider::MIX_MODE m_mixMode
 
qreal m_s
 
KisDoubleParseSpinBox * m_sInput
 
KisHsvColorSlider * m_sSlider
 
qreal m_x
 
KisDoubleParseSpinBox * m_xInput
 
QLabel * m_xLabel
 
KisHsvColorSlider * m_xSlider
 

Detailed Description

Definition at line 106 of file kis_color_input.h.

Constructor & Destructor Documentation

◆ KisHsvColorInput()

KisHsvColorInput::KisHsvColorInput ( QWidget * parent,
KoColor * color )

Definition at line 413 of file kis_color_input.cpp.

414 : QWidget(parent)
415 , m_color(color)
416 , m_hSlider(nullptr)
417 , m_sSlider(nullptr)
418 , m_xSlider(nullptr)
419 , m_hInput(nullptr)
420 , m_sInput(nullptr)
421 , m_xInput(nullptr)
422 , m_h(0)
423 , m_s(0)
424 , m_x(0)
426{
427
428 const QStringList labelNames = QStringList({
429 i18nc("@label:slider Abbreviation for 'Hue'", "H:"),
430 i18nc("@label:slider Abbreviation for 'Saturation'", "S:"),
431 QString(/* x will get initialized later in setMixMode */) });
432 qreal maxValues[3] = { 360, 100, 100 };
433
434 QGridLayout *slidersLayout = new QGridLayout(this);
435 slidersLayout->setContentsMargins(0,0,0,0);
436 slidersLayout->setHorizontalSpacing(1); // less space around the sliders
437
438 for (int i = 0; i < 3; i++) {
439 // Label
440 QLabel *label = new QLabel(labelNames[i], this);
441 slidersLayout->addWidget(label, i, 0);
442
443 // Slider itself
444 KisHsvColorSlider *slider = new KisHsvColorSlider(Qt::Horizontal, this);
445 slider->setMixMode(m_mixMode);
446 slider->setMinimum(0);
447 slider->setMaximum(maxValues[i]);
448 slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
449 slidersLayout->addWidget(slider, i, 1);
450
451 // Input box
453 input->setMinimum(0);
454 input->setMaximum(maxValues[i]);
455
456 input->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
457 input->setMinimumWidth(60);
458 input->setMaximumWidth(60);
459
460 slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
461 slidersLayout->addWidget(input, i, 2);
462
463 switch (i) {
464 case 0:
465 m_hSlider = slider;
466 m_hInput = input;
467 case 1:
468 m_sSlider = slider;
469 m_sInput = input;
470 case 2:
471 m_xLabel = label; // Save the HSX label so we can update it
472 m_xSlider = slider;
473 m_xInput = input;
474 }
475 }
476
477 // Connect slots
478 connect(m_hSlider, SIGNAL(valueChanged(int)), this, SLOT(hueSliderChanged(int)));
479 connect(m_hInput, SIGNAL(valueChanged(double)), this, SLOT(setHue(double)));
480 connect(m_sSlider, SIGNAL(valueChanged(int)), this, SLOT(saturationSliderChanged(int)));
481 connect(m_sInput, SIGNAL(valueChanged(double)), this, SLOT(setSaturation(double)));
482 connect(m_xSlider, SIGNAL(valueChanged(int)), this, SLOT(valueSliderChanged(int)));
483 connect(m_xInput, SIGNAL(valueChanged(double)), this, SLOT(setValue(double)));
484
486
487 // Set initial values
488 QColor c = m_color->toQColor();
489 getHsxF(c, &m_h, &m_s, &m_x);
490
494
495 // Update sliders
496 QColor minC, maxC;
497 minC.setHsvF(0, 1, 1);
498 maxC.setHsvF(1, 1, 1);
499 m_hSlider->setColors(minC, maxC);
501
503}
QList< QString > QStringList
The KisDoubleParseSpinBox class is a cleverer doubleSpinBox, able to parse arithmetic expressions.
void setValue(double value, bool overwriteExpression=false)
Set the value of the spinbox.
KisDoubleParseSpinBox * m_sInput
void getHsxF(const QColor &color, qreal *h, qreal *s, qreal *x)
KisHsvColorSlider * m_xSlider
void setSaturation(double)
KisHsvColorSlider::MIX_MODE m_mixMode
KisHsvColorSlider * m_hSlider
KisDoubleParseSpinBox * m_xInput
void saturationSliderChanged(int)
KisHsvColorSlider * m_sSlider
void setMixMode(KisHsvColorSlider::MIX_MODE mixMode)
KisDoubleParseSpinBox * m_hInput
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198
void setColors(const KoColor minColor, const KoColor maxColor)
void setMixMode(MIX_MODE mode)

References getHsxF(), KisHsvColorSlider::HSV, hueSliderChanged(), m_color, m_h, m_hInput, m_hSlider, m_mixMode, m_s, m_sInput, m_sSlider, m_x, m_xInput, m_xLabel, m_xSlider, recolorSliders(), saturationSliderChanged(), KisHsvColorSlider::setCircularHue(), KisHsvColorSlider::setColors(), setHue(), setMixMode(), KisHsvColorSlider::setMixMode(), setSaturation(), KisDoubleParseSpinBox::setValue(), setValue(), KoColor::toQColor(), and valueSliderChanged().

Member Function Documentation

◆ fillColor() [1/2]

void KisHsvColorInput::fillColor ( QColor & color)
private

Definition at line 649 of file kis_color_input.cpp.

649 {
650 fillColor(c, m_h, m_s, m_x);
651}
void fillColor(QColor &color)

References fillColor(), m_h, m_s, and m_x.

◆ fillColor() [2/2]

void KisHsvColorInput::fillColor ( QColor & color,
const qreal & h,
const qreal & s,
const qreal & x )
private

Definition at line 653 of file kis_color_input.cpp.

654{
655 switch (m_mixMode) {
657 c.setHslF(h, s, x);
658 break;
659
661 qreal r, g, b;
662 HSYToRGB(h, s, x, &r, &g, &b);
663
664 // Clamp
665 r = qBound(0.0, r, 1.0);
666 g = qBound(0.0, g, 1.0);
667 b = qBound(0.0, b, 1.0);
668
669 c.setRgbF(r, g, b);
670 break;
671 }
672
674 qreal r, g, b;
675 HSIToRGB(h, s, x, &r, &g, &b);
676 c.setRgbF(r, g, b);
677 break;
678 }
679
680 default: // fallthrough
682 c.setHsvF(h, s, x);
683 break;
684 }
685}
void HSYToRGB(const qreal h, const qreal s, const qreal y, qreal *red, qreal *green, qreal *blue, qreal R, qreal G, qreal B)
void HSIToRGB(const qreal h, const qreal s, const qreal i, qreal *red, qreal *green, qreal *blue)

References KisHsvColorSlider::HSI, HSIToRGB(), KisHsvColorSlider::HSL, KisHsvColorSlider::HSV, KisHsvColorSlider::HSY, HSYToRGB(), and m_mixMode.

◆ getHsxF()

void KisHsvColorInput::getHsxF ( const QColor & color,
qreal * h,
qreal * s,
qreal * x )
private

Definition at line 687 of file kis_color_input.cpp.

688{
689 qreal tempH;
690#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
691 float fS = *s;
692 float fX = *x;
693#endif
694 switch (m_mixMode) {
696 {
697#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
698 color.getHslF(&tempH, s, x);
699#else
700 float th;
701 color.getHslF(&th, &fS, &fX);
702 tempH = th;
703 *s = fS;
704 *x = fX;
705#endif
706 }
707 break;
708
710 RGBToHSY(color.redF(), color.greenF(), color.blueF(), &tempH, s, x);
711 break;
712 }
713
715 RGBToHSI(color.redF(), color.greenF(), color.blueF(), &tempH, s, x);
716 break;
717 }
718
719 default: // fallthrough
721 {
722#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
723 color.getHsvF(&tempH, s, x);
724#else
725 float th;
726 color.getHsvF(&th, &fS, &fX);
727 tempH = th;
728 *s = fS;
729 *x = fX;
730#endif
731 }
732 break;
733 }
734
735 if (tempH >= 0.0 && tempH <= 1.0) {
736 *h = tempH;
737 }
738}
void RGBToHSI(qreal r, qreal g, qreal b, qreal *h, qreal *s, qreal *i)
void RGBToHSY(const qreal r, const qreal g, const qreal b, qreal *h, qreal *s, qreal *y, qreal R, qreal G, qreal B)

References KisHsvColorSlider::HSI, KisHsvColorSlider::HSL, KisHsvColorSlider::HSV, KisHsvColorSlider::HSY, m_mixMode, RGBToHSI(), and RGBToHSY().

◆ hueSliderChanged

void KisHsvColorInput::hueSliderChanged ( int i)
slot

Definition at line 582 of file kis_color_input.cpp.

583{
584 m_hInput->setValue(i);
585}

References m_hInput, and KisDoubleParseSpinBox::setValue().

◆ recolorSliders()

void KisHsvColorInput::recolorSliders ( )
private

Definition at line 597 of file kis_color_input.cpp.

597 {
598 // Update sliders
599 QColor minC, maxC;
600
601 minC.setHsvF(m_h, 0, m_x);
602 maxC.setHsvF(m_h, 1, m_x);
603 m_sSlider->setColors(minC, maxC);
604
605 minC.setHsvF(m_h, m_s, 0);
606 maxC.setHsvF(m_h, m_s, 1);
607 m_xSlider->setColors(minC, maxC);
608}

References m_h, m_s, m_sSlider, m_x, m_xSlider, and KisHsvColorSlider::setColors().

◆ saturationSliderChanged

void KisHsvColorInput::saturationSliderChanged ( int i)
slot

Definition at line 587 of file kis_color_input.cpp.

588{
589 m_sInput->setValue(i);
590}

References m_sInput, and KisDoubleParseSpinBox::setValue().

◆ sendUpdate()

void KisHsvColorInput::sendUpdate ( )
private

Definition at line 533 of file kis_color_input.cpp.

534{
535 {
536 KisSignalsBlocker blocker(
539 );
540 m_hSlider->setValue(m_h * 360);
541 m_sSlider->setValue(m_s * 100);
542 m_xSlider->setValue(m_x * 100);
543
544 m_hInput->setValue(m_h * 360);
545 m_sInput->setValue(m_s * 100);
546 m_xInput->setValue(m_x * 100);
547 }
548
550
551 QColor c;
552 fillColor(c);
553
555 emit(updated());
556}
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
Definition KoColor.cpp:213

References fillColor(), KoColor::fromQColor(), m_color, m_h, m_hInput, m_hSlider, m_s, m_sInput, m_sSlider, m_x, m_xInput, m_xSlider, recolorSliders(), KisDoubleParseSpinBox::setValue(), and updated().

◆ setHue

void KisHsvColorInput::setHue ( double x)
slot

Definition at line 558 of file kis_color_input.cpp.

559{
560 x = qBound(0.0, x, 360.0);
561
562 m_h = x / 360;
563 sendUpdate();
564}

References m_h, and sendUpdate().

◆ setMixMode()

void KisHsvColorInput::setMixMode ( KisHsvColorSlider::MIX_MODE mixMode)

Definition at line 505 of file kis_color_input.cpp.

505 {
506
507 switch (mixMode) {
509 m_xLabel->setText(i18nc("@label:slider Abbreviation for 'Lightness' of HSL color model", "L:"));
510 break;
512 m_xLabel->setText(i18nc("@label:slider Abbreviation for 'Luma' of HSY color model", "Y:"));
513 break;
515 m_xLabel->setText(i18nc("@label:slider Abbreviation for 'Intensity' of HSI color model", "I:"));
516 break;
517 default: // fallthrough
519 m_xLabel->setText(i18nc("@label:slider Abbreviation for 'Value' of HSV color model", "V:"));
520 break;
521 }
522
523 QColor c = m_color->toQColor();
524 m_mixMode = mixMode;
525 getHsxF(c, &m_h, &m_s, &m_x);
526
529
530 sendUpdate();
531}

References getHsxF(), KisHsvColorSlider::HSI, KisHsvColorSlider::HSL, KisHsvColorSlider::HSV, KisHsvColorSlider::HSY, m_color, m_h, m_mixMode, m_s, m_sSlider, m_x, m_xLabel, m_xSlider, sendUpdate(), KisHsvColorSlider::setMixMode(), and KoColor::toQColor().

◆ setSaturation

void KisHsvColorInput::setSaturation ( double x)
slot

Definition at line 566 of file kis_color_input.cpp.

567{
568 x = qBound(0.0, x, 100.0);
569
570 m_s = x / 100;
571 sendUpdate();
572}

References m_s, and sendUpdate().

◆ setValue

void KisHsvColorInput::setValue ( double x)
slot

Definition at line 574 of file kis_color_input.cpp.

575{
576 x = qBound(0.0, x, 100.0);
577
578 m_x = x / 100;
579 sendUpdate();
580}

References m_x, and sendUpdate().

◆ update

void KisHsvColorInput::update ( )
slot

Definition at line 610 of file kis_color_input.cpp.

611{
612 KisSignalsBlocker blocker(
615 );
616
617 // Check if it is the same color we have
618 QColor current;
619
620 fillColor(current);
621
622 QColor theirs = m_color->toQColor();
623
624 // Truncate to integer for this check
625 if (!(current.red() == theirs.red() && current.green() == theirs.green() && current.blue() == theirs.blue())) {
626 // Apply the update
627 qreal theirH;
628 getHsxF(theirs, &theirH, &m_s, &m_x);
629
630 // Don't jump the Hue slider around to 0 if it is currently on 360
631 const qreal EPSILON = 1e-6;
632 if (!((1.0 - m_h) < EPSILON && (theirH - 0.0) < EPSILON)) {
633 m_h = theirH;
634 }
635
636 m_hInput->setValue(m_h * 360);
637 m_sInput->setValue(m_s * 100);
638 m_xInput->setValue(m_x * 100);
639
641
642 // Update slider positions
643 m_hSlider->setValue(m_h * 360);
644 m_sSlider->setValue(m_s * 100);
645 m_xSlider->setValue(m_x * 100);
646 }
647}
#define EPSILON

References EPSILON, fillColor(), getHsxF(), m_color, m_h, m_hInput, m_hSlider, m_s, m_sInput, m_sSlider, m_x, m_xInput, m_xSlider, recolorSliders(), KisDoubleParseSpinBox::setValue(), and KoColor::toQColor().

◆ updated

void KisHsvColorInput::updated ( )
signal

◆ valueSliderChanged

void KisHsvColorInput::valueSliderChanged ( int i)
slot

Definition at line 592 of file kis_color_input.cpp.

593{
594 m_xInput->setValue(i);
595}

References m_xInput, and KisDoubleParseSpinBox::setValue().

Member Data Documentation

◆ m_color

KoColor* KisHsvColorInput::m_color
private

Definition at line 136 of file kis_color_input.h.

◆ m_h

qreal KisHsvColorInput::m_h
private

Definition at line 148 of file kis_color_input.h.

◆ m_hInput

KisDoubleParseSpinBox* KisHsvColorInput::m_hInput
private

Definition at line 144 of file kis_color_input.h.

◆ m_hSlider

KisHsvColorSlider* KisHsvColorInput::m_hSlider
private

Definition at line 140 of file kis_color_input.h.

◆ m_mixMode

KisHsvColorSlider::MIX_MODE KisHsvColorInput::m_mixMode
private

Definition at line 152 of file kis_color_input.h.

◆ m_s

qreal KisHsvColorInput::m_s
private

Definition at line 149 of file kis_color_input.h.

◆ m_sInput

KisDoubleParseSpinBox* KisHsvColorInput::m_sInput
private

Definition at line 145 of file kis_color_input.h.

◆ m_sSlider

KisHsvColorSlider* KisHsvColorInput::m_sSlider
private

Definition at line 141 of file kis_color_input.h.

◆ m_x

qreal KisHsvColorInput::m_x
private

Definition at line 150 of file kis_color_input.h.

◆ m_xInput

KisDoubleParseSpinBox* KisHsvColorInput::m_xInput
private

Definition at line 146 of file kis_color_input.h.

◆ m_xLabel

QLabel* KisHsvColorInput::m_xLabel
private

Definition at line 138 of file kis_color_input.h.

◆ m_xSlider

KisHsvColorSlider* KisHsvColorInput::m_xSlider
private

Definition at line 142 of file kis_color_input.h.


The documentation for this class was generated from the following files: