7#include "QskAnimationHint.h"
9#include "QskIntervalF.h"
21static inline
QskAspect qskAspectGraduationPolicy()
23 return QskSlider::Tick | QskAspect::Option;
26class QskSlider::PrivateData
29 PrivateData( Qt::Orientation orientation )
32 , orientation( orientation )
42QskSlider::QskSlider( QQuickItem* parent )
47QskSlider::QskSlider( Qt::Orientation orientation, QQuickItem* parent )
49 , m_data( new PrivateData( orientation ) )
51 setAcceptHoverEvents(
true );
52 setFocusPolicy( Qt::StrongFocus );
54 if ( orientation == Qt::Horizontal )
55 initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Fixed );
57 initSizePolicy( QskSizePolicy::Fixed, QskSizePolicy::Minimum );
59 connect(
this, &QskSlider::boundariesChanged,
this, &QskSlider::moveHandle );
60 connect(
this, &QskSlider::valueChanged,
this, &QskSlider::moveHandle );
63QskSlider::~QskSlider()
67bool QskSlider::isPressed()
const
69 return hasSkinState( Pressed );
72void QskSlider::setOrientation( Qt::Orientation orientation )
74 if ( orientation != m_data->orientation )
76 m_data->orientation = orientation;
84 Q_EMIT orientationChanged( this->orientation() );
88Qt::Orientation QskSlider::orientation()
const
90 return static_cast< Qt::Orientation
>( m_data->orientation );
98void QskSlider::setGraduationPolicy( Qsk::Policy policy )
100 if (
setFlagHint( qskAspectGraduationPolicy(), policy ) )
101 Q_EMIT graduationPolicyChanged( graduationPolicy() );
104void QskSlider::resetGraduationPolicy()
107 Q_EMIT graduationPolicyChanged( graduationPolicy() );
110Qsk::Policy QskSlider::graduationPolicy()
const
112 return flagHint< Qsk::Policy >( qskAspectGraduationPolicy(), Qsk::Never );
115void QskSlider::setTracking(
bool on )
117 if ( on != m_data->tracking )
119 m_data->tracking = on;
120 Q_EMIT trackingChanged( on );
124bool QskSlider::isTracking()
const
126 return m_data->tracking;
131 setPositionHint( Handle, valueAsRatio() );
135QSizeF QskSlider::handleSize()
const
137 return handleRect().size();
140QRectF QskSlider::handleRect()
const
145 const QSizeF strutSize( 60, 60 );
146 const auto w = qMax( ( strutSize.width() -
rect.width() ) / 2, 0.0 );
147 const auto h = qMax( ( strutSize.height() -
rect.height() ) / 2, 0.0 );
150 return rect.marginsAdded( { w, h, w, h } );
153void QskSlider::mousePressEvent( QMouseEvent* event )
155 if ( handleRect().contains( event->pos() ) )
159 m_data->pressedPos =
event->pos();
160 m_data->pressedValue = value();
162 Q_EMIT pressedChanged(
true );
164 else if ( pageSteps() == 0 )
177void QskSlider::mouseMoveEvent( QMouseEvent* event )
182 const auto mousePos = qskMousePosition( event );
187 if ( m_data->orientation == Qt::Horizontal )
189 const auto distance = mousePos.x() - m_data->pressedPos.x();
190 newValue = m_data->pressedValue + distance / r.width() * boundaryLength();
194 const auto distance = mousePos.y() - m_data->pressedPos.y();
195 newValue = m_data->pressedValue - distance / r.height() * boundaryLength();
198 if ( m_data->tracking )
200 setValue( newValue );
208void QskSlider::mouseReleaseEvent( QMouseEvent* event )
212 const auto mousePos = qskMousePosition( event );
214 const auto szHandle = handleSize();
218 if ( m_data->orientation == Qt::Horizontal )
220 const qreal w = szHandle.width();
222 const qreal x = ( mousePos.x() -
rect.x() - w * 0.5 ) / (
rect.width() - w );
223 up = x > valueAsRatio();
227 const qreal h = szHandle.height();
229 const qreal y = ( mousePos.y() -
rect.y() - h * 0.5 ) / (
rect.height() - h );
230 up = y < 1.0 - valueAsRatio();
240 if ( !m_data->tracking )
242 const auto pos = handlePosition();
243 setValue( valueFromRatio( pos ) );
248 Q_EMIT pressedChanged(
false );
251qreal QskSlider::handlePosition()
const
253 return positionHint( Handle );
256void QskSlider::moveHandle()
259 moveHandleTo( value(),
animationHint( aspect | skinStates() ) );
264 const qreal pos = valueAsRatio( value );
266 if ( hint.isValid() )
268 const qreal oldPos = positionHint( Handle );
269 setPositionHint( Handle, pos );
272 startTransition( aspect, hint, oldPos, pos );
276 setPositionHint( Handle, pos );
282#include "moc_QskSlider.cpp"
Lookup key for a QskSkinHintTable.
Variation
Some sort of variation.
QRectF subControlRect(QskAspect::Subcontrol) const
void setSizePolicy(QskSizePolicy)
QRectF contentsRect() const
virtual void aboutToShow()
bool resetSkinHint(QskAspect)
Remove a hint from the local hint table.
QskAnimationHint animationHint(QskAspect, QskSkinHintStatus *=nullptr) const
void setSkinStateFlag(QskAspect::State, bool on=true)
bool setFlagHint(QskAspect, int flag)
Sets a flag hint.
QskAspect::Variation effectiveVariation() const override
void aboutToShow() override