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

#include <KisHsvColorSlider.h>

+ Inheritance diagram for KisHsvColorSlider:

Public Types

enum class  MIX_MODE {
  COLOR_SPACE , HSV , HSL , HSI ,
  HSY
}
 

Public Member Functions

 KisHsvColorSlider (Qt::Orientation orientation, QWidget *parent=0, KoColorDisplayRendererInterface *displayRenderer=KoDumbColorDisplayRenderer::instance())
 
 KisHsvColorSlider (QWidget *parent=0, KoColorDisplayRendererInterface *displayRenderer=KoDumbColorDisplayRenderer::instance())
 
 Private ()
 
void setCircularHue (bool)
 
void setColors (const KoColor minColor, const KoColor maxColor)
 
void setColors (const QColor minColor, const QColor maxColor)
 
void setColors (qreal minH, qreal minS, qreal minV, qreal maxH, qreal maxS, qreal maxV)
 
void setMixMode (MIX_MODE mode)
 
 ~KisHsvColorSlider () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Public Attributes

bool circularHue
 
QPointer< KoColorDisplayRendererInterfacedisplayRenderer
 
HSVColor maxColor
 
KoColor maxKoColor
 
HSVColor minColor
 
KoColor minKoColor
 
MIX_MODE mixMode
 
QPixmap pixmap
 
KisSignalCompressor updateCompressor
 
bool upToDate
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Protected Member Functions

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

Protected Attributes

Private *const d
 

Detailed Description

Definition at line 186 of file KisHsvColorSlider.cpp.

Member Enumeration Documentation

◆ MIX_MODE

enum class KisHsvColorSlider::MIX_MODE
strong

Constructor & Destructor Documentation

◆ KisHsvColorSlider() [1/2]

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

Definition at line 217 of file KisHsvColorSlider.cpp.

218 : KisHsvColorSlider(Qt::Horizontal, parent, displayRenderer)
219{
220}
QPointer< KoColorDisplayRendererInterface > displayRenderer
KisHsvColorSlider(QWidget *parent=0, KoColorDisplayRendererInterface *displayRenderer=KoDumbColorDisplayRenderer::instance())

◆ KisHsvColorSlider() [2/2]

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

Definition at line 222 of file KisHsvColorSlider.cpp.

223 : KSelector(orientation, parent)
224 , d(new Private)
225{
226 setMaximum(255);
227 d->displayRenderer = displayRenderer;
228 connect(d->displayRenderer, SIGNAL(displayConfigurationChanged()), SLOT(update()), Qt::UniqueConnection);
229 connect(&d->updateCompressor, SIGNAL(timeout()), SLOT(update()), Qt::UniqueConnection);
230}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
bool update(QSpinBox *spinBox)

References connect(), d, and displayRenderer.

◆ ~KisHsvColorSlider()

KisHsvColorSlider::~KisHsvColorSlider ( )
override

Definition at line 232 of file KisHsvColorSlider.cpp.

233{
234 delete d;
235}

References d.

Member Function Documentation

◆ calcArrowPos()

QPoint KisHsvColorSlider::calcArrowPos ( int value)
protected

Definition at line 344 of file KisHsvColorSlider.cpp.

344 {
345 QPoint p;
346 int w = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
347 int iw = (w < FRAME_SIZE) ? FRAME_SIZE : w;
348
349 double t = static_cast<double>(value - minimum()) / static_cast<double>(maximum() - minimum());
350 if (orientation() == Qt::Vertical) {
351 p.setY(height() - iw - 1 - (height() - 2 * iw - 1) * t);
352
353 if (arrowDirection() == Qt::RightArrow) {
354 p.setX(0);
355 } else {
356 p.setX(width() - FRAME_SIZE);
357 }
358 } else {
359 p.setX(iw + (width() - 2 * iw - 1) * t);
360
361 if (arrowDirection() == Qt::DownArrow) {
362 p.setY(0);
363 } else {
364 p.setY(height() - FRAME_SIZE);
365 }
366 }
367
368 return p;
369}
float value(const T *src, size_t ch)
const Params2D p

References p, and value().

◆ drawArrow()

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

Definition at line 371 of file KisHsvColorSlider.cpp.

372{
373 painter->setPen(QPen(palette().text().color(), 0));
374 painter->setBrush(palette().text());
375
376 QStyleOption o;
377 o.initFrom(this);
378 o.state &= ~QStyle::State_MouseOver;
379
380 // Recalculate pos since the value returned by the parent is bugged and doesn't account for negative setMinimum/setMaximum values
381 QPoint pos = calcArrowPos(value());
382
383 if (orientation() == Qt::Vertical) {
384 o.rect = QRect(pos.x(), pos.y() - ARROW_SIZE / 2, ARROW_SIZE, ARROW_SIZE);
385 } else {
386 o.rect = QRect(pos.x() - ARROW_SIZE / 2, pos.y(), ARROW_SIZE, ARROW_SIZE);
387 }
388
389 QStyle::PrimitiveElement arrowPE;
390 switch (arrowDirection()) {
391 case Qt::UpArrow:
392 arrowPE = QStyle::PE_IndicatorArrowUp;
393 break;
394 case Qt::DownArrow:
395 arrowPE = QStyle::PE_IndicatorArrowDown;
396 break;
397 case Qt::RightArrow:
398 arrowPE = QStyle::PE_IndicatorArrowRight;
399 break;
400 case Qt::LeftArrow:
401 arrowPE = QStyle::PE_IndicatorArrowLeft;
402 break;
403 default:
404 arrowPE = QStyle::PE_IndicatorArrowLeft;
405 break;
406 }
407
408 style()->drawPrimitive(arrowPE, &o, painter, this);
409
410}
rgba palette[MAX_PALETTE]
Definition palette.c:35
QPoint calcArrowPos(int value)

References calcArrowPos(), palette, and value().

◆ drawContents()

void KisHsvColorSlider::drawContents ( QPainter * painter)
overrideprotected

Definition at line 282 of file KisHsvColorSlider.cpp.

283{
284 QPixmap checker(8, 8);
285 QPainter p(&checker);
286 p.fillRect(0, 0, 4, 4, Qt::lightGray);
287 p.fillRect(4, 0, 4, 4, Qt::darkGray);
288 p.fillRect(0, 4, 4, 4, Qt::darkGray);
289 p.fillRect(4, 4, 4, 4, Qt::lightGray);
290 p.end();
291
292 QRect contentsRect_(contentsRect());
293 painter->fillRect(contentsRect_, QBrush(checker));
294
295 if (!d->upToDate || d->pixmap.isNull() || d->pixmap.width() != contentsRect_.width()
296 || d->pixmap.height() != contentsRect_.height())
297 {
298 std::unique_ptr<Mixer> m;
299 switch (d->mixMode) {
301 m = std::make_unique<ColorSpaceMixer>(d->minKoColor, d->maxKoColor, d->displayRenderer);
302 break;
303
304 default: // fallthrough
305 case MIX_MODE::HSV: // fallthrough
306 case MIX_MODE::HSL: // fallthrough
307 case MIX_MODE::HSI: // fallthrough
308 case MIX_MODE::HSY: // fallthrough
309 m = std::make_unique<HsxMixer>(d->minColor, d->maxColor, d->circularHue, d->mixMode);
310 break;
311 }
312
313 QImage image(contentsRect_.width(), contentsRect_.height(), QImage::Format_ARGB32);
314
315 if (orientation() == Qt::Horizontal) {
316 if (contentsRect_.width() > 0) {
317 for (int x = 0; x < contentsRect_.width(); x++) {
318 const qreal t = static_cast<qreal>(x) / (contentsRect_.width() - 1);
319
320 for (int y = 0; y < contentsRect_.height(); y++) {
321 image.setPixel(x, y, m->mix(t).rgba());
322 }
323 }
324 }
325 } else {
326 if (contentsRect_.height() > 0) {
327 for (int y = 0; y < contentsRect_.height(); y++) {
328 const qreal t = static_cast<qreal>(y) / (contentsRect_.height() - 1);
329
330 for (int x = 0; x < contentsRect_.width(); x++) {
331 image.setPixel(x, y, m->mix(t).rgba());
332 }
333 }
334 }
335 }
336
337 d->pixmap = QPixmap::fromImage(image);
338 d->upToDate = true;
339 }
340
341 painter->drawPixmap(contentsRect_, d->pixmap, QRect(0, 0, d->pixmap.width(), d->pixmap.height()));
342}

References COLOR_SPACE, d, HSI, HSL, HSV, HSY, and p.

◆ Private()

KisHsvColorSlider::Private ( )
inline

◆ setCircularHue()

void KisHsvColorSlider::setCircularHue ( bool value)

Definition at line 270 of file KisHsvColorSlider.cpp.

270 {
271 d->circularHue = value;
272 d->upToDate = false;
273 d->updateCompressor.start();
274}

References d, and value().

◆ setColors() [1/3]

void KisHsvColorSlider::setColors ( const KoColor minColor,
const KoColor maxColor )

Definition at line 237 of file KisHsvColorSlider.cpp.

238{
239 fromQColor(min.toQColor(), max.toQColor(), d->minColor, d->maxColor);
240 d->minKoColor = min;
241 d->maxKoColor = max;
242 d->upToDate = false;
243 d->updateCompressor.start();
244}
T min(T a, T b, T c)
constexpr std::enable_if< sizeof...(values)==0, size_t >::type max()

References d.

◆ setColors() [2/3]

void KisHsvColorSlider::setColors ( const QColor minColor,
const QColor maxColor )

Definition at line 246 of file KisHsvColorSlider.cpp.

247{
248 fromQColor(min, max, d->minColor, d->maxColor);
249 d->minKoColor.fromQColor(min);
250 d->maxKoColor.fromQColor(max);
251 d->upToDate = false;
252 d->updateCompressor.start();
253}

References d.

◆ setColors() [3/3]

void KisHsvColorSlider::setColors ( qreal minH,
qreal minS,
qreal minV,
qreal maxH,
qreal maxS,
qreal maxV )

Definition at line 255 of file KisHsvColorSlider.cpp.

256{
257 d->minColor = HSVColor(minH, minS, minV);
258 d->maxColor = HSVColor(maxH, maxS, maxV);
259
260 QColor minQ, maxQ;
261 minQ.setHsvF(minH, minS, minV);
262 maxQ.setHsvF(maxH, maxS, maxV);
263 d->minKoColor.fromQColor(minQ);
264 d->maxKoColor.fromQColor(maxQ);
265 d->upToDate = false;
266
267 d->updateCompressor.start();
268}

References d.

◆ setMixMode()

void KisHsvColorSlider::setMixMode ( MIX_MODE mode)

Definition at line 276 of file KisHsvColorSlider.cpp.

276 {
277 d->mixMode = mode;
278 d->upToDate = false;
279 d->updateCompressor.start();
280}

References d.

Member Data Documentation

◆ circularHue

bool KisHsvColorSlider::circularHue

Definition at line 213 of file KisHsvColorSlider.cpp.

◆ d

Private* const KisHsvColorSlider::d
protected

Definition at line 44 of file KisHsvColorSlider.h.

◆ displayRenderer

QPointer<KoColorDisplayRendererInterface> KisHsvColorSlider::displayRenderer

Definition at line 209 of file KisHsvColorSlider.cpp.

◆ maxColor

HSVColor KisHsvColorSlider::maxColor

Definition at line 204 of file KisHsvColorSlider.cpp.

◆ maxKoColor

KoColor KisHsvColorSlider::maxKoColor

Definition at line 206 of file KisHsvColorSlider.cpp.

◆ minColor

HSVColor KisHsvColorSlider::minColor

Definition at line 203 of file KisHsvColorSlider.cpp.

◆ minKoColor

KoColor KisHsvColorSlider::minKoColor

Definition at line 205 of file KisHsvColorSlider.cpp.

◆ mixMode

MIX_MODE KisHsvColorSlider::mixMode

Definition at line 214 of file KisHsvColorSlider.cpp.

◆ pixmap

QPixmap KisHsvColorSlider::pixmap

Definition at line 207 of file KisHsvColorSlider.cpp.

◆ updateCompressor

KisSignalCompressor KisHsvColorSlider::updateCompressor

Definition at line 210 of file KisHsvColorSlider.cpp.

◆ upToDate

bool KisHsvColorSlider::upToDate

Definition at line 208 of file KisHsvColorSlider.cpp.


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