Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP > Class Template Reference

#include <kis_slider_spin_box_p.h>

+ Inheritance diagram for KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >:

Public Types

using BaseSpinBoxType = BaseSpinBoxTypeTP
 
using SpinBoxType = SpinBoxTypeTP
 
using ValueType = decltype(std::declval<SpinBoxType>().value())
 
enum  ValueUpdateMode { ValueUpdateMode_NoChange , ValueUpdateMode_UseLastValidValue , ValueUpdateMode_UseValueBeforeEditing }
 

Public Member Functions

double computeSliderWidth (double min, double max, double value) const
 
void emitSignals () const
 
void endEditing (ValueUpdateMode updateMode=ValueUpdateMode_UseLastValidValue)
 
bool eventFilter (QObject *o, QEvent *e) override
 
ValueType fastSliderStep () const
 
bool isDragging () const
 
bool isEditModeActive () const
 
bool isSoftRangeValid () const
 
 KisSliderSpinBoxPrivate (SpinBoxType *q)
 
bool lineEditMouseMoveEvent (QMouseEvent *e)
 
bool lineEditMousePressEvent (QMouseEvent *e, bool edit)
 
bool lineEditMouseReleaseEvent (QMouseEvent *e)
 
bool lineEditPaintEvent (QPaintEvent *)
 
void makeHardRangeActive ()
 
void makeSoftRangeActive ()
 
QSize minimumSizeHint () const
 
void paintGenericSliderText (QPainter &painter, const QString &text, const QRectF &rect, const QRectF &sliderRect)
 
void paintSlider (QPainter &painter, const QString &text, double slider01Width, double slider02Width=-1.0)
 
void paintSliderRect (QPainter &painter, const QRectF &rect, const QBrush &brush)
 
void paintSliderText (QPainter &painter, const QString &text, const QRectF &rect, const QRectF &clipRect, const QColor &color, const QTextOption &textOption)
 
QPoint pointForValue (ValueType value) const
 
bool qContextMenuEvent (QContextMenuEvent *e)
 
bool qFocusOutEvent (QFocusEvent *)
 
bool qKeyPressEvent (QKeyEvent *e)
 
bool qMousePressEvent (QMouseEvent *)
 
bool qResizeEvent (QResizeEvent *)
 
void resetRangeMode ()
 
void setBlockUpdateSignalOnDrag (bool newBlockUpdateSignalOnDrag)
 
void setExponentRatio (double newExponentRatio)
 
void setFastSliderStep (ValueType newFastSliderStep)
 
template<typename U = SpinBoxTypeTP, typename = typename std::enable_if<std::is_same<ValueType, double>::value, U>::type>
void setRange (double newMinimum, double newMaximum, int newNumberOfDecimals, bool computeNewFastSliderStep)
 
template<typename U = SpinBoxTypeTP, typename = typename std::enable_if<std::is_same<ValueType, int>::value, U>::type>
void setRange (int newMinimum, int newMaximum, bool computeNewFastSliderStep)
 
void setSoftRange (ValueType newSoftMinimum, ValueType newSoftMaximum)
 
void setValue (ValueType newValue, bool blockSignals=false, bool emitSignalsEvenWhenValueNotChanged=false, bool overwriteExpression=false)
 
QSize sizeHint () const
 
ValueType softMaximum () const
 
ValueType softMinimum () const
 
void startEditing ()
 
void updateWidgetRangeToggleTooltip ()
 
ValueType valueForPoint (const QPoint &p, Qt::KeyboardModifiers modifiers) const
 
bool widgetRangeToggleEnterEvent (QEvent *)
 
bool widgetRangeToggleLeaveEvent (QEvent *)
 
bool widgetRangeToggleMouseReleaseEvent (QMouseEvent *e)
 
bool widgetRangeTogglePaintEvent (QPaintEvent *)
 

Private Types

enum  SoftRangeViewMode { SoftRangeViewMode_AlwaysShowSoftRange , SoftRangeViewMode_ShowBothRanges }
 

Private Attributes

bool m_blockUpdateSignalOnDrag {false}
 
double m_exponentRatio {1.0}
 
ValueType m_fastSliderStep {static_cast<ValueType>(5)}
 
bool m_focusLostDueToMenu {false}
 
bool m_isDragging {false}
 
bool m_isSoftRangeActive {true}
 
QPoint m_lastMousePressPosition
 
QLineEdit * m_lineEdit {nullptr}
 
SpinBoxTypem_q {nullptr}
 
QVariantAnimation m_rangeToggleHoverAnimation
 
int m_relativeDraggingOffset {0}
 
int m_rightClickCounter {0}
 
QVariantAnimation m_sliderAnimation
 
ValueType m_softMaximum {static_cast<ValueType>(0)}
 
ValueType m_softMinimum {static_cast<ValueType>(0)}
 
SignalToFunctionProxy m_startEditingSignalProxy
 
bool m_useRelativeDragging {false}
 
ValueType m_valueBeforeEditing {static_cast<ValueType>(0)}
 
QWidget * m_widgetRangeToggle {nullptr}
 
enum KisSliderSpinBoxPrivate::SoftRangeViewMode SoftRangeViewMode_ShowBothRanges
 

Static Private Attributes

static constexpr double constantDraggingMargin {32.0}
 
static constexpr double fullAnimationDuration {200.0}
 
static constexpr double heightOfCollapsedSlider {3.0}
 
static constexpr double heightOfSpaceBetweenSliders {0.0}
 
static constexpr double widthOfRangeModeToggle {16.0}
 

Detailed Description

template<typename SpinBoxTypeTP, typename BaseSpinBoxTypeTP>
class KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >

Definition at line 43 of file kis_slider_spin_box_p.h.

Member Typedef Documentation

◆ BaseSpinBoxType

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
using KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::BaseSpinBoxType = BaseSpinBoxTypeTP

Definition at line 47 of file kis_slider_spin_box_p.h.

◆ SpinBoxType

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
using KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::SpinBoxType = SpinBoxTypeTP

Definition at line 46 of file kis_slider_spin_box_p.h.

◆ ValueType

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
using KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::ValueType = decltype(std::declval<SpinBoxType>().value())

Definition at line 48 of file kis_slider_spin_box_p.h.

Member Enumeration Documentation

◆ SoftRangeViewMode

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
enum KisSliderSpinBoxPrivate::SoftRangeViewMode
private
Enumerator
SoftRangeViewMode_AlwaysShowSoftRange 
SoftRangeViewMode_ShowBothRanges 

Definition at line 936 of file kis_slider_spin_box_p.h.

937 {
940 } m_softRangeViewMode{SoftRangeViewMode_ShowBothRanges};
enum KisSliderSpinBoxPrivate::SoftRangeViewMode SoftRangeViewMode_ShowBothRanges

◆ ValueUpdateMode

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
enum KisSliderSpinBoxPrivate::ValueUpdateMode
Enumerator
ValueUpdateMode_NoChange 
ValueUpdateMode_UseLastValidValue 
ValueUpdateMode_UseValueBeforeEditing 

Definition at line 50 of file kis_slider_spin_box_p.h.

Constructor & Destructor Documentation

◆ KisSliderSpinBoxPrivate()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::KisSliderSpinBoxPrivate ( SpinBoxType * q)
inline

Definition at line 57 of file kis_slider_spin_box_p.h.

58 : m_q(q)
59 , m_lineEdit(m_q->lineEdit())
61 {
62 m_q->installEventFilter(this);
63
64 m_lineEdit->setReadOnly(true);
65 m_lineEdit->setAlignment(Qt::AlignCenter);
66 m_lineEdit->setAutoFillBackground(false);
68 m_lineEdit->installEventFilter(this);
69
70 m_widgetRangeToggle = new QWidget(m_q);
71 m_widgetRangeToggle->hide();
72 m_widgetRangeToggle->installEventFilter(this);
73
74 m_sliderAnimation.setStartValue(0.0);
75 m_sliderAnimation.setEndValue(1.0);
76 m_sliderAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
77 connect(&m_sliderAnimation, &QVariantAnimation::valueChanged, m_lineEdit, QOverload<>::of(&QLineEdit::update));
78 connect(&m_sliderAnimation, &QVariantAnimation::valueChanged, m_widgetRangeToggle, QOverload<>::of(&QLineEdit::update));
79
80 m_rangeToggleHoverAnimation.setStartValue(0.0);
81 m_rangeToggleHoverAnimation.setEndValue(1.0);
82 m_rangeToggleHoverAnimation.setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
83 connect(&m_rangeToggleHoverAnimation, &QVariantAnimation::valueChanged, m_widgetRangeToggle, QOverload<>::of(&QLineEdit::update));
84 }
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static QCursor splitHCursor()
Definition kis_cursor.cc:99
QVariantAnimation m_sliderAnimation
QVariantAnimation m_rangeToggleHoverAnimation
SignalToFunctionProxy m_startEditingSignalProxy

References connect(), and KisCursor::splitHCursor().

Member Function Documentation

◆ computeSliderWidth()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
double KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::computeSliderWidth ( double min,
double max,
double value ) const
inline

Definition at line 664 of file kis_slider_spin_box_p.h.

665 {
666 const double rangeSize = max - min;
667 const double localPosition = value - min;
668 const double normalizedValue = std::pow(localPosition / rangeSize, 1.0 / m_exponentRatio);
669 const double width = static_cast<double>(m_lineEdit->width());
670 return qBound(0.0, std::round(normalizedValue * width), width);
671 }
float value(const T *src, size_t ch)
T min(T a, T b, T c)
constexpr std::enable_if< sizeof...(values)==0, size_t >::type max()

References value().

◆ emitSignals()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::emitSignals ( ) const
inline

Definition at line 399 of file kis_slider_spin_box_p.h.

400 {
401#if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
402 Q_EMIT m_q->textChanged(m_q->text());
403#else
404 Q_EMIT m_q->valueChanged(m_q->text());
405#endif
406 Q_EMIT m_q->valueChanged(m_q->value());
407 }

◆ endEditing()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::endEditing ( ValueUpdateMode updateMode = ValueUpdateMode_UseLastValidValue)
inline

Definition at line 99 of file kis_slider_spin_box_p.h.

100 {
101 if (!isEditModeActive()) {
102 return;
103 }
104 if (updateMode == ValueUpdateMode_UseLastValidValue) {
105 setValue(m_q->value(), false, false, true);
106 } else if (updateMode == ValueUpdateMode_UseValueBeforeEditing) {
107 setValue(m_valueBeforeEditing, false, false, true);
108 }
109 // Restore palette colors
110 QPalette pal = m_lineEdit->palette();
111 pal.setBrush(QPalette::Text, m_q->palette().text());
112 m_lineEdit->setPalette(pal);
114 m_lineEdit->setReadOnly(true);
116 m_lineEdit->update();
117 m_q->update();
118 }
void setValue(ValueType newValue, bool blockSignals=false, bool emitSignalsEvenWhenValueNotChanged=false, bool overwriteExpression=false)

References KisCursor::splitHCursor().

◆ eventFilter()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::eventFilter ( QObject * o,
QEvent * e )
inlineoverride

Definition at line 868 of file kis_slider_spin_box_p.h.

869 {
870 if (!o || !e) {
871 return false;
872 }
873 if (o == m_q) {
874 switch (e->type()) {
875 case QEvent::Resize : return qResizeEvent(static_cast<QResizeEvent*>(e));
876 case QEvent::FocusOut : return qFocusOutEvent(static_cast<QFocusEvent*>(e));
877 case QEvent::MouseButtonPress : return qMousePressEvent(static_cast<QMouseEvent*>(e));
878 case QEvent::KeyPress : return qKeyPressEvent(static_cast<QKeyEvent*>(e));
879 case QEvent::ContextMenu : return qContextMenuEvent(static_cast<QContextMenuEvent*>(e));
880 default: break;
881 }
882 } else if (o == m_lineEdit) {
883 switch (e->type()) {
884 case QEvent::Paint : return lineEditPaintEvent(static_cast<QPaintEvent*>(e));
885 case QEvent::MouseButtonPress : return lineEditMousePressEvent(static_cast<QMouseEvent*>(e), false);
886 case QEvent::MouseButtonDblClick : return lineEditMousePressEvent(static_cast<QMouseEvent*>(e), true);
887 case QEvent::MouseButtonRelease : return lineEditMouseReleaseEvent(static_cast<QMouseEvent*>(e));
888 case QEvent::MouseMove : return lineEditMouseMoveEvent(static_cast<QMouseEvent*>(e));
889 default: break;
890 }
891 } else if (o == m_widgetRangeToggle) {
892 switch (e->type()) {
893 case QEvent::Paint : return widgetRangeTogglePaintEvent(static_cast<QPaintEvent*>(e));
894 case QEvent::MouseButtonRelease: return widgetRangeToggleMouseReleaseEvent(static_cast<QMouseEvent*>(e));
895 case QEvent::Enter: return widgetRangeToggleEnterEvent(e);
896 case QEvent::Leave: return widgetRangeToggleLeaveEvent(e);
897 default: break;
898 }
899 }
900 return false;
901 }
bool lineEditMousePressEvent(QMouseEvent *e, bool edit)
bool lineEditMouseMoveEvent(QMouseEvent *e)
bool qMousePressEvent(QMouseEvent *)
bool widgetRangeTogglePaintEvent(QPaintEvent *)
bool qContextMenuEvent(QContextMenuEvent *e)
bool widgetRangeToggleMouseReleaseEvent(QMouseEvent *e)
bool widgetRangeToggleLeaveEvent(QEvent *)
bool qFocusOutEvent(QFocusEvent *)
bool lineEditMouseReleaseEvent(QMouseEvent *e)
bool lineEditPaintEvent(QPaintEvent *)
bool qResizeEvent(QResizeEvent *)
bool qKeyPressEvent(QKeyEvent *e)
bool widgetRangeToggleEnterEvent(QEvent *)

◆ fastSliderStep()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
ValueType KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::fastSliderStep ( ) const
inline

Definition at line 315 of file kis_slider_spin_box_p.h.

316 {
317 return m_fastSliderStep;
318 }

◆ isDragging()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::isDragging ( ) const
inline

Definition at line 330 of file kis_slider_spin_box_p.h.

331 {
332 return m_isDragging;
333 }

◆ isEditModeActive()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::isEditModeActive ( ) const
inline

Definition at line 120 of file kis_slider_spin_box_p.h.

121 {
122 return !m_lineEdit->isReadOnly();
123 }

◆ isSoftRangeValid()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::isSoftRangeValid ( ) const
inline

Definition at line 310 of file kis_slider_spin_box_p.h.

◆ lineEditMouseMoveEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::lineEditMouseMoveEvent ( QMouseEvent * e)
inline

Definition at line 776 of file kis_slider_spin_box_p.h.

777 {
778 if (!m_q->isEnabled()) {
779 return false;
780 }
781 if (!isEditModeActive()) {
782 if (e->buttons() & Qt::LeftButton) {
783 m_isDragging = true;
784 // At this point we are dragging so record the position and set
785 // the value
786 const QPoint p(m_useRelativeDragging ? e->pos().x() + m_relativeDraggingOffset : e->pos().x(),
787 e->pos().y());
789 return true;
790 }
791 }
792 return false;
793 }
const Params2D p
ValueType valueForPoint(const QPoint &p, Qt::KeyboardModifiers modifiers) const

References p.

◆ lineEditMousePressEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::lineEditMousePressEvent ( QMouseEvent * e,
bool edit )
inline

Definition at line 718 of file kis_slider_spin_box_p.h.

719 {
720 if (!m_q->isEnabled()) {
721 return false;
722 }
723 if (!isEditModeActive()) {
724 if (e->button() == Qt::LeftButton) {
725 m_lastMousePressPosition = e->pos();
726 const QPoint currentValuePosition = pointForValue(m_q->value());
727 m_relativeDraggingOffset = currentValuePosition.x() - e->x();
728 m_useRelativeDragging = (e->modifiers() & Qt::ShiftModifier);
729 if (edit) {
730 QTimer::singleShot(0, &m_startEditingSignalProxy, SLOT(start()));
731 } else {
733 }
734 }
735 return true;
736 }
737 return false;
738 }
QPoint pointForValue(ValueType value) const

◆ lineEditMouseReleaseEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::lineEditMouseReleaseEvent ( QMouseEvent * e)
inline

Definition at line 740 of file kis_slider_spin_box_p.h.

741 {
742 if (!m_q->isEnabled()) {
743 return false;
744 }
745 if (!isEditModeActive()) {
746 // Releasing the right mouse button makes the lineedit enter
747 // the edition mode if we are not editing
748 if (e->button() == Qt::RightButton) {
749 // If we call startEditing() right from the eventFilter(),
750 // then the mouse release event will be somehow be passed
751 // to Qt further and generate ContextEvent on Windows.
752 // Therefore we should call it from a normal timer event.
753 QTimer::singleShot(0, &m_startEditingSignalProxy, SLOT(start()));
754 // Releasing the left mouse button stops the dragging. If signals
755 // must be blocked when dragging then we set the value here and
756 // Q_EMIT a signal
757 } else if (e->button() == Qt::LeftButton) {
759 const QPoint p(m_useRelativeDragging ? e->pos().x() + m_relativeDraggingOffset : e->pos().x(),
760 e->pos().y());
761 setValue(valueForPoint(p, e->modifiers()), false, true);
762 } else {
763 if (!m_isDragging) {
764 setValue(valueForPoint(e->pos(), e->modifiers()), false, true);
765 }
766 }
767
768 m_isDragging = false;
769 Q_EMIT m_q->draggingFinished();
770 }
771 return true;
772 }
773 return false;
774 }

References p.

◆ lineEditPaintEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::lineEditPaintEvent ( QPaintEvent * )
inline

Definition at line 673 of file kis_slider_spin_box_p.h.

674 {
675 QPainter painter(m_lineEdit);
676 painter.setRenderHint(QPainter::Antialiasing, true);
677
678 const double value = m_q->value();
679
680 // If we are not editing, just draw the text, otherwise draw a
681 // semi-transparent rect to dim the background and let the QLineEdit
682 // draw the rest (text, selection, cursor, etc.)
683 const double hardSliderWidth = computeSliderWidth(static_cast<double>(m_q->minimum()), static_cast<double>(m_q->maximum()), value);
684 const double softSliderWidth = computeSliderWidth(m_softMinimum, m_softMaximum, value);
685 if (!isEditModeActive()) {
686 QString text = m_q->text();
687 if (isSoftRangeValid()) {
688 if (m_softRangeViewMode == SoftRangeViewMode_AlwaysShowSoftRange) {
689 paintSlider(painter, text, softSliderWidth);
690 } else {
691 paintSlider(painter, text, hardSliderWidth, softSliderWidth);
692 }
693 } else {
694 // Draw the slider
695 paintSlider(painter, text, hardSliderWidth);
696 }
697 } else {
698 // Draw the slider
699 if (isSoftRangeValid()) {
700 if (m_softRangeViewMode == SoftRangeViewMode_AlwaysShowSoftRange) {
701 paintSlider(painter, QString(), softSliderWidth);
702 } else {
703 paintSlider(painter, QString(), hardSliderWidth, softSliderWidth);
704 }
705 } else {
706 paintSlider(painter, QString(), hardSliderWidth);
707 }
708 // Paint the overlay with the base color
709 QColor color = m_q->palette().base().color();
710 color.setAlpha(128);
711 paintSliderRect(painter, m_lineEdit->rect(), color);
712 }
713 // If we are editing the text then return false and let the QLineEdit
714 // paint all the edit related stuff (e.g. selection)
715 return !isEditModeActive();
716 }
double computeSliderWidth(double min, double max, double value) const
void paintSlider(QPainter &painter, const QString &text, double slider01Width, double slider02Width=-1.0)
void paintSliderRect(QPainter &painter, const QRectF &rect, const QBrush &brush)

References value().

◆ makeHardRangeActive()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::makeHardRangeActive ( )
inline

Definition at line 348 of file kis_slider_spin_box_p.h.

349 {
350 m_sliderAnimation.stop();
351 m_isSoftRangeActive = false;
352 // scale the duration in case the animation is in the middle
353 const int animationDuration =
354 static_cast<int>(std::round((1.0 - m_sliderAnimation.currentValue().toReal()) * fullAnimationDuration));
355 m_sliderAnimation.setStartValue(m_sliderAnimation.currentValue());
356 m_sliderAnimation.setEndValue(1.0);
357 m_sliderAnimation.setDuration(animationDuration);
358 m_sliderAnimation.start();
359 }
static constexpr double fullAnimationDuration

◆ makeSoftRangeActive()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::makeSoftRangeActive ( )
inline

Definition at line 335 of file kis_slider_spin_box_p.h.

336 {
337 m_sliderAnimation.stop();
338 m_isSoftRangeActive = true;
339 // scale the animation duration in case the animation is in the middle
340 const int animationDuration =
341 static_cast<int>(std::round(m_sliderAnimation.currentValue().toReal() * fullAnimationDuration));
342 m_sliderAnimation.setStartValue(m_sliderAnimation.currentValue());
343 m_sliderAnimation.setEndValue(0.0);
344 m_sliderAnimation.setDuration(animationDuration);
345 m_sliderAnimation.start();
346 }

◆ minimumSizeHint()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QSize KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::minimumSizeHint ( ) const
inline

Definition at line 390 of file kis_slider_spin_box_p.h.

391 {
392 QSize hint = m_q->BaseSpinBoxType::minimumSizeHint();
393 return
394 (isSoftRangeValid() && m_softRangeViewMode == SoftRangeViewMode_ShowBothRanges)
395 ? QSize(hint.width() + widthOfRangeModeToggle, hint.height())
396 : hint;
397 }
static constexpr double widthOfRangeModeToggle

◆ paintGenericSliderText()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::paintGenericSliderText ( QPainter & painter,
const QString & text,
const QRectF & rect,
const QRectF & sliderRect )
inline

Definition at line 603 of file kis_slider_spin_box_p.h.

604 {
605 QTextOption textOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter);
606 textOption.setWrapMode(QTextOption::NoWrap);
607 // Draw portion of the text that is over the background
608 paintSliderText(painter, text, rect, rect.adjusted(sliderRect.width(), 0, 0, 0), m_lineEdit->palette().text().color(), textOption);
609 // Draw portion of the text that is over the progress bar
610 paintSliderText(painter, text, rect, sliderRect, m_lineEdit->palette().highlightedText().color(), textOption);
611 };
void paintSliderText(QPainter &painter, const QString &text, const QRectF &rect, const QRectF &clipRect, const QColor &color, const QTextOption &textOption)

◆ paintSlider()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::paintSlider ( QPainter & painter,
const QString & text,
double slider01Width,
double slider02Width = -1.0 )
inline

Definition at line 613 of file kis_slider_spin_box_p.h.

614 {
615 const QRectF rect = m_lineEdit->rect();
616 const QColor highlightColor = m_q->palette().highlight().color();
617 if (slider02Width < 0.0) {
618 const QRectF sliderRect = rect.adjusted(0, 0, -(rect.width() - slider01Width), 0);
619 paintSliderRect(painter, sliderRect, highlightColor);
620 if (!text.isNull()) {
621 paintGenericSliderText(painter, text, rect, sliderRect);
622 }
623 } else {
624 static constexpr double heightOfCollapsedSliderPlusSpace = heightOfCollapsedSlider + heightOfSpaceBetweenSliders;
625 const double heightBetween = rect.height() - 2.0 * heightOfCollapsedSlider - heightOfSpaceBetweenSliders;
626 const double animationPos = m_sliderAnimation.currentValue().toReal();
627 const double a = heightOfCollapsedSliderPlusSpace;
628 const double b = heightOfCollapsedSliderPlusSpace + heightBetween;
629 // Paint background text
630 QTextOption textOption(Qt::AlignAbsolute | Qt::AlignHCenter | Qt::AlignVCenter);
631 textOption.setWrapMode(QTextOption::NoWrap);
632 paintSliderText(painter, text, rect, rect, m_lineEdit->palette().text().color(), textOption);
633 // Paint soft range slider
634 const QColor softSliderColor = KisPaintingTweaks::blendColors(highlightColor, m_q->palette().base().color(), 1.0 - 0.25);
635 const double softSliderAdjustment = -KisAlgebra2D::lerp(a, b, animationPos);
637 painter,
638 rect.adjusted(0, 0, -(rect.width() - slider02Width), softSliderAdjustment),
639 softSliderColor
640 );
641 // Paint hard range slider
642 const double hardSliderAdjustment = KisAlgebra2D::lerp(a, b, 1.0 - animationPos);
644 painter,
645 rect.adjusted(0, hardSliderAdjustment, -(rect.width() - slider01Width), 0),
646 highlightColor
647 );
648 // Paint text in the sliders
650 painter, text, rect,
651 rect.adjusted(0, 0, -(rect.width() - slider02Width), softSliderAdjustment),
652 m_lineEdit->palette().highlightedText().color(),
653 textOption
654 );
656 painter, text, rect,
657 rect.adjusted(0, hardSliderAdjustment, -(rect.width() - slider01Width), 0),
658 m_lineEdit->palette().highlightedText().color(),
659 textOption
660 );
661 }
662 }
void paintGenericSliderText(QPainter &painter, const QString &text, const QRectF &rect, const QRectF &sliderRect)
static constexpr double heightOfCollapsedSlider
static constexpr double heightOfSpaceBetweenSliders
Point lerp(const Point &pt1, const Point &pt2, qreal t)
QColor blendColors(const QColor &c1, const QColor &c2, qreal r1)

References KisPaintingTweaks::blendColors(), and KisAlgebra2D::lerp().

◆ paintSliderRect()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::paintSliderRect ( QPainter & painter,
const QRectF & rect,
const QBrush & brush )
inline

Definition at line 580 of file kis_slider_spin_box_p.h.

581 {
582 painter.save();
583 painter.setBrush(brush);
584 painter.setPen(Qt::NoPen);
585 if (qApp->property(currentUnderlyingStyleNameProperty).toString().toLower() == "fusion") {
586 painter.drawRoundedRect(rect, 1, 1);
587 } else {
588 painter.drawRoundedRect(rect, 0, 0);
589 }
590 painter.restore();
591 }
constexpr const char * currentUnderlyingStyleNameProperty
Definition kis_global.h:116

References currentUnderlyingStyleNameProperty.

◆ paintSliderText()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::paintSliderText ( QPainter & painter,
const QString & text,
const QRectF & rect,
const QRectF & clipRect,
const QColor & color,
const QTextOption & textOption )
inline

Definition at line 593 of file kis_slider_spin_box_p.h.

594 {
595 painter.setBrush(Qt::NoBrush);
596 painter.setPen(color);
597 painter.setClipping(true);
598 painter.setClipRect(clipRect);
599 painter.drawText(rect, text, textOption);
600 painter.setClipping(false);
601 };

◆ pointForValue()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QPoint KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::pointForValue ( ValueType value) const
inline

Definition at line 185 of file kis_slider_spin_box_p.h.

186 {
188 if (isSoftRangeValid()) {
189 if (m_softRangeViewMode == SoftRangeViewMode_ShowBothRanges) {
191 min = softMinimum();
192 max = softMaximum();
193 } else {
194 min = m_q->minimum();
195 max = m_q->maximum();
196 }
197 } else {
198 min = softMinimum();
199 max = softMaximum();
200 }
201 } else {
202 min = m_q->minimum();
203 max = m_q->maximum();
204 }
205 return QPoint(static_cast<int>(qRound(computeSliderWidth(min, max, value))), 0);
206 }
decltype(std::declval< SpinBoxType >().value()) ValueType

References value().

◆ qContextMenuEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::qContextMenuEvent ( QContextMenuEvent * e)
inline

Definition at line 517 of file kis_slider_spin_box_p.h.

518 {
519 // Shows a menu. Code inspired by the QAbstractSpinBox
520 // contextMenuEvent function
521
522 // Return if we are in slider mode and the mouse is in the line edit
523 if (!isEditModeActive() && m_lineEdit->rect().contains(e->pos())) {
524 return true;
525 }
526 // Create the menu
527 QPointer<QMenu> menu;
528 // If we are in edit mode, then add the line edit
529 // actions
530 if (isEditModeActive()) {
531 menu = m_lineEdit->createStandardContextMenu();
533 } else {
534 menu = new QMenu;
535 }
536 if (!menu) {
537 return true;
538 }
539 // Override select all action
540 QAction *selectAllAction = nullptr;
541 if (isEditModeActive()) {
542 selectAllAction = new QAction(i18nc("Menu action to select all text in the slider spin box", "&Select All"), menu);
543#if QT_CONFIG(shortcut)
544 selectAllAction->setShortcut(QKeySequence::SelectAll);
545#endif
546 menu->removeAction(menu->actions().last());
547 menu->addAction(selectAllAction);
548 menu->addSeparator();
549 }
550 // Add step up and step down actions
551 const uint stepEnabled = m_q->stepEnabled();
552 QAction *stepUpAction = menu->addAction(i18nc("Menu action to step up in the slider spin box", "&Step up"));
553 stepUpAction->setEnabled(stepEnabled & SpinBoxType::StepUpEnabled);
554 QAction *stepDown = menu->addAction(i18nc("Menu action to step down in the slider spin box", "Step &down"));
555 stepDown->setEnabled(stepEnabled & SpinBoxType::StepDownEnabled);
556 menu->addSeparator();
557 // This code is taken from QAbstractSpinBox. Use a QPointer in case the
558 // spin box is destroyed while the menu is shown??
559 const QPointer<SpinBoxType> spinbox = m_q;
560 const QPoint pos =
561 (e->reason() == QContextMenuEvent::Mouse)
562 ? e->globalPos()
563 : m_q->mapToGlobal(QPoint(e->pos().x(), 0)) + QPoint(m_q->width() / 2, m_q->height() / 2);
564 const QAction *action = menu->exec(pos);
565 delete static_cast<QMenu *>(menu);
566 if (spinbox && action) {
567 if (action == stepUpAction) {
568 m_q->stepBy(static_cast<ValueType>(1));
569 } else if (action == stepDown) {
570 m_q->stepBy(static_cast<ValueType>(-1));
571 } else if (action == selectAllAction) {
572 m_q->selectAll();
573 }
574 }
575 e->accept();
576 return true;
577 }
unsigned int uint

◆ qFocusOutEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::qFocusOutEvent ( QFocusEvent * )
inline

Definition at line 437 of file kis_slider_spin_box_p.h.

438 {
439 // If the focus is lost then the edition stops, unless the focus
440 // was lost because the menu was shown
442 m_focusLostDueToMenu = false;
443 } else {
444 if (m_q->isLastValid()) {
445 endEditing();
446 }
447 }
448 return false;
449 }
void endEditing(ValueUpdateMode updateMode=ValueUpdateMode_UseLastValidValue)

◆ qKeyPressEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::qKeyPressEvent ( QKeyEvent * e)
inline

Definition at line 459 of file kis_slider_spin_box_p.h.

460 {
461 switch (e->key()) {
462 // If the lineedit is not in edition mode, make the left and right
463 // keys have the same effect as the down and up keys. This replicates
464 // the behaviour of the old slider spinbox
465 case Qt::Key_Right:
466 if (!isEditModeActive()) {
467 qApp->postEvent(m_q, new QKeyEvent(QEvent::KeyPress, Qt::Key_Up, e->modifiers()));
468 return true;
469 }
470 break;
471 case Qt::Key_Left:
472 if (!isEditModeActive()) {
473 qApp->postEvent(m_q, new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, e->modifiers()));
474 return true;
475 }
476 break;
477 // The enter key can be used to enter the edition mode if the
478 // lineedit is not in it or to commit the entered value and leave
479 // the edition mode if we are in it
480 case Qt::Key_Enter:
481 case Qt::Key_Return:
482 if (!e->isAutoRepeat()) {
483 if (!isEditModeActive()) {
484 startEditing();
485 } else {
486 if (m_q->isLastValid()) {
487 endEditing();
488 } else {
489 return false;
490 }
491 }
492 }
493 return true;
494 // The escape key can be used to leave the edition mode rejecting
495 // the written value
496 case Qt::Key_Escape:
497 if (isEditModeActive()) {
499 return true;
500 }
501 break;
502 // If we press a number key when in slider mode, then start the edit
503 // mode and resend the key event so that the key is processed again
504 // in edit mode. Since entering edit mode selects all text, the new
505 // event will replace the text by the new key text
506 default:
507 if (!isEditModeActive() && e->key() >= Qt::Key_0 && e->key() <= Qt::Key_9) {
508 startEditing();
509 qApp->postEvent(m_q, new QKeyEvent(QEvent::KeyPress, e->key(), e->modifiers(), e->text(), e->isAutoRepeat()));
510 return true;
511 }
512 break;
513 }
514 return false;
515 }

◆ qMousePressEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::qMousePressEvent ( QMouseEvent * )
inline

Definition at line 451 of file kis_slider_spin_box_p.h.

452 {
453 // If we click in any part of the spinbox outside the lineedit
454 // then the edition stops
455 endEditing();
456 return false;
457 }

◆ qResizeEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::qResizeEvent ( QResizeEvent * )
inline

Definition at line 409 of file kis_slider_spin_box_p.h.

410 {
411 // When resizing the spinbox, perform style specific positioning
412 // of the lineedit
413
414 // Get the default rect for the lineedit widget
415 QStyleOptionSpinBox spinBoxOptions;
416 m_q->initStyleOption(&spinBoxOptions);
417 QRect rect = m_q->style()->subControlRect(QStyle::CC_SpinBox, &spinBoxOptions, QStyle::SC_SpinBoxEditField);
418 // Offset the rect to make it take all the available space inside the
419 // spinbox, without overlapping the buttons
420 QString style = qApp->property(currentUnderlyingStyleNameProperty).toString().toLower();
421 if (style == "breeze") {
422 rect.adjust(-4, -4, 0, 4);
423 } else if (style == "fusion") {
424 rect.adjust(-2, -1, 2, 1);
425 }
426 // Set the rect
427 if (isSoftRangeValid() && m_softRangeViewMode == SoftRangeViewMode_ShowBothRanges) {
428 m_lineEdit->setGeometry(rect.adjusted(0, 0, -widthOfRangeModeToggle, 0));
429 m_widgetRangeToggle->setGeometry(rect.adjusted(rect.width() - widthOfRangeModeToggle, 0, 0, 0));
430 } else {
431 m_lineEdit->setGeometry(rect);
432 }
433
434 return true;
435 }

References currentUnderlyingStyleNameProperty.

◆ resetRangeMode()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::resetRangeMode ( )
inline

Definition at line 230 of file kis_slider_spin_box_p.h.

231 {
232 if (isSoftRangeValid() && m_softRangeViewMode == SoftRangeViewMode_ShowBothRanges) {
235 } else {
237 }
239 m_widgetRangeToggle->show();
240 } else {
241 m_sliderAnimation.stop();
242 m_widgetRangeToggle->hide();
243 }
244 qResizeEvent(nullptr);
245 }

◆ setBlockUpdateSignalOnDrag()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::setBlockUpdateSignalOnDrag ( bool newBlockUpdateSignalOnDrag)
inline

Definition at line 286 of file kis_slider_spin_box_p.h.

287 {
288 m_blockUpdateSignalOnDrag = newBlockUpdateSignalOnDrag;
289 }

◆ setExponentRatio()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::setExponentRatio ( double newExponentRatio)
inline

Definition at line 361 of file kis_slider_spin_box_p.h.

362 {
363 m_exponentRatio = newExponentRatio;
364 m_lineEdit->update();
365 }

◆ setFastSliderStep()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::setFastSliderStep ( ValueType newFastSliderStep)
inline

Definition at line 291 of file kis_slider_spin_box_p.h.

292 {
293 m_fastSliderStep = newFastSliderStep;
294 }

◆ setRange() [1/2]

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
template<typename U = SpinBoxTypeTP, typename = typename std::enable_if<std::is_same<ValueType, double>::value, U>::type>
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::setRange ( double newMinimum,
double newMaximum,
int newNumberOfDecimals,
bool computeNewFastSliderStep )
inline

Definition at line 265 of file kis_slider_spin_box_p.h.

266 {
267 m_q->setDecimals(newNumberOfDecimals);
268 m_q->BaseSpinBoxType::setRange(newMinimum, newMaximum);
269 if (computeNewFastSliderStep) {
270 // Behavior taken from the old slider. Kind of arbitrary
271 const double rangeSize = m_q->maximum() - m_q->minimum();
272 if (rangeSize >= 2.0 || newNumberOfDecimals <= 0) {
273 m_fastSliderStep = 1.0;
274 } else if (newNumberOfDecimals == 1) {
275 m_fastSliderStep = rangeSize / 10.0;
276 } else {
277 m_fastSliderStep = rangeSize / 20.0;
278 }
279 }
280 m_softMinimum = qBound(m_q->minimum(), m_softMinimum, m_q->maximum());
281 m_softMaximum = qBound(m_q->minimum(), m_softMaximum, m_q->maximum());
283 m_lineEdit->update();
284 }

◆ setRange() [2/2]

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
template<typename U = SpinBoxTypeTP, typename = typename std::enable_if<std::is_same<ValueType, int>::value, U>::type>
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::setRange ( int newMinimum,
int newMaximum,
bool computeNewFastSliderStep )
inline

Definition at line 248 of file kis_slider_spin_box_p.h.

249 {
250 m_q->BaseSpinBoxType::setRange(newMinimum, newMaximum);
251 if (computeNewFastSliderStep) {
252 // Behavior taken from the old slider spinbox. Kind of arbitrary
253 m_fastSliderStep = (m_q->maximum() - m_q->minimum()) / 20;
254 if (m_fastSliderStep == 0) {
256 }
257 }
258 m_softMinimum = qBound(m_q->minimum(), m_softMinimum, m_q->maximum());
259 m_softMaximum = qBound(m_q->minimum(), m_softMaximum, m_q->maximum());
261 m_q->update();
262 }

◆ setSoftRange()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::setSoftRange ( ValueType newSoftMinimum,
ValueType newSoftMaximum )
inline

Definition at line 298 of file kis_slider_spin_box_p.h.

299 {
300 if ((newSoftMinimum != newSoftMaximum) &&
301 (newSoftMinimum > newSoftMaximum || newSoftMinimum < m_q->minimum() || newSoftMaximum > m_q->maximum())) {
302 return;
303 }
304 m_softMinimum = newSoftMinimum;
305 m_softMaximum = newSoftMaximum;
307 m_lineEdit->update();
308 }

◆ setValue()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::setValue ( ValueType newValue,
bool blockSignals = false,
bool emitSignalsEvenWhenValueNotChanged = false,
bool overwriteExpression = false )
inline

Definition at line 209 of file kis_slider_spin_box_p.h.

213 {
214 if (blockSignals) {
215 m_q->blockSignals(true);
216 m_q->BaseSpinBoxType::setValue(newValue, overwriteExpression);
217 m_q->blockSignals(false);
218 } else {
219 ValueType v = m_q->value();
220 m_q->BaseSpinBoxType::setValue(newValue, overwriteExpression);
221 if (v == m_q->value() && emitSignalsEvenWhenValueNotChanged) {
222 emitSignals();
223 }
224 }
225 if (!m_q->hasFocus()) {
227 }
228 }
qreal v

References v.

◆ sizeHint()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QSize KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::sizeHint ( ) const
inline

Definition at line 381 of file kis_slider_spin_box_p.h.

382 {
383 QSize hint = m_q->BaseSpinBoxType::sizeHint();
384 return
385 (isSoftRangeValid() && m_softRangeViewMode == SoftRangeViewMode_ShowBothRanges)
386 ? QSize(hint.width() + widthOfRangeModeToggle, hint.height())
387 : hint;
388 }

◆ softMaximum()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
ValueType KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::softMaximum ( ) const
inline

Definition at line 325 of file kis_slider_spin_box_p.h.

326 {
327 return m_softMaximum;
328 }

◆ softMinimum()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
ValueType KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::softMinimum ( ) const
inline

Definition at line 320 of file kis_slider_spin_box_p.h.

321 {
322 return m_softMinimum;
323 }

◆ startEditing()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::startEditing ( )
inline

Definition at line 86 of file kis_slider_spin_box_p.h.

87 {
88 if (isEditModeActive()) {
89 return;
90 }
91 // Store the current value
92 m_valueBeforeEditing = m_q->value();
93 m_lineEdit->setReadOnly(false);
94 m_q->selectAll();
95 m_lineEdit->setFocus(Qt::OtherFocusReason);
97 }
static QCursor ibeamCursor()
Definition kis_cursor.cc:59

References KisCursor::ibeamCursor().

◆ updateWidgetRangeToggleTooltip()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
void KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::updateWidgetRangeToggleTooltip ( )
inline

Definition at line 367 of file kis_slider_spin_box_p.h.

368 {
369 m_widgetRangeToggle->setToolTip(
370 i18nc(
371 "@info:tooltip toggle between soft and hard range in the slider spin box",
372 "Toggle between full range and subrange.\nFull range: [%1, %2]\nSubrange: [%3, %4]",
373 QString::number(m_q->minimum()),
374 QString::number(m_q->maximum()),
375 QString::number(m_softMinimum),
376 QString::number(m_softMaximum)
377 )
378 );
379 }

◆ valueForPoint()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
ValueType KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::valueForPoint ( const QPoint & p,
Qt::KeyboardModifiers modifiers ) const
inline

Definition at line 127 of file kis_slider_spin_box_p.h.

128 {
129 const QRectF rect(m_lineEdit->rect());
130 const QPointF center(
131 static_cast<double>(
133 ),
134 rect.height() / 2.0
135 );
136 const bool useSoftRange = isSoftRangeValid() && (m_softRangeViewMode == SoftRangeViewMode_AlwaysShowSoftRange || m_isSoftRangeActive);
137 const double minimum = static_cast<double>(useSoftRange ? m_softMinimum : m_q->minimum());
138 const double maximum = static_cast<double>(useSoftRange ? m_softMaximum : m_q->maximum());
139 const double rangeSize = maximum - minimum;
140 // Get the distance relative to the line edit center and transformed
141 // so that it starts counting 32px away from the widget. If the position
142 // is inside the widget or that 32px area the distance will be 0 so that
143 // the value change will be the same near the widget
144 const double distanceY =
145 std::max(
146 0.0,
147 std::abs(static_cast<double>(p.y()) - center.y()) - center.y() - constantDraggingMargin
148 );
149 // Get the scale
150 double scale;
151 if (modifiers & Qt::ShiftModifier) {
152 // If the shift key is pressed we scale the distanceY value to make the scale
153 // have a stronger effect and also offset it so that the minimum
154 // scale will be 5x (1x + 4x).
155 // function
156 scale = (rect.width() + 2.0 * distanceY * 10.0) / rect.width() + 4.0;
157 } else {
158 // Get the scale as a function of the vertical position
159 scale = (rect.width() + 2.0 * distanceY * 2.0) / rect.width();
160 }
161 // Scale the horizontal coordinates around where we first clicked
162 // as a function of the y coordinate
163 const double scaledRectLeft = (0.0 - center.x()) * scale + center.x();
164 const double scaledRectRight = (rect.width() - center.x()) * scale + center.x();
165 // Map the current horizontal position to the new rect
166 const double scaledRectWidth = scaledRectRight - scaledRectLeft;
167 const double posX = static_cast<double>(p.x()) - scaledRectLeft;
168 // Normalize
169 const double normalizedPosX = qBound(0.0, posX / scaledRectWidth, 1.0);
170 // Final value
171 const double normalizedValue = std::pow(normalizedPosX, m_exponentRatio);
172 double value = normalizedValue * rangeSize + minimum;
173 // If key CTRL is pressed, round to the closest step.
174 if (modifiers & Qt::ControlModifier) {
176 }
177 //Return the value
178 if (std::is_same<ValueType, double>::value) {
179 return value;
180 } else {
181 return static_cast<ValueType>(std::round(value));
182 }
183 }
static constexpr double constantDraggingMargin

References p, and value().

◆ widgetRangeToggleEnterEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::widgetRangeToggleEnterEvent ( QEvent * )
inline

Definition at line 842 of file kis_slider_spin_box_p.h.

843 {
845 // scale the animation duration in case the animation is in the middle
846 const int animationDuration =
847 static_cast<int>(std::round(m_rangeToggleHoverAnimation.currentValue().toReal() * fullAnimationDuration));
848 m_rangeToggleHoverAnimation.setStartValue(m_rangeToggleHoverAnimation.currentValue());
849 m_rangeToggleHoverAnimation.setEndValue(1.0);
850 m_rangeToggleHoverAnimation.setDuration(animationDuration);
852 return false;
853 }

◆ widgetRangeToggleLeaveEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::widgetRangeToggleLeaveEvent ( QEvent * )
inline

Definition at line 855 of file kis_slider_spin_box_p.h.

856 {
858 // scale the animation duration in case the animation is in the middle
859 const int animationDuration =
860 static_cast<int>(std::round(m_rangeToggleHoverAnimation.currentValue().toReal() * fullAnimationDuration));
861 m_rangeToggleHoverAnimation.setStartValue(m_rangeToggleHoverAnimation.currentValue());
862 m_rangeToggleHoverAnimation.setEndValue(0.0);
863 m_rangeToggleHoverAnimation.setDuration(animationDuration);
865 return false;
866 }

◆ widgetRangeToggleMouseReleaseEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::widgetRangeToggleMouseReleaseEvent ( QMouseEvent * e)
inline

Definition at line 826 of file kis_slider_spin_box_p.h.

827 {
828 if (!m_q->isEnabled()) {
829 return false;
830 }
831 if (e->button() == Qt::LeftButton) {
832 if (!m_isSoftRangeActive) {
834 } else {
836 }
837 return true;
838 }
839 return false;
840 }

◆ widgetRangeTogglePaintEvent()

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::widgetRangeTogglePaintEvent ( QPaintEvent * )
inline

Definition at line 795 of file kis_slider_spin_box_p.h.

796 {
797 QPainter painter(m_widgetRangeToggle);
798 painter.setRenderHint(QPainter::Antialiasing, true);
799 // Compute sizes and positions
800 const double width = static_cast<double>(m_widgetRangeToggle->width());
801 const double height = static_cast<double>(m_widgetRangeToggle->height());
802 constexpr double marginX = 4.0;
803 const double toggleWidth = width - 2.0 * marginX;
804 const double centerX = width * 0.5;
805 const double centerY = height * 0.5;
806 const double bigRadius = centerX - std::floor(centerX - (toggleWidth * 0.5)) + 0.5;
807 const double smallRadius = bigRadius * 0.5;
808 const double sliderAnimationPos = m_sliderAnimation.currentValue().toReal();
809 const double radius = smallRadius + sliderAnimationPos * (bigRadius - smallRadius);
810 // Compute color
811 const double rangeToggleHoverAnimationPos = m_rangeToggleHoverAnimation.currentValue().toReal();
812 const QColor baseColor = m_q->palette().base().color();
813 const QColor textColor = m_q->palette().text().color();
814 const QColor color = KisPaintingTweaks::blendColors(baseColor, textColor, 1.0 - (0.60 + 0.40 * rangeToggleHoverAnimationPos));
815 // Paint outer circle
816 painter.setPen(color);
817 painter.setBrush(Qt::NoBrush);
818 painter.drawEllipse(QPointF(centerX, centerY), bigRadius, bigRadius);
819 // Paint dot
820 painter.setPen(Qt::NoPen);
821 painter.setBrush(color);
822 painter.drawEllipse(QPointF(centerX, centerY), radius, radius);
823 return true;
824 }

References KisPaintingTweaks::blendColors().

Member Data Documentation

◆ constantDraggingMargin

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
constexpr double KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::constantDraggingMargin {32.0}
staticconstexprprivate

Definition at line 906 of file kis_slider_spin_box_p.h.

906{32.0};

◆ fullAnimationDuration

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
constexpr double KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::fullAnimationDuration {200.0}
staticconstexprprivate

Definition at line 914 of file kis_slider_spin_box_p.h.

914{200.0};

◆ heightOfCollapsedSlider

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
constexpr double KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::heightOfCollapsedSlider {3.0}
staticconstexprprivate

Definition at line 908 of file kis_slider_spin_box_p.h.

908{3.0};

◆ heightOfSpaceBetweenSliders

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
constexpr double KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::heightOfSpaceBetweenSliders {0.0}
staticconstexprprivate

Definition at line 910 of file kis_slider_spin_box_p.h.

910{0.0};

◆ m_blockUpdateSignalOnDrag

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_blockUpdateSignalOnDrag {false}
private

Definition at line 922 of file kis_slider_spin_box_p.h.

922{false};

◆ m_exponentRatio

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
double KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_exponentRatio {1.0}
private

Definition at line 921 of file kis_slider_spin_box_p.h.

921{1.0};

◆ m_fastSliderStep

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
ValueType KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_fastSliderStep {static_cast<ValueType>(5)}
private

Definition at line 923 of file kis_slider_spin_box_p.h.

923{static_cast<ValueType>(5)};

◆ m_focusLostDueToMenu

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_focusLostDueToMenu {false}
private

Definition at line 930 of file kis_slider_spin_box_p.h.

930{false};

◆ m_isDragging

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_isDragging {false}
private

Definition at line 925 of file kis_slider_spin_box_p.h.

925{false};

◆ m_isSoftRangeActive

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_isSoftRangeActive {true}
private

Definition at line 931 of file kis_slider_spin_box_p.h.

931{true};

◆ m_lastMousePressPosition

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QPoint KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_lastMousePressPosition
private

Definition at line 928 of file kis_slider_spin_box_p.h.

◆ m_lineEdit

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QLineEdit* KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_lineEdit {nullptr}
private

Definition at line 917 of file kis_slider_spin_box_p.h.

917{nullptr};

◆ m_q

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
SpinBoxType* KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_q {nullptr}
private

Definition at line 916 of file kis_slider_spin_box_p.h.

916{nullptr};

◆ m_rangeToggleHoverAnimation

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QVariantAnimation KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_rangeToggleHoverAnimation
private

Definition at line 933 of file kis_slider_spin_box_p.h.

◆ m_relativeDraggingOffset

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
int KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_relativeDraggingOffset {0}
private

Definition at line 927 of file kis_slider_spin_box_p.h.

927{0};

◆ m_rightClickCounter

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
int KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_rightClickCounter {0}
private

Definition at line 929 of file kis_slider_spin_box_p.h.

929{0};

◆ m_sliderAnimation

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QVariantAnimation KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_sliderAnimation
private

Definition at line 932 of file kis_slider_spin_box_p.h.

◆ m_softMaximum

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
ValueType KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_softMaximum {static_cast<ValueType>(0)}
private

Definition at line 920 of file kis_slider_spin_box_p.h.

920{static_cast<ValueType>(0)};

◆ m_softMinimum

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
ValueType KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_softMinimum {static_cast<ValueType>(0)}
private

Definition at line 919 of file kis_slider_spin_box_p.h.

919{static_cast<ValueType>(0)};

◆ m_startEditingSignalProxy

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
SignalToFunctionProxy KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_startEditingSignalProxy
private

Definition at line 934 of file kis_slider_spin_box_p.h.

◆ m_useRelativeDragging

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
bool KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_useRelativeDragging {false}
private

Definition at line 926 of file kis_slider_spin_box_p.h.

926{false};

◆ m_valueBeforeEditing

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
ValueType KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_valueBeforeEditing {static_cast<ValueType>(0)}
mutableprivate

Definition at line 924 of file kis_slider_spin_box_p.h.

924{static_cast<ValueType>(0)};

◆ m_widgetRangeToggle

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
QWidget* KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::m_widgetRangeToggle {nullptr}
private

Definition at line 918 of file kis_slider_spin_box_p.h.

918{nullptr};

◆ SoftRangeViewMode_ShowBothRanges

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
enum KisSliderSpinBoxPrivate::SoftRangeViewMode KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::SoftRangeViewMode_ShowBothRanges
private

◆ widthOfRangeModeToggle

template<typename SpinBoxTypeTP , typename BaseSpinBoxTypeTP >
constexpr double KisSliderSpinBoxPrivate< SpinBoxTypeTP, BaseSpinBoxTypeTP >::widthOfRangeModeToggle {16.0}
staticconstexprprivate

Definition at line 912 of file kis_slider_spin_box_p.h.

912{16.0};

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