qskinny/examples/gallery/slider/CustomSlider.cpp

63 lines
1.8 KiB
C++
Raw Normal View History

2019-06-20 12:02:28 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
2020-08-11 17:56:53 +02:00
#include "CustomSlider.h"
#include "CustomSliderSkinlet.h"
2017-07-21 18:21:34 +02:00
2018-08-03 08:15:28 +02:00
#include <QskAnimationHint.h>
2017-07-21 18:21:34 +02:00
#include <QskAspect.h>
2017-10-20 20:26:39 +02:00
#include <QskBoxShapeMetrics.h>
#include <QskGradient.h>
2018-08-03 08:15:28 +02:00
#include <QskRgbValue.h>
2017-07-21 18:21:34 +02:00
2020-08-11 17:56:53 +02:00
QSK_SUBCONTROL( CustomSlider, Scale )
QSK_SUBCONTROL( CustomSlider, Decoration )
2017-07-21 18:21:34 +02:00
2020-08-11 17:56:53 +02:00
CustomSlider::CustomSlider( QQuickItem* parentItem )
2018-08-03 08:15:28 +02:00
: QskSlider( parentItem )
2017-07-21 18:21:34 +02:00
{
2020-12-17 08:50:35 +01:00
using namespace QskRgb;
2017-10-20 20:26:39 +02:00
setBoxShapeHint( Fill, 0 );
2020-12-17 08:50:35 +01:00
setGradientHint( Fill, Grey700 );
setColor( Scale, qRgb( 178, 178, 178 ) ); // for the ticks
2017-07-21 18:21:34 +02:00
2020-12-17 16:14:56 +01:00
setStrutSizeHint( Handle, 80, 80 );
2020-12-17 08:50:35 +01:00
setColor( Handle, Grey800 );
2017-07-21 18:21:34 +02:00
for ( auto state : { Pressed, Focused | Hovered, Hovered, Focused } )
2020-12-17 08:50:35 +01:00
setColor( Handle | state, Orange600 );
2017-07-21 18:21:34 +02:00
setAnimation( QskSlider::Handle | QskAspect::Color, 1000 );
for ( auto state : { Focused | Hovered, Hovered, Focused } )
setAnimation( QskSlider::Handle | QskAspect::Color | state, 300 );
2017-07-21 18:21:34 +02:00
// using an individual skinlet, not known by the skin
2020-08-11 17:56:53 +02:00
auto skinlet = new CustomSliderSkinlet();
2017-07-21 18:21:34 +02:00
skinlet->setOwnedBySkinnable( true );
setSkinlet( skinlet );
connect( this, &QskSlider::valueChanged,
this, &QskControl::focusIndicatorRectChanged );
2017-07-21 18:21:34 +02:00
}
2020-08-11 17:56:53 +02:00
QSizeF CustomSlider::contentsSizeHint(
Qt::SizeHint which, const QSizeF& constraint ) const
2017-07-21 18:21:34 +02:00
{
auto size = Inherited::contentsSizeHint( which, constraint );
if ( which == Qt::PreferredSize && size.height() >= 0 )
size.setHeight( size.height() + 40 );
return size;
2017-07-21 18:21:34 +02:00
}
2020-08-11 17:56:53 +02:00
QRectF CustomSlider::focusIndicatorRect() const
{
2020-12-17 08:50:35 +01:00
return subControlRect( Handle );
}