tab button: Fix size hint

... and style properly for Material
This commit is contained in:
Peter Hartmann 2023-05-06 10:13:47 +02:00 committed by uwerat
parent 0c17aa3a81
commit d0934cb0fd
2 changed files with 16 additions and 39 deletions

View File

@ -984,7 +984,7 @@ void Editor::setupTabButton()
using A = QskAspect;
using Q = QskTabButton;
setStrutSize( Q::Panel, 48_dp, 48_dp );
setStrutSize( Q::Panel, 48_dp, 64_dp );
setGradient( Q::Panel, m_pal.surface );
setColor( Q::Text, m_pal.onSurfaceVariant );
@ -994,44 +994,15 @@ void Editor::setupTabButton()
setColor( Q::Text | Q::Checked, m_pal.primary );
setColor( Q::Text | Q::Hovered, m_pal.primary );
for ( const auto variation : { A::Left, A::Right, A::Top, A::Bottom } )
{
const auto aspect = Q::Panel | variation;
Qt::Edge edge;
switch( variation )
{
case A::Left:
edge = Qt::RightEdge;
break;
case A::Right:
edge = Qt::LeftEdge;
break;
case A::Top:
edge = Qt::BottomEdge;
break;
case A::Bottom:
edge = Qt::TopEdge;
break;
default:
edge = Qt::Edge( 0 ); // making gcc4 happy
}
QskBoxBorderMetrics border;
border.setWidthAt( edge, 3_dp );
setBoxBorderMetrics( aspect, border );
border.setWidthAt( Qt::BottomEdge, 3_dp );
setBoxBorderMetrics( Q::Panel, border );
QskBoxBorderColors borderColors( m_pal.surface );
setBoxBorderColors( aspect, borderColors );
setBoxBorderColors( Q::Panel, borderColors );
borderColors.setGradientAt( edge, m_pal.primary );
setBoxBorderColors( aspect | Q::Checked, borderColors );
}
borderColors.setGradientAt( Qt::BottomEdge, m_pal.primary );
setBoxBorderColors( Q::Panel | Q::Checked, borderColors );
setGradient( Q::Panel | Q::Hovered,
QskRgb::toTransparentF( m_pal.surface, m_pal.hoverOpacity ) );

View File

@ -57,20 +57,26 @@ QSGNode* QskTabButtonSkinlet::updateSubNode(
QSizeF QskTabButtonSkinlet::sizeHint( const QskSkinnable* skinnable,
Qt::SizeHint which, const QSizeF& ) const
{
using Q = QskTabButton;
if ( which != Qt::PreferredSize )
return QSizeF();
const auto tabButton = static_cast< const QskTabButton* >( skinnable );
auto size = tabButton->strutSizeHint( QskTabButton::Panel );
QSizeF size;
const auto text = tabButton->text();
if ( !text.isEmpty() )
{
const QFontMetricsF fm( tabButton->effectiveFont( QskTabButton::Text ) );
size += fm.size( Qt::TextShowMnemonic, text );
size = fm.size( Qt::TextShowMnemonic, text );
}
size = tabButton->outerBoxSize( Q::Panel, size );
size = size.expandedTo( tabButton->strutSizeHint( Q::Panel ) );
size = size.grownBy( skinnable->marginHint( Q::Panel ) );
return size;
}