2017-07-21 18:21:34 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskSliderSkinlet.h"
|
2018-08-03 08:30:23 +02:00
|
|
|
#include "QskSlider.h"
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
#include "QskAspect.h"
|
2017-10-17 17:34:00 +02:00
|
|
|
#include "QskBoxBorderMetrics.h"
|
2017-07-21 18:21:34 +02:00
|
|
|
#include "QskFunctions.h"
|
|
|
|
|
2020-12-17 16:14:56 +01:00
|
|
|
static inline QRectF qskInnerPanelRect(
|
|
|
|
const QskSlider* slider, const QRectF& contentsRect )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2020-12-17 16:14:56 +01:00
|
|
|
using Q = QskSlider;
|
|
|
|
|
|
|
|
// QskSkinnable::innerBox ???
|
|
|
|
auto padding = slider->paddingHint( Q::Panel );
|
|
|
|
padding += slider->boxBorderMetricsHint( Q::Panel ).widths();
|
|
|
|
|
|
|
|
auto r = slider->subControlRect( contentsRect, Q::Panel );
|
|
|
|
r = r.marginsRemoved( padding );
|
|
|
|
|
|
|
|
return r;
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
QskSliderSkinlet::QskSliderSkinlet( QskSkin* skin )
|
|
|
|
: Inherited( skin )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
setNodeRoles( { PanelRole, GrooveRole, FillRole, HandleRole } );
|
|
|
|
}
|
|
|
|
|
2020-12-16 12:49:24 +01:00
|
|
|
QskSliderSkinlet::~QskSliderSkinlet()
|
|
|
|
{
|
|
|
|
}
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-04-25 14:23:39 +02:00
|
|
|
QRectF QskSliderSkinlet::subControlRect( const QskSkinnable* skinnable,
|
|
|
|
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
const auto slider = static_cast< const QskSlider* >( skinnable );
|
|
|
|
|
|
|
|
if ( subControl == QskSlider::Panel )
|
2017-09-01 11:55:55 +02:00
|
|
|
{
|
2019-04-25 14:23:39 +02:00
|
|
|
return panelRect( slider, contentsRect );
|
2017-09-01 11:55:55 +02:00
|
|
|
}
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
if ( subControl == QskSlider::Groove )
|
2017-09-01 11:55:55 +02:00
|
|
|
{
|
2019-04-25 14:23:39 +02:00
|
|
|
return grooveRect( slider, contentsRect );
|
2017-09-01 11:55:55 +02:00
|
|
|
}
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
if ( subControl == QskSlider::Fill )
|
2017-09-01 11:55:55 +02:00
|
|
|
{
|
2019-04-25 14:23:39 +02:00
|
|
|
return fillRect( slider, contentsRect );
|
2017-09-01 11:55:55 +02:00
|
|
|
}
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
if ( subControl == QskSlider::Handle )
|
2017-09-01 11:55:55 +02:00
|
|
|
{
|
2019-04-25 14:23:39 +02:00
|
|
|
return handleRect( slider, contentsRect );
|
2017-09-01 11:55:55 +02:00
|
|
|
}
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
if ( subControl == QskSlider::Scale )
|
2017-09-01 11:55:55 +02:00
|
|
|
{
|
2019-04-25 14:23:39 +02:00
|
|
|
return scaleRect( slider, contentsRect );
|
2017-09-01 11:55:55 +02:00
|
|
|
}
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2019-04-25 14:23:39 +02:00
|
|
|
return Inherited::subControlRect( skinnable, contentsRect, subControl );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2017-09-01 11:55:55 +02:00
|
|
|
QSGNode* QskSliderSkinlet::updateSubNode(
|
|
|
|
const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const
|
|
|
|
{
|
|
|
|
const auto slider = static_cast< const QskSlider* >( skinnable );
|
|
|
|
|
2018-08-03 08:15:28 +02:00
|
|
|
switch ( nodeRole )
|
2017-09-01 11:55:55 +02:00
|
|
|
{
|
|
|
|
case PanelRole:
|
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
return updateBoxNode( slider, node, QskSlider::Panel );
|
2017-09-01 11:55:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case GrooveRole:
|
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
return updateBoxNode( slider, node, QskSlider::Groove );
|
2017-09-01 11:55:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case FillRole:
|
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
return updateBoxNode( slider, node, QskSlider::Fill );
|
2017-09-01 11:55:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case HandleRole:
|
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
return updateBoxNode( slider, node, QskSlider::Handle );
|
2017-09-01 11:55:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Inherited::updateSubNode( skinnable, nodeRole, node );
|
|
|
|
}
|
|
|
|
|
2019-04-25 14:23:39 +02:00
|
|
|
QRectF QskSliderSkinlet::panelRect(
|
|
|
|
const QskSlider* slider, const QRectF& contentsRect ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2020-12-16 12:49:24 +01:00
|
|
|
auto r = contentsRect;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-12-16 12:49:24 +01:00
|
|
|
const qreal size = slider->metric( QskSlider::Panel | QskAspect::Size ); // 0: no hint
|
2017-07-21 18:21:34 +02:00
|
|
|
if ( size > 0 && size < r.height() )
|
|
|
|
{
|
2020-12-16 12:49:24 +01:00
|
|
|
const auto alignment = slider->alignmentHint( QskSlider::Panel );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
if ( slider->orientation() == Qt::Horizontal )
|
|
|
|
r = qskAlignedRectF( r, r.width(), size, alignment & Qt::AlignVertical_Mask );
|
|
|
|
else
|
|
|
|
r = qskAlignedRectF( r, size, r.height(), alignment & Qt::AlignHorizontal_Mask );
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2019-04-25 14:23:39 +02:00
|
|
|
QRectF QskSliderSkinlet::innerRect( const QskSlider* slider,
|
|
|
|
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2020-12-17 16:14:56 +01:00
|
|
|
auto r = qskInnerPanelRect( slider, contentsRect );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
QskSkinHintStatus status;
|
|
|
|
|
2020-12-15 07:21:12 +01:00
|
|
|
const qreal extent = slider->metric( subControl | QskAspect::Size, &status );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
if ( slider->orientation() == Qt::Horizontal )
|
|
|
|
{
|
2020-12-15 07:21:12 +01:00
|
|
|
if ( status.isValid() && ( extent < r.height() ) )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2020-12-15 07:21:12 +01:00
|
|
|
r.setTop( r.center().y() - 0.5 * extent );
|
|
|
|
r.setHeight( extent );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-15 07:21:12 +01:00
|
|
|
if ( status.isValid() && ( extent < r.width() ) )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2020-12-15 07:21:12 +01:00
|
|
|
r.setLeft( r.center().x() - 0.5 * extent );
|
|
|
|
r.setWidth( extent );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2019-04-25 14:23:39 +02:00
|
|
|
QRectF QskSliderSkinlet::grooveRect(
|
|
|
|
const QskSlider* slider, const QRectF& rect ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2019-04-25 14:23:39 +02:00
|
|
|
return innerRect( slider, rect, QskSlider::Groove );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2019-04-25 14:23:39 +02:00
|
|
|
QRectF QskSliderSkinlet::scaleRect(
|
|
|
|
const QskSlider* slider, const QRectF& rect ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2019-04-25 14:23:39 +02:00
|
|
|
return innerRect( slider, rect, QskSlider::Groove );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2019-04-25 14:23:39 +02:00
|
|
|
QRectF QskSliderSkinlet::fillRect(
|
|
|
|
const QskSlider* slider, const QRectF& contentsRect ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2020-12-17 16:14:56 +01:00
|
|
|
const auto r = qskInnerPanelRect( slider, contentsRect );
|
|
|
|
const auto pos = qBound( 0.0, slider->handlePosition(), 1.0 );
|
2020-12-16 12:49:24 +01:00
|
|
|
|
2020-12-17 16:14:56 +01:00
|
|
|
auto fillRect = innerRect( slider, contentsRect, QskSlider::Fill );
|
2017-07-21 18:21:34 +02:00
|
|
|
if ( slider->orientation() == Qt::Horizontal )
|
|
|
|
{
|
|
|
|
fillRect.setLeft( r.left() );
|
|
|
|
fillRect.setRight( r.left() + pos * r.width() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fillRect.setBottom( r.bottom() );
|
|
|
|
fillRect.setTop( r.bottom() - pos * r.height() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return fillRect;
|
|
|
|
}
|
|
|
|
|
2019-04-25 14:23:39 +02:00
|
|
|
QRectF QskSliderSkinlet::handleRect(
|
|
|
|
const QskSlider* slider, const QRectF& contentsRect ) const
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2020-12-15 07:21:12 +01:00
|
|
|
using Q = QskSlider;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-12-17 16:14:56 +01:00
|
|
|
auto handleSize = slider->strutSizeHint( Q::Handle );
|
|
|
|
const auto pos = qBound( 0.0, slider->handlePosition(), 1.0 );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-12-17 16:14:56 +01:00
|
|
|
const auto r = qskInnerPanelRect( slider, contentsRect );
|
|
|
|
auto center = r.center();
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-12-17 16:14:56 +01:00
|
|
|
if ( slider->orientation() == Qt::Horizontal )
|
2017-10-17 17:34:00 +02:00
|
|
|
{
|
2020-12-17 16:14:56 +01:00
|
|
|
if ( handleSize.height() < 0.0 )
|
|
|
|
handleSize.setHeight( r.height() );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-12-17 16:14:56 +01:00
|
|
|
if ( handleSize.width() < 0.0 )
|
|
|
|
handleSize.setWidth( handleSize.height() );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
2020-12-17 16:14:56 +01:00
|
|
|
center.setX( r.left() + pos * r.width() );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-17 16:14:56 +01:00
|
|
|
if ( handleSize.width() < 0.0 )
|
|
|
|
handleSize.setWidth( r.width() );
|
|
|
|
|
|
|
|
if ( handleSize.height() < 0.0 )
|
|
|
|
handleSize.setHeight( handleSize.width() );
|
|
|
|
|
|
|
|
center.setY( r.bottom() - pos * r.height() );
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2020-12-17 16:14:56 +01:00
|
|
|
QRectF handleRect( 0, 0, handleSize.width(), handleSize.height() );
|
|
|
|
handleRect.moveCenter( center );
|
|
|
|
|
|
|
|
handleRect = handleRect.marginsRemoved( slider->marginHint( Q::Handle ) );
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
return handleRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "moc_QskSliderSkinlet.cpp"
|