7#include "QskAnimationHint.h"
9#include "QskIntervalF.h"
17QSK_SUBCONTROL(
QskSlider, GrooveStopIndicators )
18QSK_SUBCONTROL(
QskSlider, FillStopIndicators )
25 PrivateData( Qt::Orientation orientation )
28 , orientation( orientation )
35 Qt::Orientation orientation : 2;
38QskSlider::QskSlider( QQuickItem* parent )
43QskSlider::QskSlider( Qt::Orientation orientation, QQuickItem* parent )
45 , m_data( new PrivateData( orientation ) )
47 setAcceptHoverEvents(
true );
48 setFocusPolicy( Qt::StrongFocus );
50 if ( orientation == Qt::Horizontal )
51 initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Fixed );
53 initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Minimum );
55 connect(
this, &QskSlider::boundariesChanged,
this, &QskSlider::moveHandle );
56 connect(
this, &QskSlider::valueChanged,
this, &QskSlider::moveHandle );
59QskSlider::~QskSlider()
63bool QskSlider::isPressed()
const
65 return hasSkinState( Pressed );
68void QskSlider::setOrientation( Qt::Orientation orientation )
70 if ( orientation != m_data->orientation )
72 m_data->orientation = orientation;
80 Q_EMIT orientationChanged( m_data->orientation );
84Qt::Orientation QskSlider::orientation()
const
86 return m_data->orientation;
94void QskSlider::setTracking(
bool on )
96 if ( on != m_data->tracking )
98 m_data->tracking = on;
99 Q_EMIT trackingChanged( on );
103bool QskSlider::isTracking()
const
105 return m_data->tracking;
110 setPositionHint( Handle, valueAsRatio() );
114QSizeF QskSlider::handleSize()
const
116 return handleRect().size();
119QRectF QskSlider::handleRect()
const
124 const QSizeF strutSize( 60, 60 );
125 const auto w = qMax( ( strutSize.width() -
rect.width() ) / 2, 0.0 );
126 const auto h = qMax( ( strutSize.height() -
rect.height() ) / 2, 0.0 );
129 return rect.marginsAdded( { w, h, w, h } );
132void QskSlider::mousePressEvent( QMouseEvent* event )
134 if ( handleRect().contains( event->pos() ) )
138 m_data->pressedPos =
event->pos();
139 m_data->pressedValue = value();
141 Q_EMIT pressedChanged(
true );
143 else if ( pageSteps() == 0 )
156void QskSlider::mouseMoveEvent( QMouseEvent* event )
161 const auto mousePos = qskMousePosition( event );
166 if ( m_data->orientation == Qt::Horizontal )
168 const auto distance = mousePos.x() - m_data->pressedPos.x();
169 newValue = m_data->pressedValue + distance / r.width() * boundaryLength();
173 const auto distance = mousePos.y() - m_data->pressedPos.y();
174 newValue = m_data->pressedValue - distance / r.height() * boundaryLength();
177 if ( m_data->tracking )
179 setValue( newValue );
187void QskSlider::mouseReleaseEvent( QMouseEvent* event )
191 const auto mousePos = qskMousePosition( event );
193 const auto szHandle = handleSize();
197 if ( m_data->orientation == Qt::Horizontal )
199 const qreal w = szHandle.width();
201 const qreal x = ( mousePos.x() -
rect.x() - w * 0.5 ) / (
rect.width() - w );
202 up = x > valueAsRatio();
206 const qreal h = szHandle.height();
208 const qreal y = ( mousePos.y() -
rect.y() - h * 0.5 ) / (
rect.height() - h );
209 up = y < 1.0 - valueAsRatio();
219 if ( !m_data->tracking )
221 const auto pos = handlePosition();
222 setValue( valueFromRatio( pos ) );
227 Q_EMIT pressedChanged(
false );
230qreal QskSlider::handlePosition()
const
232 return positionHint( Handle );
235void QskSlider::moveHandle()
238 moveHandleTo( value(),
animationHint( aspect | skinStates() ) );
243 const qreal pos = valueAsRatio( value );
245 if ( hint.isValid() )
247 const qreal oldPos = positionHint( Handle );
248 setPositionHint( Handle, pos );
251 startTransition( aspect, hint, oldPos, pos );
255 setPositionHint( Handle, pos );
261#include "moc_QskSlider.cpp"
Variation
Some sort of variation.
QRectF subControlRect(QskAspect::Subcontrol) const
void setSizePolicy(QskSizePolicy)
QRectF contentsRect() const
virtual void aboutToShow()
QskAnimationHint animationHint(QskAspect, QskSkinHintStatus *=nullptr) const
void setSkinStateFlag(QskAspect::State, bool on=true)
QskAspect::Variation effectiveVariation() const override
void aboutToShow() override