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

#include <kis_color_input.h>

+ Inheritance diagram for KisHexColorInput:

Public Slots

void setValue ()
 
void update ()
 

Public Member Functions

 KisHexColorInput (QWidget *parent, KoColor *color, KoColorDisplayRendererInterface *displayRenderer=KoDumbColorDisplayRenderer::instance(), bool usePercentage=false, bool usePreview=false)
 
- Public Member Functions inherited from KisColorInput
 KisColorInput (QWidget *parent, const KoChannelInfo *, KoColor *color, KoColorDisplayRendererInterface *displayRenderer=KoDumbColorDisplayRenderer::instance(), bool usePercentage=false)
 
virtual void setPercentageWise (bool val)
 
bool usePercentage () const
 

Protected Member Functions

QWidget * createInput () override
 
- Protected Member Functions inherited from KisColorInput
void init ()
 

Private Attributes

QLabel * m_colorPreview =nullptr
 
QLineEdit * m_hexInput {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 90 of file kis_color_input.h.

Constructor & Destructor Documentation

◆ KisHexColorInput()

KisHexColorInput::KisHexColorInput ( QWidget * parent,
KoColor * color,
KoColorDisplayRendererInterface * displayRenderer = KoDumbColorDisplayRenderer::instance(),
bool usePercentage = false,
bool usePreview = false )

Definition at line 330 of file kis_color_input.cpp.

330 :
331 KisColorInput(parent, 0, color, displayRenderer, usePercentage)
332{
333 QHBoxLayout* m_layout = new QHBoxLayout(this);
334 m_layout->setContentsMargins(0,0,0,0);
335 m_layout->setSpacing(1);
336
337 QLabel* m_label = new QLabel(i18n("Color name:"), this);
338 m_label->setMinimumWidth(50);
339 m_layout->addWidget(m_label);
340
341 QWidget* m_input = createInput();
342 m_input->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
343
344 if(usePreview) {
345 m_colorPreview = new QLabel("");
346 m_colorPreview->setMinimumWidth(30);
347 m_layout->addWidget(m_colorPreview);
348 }
349
350 m_layout->addWidget(m_input);
351}
KisColorInput(QWidget *parent, const KoChannelInfo *, KoColor *color, KoColorDisplayRendererInterface *displayRenderer=KoDumbColorDisplayRenderer::instance(), bool usePercentage=false)
bool usePercentage() const
QWidget * createInput() override

References createInput(), and m_colorPreview.

Member Function Documentation

◆ createInput()

QWidget * KisHexColorInput::createInput ( )
overrideprotectedvirtual

Implements KisColorInput.

Definition at line 392 of file kis_color_input.cpp.

393{
394 m_hexInput = new QLineEdit(this);
395 m_hexInput->setAlignment(Qt::AlignRight);
396
397 int digits = 2*m_color->colorSpace()->colorChannelCount();
398 QString pattern = QString("#?[a-fA-F0-9]{%1,%2}").arg(digits).arg(digits);
399 m_hexInput->setValidator(new QRegularExpressionValidator(QRegularExpression(pattern), this));
400 connect(m_hexInput, SIGNAL(editingFinished()), this, SLOT(setValue()));
401 return m_hexInput;
402}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KoColor * m_color
QLineEdit * m_hexInput
virtual quint32 colorChannelCount() const =0
const KoColorSpace * colorSpace() const
return the current colorSpace
Definition KoColor.h:82

References KoColorSpace::colorChannelCount(), KoColor::colorSpace(), connect(), KisColorInput::m_color, m_hexInput, and setValue().

◆ setValue

void KisHexColorInput::setValue ( )
slot

Definition at line 353 of file kis_color_input.cpp.

354{
355 QString valueString = m_hexInput->text();
356 valueString.remove(QChar('#'));
357
359 channels = KoChannelInfo::displayOrderSorted(channels);
360 Q_FOREACH (KoChannelInfo* channel, channels) {
361 if (channel->channelType() == KoChannelInfo::COLOR) {
362 Q_ASSERT(channel->channelValueType() == KoChannelInfo::UINT8);
363 quint8* data = m_color->data() + channel->pos();
364
365 int value = valueString.left(2).toInt(0, 16);
366 *(reinterpret_cast<quint8*>(data)) = value;
367 valueString.remove(0, 2);
368 }
369 }
370 emit(updated());
371}
float value(const T *src, size_t ch)
@ COLOR
The channel represents a color.
qint32 pos() const
@ UINT8
use this for an unsigned integer 8bits channel
enumChannelType channelType() const
enumChannelValueType channelValueType() const
static QList< KoChannelInfo * > displayOrderSorted(const QList< KoChannelInfo * > &channels)
QList< KoChannelInfo * > channels
quint8 * data()
Definition KoColor.h:144

References KoColorSpace::channels, KoChannelInfo::channelType(), KoChannelInfo::channelValueType(), KoChannelInfo::COLOR, KoColor::colorSpace(), KoColor::data(), KoChannelInfo::displayOrderSorted(), KisColorInput::m_color, m_hexInput, KoChannelInfo::pos(), KoChannelInfo::UINT8, KisColorInput::updated(), and value().

◆ update

void KisHexColorInput::update ( )
slot

Definition at line 373 of file kis_color_input.cpp.

374{
375 QString hexString("#");
376
378 channels = KoChannelInfo::displayOrderSorted(channels);
379 Q_FOREACH (KoChannelInfo* channel, channels) {
380 if (channel->channelType() == KoChannelInfo::COLOR) {
381 Q_ASSERT(channel->channelValueType() == KoChannelInfo::UINT8);
382 quint8* data = m_color->data() + channel->pos();
383 hexString.append(QString("%1").arg(*(reinterpret_cast<quint8*>(data)), 2, 16, QChar('0')));
384 }
385 }
386 m_hexInput->setText(hexString);
387 if( m_colorPreview) {
388 m_colorPreview->setStyleSheet(QString("background-color: %1").arg(m_displayRenderer->toQColor(*m_color).name()));
389 }
390}
KoColorDisplayRendererInterface * m_displayRenderer
virtual QColor toQColor(const KoColor &c, bool proofToPaintColors=false) const =0

References KoColorSpace::channels, KoChannelInfo::channelType(), KoChannelInfo::channelValueType(), KoChannelInfo::COLOR, KoColor::colorSpace(), KoColor::data(), KoChannelInfo::displayOrderSorted(), KisColorInput::m_color, m_colorPreview, KisColorInput::m_displayRenderer, m_hexInput, KoChannelInfo::pos(), KoColorDisplayRendererInterface::toQColor(), and KoChannelInfo::UINT8.

Member Data Documentation

◆ m_colorPreview

QLabel* KisHexColorInput::m_colorPreview =nullptr
private

Definition at line 102 of file kis_color_input.h.

◆ m_hexInput

QLineEdit* KisHexColorInput::m_hexInput {nullptr}
private

Definition at line 101 of file kis_color_input.h.

101{nullptr};

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