QskRadioBox: using the shadow ( instead of an additional Halo subcontrol )

This commit is contained in:
Uwe Rathmann 2024-10-24 12:15:02 +02:00
parent 1258c17534
commit 635cd3c91f
6 changed files with 57 additions and 53 deletions

View File

@ -489,7 +489,7 @@ void Editor::setupRadioBox()
setStrutSize( Q::CheckIndicatorPanel, 20_dp, 20_dp );
for ( auto subControl : { Q::CheckIndicatorPanel, Q::CheckIndicator, Q::Halo } )
for ( auto subControl : { Q::CheckIndicatorPanel, Q::CheckIndicator } )
setBoxShape( subControl, 100, Qt::RelativeSize ); // circular
setBoxBorderMetrics( Q::CheckIndicatorPanel, 1_dp );

View File

@ -480,9 +480,17 @@ void Editor::setupRadioBox()
setSpacing( Q::Button, 10_dp );
setStrutSize( Q::CheckIndicatorPanel, 20_dp, 20_dp );
setStrutSize( Q::Halo, 40_dp, 40_dp );
for ( auto subControl : { Q::CheckIndicatorPanel, Q::CheckIndicator, Q::Halo } )
for ( const auto state1 : { Q::Hovered, Q::Focused, Q::Pressed } )
{
for ( const auto state2 : { A::NoState, Q::Selected } )
{
const auto aspect = Q::CheckIndicatorPanel | state1 | state2;
setShadowMetrics( aspect, { 10_dp, 0 } );
}
}
for ( auto subControl : { Q::CheckIndicatorPanel, Q::CheckIndicator } )
setBoxShape( subControl, 100, Qt::RelativeSize ); // circular
setBoxBorderMetrics( Q::CheckIndicatorPanel, 2_dp );
@ -494,11 +502,41 @@ void Editor::setupRadioBox()
setColor( Q::Text, m_pal.onBackground );
setColor( Q::Text | Q::Disabled, m_pal.onSurface38 );
setColor( Q::Halo, stateLayerColor( m_pal.onSurface, m_pal.focusOpacity ) );
setColor( Q::Halo | Q::Selected,
stateLayerColor( m_pal.primary, m_pal.focusOpacity ) );
for ( const auto state1 : { Q::Hovered, Q::Focused, Q::Pressed } )
{
for ( const auto state2 : { A::NoState, Q::Selected } )
{
const auto aspect = Q::CheckIndicatorPanel | state1 | state2;
setColor( Q::CheckIndicator, Qt::transparent);
QRgb rgb;
if ( state1 == Q::Hovered )
{
rgb = ( state2 == Q::Selected ) ? m_pal.primary8 : m_pal.onSurface8;
rgb = stateLayerColor( rgb, m_pal.hoverOpacity );
setShadowColor( aspect, rgb );
}
else if ( state1 == Q::Focused )
{
rgb = ( state2 == Q::Selected ) ? m_pal.primary12 : m_pal.onSurface12;
rgb = stateLayerColor( rgb, m_pal.focusOpacity );
setShadowColor( aspect, rgb );
}
else
{
rgb = ( state2 == Q::Selected ) ? m_pal.onSurface12 : m_pal.primary12;
rgb = stateLayerColor( rgb, m_pal.pressedOpacity );
setShadowColor( aspect, rgb );
setShadowColor( aspect | Q::Focused, rgb );
}
}
}
setColor( Q::CheckIndicator, Qt::transparent );
setColor( Q::CheckIndicator | Q::Selected, m_pal.primary );
setColor( Q::CheckIndicator | Q::Selected | Q::Disabled, m_pal.onSurface38 );
@ -509,7 +547,7 @@ void Editor::setupRadioBox()
setBoxBorderColors(
Q::CheckIndicatorPanel | Q::Disabled | Q::Selected, m_pal.onSurface38 );
setAnimation( Q::Halo | A::Metric | A::Position, qskDuration );
setAnimation( Q::CheckIndicator | A::Metric | A::Position, qskDuration );
}
void Editor::setupFocusIndicator()
@ -1484,7 +1522,7 @@ static inline QFont createFont( int pointSize, int lineHeight,
}
checkFont = false;
}
font.setPixelSize( pixelSize );
if ( spacing > 0.0 )

View File

@ -13,7 +13,6 @@ QSK_SUBCONTROL( QskRadioBox, Button )
QSK_SUBCONTROL( QskRadioBox, CheckIndicatorPanel )
QSK_SUBCONTROL( QskRadioBox, CheckIndicator )
QSK_SUBCONTROL( QskRadioBox, Text )
QSK_SUBCONTROL( QskRadioBox, Halo )
QSK_STATE( QskRadioBox, Selected, QskAspect::FirstUserState << 1 )
QSK_STATE( QskRadioBox, Pressed, QskAspect::FirstUserState << 2 )
@ -38,7 +37,7 @@ QskRadioBox::QskRadioBox( QQuickItem* parent )
setFocusPolicy( Qt::StrongFocus );
setAcceptedMouseButtons( Qt::LeftButton );
setPositionHint( Halo, -1 );
setPositionHint( CheckIndicator, -1 );
setAcceptHoverEvents( true );
}
@ -182,7 +181,7 @@ void QskRadioBox::keyPressEvent( QKeyEvent* event )
{
setFocusedIndex( nextTabIndex );
const auto aspect = Halo | QskAspect::Metric | QskAspect::Position;
const auto aspect = CheckIndicator | QskAspect::Metric | QskAspect::Position;
const auto hint = animationHint( aspect | skinStates() );
if( hint.isValid() )
@ -277,7 +276,7 @@ void QskRadioBox::setHoveredIndex( int index )
return;
m_data->hoveredIndex = index;
setPositionHint( Halo | Hovered, index );
setPositionHint( CheckIndicator | Hovered, index );
update();
}
@ -288,7 +287,7 @@ void QskRadioBox::setFocusedIndex( int index )
return;
m_data->focusedIndex = index;
setPositionHint( Halo, index );
setPositionHint( CheckIndicator, index );
update();

View File

@ -22,7 +22,7 @@ class QSK_EXPORT QskRadioBox : public QskControl
using Inherited = QskControl;
public:
QSK_SUBCONTROLS( Panel, Button, CheckIndicatorPanel, CheckIndicator, Text, Halo )
QSK_SUBCONTROLS( Panel, Button, CheckIndicatorPanel, CheckIndicator, Text )
QSK_STATES( Selected, Pressed )
QskRadioBox( QQuickItem* parent = nullptr );

View File

@ -40,7 +40,7 @@ namespace
QskRadioBoxSkinlet::QskRadioBoxSkinlet( QskSkin* )
{
setNodeRoles( { PanelRole, ButtonRole, CheckPanelRole,
CheckIndicatorRole, TextRole, HaloRole } );
CheckIndicatorRole, TextRole } );
}
QskRadioBoxSkinlet::~QskRadioBoxSkinlet()
@ -50,12 +50,8 @@ QskRadioBoxSkinlet::~QskRadioBoxSkinlet()
QRectF QskRadioBoxSkinlet::subControlRect( const QskSkinnable* skinnable,
const QRectF& contentsRect, QskAspect::Subcontrol subcontrol ) const
{
using Q = QskRadioBox;
auto radioBox = static_cast< const QskRadioBox* >( skinnable );
if( subcontrol == Q::Halo )
return haloRect( radioBox, contentsRect );
Q_UNUSED( skinnable );
Q_UNUSED( subcontrol );
return contentsRect;
}
@ -81,9 +77,6 @@ QSGNode* QskRadioBoxSkinlet::updateSubNode( const QskSkinnable* skinnable,
case TextRole:
return updateSeriesNode( skinnable, Q::Text, node );
case HaloRole:
return updateBoxNode( skinnable, node, Q::Halo );
}
return Inherited::updateSubNode( skinnable, nodeRole, node );
@ -96,29 +89,6 @@ int QskRadioBoxSkinlet::sampleCount(
return radioBox->options().count();
}
QRectF QskRadioBoxSkinlet::haloRect(
const QskRadioBox* radioBox, const QRectF& rect ) const
{
using Q = QskRadioBox;
const auto index = qFloor( radioBox->positionHint( Q::Halo ) );
if( index < 0 )
return QRectF();
QRectF r;
r.setSize( radioBox->strutSizeHint( Q::Halo ) );
if ( !r.isEmpty() )
{
const auto checkBoxRect = sampleRect(
radioBox, rect, Q::CheckIndicatorPanel, index );
r.moveCenter( checkBoxRect.center() );
}
return r;
}
QRectF QskRadioBoxSkinlet::buttonRect(
const QskRadioBox* radioBox, const QRectF& rect, int index ) const
{
@ -219,12 +189,12 @@ QskAspect::States QskRadioBoxSkinlet::sampleStates(
states |= Q::Pressed;
#if 1
if( radioBox->positionHint( Q::Halo | Q::Hovered ) == index )
if( radioBox->positionHint( Q::CheckIndicator | Q::Hovered ) == index )
states |= Q::Hovered;
else
states &= ~Q::Hovered;
if( radioBox->positionHint( Q::Halo ) == index )
if( radioBox->positionHint( Q::CheckIndicator ) == index )
states |= Q::Focused;
else
states &= ~Q::Focused;

View File

@ -24,7 +24,6 @@ class QSK_EXPORT QskRadioBoxSkinlet : public QskSkinlet
CheckPanelRole,
CheckIndicatorRole,
TextRole,
HaloRole,
RoleCount
};
@ -57,8 +56,6 @@ class QSK_EXPORT QskRadioBoxSkinlet : public QskSkinlet
QRectF textRect( const QskRadioBox*, const QRectF&, int ) const;
QRectF checkPanelRect( const QskRadioBox*, const QRectF&, int index ) const;
QRectF buttonRect( const QskRadioBox*, const QRectF&, int index ) const;
QRectF haloRect( const QskRadioBox*, const QRectF& ) const;
};
#endif