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

#include <kis_color_input.h>

+ Inheritance diagram for KisIntegerColorInput:

Public Slots

void setValue (int)
 
void update ()
 

Public Member Functions

 KisIntegerColorInput (QWidget *parent, const KoChannelInfo *, KoColor *color, KoColorDisplayRendererInterface *displayRenderer=KoDumbColorDisplayRenderer::instance(), bool usePercentage=false)
 
- Public Member Functions inherited from KisColorInput
 KisColorInput (QWidget *parent, const KoChannelInfo *, KoColor *color, KoColorDisplayRendererInterface *displayRenderer=KoDumbColorDisplayRenderer::instance(), bool usePercentage=false)
 
bool usePercentage () const
 

Protected Member Functions

QWidget * createInput () override
 
void setPercentageWise (bool val) override
 
void updateMaximums ()
 
- Protected Member Functions inherited from KisColorInput
void init ()
 

Private Slots

void onColorSliderChanged (int)
 
void onNumInputChanged (int)
 

Private Attributes

KisIntParseSpinBoxm_intNumInput {nullptr}
 

Additional Inherited Members

- Signals inherited from KisColorInput
void updated ()
 
- Protected Attributes inherited from KisColorInput
const KoChannelInfom_channelInfo {nullptr}
 
KoColorm_color {nullptr}
 
KoColorSliderm_colorSlider {nullptr}
 
KoColorDisplayRendererInterfacem_displayRenderer {nullptr}
 
bool m_usePercentage {false}
 

Detailed Description

Definition at line 53 of file kis_color_input.h.

Constructor & Destructor Documentation

◆ KisIntegerColorInput()

KisIntegerColorInput::KisIntegerColorInput ( QWidget * parent,
const KoChannelInfo * channelInfo,
KoColor * color,
KoColorDisplayRendererInterface * displayRenderer = KoDumbColorDisplayRenderer::instance(),
bool usePercentage = false )

Definition at line 65 of file kis_color_input.cpp.

65 :
66 KisColorInput(parent, channelInfo, color, displayRenderer, usePercentage)
67{
68 init();
69}
KisColorInput(QWidget *parent, const KoChannelInfo *, KoColor *color, KoColorDisplayRendererInterface *displayRenderer=KoDumbColorDisplayRenderer::instance(), bool usePercentage=false)
bool usePercentage() const

References KisColorInput::init().

Member Function Documentation

◆ createInput()

QWidget * KisIntegerColorInput::createInput ( )
overrideprotectedvirtual

Implements KisColorInput.

Definition at line 132 of file kis_color_input.cpp.

133{
135 m_intNumInput->setMinimum(0);
136 m_colorSlider->setMinimum(0);
137
138 if (m_usePercentage) {
139 KisSpinBoxI18nHelper::setText(m_intNumInput, i18nc("{n} is the number value, % is the percent sign", "{n}%"));
140 }
141
143
144 connect(m_colorSlider, SIGNAL(valueChanged(int)), this, SLOT(onColorSliderChanged(int)));
145 connect(m_intNumInput, SIGNAL(valueChanged(int)), this, SLOT(onNumInputChanged(int)));
146 return m_intNumInput;
147}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KoColorSlider * m_colorSlider
The KisIntParseSpinBox class is a cleverer SpinBox, able to parse arithmetic expressions.
KisIntParseSpinBox * m_intNumInput
void setText(QSpinBox *spinBox, const QStringView textTemplate)

References connect(), KisColorInput::m_colorSlider, m_intNumInput, KisColorInput::m_usePercentage, onColorSliderChanged(), onNumInputChanged(), KisSpinBoxI18nHelper::setText(), and updateMaximums().

◆ onColorSliderChanged

void KisIntegerColorInput::onColorSliderChanged ( int val)
privateslot

Definition at line 179 of file kis_color_input.cpp.

180{
181 m_intNumInput->blockSignals(true);
182
186
187 m_intNumInput->setValue(m_usePercentage ? round(val * 100.0 / ((1 << 8 * m_channelInfo->size()) - 1))
188 : val);
189
190 m_intNumInput->blockSignals(false);
191 setValue(val);
192}
const KoChannelInfo * m_channelInfo
void setValue(int value, bool overwriteExpression=false)
Set the value of the spinbox.
qint32 size() const
@ UINT8
use this for an unsigned integer 8bits channel
@ UINT16
use this for an integer 16bits channel
@ UINT32
use this for an unsigned integer 21bits channel
enumChannelValueType channelValueType() const

References KoChannelInfo::channelValueType(), KisColorInput::m_channelInfo, m_intNumInput, KisColorInput::m_usePercentage, KisIntParseSpinBox::setValue(), setValue(), KoChannelInfo::size(), KoChannelInfo::UINT16, KoChannelInfo::UINT32, and KoChannelInfo::UINT8.

◆ onNumInputChanged

void KisIntegerColorInput::onNumInputChanged ( int val)
privateslot

◆ setPercentageWise()

void KisIntegerColorInput::setPercentageWise ( bool val)
overrideprotectedvirtual

Reimplemented from KisColorInput.

Definition at line 163 of file kis_color_input.cpp.

164{
165 m_usePercentage = val;
166
167 m_intNumInput->clearFocus(); // make sure focus doesn't interfere with updating
168
169 if (m_usePercentage) {
170 KisSpinBoxI18nHelper::setText(m_intNumInput, i18nc("{n} is the number value, % is the percent sign", "{n}%"));
171 } else {
172 m_intNumInput->setPrefix("");
173 m_intNumInput->setSuffix("");
174 }
175
177}

References m_intNumInput, KisColorInput::m_usePercentage, KisSpinBoxI18nHelper::setText(), and updateMaximums().

◆ setValue

void KisIntegerColorInput::setValue ( int v)
slot

Definition at line 71 of file kis_color_input.cpp.

72{
73 quint8* data = m_color->data() + m_channelInfo->pos();
76 *(reinterpret_cast<quint8*>(data)) = v;
77 break;
79 *(reinterpret_cast<quint16*>(data)) = v;
80 break;
82 *(reinterpret_cast<quint32*>(data)) = v;
83 break;
84 default:
85 Q_ASSERT(false);
86 }
87 emit(updated());
88}
qreal v
KoColor * m_color
qint32 pos() const
quint8 * data()
Definition KoColor.h:144

References KoChannelInfo::channelValueType(), KoColor::data(), KisColorInput::m_channelInfo, KisColorInput::m_color, KoChannelInfo::pos(), KoChannelInfo::UINT16, KoChannelInfo::UINT32, KoChannelInfo::UINT8, KisColorInput::updated(), and v.

◆ update

void KisIntegerColorInput::update ( )
slot

Definition at line 90 of file kis_color_input.cpp.

91{
94 quint8* data = m_color->data() + m_channelInfo->pos();
95 quint8* dataMin = min.data() + m_channelInfo->pos();
96 quint8* dataMax = max.data() + m_channelInfo->pos();
97 m_intNumInput->blockSignals(true);
98 m_colorSlider->blockSignals(true);
101 quint8 value = *(reinterpret_cast<quint8*>(data));
102 m_intNumInput->setValue(m_usePercentage ? round(value * 100.0 / 0xFF) : value);
103 m_colorSlider->setValue(value);
104 *(reinterpret_cast<quint8*>(dataMin)) = 0x0;
105 *(reinterpret_cast<quint8*>(dataMax)) = 0xFF;
106 break;
107 }
109 quint16 value = *(reinterpret_cast<quint16*>(data));
110 m_intNumInput->setValue(m_usePercentage ? round(value * 100.0 / 0xFFFF) : value);
111 m_colorSlider->setValue(value);
112 *(reinterpret_cast<quint16*>(dataMin)) = 0x0;
113 *(reinterpret_cast<quint16*>(dataMax)) = 0xFFFF;
114 break;
115 }
117 quint32 value = *(reinterpret_cast<quint32*>(data));
118 m_intNumInput->setValue(m_usePercentage ? round(value * 100.0 / 0xFFFF'FFFF) : value);
119 m_colorSlider->setValue(value);
120 *(reinterpret_cast<quint32*>(dataMin)) = 0x0;
121 *(reinterpret_cast<quint32*>(dataMax)) = 0xFFFF'FFFF;
122 break;
123 }
124 default:
125 Q_ASSERT(false);
126 }
127 m_colorSlider->setColors(min, max);
128 m_intNumInput->blockSignals(false);
129 m_colorSlider->blockSignals(false);
130}
float value(const T *src, size_t ch)
T min(T a, T b, T c)
constexpr std::enable_if< sizeof...(values)==0, size_t >::type max()
void setColors(const KoColor &minColor, const KoColor &maxColor)

References KoChannelInfo::channelValueType(), KoColor::data(), KisColorInput::m_channelInfo, KisColorInput::m_color, KisColorInput::m_colorSlider, m_intNumInput, KisColorInput::m_usePercentage, KoChannelInfo::pos(), KoColorSlider::setColors(), KisIntParseSpinBox::setValue(), KoChannelInfo::UINT16, KoChannelInfo::UINT32, KoChannelInfo::UINT8, and value().

◆ updateMaximums()

void KisIntegerColorInput::updateMaximums ( )
protected

Definition at line 149 of file kis_color_input.cpp.

150{
151 m_intNumInput->clearFocus(); // make sure focus doesn't interfere with updating
152
156
157 m_intNumInput->blockSignals(true); // prevent clamping from triggering a value update
158 m_intNumInput->setMaximum(m_usePercentage ? 100 : (1 << 8 * m_channelInfo->size()) - 1);
159 m_colorSlider->setMaximum((1 << 8 * m_channelInfo->size()) - 1);
160 m_intNumInput->blockSignals(false);
161}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References KoChannelInfo::channelValueType(), KisColorInput::m_channelInfo, KisColorInput::m_colorSlider, m_intNumInput, KisColorInput::m_usePercentage, KoChannelInfo::size(), KoChannelInfo::UINT16, KoChannelInfo::UINT32, and KoChannelInfo::UINT8.

Member Data Documentation

◆ m_intNumInput

KisIntParseSpinBox* KisIntegerColorInput::m_intNumInput {nullptr}
private

Definition at line 69 of file kis_color_input.h.

69{nullptr};

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