QskSwitchButton M3 fixes, using shadows instead of an additonal

subcontrol
This commit is contained in:
Uwe Rathmann 2024-10-25 11:37:34 +02:00
parent 635cd3c91f
commit 99b4bddac9
6 changed files with 58 additions and 77 deletions

View File

@ -481,15 +481,6 @@ void Editor::setupRadioBox()
setStrutSize( Q::CheckIndicatorPanel, 20_dp, 20_dp );
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
@ -508,6 +499,8 @@ void Editor::setupRadioBox()
{
const auto aspect = Q::CheckIndicatorPanel | state1 | state2;
setShadowMetrics( aspect, { 10_dp, 0 } );
QRgb rgb;
if ( state1 == Q::Hovered )
@ -1030,26 +1023,53 @@ void Editor::setupSwitchButton()
setBoxBorderMetrics( Q::Groove | Q::Checked, 0 );
setBoxShape( Q::Handle, 100, Qt::RelativeSize );
setStrutSize( Q::Handle, 16_dp, 16_dp );
setStrutSize( Q::Handle | Q::Checked, 24_dp, 24_dp,
{ QskStateCombination::CombinationNoState, Q::Disabled } );
setStrutSize( Q::Handle, 30_dp, 30_dp );
setMargin( Q::Handle, 7_dp );
setShadowMetrics( Q::Handle, { 17_dp, 0 } );
setShadowColor( Q::Handle, QskRgb::Transparent );
setGradient( Q::Handle, m_pal.outline );
setGradient( Q::Handle | Q::Checked, m_pal.primaryContainer );
setGradient( Q::Handle | Q::Checked, m_pal.onPrimary );
for ( auto state1 : { A::NoState, Q::Hovered, Q::Focused, Q::Pressed } )
{
const qreal opacity = m_pal.stateOpacity( state1 );
for ( const auto state2 : { A::NoState, Q::Checked } )
{
const auto aspect = Q::Handle | state1 | state2;
if ( state1 == Q::Pressed )
{
setShadowMetrics( aspect, { 10_dp, 0 } );
setMargin( aspect, 0.0 );
}
else if ( state2 == Q::Checked )
{
setShadowMetrics( aspect, { 13_dp, 0 } );
setMargin( aspect, 3_dp );
}
if ( state1 )
{
if ( state2 == Q::Checked )
{
setGradient( aspect, m_pal.primaryContainer );
setShadowColor( aspect, stateLayerColor( m_pal.primary, opacity ) );
}
else
{
setGradient( aspect, m_pal.onSurfaceVariant );
setShadowColor( aspect, stateLayerColor( m_pal.onSurface, opacity ) );
}
}
}
}
setGradient( Q::Handle | Q::Disabled, m_pal.onSurface38 );
setGradient( Q::Handle | Q::Disabled | Q::Checked, m_pal.surface );
// just to keep the strut size the same at all times:
setStrutSize( Q::Halo, 40_dp, 40_dp );
setGradient( Q::Halo, Qt::transparent );
setStrutSize( Q::Halo | Q::Hovered, 40_dp, 40_dp );
setBoxShape( Q::Halo, 100, Qt::RelativeSize );
setGradient( Q::Halo | Q::Hovered, stateLayerColor( m_pal.onSurface, m_pal.focusOpacity ) );
setGradient( Q::Halo | Q::Hovered | Q::Checked,
stateLayerColor( m_pal.primary, m_pal.focusOpacity ) );
setBoxBorderColors( Q::Handle, m_pal.outline );
setBoxBorderColors( Q::Handle | Q::Checked, m_pal.primary );
@ -1490,6 +1510,17 @@ QskMaterial3Theme::QskMaterial3Theme( QskSkin::ColorScheme colorScheme,
shapeExtraSmallTop = QskBoxShapeMetrics( 4_dp, 4_dp, 0, 0 );
}
qreal QskMaterial3Theme::stateOpacity( int state ) const
{
if ( state == QskControl::Hovered )
return hoverOpacity;
if ( state == QskControl::Focused )
return focusOpacity;
return state ? pressedOpacity : 0.0;
}
QskMaterial3Skin::QskMaterial3Skin( QObject* parent )
: Inherited( parent )
{

View File

@ -93,6 +93,8 @@ class QSK_MATERIAL3_EXPORT QskMaterial3Theme
const qreal pressedOpacity = 0.12;
const qreal draggedOpacity = 0.16;
qreal stateOpacity( int state ) const;
QskBoxShapeMetrics shapeExtraSmallTop;
};

View File

@ -7,7 +7,6 @@
QSK_SUBCONTROL( QskSwitchButton, Handle )
QSK_SUBCONTROL( QskSwitchButton, Groove )
QSK_SUBCONTROL( QskSwitchButton, Halo )
struct QskSwitchButton::PrivateData
{

View File

@ -22,7 +22,7 @@ class QSK_EXPORT QskSwitchButton : public QskAbstractButton
WRITE setInverted NOTIFY invertedChanged FINAL )
public:
QSK_SUBCONTROLS( Groove, Handle, Halo )
QSK_SUBCONTROLS( Groove, Handle )
QskSwitchButton( Qt::Orientation, QQuickItem* parent = nullptr );
QskSwitchButton( QQuickItem* parent = nullptr );

View File

@ -26,7 +26,7 @@ static inline qreal qskEffectivePosition( const QskSwitchButton* switchButton )
QskSwitchButtonSkinlet::QskSwitchButtonSkinlet( QskSkin* skin )
: Inherited( skin )
{
setNodeRoles( { GrooveRole, HandleRole, HaloRole } );
setNodeRoles( { GrooveRole, HandleRole } );
}
QskSwitchButtonSkinlet::~QskSwitchButtonSkinlet()
@ -48,12 +48,6 @@ QRectF QskSwitchButtonSkinlet::subControlRect( const QskSkinnable* skinnable,
return grooveRect( skinnable, contentsRect );
}
if ( subControl == Q::Halo )
{
return haloRect( skinnable, contentsRect );
}
return Inherited::subControlRect( skinnable, contentsRect, subControl );
}
@ -65,10 +59,8 @@ QSizeF QskSwitchButtonSkinlet::sizeHint( const QskSkinnable* skinnable,
const auto grooveHint = skinnable->strutSizeHint( QskSwitchButton::Groove );
const auto handleHint = skinnable->strutSizeHint( QskSwitchButton::Handle );
const auto haloHint = skinnable->strutSizeHint( QskSwitchButton::Halo );
auto hint = grooveHint;
hint = hint.expandedTo( haloHint );
hint = hint.expandedTo( handleHint );
return hint;
@ -81,9 +73,6 @@ QSGNode* QskSwitchButtonSkinlet::updateSubNode( const QskSkinnable* skinnable,
switch ( nodeRole )
{
case HaloRole:
return updateBoxNode( skinnable, node, Q::Halo );
case HandleRole:
return updateBoxNode( skinnable, node, Q::Handle );
@ -166,42 +155,4 @@ QRectF QskSwitchButtonSkinlet::handleRect(
return r;
}
QRectF QskSwitchButtonSkinlet::haloRect(
const QskSkinnable* skinnable, const QRectF& contentsRect ) const
{
using Q = QskSwitchButton;
const auto switchButton = static_cast< const Q* >( skinnable );
const auto grooveRect = subControlRect( skinnable, contentsRect, Q::Groove );
const auto pos = qskEffectivePosition( switchButton );
const auto sizeHandle = skinnable->strutSizeHint( Q::Handle );
const auto sizeHalo = skinnable->strutSizeHint( Q::Halo );
qreal cx, cy;
if( switchButton->orientation() == Qt::Vertical )
{
const qreal y0 = grooveRect.y() + 0.5 * sizeHandle.height();
const qreal h = grooveRect.height() - sizeHandle.height();
cx = grooveRect.x() + 0.5 * grooveRect.width();
cy = y0 + pos * h;
}
else
{
const qreal x0 = grooveRect.x() + 0.5 * sizeHandle.width();
const qreal w = grooveRect.width() - sizeHandle.width();
cx = x0 + pos * w;
cy = grooveRect.y() + 0.5 * grooveRect.height();
}
QRectF r;
r.setSize( sizeHalo );
r.moveCenter( QPointF( cx, cy ) );
return r;
}
#include "moc_QskSwitchButtonSkinlet.cpp"

View File

@ -19,7 +19,6 @@ class QSK_EXPORT QskSwitchButtonSkinlet : public QskSkinlet
{
GrooveRole,
HandleRole,
HaloRole,
RoleCount
};
@ -40,7 +39,6 @@ class QSK_EXPORT QskSwitchButtonSkinlet : public QskSkinlet
private:
QRectF grooveRect( const QskSkinnable*, const QRectF& ) const;
QRectF handleRect( const QskSkinnable*, const QRectF& ) const;
QRectF haloRect( const QskSkinnable*, const QRectF& ) const;
};
#endif