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 textChanged (const QString &text)
 
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 KoChannelInfo * m_channelInfo {nullptr}
 
KoColor * m_color {nullptr}
 
KoColorSlider * m_colorSlider {nullptr}
 
KoColorDisplayRendererInterface * m_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 connect(m_input, SIGNAL(textChanged(const QString&)), SLOT(setValue()));
351 connect(m_input, SIGNAL(textEdited(const QString &)), SLOT(textChanged(const QString &)));
352
353 m_layout->addWidget(m_input);
354}
KisColorInput(QWidget *parent, const KoChannelInfo *, KoColor *color, KoColorDisplayRendererInterface *displayRenderer=KoDumbColorDisplayRenderer::instance(), bool usePercentage=false)
bool usePercentage() const
QWidget * createInput() override
void textChanged(const QString &text)

References createInput(), m_colorPreview, setValue(), and textChanged().

Member Function Documentation

◆ createInput()

QWidget * KisHexColorInput::createInput ( )
overrideprotectedvirtual

Implements KisColorInput.

Definition at line 400 of file kis_color_input.cpp.

401{
402 m_hexInput = new QLineEdit(this);
403 m_hexInput->setAlignment(Qt::AlignRight);
404
405 int digits = 2*m_color->colorSpace()->colorChannelCount();
406 QString pattern = QString("\\s*#?[a-fA-F0-9]{%1,%2}\\s*").arg(digits).arg(digits);
407 m_hexInput->setValidator(new QRegularExpressionValidator(QRegularExpression(pattern), this));
408 connect(m_hexInput, SIGNAL(editingFinished()), this, SLOT(setValue()));
409 return m_hexInput;
410}
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(), KisColorInput::m_color, m_hexInput, and setValue().

◆ setValue

void KisHexColorInput::setValue ( )
slot

Definition at line 361 of file kis_color_input.cpp.

362{
363 QString valueString = m_hexInput->text();
364 valueString.remove(QChar('#'));
365
367 channels = KoChannelInfo::displayOrderSorted(channels);
368 Q_FOREACH (KoChannelInfo* channel, channels) {
369 if (channel->channelType() == KoChannelInfo::COLOR) {
370 Q_ASSERT(channel->channelValueType() == KoChannelInfo::UINT8);
371 quint8* data = m_color->data() + channel->pos();
372
373 int value = valueString.left(2).toInt(0, 16);
374 *(reinterpret_cast<quint8*>(data)) = value;
375 valueString.remove(0, 2);
376 }
377 }
378 emit(updated());
379}
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().

◆ textChanged

void KisHexColorInput::textChanged ( const QString & text)
slot

Definition at line 356 of file kis_color_input.cpp.

357{
358 this->m_hexInput->setText(text.trimmed());
359}

References m_hexInput.

◆ update

void KisHexColorInput::update ( )
slot

Definition at line 381 of file kis_color_input.cpp.

382{
383 QString hexString("#");
384
386 channels = KoChannelInfo::displayOrderSorted(channels);
387 Q_FOREACH (KoChannelInfo* channel, channels) {
388 if (channel->channelType() == KoChannelInfo::COLOR) {
389 Q_ASSERT(channel->channelValueType() == KoChannelInfo::UINT8);
390 quint8* data = m_color->data() + channel->pos();
391 hexString.append(QString("%1").arg(*(reinterpret_cast<quint8*>(data)), 2, 16, QChar('0')));
392 }
393 }
394 m_hexInput->setText(hexString);
395 if( m_colorPreview) {
396 m_colorPreview->setStyleSheet(QString("background-color: %1").arg(m_displayRenderer->toQColor(*m_color).name()));
397 }
398}
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 103 of file kis_color_input.h.

◆ m_hexInput

QLineEdit* KisHexColorInput::m_hexInput {nullptr}
private

Definition at line 102 of file kis_color_input.h.

102{nullptr};

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