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

KoColorm_color
 
qreal m_h
 
KisDoubleParseSpinBoxm_hInput
 
KisHsvColorSliderm_hSlider
 
KisHsvColorSlider::MIX_MODE m_mixMode
 
qreal m_s
 
KisDoubleParseSpinBoxm_sInput
 
KisHsvColorSliderm_sSlider
 
qreal m_x
 
KisDoubleParseSpinBoxm_xInput
 
QLabel * m_xLabel
 
KisHsvColorSliderm_xSlider
 

Detailed Description

Definition at line 105 of file kis_color_input.h.

Constructor & Destructor Documentation

◆ KisHsvColorInput()

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

Definition at line 405 of file kis_color_input.cpp.

406 : QWidget(parent)
407 , m_color(color)
408 , m_hSlider(nullptr)
409 , m_sSlider(nullptr)
410 , m_xSlider(nullptr)
411 , m_hInput(nullptr)
412 , m_sInput(nullptr)
413 , m_xInput(nullptr)
414 , m_h(0)
415 , m_s(0)
416 , m_x(0)
418{
419
420 const QStringList labelNames = QStringList({
421 i18nc("@label:slider Abbreviation for 'Hue'", "H:"),
422 i18nc("@label:slider Abbreviation for 'Saturation'", "S:"),
423 QString(/* x will get initialized later in setMixMode */) });
424 qreal maxValues[3] = { 360, 100, 100 };
425
426 QGridLayout *slidersLayout = new QGridLayout(this);
427 slidersLayout->setContentsMargins(0,0,0,0);
428 slidersLayout->setHorizontalSpacing(1); // less space around the sliders
429
430 for (int i = 0; i < 3; i++) {
431 // Label
432 QLabel *label = new QLabel(labelNames[i], this);
433 slidersLayout->addWidget(label, i, 0);
434
435 // Slider itself
436 KisHsvColorSlider *slider = new KisHsvColorSlider(Qt::Horizontal, this);
437 slider->setMixMode(m_mixMode);
438 slider->setMinimum(0);
439 slider->setMaximum(maxValues[i]);
440 slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
441 slidersLayout->addWidget(slider, i, 1);
442
443 // Input box
445 input->setMinimum(0);
446 input->setMaximum(maxValues[i]);
447
448 input->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
449 input->setMinimumWidth(60);
450 input->setMaximumWidth(60);
451
452 slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
453 slidersLayout->addWidget(input, i, 2);
454
455 switch (i) {
456 case 0:
457 m_hSlider = slider;
458 m_hInput = input;
459 case 1:
460 m_sSlider = slider;
461 m_sInput = input;
462 case 2:
463 m_xLabel = label; // Save the HSX label so we can update it
464 m_xSlider = slider;
465 m_xInput = input;
466 }
467 }
468
469 // Connect slots
470 connect(m_hSlider, SIGNAL(valueChanged(int)), this, SLOT(hueSliderChanged(int)));
471 connect(m_hInput, SIGNAL(valueChanged(double)), this, SLOT(setHue(double)));
472 connect(m_sSlider, SIGNAL(valueChanged(int)), this, SLOT(saturationSliderChanged(int)));
473 connect(m_sInput, SIGNAL(valueChanged(double)), this, SLOT(setSaturation(double)));
474 connect(m_xSlider, SIGNAL(valueChanged(int)), this, SLOT(valueSliderChanged(int)));
475 connect(m_xInput, SIGNAL(valueChanged(double)), this, SLOT(setValue(double)));
476
478
479 // Set initial values
480 QColor c = m_color->toQColor();
481 getHsxF(c, &m_h, &m_s, &m_x);
482
486
487 // Update sliders
488 QColor minC, maxC;
489 minC.setHsvF(0, 1, 1);
490 maxC.setHsvF(1, 1, 1);
491 m_hSlider->setColors(minC, maxC);
493
495}
QList< QString > QStringList
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
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 connect(), 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 641 of file kis_color_input.cpp.

641 {
642 fillColor(c, m_h, m_s, m_x);
643}
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 645 of file kis_color_input.cpp.

646{
647 switch (m_mixMode) {
649 c.setHslF(h, s, x);
650 break;
651
653 qreal r, g, b;
654 HSYToRGB(h, s, x, &r, &g, &b);
655
656 // Clamp
657 r = qBound(0.0, r, 1.0);
658 g = qBound(0.0, g, 1.0);
659 b = qBound(0.0, b, 1.0);
660
661 c.setRgbF(r, g, b);
662 break;
663 }
664
666 qreal r, g, b;
667 HSIToRGB(h, s, x, &r, &g, &b);
668 c.setRgbF(r, g, b);
669 break;
670 }
671
672 default: // fallthrough
674 c.setHsvF(h, s, x);
675 break;
676 }
677}
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 679 of file kis_color_input.cpp.

680{
681 qreal tempH;
682#if (QT_VERSION > QT_VERSION_CHECK(6, 0, 0))
683 float fS = *s;
684 float fX = *x;
685#endif
686 switch (m_mixMode) {
688 {
689#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
690 color.getHslF(&tempH, s, x);
691#else
692 float th;
693 color.getHslF(&th, &fS, &fX);
694 tempH = th;
695#endif
696 }
697 break;
698
700 RGBToHSY(color.redF(), color.greenF(), color.blueF(), &tempH, s, x);
701 break;
702 }
703
705 RGBToHSI(color.redF(), color.greenF(), color.blueF(), &tempH, s, x);
706 break;
707 }
708
709 default: // fallthrough
711 {
712#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
713 color.getHsvF(&tempH, s, x);
714#else
715 float th;
716 color.getHsvF(&th, &fS, &fX);
717 tempH = th;
718#endif
719 }
720 break;
721 }
722
723 if (tempH >= 0.0 && tempH <= 1.0) {
724 *h = tempH;
725 }
726}
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 574 of file kis_color_input.cpp.

575{
576 m_hInput->setValue(i);
577}

References m_hInput, and KisDoubleParseSpinBox::setValue().

◆ recolorSliders()

void KisHsvColorInput::recolorSliders ( )
private

Definition at line 589 of file kis_color_input.cpp.

589 {
590 // Update sliders
591 QColor minC, maxC;
592
593 minC.setHsvF(m_h, 0, m_x);
594 maxC.setHsvF(m_h, 1, m_x);
595 m_sSlider->setColors(minC, maxC);
596
597 minC.setHsvF(m_h, m_s, 0);
598 maxC.setHsvF(m_h, m_s, 1);
599 m_xSlider->setColors(minC, maxC);
600}

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

◆ saturationSliderChanged

void KisHsvColorInput::saturationSliderChanged ( int i)
slot

Definition at line 579 of file kis_color_input.cpp.

580{
581 m_sInput->setValue(i);
582}

References m_sInput, and KisDoubleParseSpinBox::setValue().

◆ sendUpdate()

void KisHsvColorInput::sendUpdate ( )
private

Definition at line 525 of file kis_color_input.cpp.

526{
527 {
528 KisSignalsBlocker blocker(
531 );
532 m_hSlider->setValue(m_h * 360);
533 m_sSlider->setValue(m_s * 100);
534 m_xSlider->setValue(m_x * 100);
535
536 m_hInput->setValue(m_h * 360);
537 m_sInput->setValue(m_s * 100);
538 m_xInput->setValue(m_x * 100);
539 }
540
542
543 QColor c;
544 fillColor(c);
545
547 emit(updated());
548}
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 550 of file kis_color_input.cpp.

551{
552 x = qBound(0.0, x, 360.0);
553
554 m_h = x / 360;
555 sendUpdate();
556}

References m_h, and sendUpdate().

◆ setMixMode()

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

Definition at line 497 of file kis_color_input.cpp.

497 {
498
499 switch (mixMode) {
501 m_xLabel->setText(i18nc("@label:slider Abbreviation for 'Lightness' of HSL color model", "L:"));
502 break;
504 m_xLabel->setText(i18nc("@label:slider Abbreviation for 'Luma' of HSY color model", "Y:"));
505 break;
507 m_xLabel->setText(i18nc("@label:slider Abbreviation for 'Intensity' of HSI color model", "I:"));
508 break;
509 default: // fallthrough
511 m_xLabel->setText(i18nc("@label:slider Abbreviation for 'Value' of HSV color model", "V:"));
512 break;
513 }
514
515 QColor c = m_color->toQColor();
516 m_mixMode = mixMode;
517 getHsxF(c, &m_h, &m_s, &m_x);
518
521
522 sendUpdate();
523}

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 558 of file kis_color_input.cpp.

559{
560 x = qBound(0.0, x, 100.0);
561
562 m_s = x / 100;
563 sendUpdate();
564}

References m_s, and sendUpdate().

◆ setValue

void KisHsvColorInput::setValue ( 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_x = x / 100;
571 sendUpdate();
572}

References m_x, and sendUpdate().

◆ update

void KisHsvColorInput::update ( )
slot

Definition at line 602 of file kis_color_input.cpp.

603{
604 KisSignalsBlocker blocker(
607 );
608
609 // Check if it is the same color we have
610 QColor current;
611
612 fillColor(current);
613
614 QColor theirs = m_color->toQColor();
615
616 // Truncate to integer for this check
617 if (!(current.red() == theirs.red() && current.green() == theirs.green() && current.blue() == theirs.blue())) {
618 // Apply the update
619 qreal theirH;
620 getHsxF(theirs, &theirH, &m_s, &m_x);
621
622 // Don't jump the Hue slider around to 0 if it is currently on 360
623 const qreal EPSILON = 1e-6;
624 if (!((1.0 - m_h) < EPSILON && (theirH - 0.0) < EPSILON)) {
625 m_h = theirH;
626 }
627
628 m_hInput->setValue(m_h * 360);
629 m_sInput->setValue(m_s * 100);
630 m_xInput->setValue(m_x * 100);
631
633
634 // Update slider positions
635 m_hSlider->setValue(m_h * 360);
636 m_sSlider->setValue(m_s * 100);
637 m_xSlider->setValue(m_x * 100);
638 }
639}
#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 584 of file kis_color_input.cpp.

585{
586 m_xInput->setValue(i);
587}

References m_xInput, and KisDoubleParseSpinBox::setValue().

Member Data Documentation

◆ m_color

KoColor* KisHsvColorInput::m_color
private

Definition at line 135 of file kis_color_input.h.

◆ m_h

qreal KisHsvColorInput::m_h
private

Definition at line 147 of file kis_color_input.h.

◆ m_hInput

KisDoubleParseSpinBox* KisHsvColorInput::m_hInput
private

Definition at line 143 of file kis_color_input.h.

◆ m_hSlider

KisHsvColorSlider* KisHsvColorInput::m_hSlider
private

Definition at line 139 of file kis_color_input.h.

◆ m_mixMode

KisHsvColorSlider::MIX_MODE KisHsvColorInput::m_mixMode
private

Definition at line 151 of file kis_color_input.h.

◆ m_s

qreal KisHsvColorInput::m_s
private

Definition at line 148 of file kis_color_input.h.

◆ m_sInput

KisDoubleParseSpinBox* KisHsvColorInput::m_sInput
private

Definition at line 144 of file kis_color_input.h.

◆ m_sSlider

KisHsvColorSlider* KisHsvColorInput::m_sSlider
private

Definition at line 140 of file kis_color_input.h.

◆ m_x

qreal KisHsvColorInput::m_x
private

Definition at line 149 of file kis_color_input.h.

◆ m_xInput

KisDoubleParseSpinBox* KisHsvColorInput::m_xInput
private

Definition at line 145 of file kis_color_input.h.

◆ m_xLabel

QLabel* KisHsvColorInput::m_xLabel
private

Definition at line 137 of file kis_color_input.h.

◆ m_xSlider

KisHsvColorSlider* KisHsvColorInput::m_xSlider
private

Definition at line 141 of file kis_color_input.h.


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