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

The KisSpinboxColorSelector class This will give a widget with spinboxes depending on the color space Take responsibility for changing the color space. More...

#include <kis_spinbox_color_selector.h>

+ Inheritance diagram for KisSpinboxColorSelector:

Classes

struct  Private
 

Public Slots

void slotSetColor (KoColor color)
 
void slotSetColorSpace (const KoColorSpace *cs)
 

Signals

void sigNewColor (KoColor color)
 

Public Member Functions

void chooseAlpha (bool chooseAlpha)
 
 KisSpinboxColorSelector (QWidget *parent)
 
 ~KisSpinboxColorSelector () override
 

Private Slots

void slotUpdateFromSpinBoxes ()
 

Private Member Functions

void createColorFromSpinboxValues ()
 
void updateSpinboxesWithNewValues ()
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

The KisSpinboxColorSelector class This will give a widget with spinboxes depending on the color space Take responsibility for changing the color space.

Definition at line 21 of file kis_spinbox_color_selector.h.

Constructor & Destructor Documentation

◆ KisSpinboxColorSelector()

KisSpinboxColorSelector::KisSpinboxColorSelector ( QWidget * parent)
explicit

Definition at line 35 of file kis_spinbox_color_selector.cpp.

36 : QWidget(parent)
37 , m_d(new Private)
38{
39 this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
40 m_d->layout = new QFormLayout(this);
41}
const QScopedPointer< Private > m_d

References m_d.

◆ ~KisSpinboxColorSelector()

KisSpinboxColorSelector::~KisSpinboxColorSelector ( )
override

Definition at line 43 of file kis_spinbox_color_selector.cpp.

44{
45
46}

Member Function Documentation

◆ chooseAlpha()

void KisSpinboxColorSelector::chooseAlpha ( bool chooseAlpha)

◆ createColorFromSpinboxValues()

void KisSpinboxColorSelector::createColorFromSpinboxValues ( )
private

Definition at line 196 of file kis_spinbox_color_selector.cpp.

197{
198 KoColor newColor(m_d->cs);
199 int channelcount = m_d->cs->channelCount();
200 QVector <float> channelValues(channelcount);
201 channelValues.fill(1.0);
203
204 for (int i = 0; i < (int)qAbs(m_d->cs->colorChannelCount()); i++) {
205 int channelposition = KoChannelInfo::displayPositionToChannelIndex(i, m_d->cs->channels());
206
207 if (channels.at(i)->channelValueType()==KoChannelInfo::UINT8 && m_d->spinBoxList.at(i)){
208
209 int value = m_d->spinBoxList.at(i)->value();
210 channelValues[channelposition] = KoColorSpaceMaths<quint8,float>::scaleToA(value);
211
212 } else if (channels.at(i)->channelValueType()==KoChannelInfo::UINT16 && m_d->spinBoxList.at(i)){
213
214 channelValues[channelposition] = KoColorSpaceMaths<quint16,float>::scaleToA(m_d->spinBoxList.at(i)->value());
215
216 } else if ((channels.at(i)->channelValueType()==KoChannelInfo::FLOAT16 ||
217 channels.at(i)->channelValueType()==KoChannelInfo::FLOAT32 ||
218 channels.at(i)->channelValueType()==KoChannelInfo::FLOAT64) && m_d->doubleSpinBoxList.at(i)) {
219
220 channelValues[channelposition] = m_d->doubleSpinBoxList.at(i)->value();
221
222 }
223 }
224
225 m_d->cs->fromNormalisedChannelsValue(newColor.data(), channelValues);
226 newColor.setOpacity(m_d->color.opacityU8());
227
228 m_d->color = newColor;
229}
float value(const T *src, size_t ch)
@ UINT8
use this for an unsigned integer 8bits channel
@ UINT16
use this for an integer 16bits channel
@ FLOAT32
use this for a float 32bits channel
@ FLOAT16
use this for a float 16bits channel
@ FLOAT64
use this for a float 64bits channel
static int displayPositionToChannelIndex(int displayPosition, const QList< KoChannelInfo * > &channels)
static QList< KoChannelInfo * > displayOrderSorted(const QList< KoChannelInfo * > &channels)
static _Tdst scaleToA(_T a)

References KoColor::data(), KoChannelInfo::displayOrderSorted(), KoChannelInfo::displayPositionToChannelIndex(), KoChannelInfo::FLOAT16, KoChannelInfo::FLOAT32, KoChannelInfo::FLOAT64, m_d, KoColorSpaceMaths< _T, _Tdst >::scaleToA(), KoColor::setOpacity(), KoChannelInfo::UINT16, KoChannelInfo::UINT8, and value().

◆ sigNewColor

void KisSpinboxColorSelector::sigNewColor ( KoColor color)
signal

◆ slotSetColor

void KisSpinboxColorSelector::slotSetColor ( KoColor color)
slot

Definition at line 48 of file kis_spinbox_color_selector.cpp.

49{
50 m_d->color = color;
51 slotSetColorSpace(m_d->color.colorSpace());
53}
void slotSetColorSpace(const KoColorSpace *cs)

References m_d, slotSetColorSpace(), and updateSpinboxesWithNewValues().

◆ slotSetColorSpace

void KisSpinboxColorSelector::slotSetColorSpace ( const KoColorSpace * cs)
slot

Definition at line 55 of file kis_spinbox_color_selector.cpp.

56{
57 if (cs == m_d->cs) {
58 return;
59 }
60
61 m_d->cs = cs;
62 //remake spinboxes
63 delete m_d->layout;
64 m_d->layout = new QFormLayout(this);
65
66 Q_FOREACH(QObject *o, m_d->labels) {
67 o->deleteLater();
68 }
69 Q_FOREACH(QObject *o, m_d->spinBoxList) {
70 o->deleteLater();
71 }
72 Q_FOREACH(QObject *o, m_d->doubleSpinBoxList) {
73 o->deleteLater();
74 }
75
76 m_d->labels.clear();
77 m_d->spinBoxList.clear();
78 m_d->doubleSpinBoxList.clear();
79
80 const QList<KoChannelInfo *> channels = KoChannelInfo::displayOrderSorted(m_d->cs->channels());
81 Q_FOREACH (KoChannelInfo* channel, channels) {
82 QString inputLabel = channel->name() + ":";
83 QLabel *inlb = new QLabel(this);
84 m_d->labels << inlb;
85 inlb->setText(inputLabel);
86 switch (channel->channelValueType()) {
88 KisIntParseSpinBox *input = new KisIntParseSpinBox(this);
89 input->setMinimum(0);
90 input->setMaximum(0xFF);
91 m_d->spinBoxList.append(input);
92 connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateFromSpinBoxes()));
93 if (channel->channelType() == KoChannelInfo::ALPHA && m_d->chooseAlpha == false) {
94 inlb->setVisible(false);
95 input->setVisible(false);
96 input->blockSignals(true);
97 }
98 else {
99 m_d->layout->addRow(inlb, input);
100 }
101 }
102 break;
104 KisIntParseSpinBox *input = new KisIntParseSpinBox(this);
105 input->setMinimum(0);
106 input->setMaximum(0xFFFF);
107 m_d->spinBoxList.append(input);
108 connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateFromSpinBoxes()));
109 if (channel->channelType() == KoChannelInfo::ALPHA && m_d->chooseAlpha == false) {
110 inlb->setVisible(false);
111 input->setVisible(false);
112 input->blockSignals(true);
113 }
114 else {
115 m_d->layout->addRow(inlb,input);
116 }
117 }
118 break;
120 KisIntParseSpinBox *input = new KisIntParseSpinBox(this);
121 input->setMinimum(0);
122 input->setMaximum(0xFFFFFFFF);
123 m_d->spinBoxList.append(input);
124 connect(input, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateFromSpinBoxes()));
125 if (channel->channelType() == KoChannelInfo::ALPHA && m_d->chooseAlpha == false) {
126 inlb->setVisible(false);
127 input->setVisible(false);
128 input->blockSignals(true);
129 }
130 else {
131 m_d->layout->addRow(inlb,input);
132 }
133 }
134 break;
135#ifdef HAVE_OPENEXR
137 half m_uiMin, m_uiMax;
139 m_uiMin = channel->getUIMin();
140 m_uiMax = channel->getUIMax();
141 } else {
142 m_uiMin = 0;
144 }
145
147 input->setMinimum(m_uiMin);
148 input->setMaximum(m_uiMax);
149 input->setSingleStep(0.1);
150 m_d->doubleSpinBoxList.append(input);
151 connect(input, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateFromSpinBoxes()));
152 if (channel->channelType() == KoChannelInfo::ALPHA && m_d->chooseAlpha == false) {
153 inlb->setVisible(false);
154 input->setVisible(false);
155 input->blockSignals(true);
156 }
157 else {
158 m_d->layout->addRow(inlb,input);
159 }
160 }
161 break;
162#endif
164 float m_uiMin, m_uiMax;
166 m_uiMin = channel->getUIMin();
167 m_uiMax = channel->getUIMax();
168 } else {
169 m_uiMin = 0;
171 }
172
174 input->setMinimum(m_uiMin);
175 input->setMaximum(m_uiMax);
176 input->setSingleStep(0.1);
177 m_d->doubleSpinBoxList.append(input);
178 connect(input, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateFromSpinBoxes()));
179 if (channel->channelType() == KoChannelInfo::ALPHA && m_d->chooseAlpha == false) {
180 inlb->setVisible(false);
181 input->setVisible(false);
182 input->blockSignals(true);
183 }
184 else {
185 m_d->layout->addRow(inlb,input);
186 }
187 }
188 break;
189 default:
190 Q_ASSERT(false);
191 }
192
193 }
194}
const KoID CMYKAColorModelID("CMYKA", ki18n("CMYK/Alpha"))
const KoID LABAColorModelID("LABA", ki18n("L*a*b*/Alpha"))
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The KisDoubleParseSpinBox class is a cleverer doubleSpinBox, able to parse arithmetic expressions.
The KisIntParseSpinBox class is a cleverer SpinBox, able to parse arithmetic expressions.
@ ALPHA
The channel represents the opacity of a pixel.
@ UINT32
use this for an unsigned integer 21bits channel
enumChannelType channelType() const
enumChannelValueType channelValueType() const
QString name() const
double getUIMin(void) const
double getUIMax(void) const
virtual KoID colorModelId() const =0

References KoChannelInfo::ALPHA, KoChannelInfo::channelType(), KoChannelInfo::channelValueType(), CMYKAColorModelID, KoColorSpace::colorModelId(), connect(), KoChannelInfo::displayOrderSorted(), KoChannelInfo::FLOAT16, KoChannelInfo::FLOAT32, KoChannelInfo::getUIMax(), KoChannelInfo::getUIMin(), LABAColorModelID, m_d, KoChannelInfo::name(), slotUpdateFromSpinBoxes(), KoChannelInfo::UINT16, KoChannelInfo::UINT32, and KoChannelInfo::UINT8.

◆ slotUpdateFromSpinBoxes

void KisSpinboxColorSelector::slotUpdateFromSpinBoxes ( )
privateslot

Definition at line 231 of file kis_spinbox_color_selector.cpp.

232{
234 Q_EMIT sigNewColor(m_d->color);
235}
void sigNewColor(KoColor color)

References createColorFromSpinboxValues(), m_d, and sigNewColor().

◆ updateSpinboxesWithNewValues()

void KisSpinboxColorSelector::updateSpinboxesWithNewValues ( )
private

Definition at line 237 of file kis_spinbox_color_selector.cpp.

238{
239 int channelcount = m_d->cs->channelCount();
240 QVector <float> channelValues(channelcount);
241 channelValues.fill(1.0);
242 m_d->cs->normalisedChannelsValue(m_d->color.data(), channelValues);
244
245 int i;
246 /*while (QLayoutItem *item = this->layout()->takeAt(0))
247 {
248 item->widget()->blockSignals(true);
249 }*/
250 for (i=0; i<m_d->spinBoxList.size(); i++) {
251 m_d->spinBoxList.at(i)->blockSignals(true);
252 }
253 for (i=0; i<m_d->doubleSpinBoxList.size(); i++) {
254 m_d->doubleSpinBoxList.at(i)->blockSignals(true);
255 }
256
257 for (i = 0; i < (int)qAbs(m_d->cs->colorChannelCount()); i++) {
258 int channelposition = KoChannelInfo::displayPositionToChannelIndex(i, m_d->cs->channels());
259 if (channels.at(i)->channelValueType() == KoChannelInfo::UINT8 && m_d->spinBoxList.at(i)) {
260 int value = KoColorSpaceMaths<float, quint8>::scaleToA(channelValues[channelposition]);
261 m_d->spinBoxList.at(i)->setValue(value);
262 } else if (channels.at(i)->channelValueType() == KoChannelInfo::UINT16 && m_d->spinBoxList.at(i)) {
263 m_d->spinBoxList.at(i)->setValue(KoColorSpaceMaths<float, quint16>::scaleToA(channelValues[channelposition]));
264 } else if ((channels.at(i)->channelValueType()==KoChannelInfo::FLOAT16 ||
265 channels.at(i)->channelValueType()==KoChannelInfo::FLOAT32 ||
266 channels.at(i)->channelValueType()==KoChannelInfo::FLOAT64) && m_d->doubleSpinBoxList.at(i)) {
267 float value = channels.at(i)->getUIMin() + channelValues[channelposition] * channels.at(i)->getUIUnitValue();
268 m_d->doubleSpinBoxList.at(i)->setValue(value);
269 }
270 }
271
272 for (i=0; i<m_d->spinBoxList.size(); i++) {
273 m_d->spinBoxList.at(i)->blockSignals(false);
274 }
275 for (i=0; i<m_d->doubleSpinBoxList.size(); i++) {
276 m_d->doubleSpinBoxList.at(i)->blockSignals(false);
277 }
278 /*while (QLayoutItem *item = this->layout()->takeAt(0))
279 {
280 item->widget()->blockSignals(false);
281 }*/
282}

References KoChannelInfo::displayOrderSorted(), KoChannelInfo::displayPositionToChannelIndex(), KoChannelInfo::FLOAT16, KoChannelInfo::FLOAT32, KoChannelInfo::FLOAT64, m_d, KoColorSpaceMaths< _T, _Tdst >::scaleToA(), KoChannelInfo::UINT16, KoChannelInfo::UINT8, and value().

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisSpinboxColorSelector::m_d
private

Definition at line 42 of file kis_spinbox_color_selector.h.


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