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

#include <KoColorSlider.h>

+ Inheritance diagram for KoColorSlider:

Public Member Functions

KoColor currentColor () const
 
 KoColorSlider (Qt::Orientation orientation, QWidget *parent=0, KoColorDisplayRendererInterface *displayRenderer=KoDumbColorDisplayRenderer::instance())
 
 KoColorSlider (QWidget *parent=0, KoColorDisplayRendererInterface *displayRenderer=KoDumbColorDisplayRenderer::instance())
 
 Private ()
 
void setColors (const KoColor &minColor, const KoColor &maxColor)
 
 ~KoColorSlider () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Public Attributes

QPointer< KoColorDisplayRendererInterfacedisplayRenderer
 
KoColor maxColor
 
KoColor minColor
 
QPixmap pixmap
 
KisSignalCompressor updateCompressor
 
bool upToDate
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Protected Member Functions

void drawArrow (QPainter *painter, const QPoint &pos) override
 
void drawContents (QPainter *) override
 

Protected Attributes

Private *const d
 

Detailed Description

Definition at line 21 of file KoColorSlider.cpp.

Constructor & Destructor Documentation

◆ KoColorSlider() [1/2]

KoColorSlider::KoColorSlider ( QWidget * parent = 0,
KoColorDisplayRendererInterface * displayRenderer = KoDumbColorDisplayRenderer::instance() )
explicit

Definition at line 38 of file KoColorSlider.cpp.

39 : KSelector(parent)
40 , d(new Private)
41{
42 setMaximum(255);
43 d->displayRenderer = displayRenderer;
44 connect(d->displayRenderer, SIGNAL(displayConfigurationChanged()), SLOT(update()), Qt::UniqueConnection);
45 connect(&d->updateCompressor, SIGNAL(timeout()), SLOT(update()), Qt::UniqueConnection);
46}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
bool update(QSpinBox *spinBox)
QPointer< KoColorDisplayRendererInterface > displayRenderer
Private *const d

References connect(), d, and displayRenderer.

◆ KoColorSlider() [2/2]

KoColorSlider::KoColorSlider ( Qt::Orientation orientation,
QWidget * parent = 0,
KoColorDisplayRendererInterface * displayRenderer = KoDumbColorDisplayRenderer::instance() )
explicit

Definition at line 48 of file KoColorSlider.cpp.

49 : KSelector(o, parent), d(new Private)
50{
51 setMaximum(255);
52 d->displayRenderer = displayRenderer;
53 connect(d->displayRenderer, SIGNAL(displayConfigurationChanged()), SLOT(update()), Qt::UniqueConnection);
54 connect(&d->updateCompressor, SIGNAL(timeout()), SLOT(update()), Qt::UniqueConnection);
55}

References connect(), d, and displayRenderer.

◆ ~KoColorSlider()

KoColorSlider::~KoColorSlider ( )
override

Definition at line 57 of file KoColorSlider.cpp.

58{
59 delete d;
60}

References d.

Member Function Documentation

◆ currentColor()

KoColor KoColorSlider::currentColor ( ) const

Return the current color

Definition at line 146 of file KoColorSlider.cpp.

147{
148 const quint8 *colors[2];
149 colors[0] = d->minColor.data();
150 colors[1] = d->maxColor.data();
151 KoMixColorsOp * mixOp = d->minColor.colorSpace()->mixColorsOp();
152 KoColor c(d->minColor.colorSpace());
153 qint16 weights[2];
154 weights[1] = (value() - minimum()) / qreal(maximum() - minimum()) * 255;
155 weights[0] = 255 - weights[1];
156 mixOp->mixColors(colors, weights, 2, c.data());
157 return c;
158}
float value(const T *src, size_t ch)
virtual void mixColors(const quint8 *const *colors, const qint16 *weights, int nColors, quint8 *dst, int weightSum=255) const =0

References d, KoColor::data(), KoMixColorsOp::mixColors(), and value().

◆ drawArrow()

void KoColorSlider::drawArrow ( QPainter * painter,
const QPoint & pos )
overrideprotected

Definition at line 160 of file KoColorSlider.cpp.

161{
162 painter->setPen(QPen(palette().text().color(), 0));
163 painter->setBrush(palette().text());
164
165 QStyleOption o;
166 o.initFrom(this);
167 o.state &= ~QStyle::State_MouseOver;
168
169 if ( orientation() == Qt::Vertical ) {
170 o.rect = QRect( pos.x(), pos.y() - ARROWSIZE / 2,
172 } else {
173 o.rect = QRect( pos.x() - ARROWSIZE / 2, pos.y(),
175 }
176
177 QStyle::PrimitiveElement arrowPE;
178 switch (arrowDirection()) {
179 case Qt::UpArrow:
180 arrowPE = QStyle::PE_IndicatorArrowUp;
181 break;
182 case Qt::DownArrow:
183 arrowPE = QStyle::PE_IndicatorArrowDown;
184 break;
185 case Qt::RightArrow:
186 arrowPE = QStyle::PE_IndicatorArrowRight;
187 break;
188 case Qt::LeftArrow:
189 default:
190 arrowPE = QStyle::PE_IndicatorArrowLeft;
191 break;
192 }
193
194 style()->drawPrimitive(arrowPE, &o, painter, this);
195
196}
#define ARROWSIZE
rgba palette[MAX_PALETTE]
Definition palette.c:35

References ARROWSIZE, and palette.

◆ drawContents()

void KoColorSlider::drawContents ( QPainter * painter)
overrideprotected

Definition at line 70 of file KoColorSlider.cpp.

71{
72 QPixmap checker(8, 8);
73 QPainter p(&checker);
74 p.fillRect(0, 0, 4, 4, Qt::lightGray);
75 p.fillRect(4, 0, 4, 4, Qt::darkGray);
76 p.fillRect(0, 4, 4, 4, Qt::darkGray);
77 p.fillRect(4, 4, 4, 4, Qt::lightGray);
78 p.end();
79 QRect contentsRect_(contentsRect());
80 painter->fillRect(contentsRect_, QBrush(checker));
81
82 if( !d->upToDate || d->pixmap.isNull() || d->pixmap.width() != contentsRect_.width()
83 || d->pixmap.height() != contentsRect_.height() )
84 {
85 KoColor c = d->minColor; // smart way to fetch colorspace
86 QColor color;
87
88 const quint8 *colors[2];
89 colors[0] = d->minColor.data();
90 colors[1] = d->maxColor.data();
91
92 KoMixColorsOp * mixOp = c.colorSpace()->mixColorsOp();
93 Q_ASSERT(mixOp);
94 QImage image(contentsRect_.width(), contentsRect_.height(), QImage::Format_ARGB32 );
95
96 if( orientation() == Qt::Horizontal ) {
97 for (int x = 0; x < contentsRect_.width(); x++) {
98
99 qreal t = static_cast<qreal>(x) / (contentsRect_.width() - 1);
100
101 qint16 colorWeights[2];
102 colorWeights[0] = static_cast<quint8>((1.0 - t) * 255 + 0.5);
103 colorWeights[1] = 255 - colorWeights[0];
104
105 mixOp->mixColors(colors, colorWeights, 2, c.data());
106
107 if (d->displayRenderer) {
108 color = d->displayRenderer->toQColor(c);
109 }
110 else {
111 color = c.toQColor();
112 }
113
114 for (int y = 0; y < contentsRect_.height(); y++)
115 image.setPixel(x, y, color.rgba());
116 }
117 }
118 else {
119 for (int y = 0; y < contentsRect_.height(); y++) {
120
121 qreal t = static_cast<qreal>(y) / (contentsRect_.height() - 1);
122
123 qint16 colorWeights[2];
124 colorWeights[0] = static_cast<quint8>((t) * 255 + 0.5);
125 colorWeights[1] = 255 - colorWeights[0];
126
127 mixOp->mixColors(colors, colorWeights, 2, c.data());
128
129 if (d->displayRenderer) {
130 color = d->displayRenderer->toQColor(c);
131 }
132 else {
133 color = c.toQColor();
134 }
135
136 for (int x = 0; x < contentsRect_.width(); x++)
137 image.setPixel(x, y, color.rgba());
138 }
139 }
140 d->pixmap = QPixmap::fromImage(image);
141 d->upToDate = true;
142 }
143 painter->drawPixmap( contentsRect_, d->pixmap, QRect( 0, 0, d->pixmap.width(), d->pixmap.height()) );
144}
const Params2D p
KoMixColorsOp * mixColorsOp
quint8 * data()
Definition KoColor.h:144
const KoColorSpace * colorSpace() const
return the current colorSpace
Definition KoColor.h:82
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198

References KoColor::colorSpace(), d, KoColor::data(), KoMixColorsOp::mixColors(), KoColorSpace::mixColorsOp, p, and KoColor::toQColor().

◆ Private()

KoColorSlider::Private ( )
inline

Definition at line 23 of file KoColorSlider.cpp.

◆ setColors()

void KoColorSlider::setColors ( const KoColor & minColor,
const KoColor & maxColor )

Definition at line 62 of file KoColorSlider.cpp.

63{
64 d->minColor = mincolor;
65 d->maxColor = maxcolor;
66 d->upToDate = false;
67 d->updateCompressor.start();
68}

References d.

Member Data Documentation

◆ d

Private* const KoColorSlider::d
protected

Definition at line 36 of file KoColorSlider.h.

◆ displayRenderer

QPointer<KoColorDisplayRendererInterface> KoColorSlider::displayRenderer

Definition at line 34 of file KoColorSlider.cpp.

◆ maxColor

KoColor KoColorSlider::maxColor

Definition at line 31 of file KoColorSlider.cpp.

◆ minColor

KoColor KoColorSlider::minColor

Definition at line 30 of file KoColorSlider.cpp.

◆ pixmap

QPixmap KoColorSlider::pixmap

Definition at line 32 of file KoColorSlider.cpp.

◆ updateCompressor

KisSignalCompressor KoColorSlider::updateCompressor

Definition at line 35 of file KoColorSlider.cpp.

◆ upToDate

bool KoColorSlider::upToDate

Definition at line 33 of file KoColorSlider.cpp.


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