6#include "QskSliderSkinlet.h"
10#include "QskBoxBorderMetrics.h"
11#include "QskFunctions.h"
13#include <QFontMetricsF>
20 inline QRectF qskInnerPanelRect(
21 const QskSlider* slider,
const QRectF& contentsRect )
28 r = r.marginsRemoved( padding );
36 QRectF qskInnerValueRect(
const QskSlider* slider,
const QRectF& contentsRect )
41 const auto grooveIndicatorMargins = slider->
paddingHint( Q::GrooveStopIndicators );
42 const auto r = qskInnerPanelRect( slider, contentsRect ).marginsRemoved( grooveIndicatorMargins );
47QskSliderSkinlet::QskSliderSkinlet(
QskSkin* skin )
54 FillStopIndicatorsRole,
55 GrooveStopIndicatorsRole,
60QskSliderSkinlet::~QskSliderSkinlet()
64QRectF QskSliderSkinlet::subControlRect(
const QskSkinnable* skinnable,
67 const auto slider =
static_cast< const QskSlider*
>( skinnable );
69 if ( subControl == Q::Panel )
71 return panelRect( slider, contentsRect );
74 if ( subControl == Q::Groove )
76 return grooveRect( slider, contentsRect );
79 if ( subControl == Q::Fill )
81 return fillRect( slider, contentsRect );
84 if ( subControl == Q::Handle )
86 return handleRect( slider, contentsRect );
89 if ( subControl == Q::Scale )
91 return scaleRect( slider, contentsRect );
94 return Inherited::subControlRect( skinnable, contentsRect, subControl );
97int QskSliderSkinlet::sampleCount(
const QskSkinnable* skinnable,
100 const auto slider =
static_cast< const QskSlider*
>( skinnable );
104 const auto num = qCeil( slider->boundaryLength() / slider->stepSize() ) + 1;
109 return ( subControl == Q::GrooveStopIndicators ) ? 1 : 0;
113QRectF QskSliderSkinlet::sampleRect(
114 const QskSkinnable* skinnable,
const QRectF& contentsRect,
117 const auto slider =
static_cast< const QskSlider*
>( skinnable );
119 auto r = qskInnerValueRect( slider, contentsRect );
123 const auto filledPoints = qFloor( ( slider->value() - slider->minimum() ) / slider->stepSize() );
128 && ( ( index >= filledPoints && subControl == Q::FillStopIndicators )
129 || ( index < filledPoints && subControl == Q::GrooveStopIndicators ) ) )
135 const auto pos = slider->snap() ? slider->minimum() + index * slider->stepSize() : slider->maximum();
137 if( slider->orientation() == Qt::Horizontal )
139 r.setTop( r.center().y() - size.height() / 2 );
140 const auto x = r.left() + slider->valueAsRatio( pos ) * r.width() - size.width() / 2;
145 r.setLeft( r.center().x() - size.width() / 2 );
146 const auto y = r.bottom() - slider->valueAsRatio( pos ) * r.height() - size.height() / 2;
150 r.setHeight( size.height() );
151 r.setWidth( size.width() );
161QSGNode* QskSliderSkinlet::updateSubNode(
162 const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node )
const
164 const auto slider =
static_cast< const QskSlider*
>( skinnable );
170 return updateBoxNode( slider, node, Q::Panel );
175 return updateBoxNode( slider, node, Q::Groove );
180 return updateBoxNode( slider, node, Q::Fill );
183 case GrooveStopIndicatorsRole:
185 return updateSeriesNode( slider, Q::GrooveStopIndicators, node );
188 case FillStopIndicatorsRole:
190 return updateSeriesNode( slider, Q::FillStopIndicators, node );
195 return updateBoxNode( slider, node, Q::Handle );
199 return Inherited::updateSubNode( skinnable, nodeRole, node );
202QSGNode* QskSliderSkinlet::updateSampleNode(
const QskSkinnable* skinnable,
205 const auto slider =
static_cast< const QskSlider*
>( skinnable );
206 const auto rect = sampleRect( slider, slider->
contentsRect(), subControl, index );
208 return updateBoxNode( skinnable, node, rect, subControl );
211QRectF QskSliderSkinlet::panelRect(
212 const QskSlider* slider,
const QRectF& contentsRect )
const
214 auto r = contentsRect;
217 if ( size > 0 && size < r.height() )
221 if ( slider->orientation() == Qt::Horizontal )
222 r = qskAlignedRectF( r, r.width(), size, alignment & Qt::AlignVertical_Mask );
224 r = qskAlignedRectF( r, size, r.height(), alignment & Qt::AlignHorizontal_Mask );
230QRectF QskSliderSkinlet::innerRect(
const QskSlider* slider,
233 auto r = qskInnerPanelRect( slider, contentsRect );
239 if ( slider->orientation() == Qt::Horizontal )
241 if ( status.
isValid() && ( extent < r.height() ) )
243 r.setTop( r.center().y() - 0.5 * extent );
244 r.setHeight( extent );
249 if ( status.
isValid() && ( extent < r.width() ) )
251 r.setLeft( r.center().x() - 0.5 * extent );
252 r.setWidth( extent );
259QRectF QskSliderSkinlet::grooveRect(
260 const QskSlider* slider,
const QRectF& contentsRect )
const
262 const auto r = qskInnerPanelRect( slider, contentsRect );
263 auto grooveRect = innerRect( slider, contentsRect, Q::Groove );
266 if ( slider->orientation() == Qt::Horizontal )
268 grooveRect.setLeft( handleRect.right() );
269 grooveRect.setRight( r.right() );
273 grooveRect.setBottom( handleRect.top() );
274 grooveRect.setTop( r.top() );
280QRectF QskSliderSkinlet::scaleRect(
281 const QskSlider* slider,
const QRectF& rect )
const
283 return innerRect( slider, rect, Q::Groove );
286QRectF QskSliderSkinlet::fillRect(
287 const QskSlider* slider,
const QRectF& contentsRect )
const
289 const auto r = qskInnerPanelRect( slider, contentsRect );
292 auto fillRect = innerRect( slider, contentsRect, Q::Fill );
293 if ( slider->orientation() == Qt::Horizontal )
295 fillRect.setLeft( r.left() );
296 fillRect.setRight( handleRect.left() );
300 fillRect.setBottom( r.bottom() );
301 fillRect.setTop( handleRect.bottom() );
307QRectF QskSliderSkinlet::handleRect(
308 const QskSlider* slider,
const QRectF& contentsRect )
const
311 const auto pos = qBound( 0.0, slider->handlePosition(), 1.0 );
313 const auto r = qskInnerValueRect( slider, contentsRect );
314 auto center = r.center();
316 if ( slider->orientation() == Qt::Horizontal )
318 if ( handleSize.height() < 0.0 )
319 handleSize.setHeight( r.height() );
321 if ( handleSize.width() < 0.0 )
322 handleSize.setWidth( handleSize.height() );
324 center.setX( r.left() + pos * r.width() );
328 if ( handleSize.width() < 0.0 )
329 handleSize.setWidth( r.width() );
331 if ( handleSize.height() < 0.0 )
332 handleSize.setHeight( handleSize.width() );
334 center.setY( r.bottom() - pos * r.height() );
337 QRectF handleRect( 0, 0, handleSize.width(), handleSize.height() );
338 handleRect.moveCenter( center );
340 handleRect = handleRect.marginsRemoved( slider->
marginHint( Q::Handle ) );
345QSizeF QskSliderSkinlet::sizeHint(
const QskSkinnable* skinnable,
346 Qt::SizeHint which,
const QSizeF& )
const
348 if ( which != Qt::PreferredSize )
352 const auto grooveHint = skinnable->
strutSizeHint( Q::Groove );
354 const auto handleHint = skinnable->
strutSizeHint( Q::Handle );
356 auto hint = panelHint;
357 hint = hint.expandedTo( grooveHint );
358 hint = hint.expandedTo( fillHint );
359 hint = hint.expandedTo( handleHint );
364#include "moc_QskSliderSkinlet.cpp"
Subcontrol
For use within the rendering or lay-outing of a specific QskSkinnable.
QRectF subControlRect(QskAspect::Subcontrol) const
QRectF subControlContentsRect(QskAspect::Subcontrol) const
QRectF contentsRect() const
QMarginsF paddingHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a padding hint.
QMarginsF marginHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a margin hint.
QSizeF strutSizeHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a strut size hint.
QskBoxBorderMetrics boxBorderMetricsHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a border hint.
qreal metric(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a metric hint.
Qt::Alignment alignmentHint(QskAspect, Qt::Alignment=Qt::Alignment()) const
Retrieves an alignment hint.