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

This is a threshold slider that only has one handle. More...

#include <KisLevelsSlider.h>

+ Inheritance diagram for KisThresholdSlider:

Public Slots

void reset (qreal newBlackPoint, qreal newWhitePoint) override
 
void setBlackPoint (qreal newBlackPoint) override
 Sets the black point. For this slider the black and the white points are always in the same position, so changing the black point will also change the white point and vice-versa.
 
void setHandlePosition (int handleIndex, qreal newPosition) override
 Sets the black point. For this slider the black and the white points are always in the same position, so changing the black point will also change the white point and vice-versa.
 
void setThreshold (qreal newGamma)
 Sets the gamma value.
 
void setWhitePoint (qreal newWhitePoint) override
 Sets the white point. For this slider the black and the white points are always in the same position, so changing the black point will also change the white point and vice-versa.
 
- Public Slots inherited from KisInputLevelsSlider
virtual void reset (qreal newBlackPoint, qreal newWhitePoint)
 Sometimes you want to set the range to a totally different place, but the new black point can be greater than the old white point so the new black point position will be constrained to the old white position. This function allows to set both values at once to prevent that undesirable effect. Use it when the widget has to show new values, for a different set of levels parameters for example.
 
virtual void setBlackPoint (qreal newBlackPoint)
 Sets the black point.
 
virtual void setWhitePoint (qreal newWhitePoint)
 Sets the white point.
 
- Public Slots inherited from KisLevelsSlider
virtual void setHandleColor (int handleIndex, const QColor &newColor)
 Sets the color associated with the given handle.
 
virtual void setHandlePosition (int handleIndex, qreal newPosition)
 Sets the normalized position of the given handle.
 

Signals

void thresholdChanged (qreal newThreshold)
 Signal emitted when the threshold value changes.
 
- Signals inherited from KisInputLevelsSlider
void blackPointChanged (qreal newBlackPoint)
 Signal emitted when the black point changes.
 
void whitePointChanged (qreal newWhitePoint)
 Signal emitted when the white point changes.
 
- Signals inherited from KisLevelsSlider
void handleColorChanged (int handleIndex, const QColor &color)
 Signal emitted when the color associated with a handle changes.
 
void handlePositionChanged (int handleIndex, qreal position)
 Signal emitted when the position of a handle changes.
 

Public Member Functions

 KisThresholdSlider (QWidget *parent=nullptr)
 
qreal threshold () const
 Get the gamma value.
 
 ~KisThresholdSlider ()
 
- Public Member Functions inherited from KisInputLevelsSlider
qreal blackPoint () const
 Get the normalized black point.
 
 KisInputLevelsSlider (QWidget *parent=nullptr)
 
qreal whitePoint () const
 Get the normalized white point.
 
 ~KisInputLevelsSlider ()
 
- Public Member Functions inherited from KisLevelsSlider
virtual QRect gradientRect () const
 Gets the rect where the gradient will be painted.
 
QColor handleColor (int handleIndex) const
 Gets the color associated with a given handle.
 
qreal handlePosition (int handleIndex) const
 Gets the normalized position of a given handle.
 
 KisLevelsSlider (QWidget *parent)
 
QSize minimumSizeHint () const override
 
QSize sizeHint () const override
 
 ~KisLevelsSlider ()
 

Protected Member Functions

void paintBottomGradientMiddleSection (QImage &gradientImage, const QVector< Handle > &sortedHandles_) override
 This is used to fill the space between the tho handles in the bottom bar of the "gradient". It just paints a linear gradient that goes from black (first handle's color) to white (last handle's color). Derived classes can override this function if they only want to change that area. "gradientImage" is a 256x1px image.
 
void paintHandle (QPainter &painter, const QRect &rect, const Handle &handle) override
 Override this function to paint custom handles.
 
- Protected Member Functions inherited from KisInputLevelsSlider
void paintGradient (QPainter &painter, const QRect &rect) override
 Custom gradient painter. This paints two bars in the gradient rect, one on top of the other. The top one shows a simple black to white (more exactly, color of the first handle to color of the last handle) linear gradient. The bottom one shows black (first handle's color) from the right side of the rect to the black point, and white (last handle's color) from the white point to the left side of the rect. In the middle of the two handles, the "paintBottomGradientMiddleSection" is used to fill the bar.
 
- Protected Member Functions inherited from KisLevelsSlider
int closestHandleToPosition (qreal position) const
 Given a normalized position, this function returns the closest handle to that position.
 
int closestHandleToX (int x) const
 Given a widget-relative x position, this function returns the closest handle to that position.
 
void handleIncrementInput (int direction, Qt::KeyboardModifiers modifiers)
 
void keyPressEvent (QKeyEvent *e) override
 
void leaveEvent (QEvent *e) override
 
void mouseMoveEvent (QMouseEvent *e) override
 
void mousePressEvent (QMouseEvent *e) override
 
void paintEvent (QPaintEvent *e) override
 
qreal positionFromX (int x) const
 Given a widget-relative x position in pixels, this function returns the normalized position relative to the gradient rect.
 
QVector< HandlesortedHandles () const
 Regardless the index of a handle, they can be unordered in terms of the position. This returns a sorted vector with the handles that have a smaller position first. If two handles have the same position then the index is used for sorting.
 
void wheelEvent (QWheelEvent *e) override
 
int xFromPosition (qreal position) const
 Given a gradient rect relative position, this function returns the x position in pixels relative to the widget.
 

Additional Inherited Members

- Protected Attributes inherited from KisLevelsSlider
int m_constrainPositions
 This variable indicates if the handles can have unordered positions. If it is set to true then the user won't be able to move a handle pass another one. If it is set to false then the ser will be able to move the handles freely.
 
QVector< Handlem_handles
 The collection of handles.
 
int m_hoveredHandle
 
int m_selectedHandle
 
- Static Protected Attributes inherited from KisLevelsSlider
static constexpr int handleHeight {11}
 
static constexpr int handleWidth {11}
 
static constexpr qreal minimumSpaceBetweenHandles {0.001}
 
static constexpr qreal normalPositionIncrement {0.01}
 
static constexpr qreal slowPositionIncrement {0.001}
 

Detailed Description

This is a threshold slider that only has one handle.

Definition at line 280 of file KisLevelsSlider.h.

Constructor & Destructor Documentation

◆ KisThresholdSlider()

KisThresholdSlider::KisThresholdSlider ( QWidget * parent = nullptr)

Definition at line 596 of file KisLevelsSlider.cpp.

597 : KisInputLevelsSlider(parent)
598{
599 m_constrainPositions = false;
600}
KisInputLevelsSlider(QWidget *parent=nullptr)
int m_constrainPositions
This variable indicates if the handles can have unordered positions. If it is set to true then the us...

References KisLevelsSlider::m_constrainPositions.

◆ ~KisThresholdSlider()

KisThresholdSlider::~KisThresholdSlider ( )

Definition at line 602 of file KisLevelsSlider.cpp.

603{}

Member Function Documentation

◆ paintBottomGradientMiddleSection()

void KisThresholdSlider::paintBottomGradientMiddleSection ( QImage & gradientImage,
const QVector< Handle > & sortedHandles_ )
overrideprotectedvirtual

This is used to fill the space between the tho handles in the bottom bar of the "gradient". It just paints a linear gradient that goes from black (first handle's color) to white (last handle's color). Derived classes can override this function if they only want to change that area. "gradientImage" is a 256x1px image.

Reimplemented from KisInputLevelsSlider.

Definition at line 648 of file KisLevelsSlider.cpp.

649{}

◆ paintHandle()

void KisThresholdSlider::paintHandle ( QPainter & painter,
const QRect & rect,
const Handle & handle )
overrideprotectedvirtual

Override this function to paint custom handles.

Reimplemented from KisLevelsSlider.

Definition at line 651 of file KisLevelsSlider.cpp.

652{
653 if (handle.index != m_handles.first().index) {
654 return;
655 }
656 if (m_hoveredHandle >= 0) {
657 m_hoveredHandle = 0;
658 }
659 if (m_selectedHandle >= 0) {
661 }
662 KisLevelsSlider::paintHandle(painter, rect, handle);
663}
virtual void paintHandle(QPainter &painter, const QRect &rect, const Handle &handle)
Override this function to paint custom handles.
QVector< Handle > m_handles
The collection of handles.

References KisLevelsSlider::Handle::index, KisLevelsSlider::m_handles, KisLevelsSlider::m_hoveredHandle, KisLevelsSlider::m_selectedHandle, and KisLevelsSlider::paintHandle().

◆ reset

void KisThresholdSlider::reset ( qreal newBlackPoint,
qreal newWhitePoint )
overrideslot

Definition at line 626 of file KisLevelsSlider.cpp.

627{
628 Q_UNUSED(newWhitePoint);
629
630 newBlackPoint = qBound(0.0, newBlackPoint, 1.0);
631 if (newBlackPoint == blackPoint()) {
632 return;
633 }
634 m_handles.first().position = m_handles.last().position = newBlackPoint;
635 update();
636 Q_EMIT handlePositionChanged(0, newBlackPoint);
637 Q_EMIT blackPointChanged(newBlackPoint);
638 Q_EMIT handlePositionChanged(1, newBlackPoint);
639 Q_EMIT whitePointChanged(newBlackPoint);
640 Q_EMIT thresholdChanged(newBlackPoint);
641}
void blackPointChanged(qreal newBlackPoint)
Signal emitted when the black point changes.
void whitePointChanged(qreal newWhitePoint)
Signal emitted when the white point changes.
qreal blackPoint() const
Get the normalized black point.
void handlePositionChanged(int handleIndex, qreal position)
Signal emitted when the position of a handle changes.
void thresholdChanged(qreal newThreshold)
Signal emitted when the threshold value changes.
bool update(QSpinBox *spinBox)

References KisInputLevelsSlider::blackPoint(), KisInputLevelsSlider::blackPointChanged(), KisLevelsSlider::handlePositionChanged(), KisLevelsSlider::m_handles, thresholdChanged(), and KisInputLevelsSlider::whitePointChanged().

◆ setBlackPoint

void KisThresholdSlider::setBlackPoint ( qreal newBlackPoint)
overrideslot

Sets the black point. For this slider the black and the white points are always in the same position, so changing the black point will also change the white point and vice-versa.

Definition at line 616 of file KisLevelsSlider.cpp.

617{
618 reset(newBlackPoint, newBlackPoint);
619}
void reset(qreal newBlackPoint, qreal newWhitePoint) override

References reset().

◆ setHandlePosition

void KisThresholdSlider::setHandlePosition ( int handleIndex,
qreal newPosition )
overrideslot

Sets the black point. For this slider the black and the white points are always in the same position, so changing the black point will also change the white point and vice-versa.

Definition at line 610 of file KisLevelsSlider.cpp.

611{
612 Q_ASSERT(handleIndex >= 0 && handleIndex < m_handles.size());
613 reset(newPosition, newPosition);
614}

References KisLevelsSlider::m_handles, and reset().

◆ setThreshold

void KisThresholdSlider::setThreshold ( qreal newGamma)
slot

Sets the gamma value.

Definition at line 643 of file KisLevelsSlider.cpp.

644{
645 reset(newThreshold, newThreshold);
646}

References reset().

◆ setWhitePoint

void KisThresholdSlider::setWhitePoint ( qreal newWhitePoint)
overrideslot

Sets the white point. For this slider the black and the white points are always in the same position, so changing the black point will also change the white point and vice-versa.

Definition at line 621 of file KisLevelsSlider.cpp.

622{
623 reset(newWhitePoint, newWhitePoint);
624}

References reset().

◆ threshold()

qreal KisThresholdSlider::threshold ( ) const

Get the gamma value.

Definition at line 605 of file KisLevelsSlider.cpp.

606{
607 return blackPoint();
608}

References KisInputLevelsSlider::blackPoint().

◆ thresholdChanged

void KisThresholdSlider::thresholdChanged ( qreal newThreshold)
signal

Signal emitted when the threshold value changes.


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