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

Write API docs here. More...

#include <KoSegmentGradient.h>

Classes

class  ColorInterpolationStrategy
 
class  CurvedInterpolationStrategy
 
class  HSVCCWColorInterpolationStrategy
 
class  HSVCWColorInterpolationStrategy
 
class  InterpolationStrategy
 
class  LinearInterpolationStrategy
 
class  RGBColorInterpolationStrategy
 
class  SineInterpolationStrategy
 
class  SphereDecreasingInterpolationStrategy
 
class  SphereIncreasingInterpolationStrategy
 

Public Member Functions

void colorAt (KoColor &, qreal t) const
 
int colorInterpolation () const
 
const KoColorendColor () const
 
qreal endOffset () const
 
KoGradientSegmentEndpointType endType () const
 
bool hasVariableColors ()
 
int interpolation () const
 
bool isValid () const
 
 KoGradientSegment (int interpolationType, int colorInterpolationType, KoGradientSegmentEndpoint start, KoGradientSegmentEndpoint end, qreal middleOffset)
 
qreal length ()
 
qreal middleOffset () const
 
void mirrorSegment ()
 
void setColorInterpolation (int colorInterpolationType)
 
void setEndColor (const KoColor &color)
 
void setEndOffset (qreal t)
 
void setEndType (KoGradientSegmentEndpointType type)
 
void setInterpolation (int interpolationType)
 
void setMiddleOffset (qreal t)
 
void setStartColor (const KoColor &color)
 
void setStartOffset (qreal t)
 
void setStartType (KoGradientSegmentEndpointType type)
 
void setVariableColors (const KoColor &foreground, const KoColor &background)
 
const KoColorstartColor () const
 
qreal startOffset () const
 
KoGradientSegmentEndpointType startType () const
 

Private Attributes

ColorInterpolationStrategym_colorInterpolator
 
KoGradientSegmentEndpoint m_end
 
bool m_hasVariableColors = false
 
InterpolationStrategym_interpolator
 
qreal m_length
 
qreal m_middleOffset
 
qreal m_middleT
 
KoGradientSegmentEndpoint m_start
 

Detailed Description

Write API docs here.

Definition at line 62 of file KoSegmentGradient.h.

Constructor & Destructor Documentation

◆ KoGradientSegment()

KoGradientSegment::KoGradientSegment ( int interpolationType,
int colorInterpolationType,
KoGradientSegmentEndpoint start,
KoGradientSegmentEndpoint end,
qreal middleOffset )

Definition at line 316 of file KoSegmentGradient.cpp.

317 : m_start(start), m_end(end)
318{
319 m_interpolator = 0;
320
321 switch (interpolationType) {
322 case INTERP_LINEAR:
324 break;
325 case INTERP_CURVED:
327 break;
328 case INTERP_SINE:
330 break;
333 break;
336 break;
337 }
338
340
341 switch (colorInterpolationType) {
342 case COLOR_INTERP_RGB:
344 break;
347 break;
350 break;
351 }
352
353
354
355 if (m_start.offset < DBL_EPSILON) {
356 m_start.offset = 0;
357 } else if (m_start.offset > 1 - DBL_EPSILON) {
358 m_start.offset = 1;
359 }
360
361 if (middleOffset < m_start.offset + DBL_EPSILON) {
363 } else if (middleOffset > 1 - DBL_EPSILON) {
364 m_middleOffset = 1;
365 } else {
367 }
368
369 if (m_end.offset < m_middleOffset + DBL_EPSILON) {
371 } else if (m_end.offset > 1 - DBL_EPSILON) {
372 m_end.offset = 1;
373 }
374
376
377 if (m_length < DBL_EPSILON) {
378 m_middleT = 0.5;
379 } else {
381 }
382
384
385}
@ COLOR_ENDPOINT
@ INTERP_SPHERE_DECREASING
@ INTERP_LINEAR
@ INTERP_CURVED
@ INTERP_SINE
@ INTERP_SPHERE_INCREASING
@ COLOR_INTERP_RGB
@ COLOR_INTERP_HSV_CCW
@ COLOR_INTERP_HSV_CW
static CurvedInterpolationStrategy * instance()
static HSVCCWColorInterpolationStrategy * instance()
static HSVCWColorInterpolationStrategy * instance()
static LinearInterpolationStrategy * instance()
static RGBColorInterpolationStrategy * instance()
static SineInterpolationStrategy * instance()
static SphereDecreasingInterpolationStrategy * instance()
static SphereIncreasingInterpolationStrategy * instance()
ColorInterpolationStrategy * m_colorInterpolator
InterpolationStrategy * m_interpolator
KoGradientSegmentEndpoint m_end
KoGradientSegmentEndpoint m_start
KoGradientSegmentEndpointType type

References COLOR_ENDPOINT, COLOR_INTERP_HSV_CCW, COLOR_INTERP_HSV_CW, COLOR_INTERP_RGB, KoGradientSegment::RGBColorInterpolationStrategy::instance(), KoGradientSegment::HSVCWColorInterpolationStrategy::instance(), KoGradientSegment::HSVCCWColorInterpolationStrategy::instance(), KoGradientSegment::LinearInterpolationStrategy::instance(), KoGradientSegment::CurvedInterpolationStrategy::instance(), KoGradientSegment::SphereIncreasingInterpolationStrategy::instance(), KoGradientSegment::SphereDecreasingInterpolationStrategy::instance(), KoGradientSegment::SineInterpolationStrategy::instance(), INTERP_CURVED, INTERP_LINEAR, INTERP_SINE, INTERP_SPHERE_DECREASING, INTERP_SPHERE_INCREASING, m_colorInterpolator, m_end, m_hasVariableColors, m_interpolator, m_length, m_middleOffset, m_middleT, m_start, middleOffset(), KoGradientSegmentEndpoint::offset, and KoGradientSegmentEndpoint::type.

Member Function Documentation

◆ colorAt()

void KoGradientSegment::colorAt ( KoColor & dst,
qreal t ) const

Definition at line 566 of file KoSegmentGradient.cpp.

567{
568 Q_ASSERT(t > m_start.offset - DBL_EPSILON && t < m_end.offset + DBL_EPSILON);
569
570 qreal segmentT;
571
572 if (m_length < DBL_EPSILON) {
573 segmentT = 0.5;
574 } else {
575 segmentT = qBound(0.0, (t - m_start.offset) / m_length, 1.0);
576 }
577
578 qreal colorT = m_interpolator->valueAt(segmentT, m_middleT);
579
581
582}
virtual void colorAt(KoColor &dst, qreal t, const KoColor &start, const KoColor &end) const =0
virtual qreal valueAt(qreal t, qreal middle) const =0

References KoGradientSegmentEndpoint::color, KoGradientSegment::ColorInterpolationStrategy::colorAt(), m_colorInterpolator, m_end, m_interpolator, m_length, m_middleT, m_start, KoGradientSegmentEndpoint::offset, and KoGradientSegment::InterpolationStrategy::valueAt().

◆ colorInterpolation()

int KoGradientSegment::colorInterpolation ( ) const

◆ endColor()

const KoColor & KoGradientSegment::endColor ( ) const

Definition at line 392 of file KoSegmentGradient.cpp.

393{
394 return m_end.color;
395}

References KoGradientSegmentEndpoint::color, and m_end.

◆ endOffset()

qreal KoGradientSegment::endOffset ( ) const

Definition at line 407 of file KoSegmentGradient.cpp.

408{
409 return m_end.offset;
410}

References m_end, and KoGradientSegmentEndpoint::offset.

◆ endType()

KoGradientSegmentEndpointType KoGradientSegment::endType ( ) const

Definition at line 417 of file KoSegmentGradient.cpp.

418{
419 return m_end.type;
420}

References m_end, and KoGradientSegmentEndpoint::type.

◆ hasVariableColors()

bool KoGradientSegment::hasVariableColors ( )

Definition at line 516 of file KoSegmentGradient.cpp.

516 {
517 return m_hasVariableColors;
518}

References m_hasVariableColors.

◆ interpolation()

int KoGradientSegment::interpolation ( ) const

Definition at line 520 of file KoSegmentGradient.cpp.

521{
522 return m_interpolator->type();
523}

References m_interpolator, and KoGradientSegment::InterpolationStrategy::type().

◆ isValid()

bool KoGradientSegment::isValid ( ) const

Definition at line 609 of file KoSegmentGradient.cpp.

610{
611 if (m_interpolator == 0 || m_colorInterpolator == 0)
612 return false;
613 return true;
614}

References m_colorInterpolator, and m_interpolator.

◆ length()

qreal KoGradientSegment::length ( )
inline

Definition at line 106 of file KoSegmentGradient.h.

106 {
107 return m_length;
108 }

◆ middleOffset()

qreal KoGradientSegment::middleOffset ( ) const

Definition at line 402 of file KoSegmentGradient.cpp.

403{
404 return m_middleOffset;
405}

References m_middleOffset.

◆ mirrorSegment()

void KoGradientSegment::mirrorSegment ( )

Definition at line 584 of file KoSegmentGradient.cpp.

585{
586 KoColor tmpColor = startColor();
588 setEndColor(tmpColor);
591 setEndType(tmpType);
592
594
597 }
600 }
603 }
606 }
607}
KoGradientSegmentEndpointType
void setEndType(KoGradientSegmentEndpointType type)
void setInterpolation(int interpolationType)
void setMiddleOffset(qreal t)
KoGradientSegmentEndpointType endType() const
void setColorInterpolation(int colorInterpolationType)
KoGradientSegmentEndpointType startType() const
void setStartColor(const KoColor &color)
void setStartType(KoGradientSegmentEndpointType type)
void setEndColor(const KoColor &color)
const KoColor & startColor() const
const KoColor & endColor() const

References COLOR_INTERP_HSV_CCW, COLOR_INTERP_HSV_CW, colorInterpolation(), endColor(), endOffset(), endType(), INTERP_SPHERE_DECREASING, INTERP_SPHERE_INCREASING, interpolation(), middleOffset(), setColorInterpolation(), setEndColor(), setEndType(), setInterpolation(), setMiddleOffset(), setStartColor(), setStartType(), startColor(), startOffset(), and startType().

◆ setColorInterpolation()

◆ setEndColor()

void KoGradientSegment::setEndColor ( const KoColor & color)
inline

Definition at line 83 of file KoSegmentGradient.h.

83 {
84 m_end.color = color;
86 m_end.color.setOpacity(quint8(0));
88 m_end.color.setOpacity(quint8(255));
89 }
90 }
@ BACKGROUND_TRANSPARENT_ENDPOINT
@ FOREGROUND_ENDPOINT
@ BACKGROUND_ENDPOINT
@ FOREGROUND_TRANSPARENT_ENDPOINT
void setOpacity(quint8 alpha)
Definition KoColor.cpp:333

References BACKGROUND_ENDPOINT, BACKGROUND_TRANSPARENT_ENDPOINT, FOREGROUND_ENDPOINT, FOREGROUND_TRANSPARENT_ENDPOINT, and KoColor::setOpacity().

◆ setEndOffset()

void KoGradientSegment::setEndOffset ( qreal t)

Definition at line 464 of file KoSegmentGradient.cpp.

465{
466 m_end.offset = t;
468
469 if (m_length < DBL_EPSILON) {
470 m_middleT = 0.5;
471 } else {
473 }
474}

References m_end, m_length, m_middleOffset, m_middleT, m_start, and KoGradientSegmentEndpoint::offset.

◆ setEndType()

void KoGradientSegment::setEndType ( KoGradientSegmentEndpointType type)

Definition at line 432 of file KoSegmentGradient.cpp.

432 {
433 m_end.type = type;
434 if (type != COLOR_ENDPOINT) {
435 m_hasVariableColors = true;
436 }
437 else if (m_start.type == COLOR_ENDPOINT) {
438 m_hasVariableColors = false;
439 }
440}

References COLOR_ENDPOINT, m_end, m_hasVariableColors, m_start, and KoGradientSegmentEndpoint::type.

◆ setInterpolation()

◆ setMiddleOffset()

void KoGradientSegment::setMiddleOffset ( qreal t)

Definition at line 453 of file KoSegmentGradient.cpp.

454{
455 m_middleOffset = t;
456
457 if (m_length < DBL_EPSILON) {
458 m_middleT = 0.5;
459 } else {
461 }
462}

References m_length, m_middleOffset, m_middleT, m_start, and KoGradientSegmentEndpoint::offset.

◆ setStartColor()

void KoGradientSegment::setStartColor ( const KoColor & color)
inline

◆ setStartOffset()

void KoGradientSegment::setStartOffset ( qreal t)

Definition at line 442 of file KoSegmentGradient.cpp.

443{
444 m_start.offset = t;
446
447 if (m_length < DBL_EPSILON) {
448 m_middleT = 0.5;
449 } else {
451 }
452}

References m_end, m_length, m_middleOffset, m_middleT, m_start, and KoGradientSegmentEndpoint::offset.

◆ setStartType()

void KoGradientSegment::setStartType ( KoGradientSegmentEndpointType type)

Definition at line 422 of file KoSegmentGradient.cpp.

422 {
423 m_start.type = type;
424 if (type != COLOR_ENDPOINT) {
425 m_hasVariableColors = true;
426 }
427 else if (m_end.type == COLOR_ENDPOINT) {
428 m_hasVariableColors = false;
429 }
430}

References COLOR_ENDPOINT, m_end, m_hasVariableColors, m_start, and KoGradientSegmentEndpoint::type.

◆ setVariableColors()

void KoGradientSegment::setVariableColors ( const KoColor & foreground,
const KoColor & background )

Definition at line 476 of file KoSegmentGradient.cpp.

476 {
477 switch (m_start.type) {
478 case COLOR_ENDPOINT:
479 break;
481 m_start.color = foreground;
482 break;
483 case FOREGROUND_TRANSPARENT_ENDPOINT: //TODO: add Transparent options to gradient editor...
484 m_start.color = foreground;
485 m_start.color.setOpacity(quint8(0));
486 break;
488 m_start.color = background;
489 break;
491 m_start.color = background;
492 m_start.color.setOpacity(quint8(0));
493 break;
494 }
495
496 switch (m_end.type) {
497 case COLOR_ENDPOINT:
498 break;
500 m_end.color = foreground;
501 break;
503 m_end.color = foreground;
504 m_end.color.setOpacity(quint8(0));
505 break;
507 m_end.color = background;
508 break;
510 m_end.color = background;
511 m_end.color.setOpacity(quint8(0));
512 break;
513 }
514}

References BACKGROUND_ENDPOINT, BACKGROUND_TRANSPARENT_ENDPOINT, KoGradientSegmentEndpoint::color, COLOR_ENDPOINT, FOREGROUND_ENDPOINT, FOREGROUND_TRANSPARENT_ENDPOINT, m_end, m_start, KoColor::setOpacity(), and KoGradientSegmentEndpoint::type.

◆ startColor()

const KoColor & KoGradientSegment::startColor ( ) const

Definition at line 387 of file KoSegmentGradient.cpp.

388{
389 return m_start.color;
390}

References KoGradientSegmentEndpoint::color, and m_start.

◆ startOffset()

qreal KoGradientSegment::startOffset ( ) const

Definition at line 397 of file KoSegmentGradient.cpp.

398{
399 return m_start.offset;
400}

References m_start, and KoGradientSegmentEndpoint::offset.

◆ startType()

KoGradientSegmentEndpointType KoGradientSegment::startType ( ) const

Definition at line 412 of file KoSegmentGradient.cpp.

413{
414 return m_start.type;
415}

References m_start, and KoGradientSegmentEndpoint::type.

Member Data Documentation

◆ m_colorInterpolator

ColorInterpolationStrategy* KoGradientSegment::m_colorInterpolator
private

Definition at line 274 of file KoSegmentGradient.h.

◆ m_end

KoGradientSegmentEndpoint KoGradientSegment::m_end
private

Definition at line 280 of file KoSegmentGradient.h.

◆ m_hasVariableColors

bool KoGradientSegment::m_hasVariableColors = false
private

Definition at line 281 of file KoSegmentGradient.h.

◆ m_interpolator

InterpolationStrategy* KoGradientSegment::m_interpolator
private

Definition at line 273 of file KoSegmentGradient.h.

◆ m_length

qreal KoGradientSegment::m_length
private

Definition at line 277 of file KoSegmentGradient.h.

◆ m_middleOffset

qreal KoGradientSegment::m_middleOffset
private

Definition at line 276 of file KoSegmentGradient.h.

◆ m_middleT

qreal KoGradientSegment::m_middleT
private

Definition at line 278 of file KoSegmentGradient.h.

◆ m_start

KoGradientSegmentEndpoint KoGradientSegment::m_start
private

Definition at line 280 of file KoSegmentGradient.h.


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