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 ); 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 setBoxShape( subControl, 100, Qt::RelativeSize ); // circular
setBoxBorderMetrics( Q::CheckIndicatorPanel, 1_dp ); setBoxBorderMetrics( Q::CheckIndicatorPanel, 1_dp );

View File

@ -480,9 +480,17 @@ void Editor::setupRadioBox()
setSpacing( Q::Button, 10_dp ); setSpacing( Q::Button, 10_dp );
setStrutSize( Q::CheckIndicatorPanel, 20_dp, 20_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 setBoxShape( subControl, 100, Qt::RelativeSize ); // circular
setBoxBorderMetrics( Q::CheckIndicatorPanel, 2_dp ); setBoxBorderMetrics( Q::CheckIndicatorPanel, 2_dp );
@ -494,9 +502,39 @@ void Editor::setupRadioBox()
setColor( Q::Text, m_pal.onBackground ); setColor( Q::Text, m_pal.onBackground );
setColor( Q::Text | Q::Disabled, m_pal.onSurface38 ); setColor( Q::Text | Q::Disabled, m_pal.onSurface38 );
setColor( Q::Halo, stateLayerColor( m_pal.onSurface, m_pal.focusOpacity ) ); for ( const auto state1 : { Q::Hovered, Q::Focused, Q::Pressed } )
setColor( Q::Halo | Q::Selected, {
stateLayerColor( m_pal.primary, m_pal.focusOpacity ) ); for ( const auto state2 : { A::NoState, Q::Selected } )
{
const auto aspect = Q::CheckIndicatorPanel | state1 | state2;
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, Qt::transparent );
setColor( Q::CheckIndicator | Q::Selected, m_pal.primary ); setColor( Q::CheckIndicator | Q::Selected, m_pal.primary );
@ -509,7 +547,7 @@ void Editor::setupRadioBox()
setBoxBorderColors( setBoxBorderColors(
Q::CheckIndicatorPanel | Q::Disabled | Q::Selected, m_pal.onSurface38 ); 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() void Editor::setupFocusIndicator()

View File

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

View File

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

View File

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

View File

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