fix horizontal page indicators

This commit is contained in:
Peter Hartmann 2021-10-25 09:32:32 +02:00
parent a00513ebf7
commit 4f2c87acb0
1 changed files with 22 additions and 10 deletions

View File

@ -62,6 +62,9 @@ QRectF QskPageIndicatorSkinlet::bulletRect(
const qreal wNormal = szNormal.width(); const qreal wNormal = szNormal.width();
const qreal wHighlighted = szHighlighted.width(); const qreal wHighlighted = szHighlighted.width();
const qreal hNormal = szNormal.height();
const qreal hHighlighted = szHighlighted.height();
const auto currentIndex = indicator->currentIndex(); const auto currentIndex = indicator->currentIndex();
// scale bullet size if we are in between a transition: // scale bullet size if we are in between a transition:
@ -69,9 +72,12 @@ QRectF QskPageIndicatorSkinlet::bulletRect(
if ( indexDiff > ( indicator->count() - 1 ) ) if ( indexDiff > ( indicator->count() - 1 ) )
indexDiff = ( indicator->count() - currentIndex ); // wrapping indexDiff = ( indicator->count() - currentIndex ); // wrapping
const qreal sz0 = ( indexDiff < 1 ) ? const qreal w0 = ( indexDiff < 1 ) ?
( 1 - indexDiff ) * wHighlighted + indexDiff * wNormal : wNormal; ( 1 - indexDiff ) * wHighlighted + indexDiff * wNormal : wNormal;
const qreal h0 = ( indexDiff < 1 ) ?
( 1 - indexDiff ) * hHighlighted + indexDiff * hNormal : hNormal;
const qreal spacing = indicator->spacingHint( Q::Panel ); const qreal spacing = indicator->spacingHint( Q::Panel );
const bool horizontal = ( indicator->orientation() == Qt::Horizontal ); const bool horizontal = ( indicator->orientation() == Qt::Horizontal );
@ -84,20 +90,23 @@ QRectF QskPageIndicatorSkinlet::bulletRect(
else else
{ {
w = rect.width(); w = rect.width();
h = ( indicator->count() - 1 ) * ( wNormal + spacing ) + wHighlighted; h = ( indicator->count() - 1 ) * ( hNormal + spacing ) + hHighlighted;
} }
QRectF r( 0, 0, w, h ); QRectF r( 0, 0, w, h );
r.moveCenter( rect.center() ); r.moveCenter( rect.center() );
qreal s2; qreal x2, y2;
{ {
const qreal s = ( index > currentIndex ) ? wHighlighted : wNormal; const qreal w = ( index > currentIndex ) ? wHighlighted : wNormal;
const qreal h = ( index > currentIndex ) ? hHighlighted : hNormal;
if ( indexDiff < 1 && index >= currentIndex ) if ( indexDiff < 1 && index >= currentIndex )
{ {
// scrolling from or to this bullet: // scrolling from or to this bullet:
s2 = wNormal + qAbs( wHighlighted - wNormal ) * indexDiff; x2 = wNormal + qAbs( wHighlighted - wNormal ) * indexDiff;
y2 = hNormal + qAbs( hHighlighted - hNormal ) * indexDiff;
} }
else if ( ( currentIndex > ( indicator->count() - 1 ) && else if ( ( currentIndex > ( indicator->count() - 1 ) &&
index > ( currentIndex - indicator->count() + 1 ) ) ) index > ( currentIndex - indicator->count() + 1 ) ) )
@ -107,15 +116,18 @@ QRectF QskPageIndicatorSkinlet::bulletRect(
while ( wrappingDiff > 1 ) while ( wrappingDiff > 1 )
wrappingDiff -= 1; wrappingDiff -= 1;
s2 = wNormal + qAbs( wHighlighted - wNormal ) * wrappingDiff; x2 = wNormal + qAbs( wHighlighted - wNormal ) * wrappingDiff;
y2 = hNormal + qAbs( hHighlighted - hNormal ) * wrappingDiff;
} }
else else
{ {
s2 = s; x2 = w;
y2 = h;
} }
} }
const qreal x = r.left() + s2 + spacing + ( index - 1 ) * ( wNormal + spacing ); const qreal x = r.left() + x2 + spacing + ( index - 1 ) * ( wNormal + spacing );
const qreal y = r.top() + y2 + spacing + ( index - 1 ) * ( hNormal + spacing );
qreal adjust = ( currentIndex == index ) qreal adjust = ( currentIndex == index )
? ( wNormal - wHighlighted ) : ( wHighlighted - wNormal ); ? ( wNormal - wHighlighted ) : ( wHighlighted - wNormal );
@ -124,12 +136,12 @@ QRectF QskPageIndicatorSkinlet::bulletRect(
if ( indexDiff < 1 ) if ( indexDiff < 1 )
adjust *= indexDiff; adjust *= indexDiff;
QRectF bulletRect( 0.0, 0.0, sz0, szNormal.height() ); QRectF bulletRect( 0.0, 0.0, w0, h0 );
if ( horizontal ) if ( horizontal )
bulletRect.moveTo( x, r.top() + adjust ); bulletRect.moveTo( x, r.top() + adjust );
else else
bulletRect.moveTo( r.left() + adjust, x ); bulletRect.moveTo( r.left() + adjust, y );
return bulletRect; return bulletRect;
} }