minor QskPageIndicator cleanups

This commit is contained in:
Uwe Rathmann 2017-09-01 13:09:24 +02:00
parent 8ba11e2136
commit 8d80b6acc1
3 changed files with 15 additions and 28 deletions

View File

@ -102,8 +102,8 @@ QSizeF QskPageIndicator::contentsSizeHint() const
{ {
using namespace QskAspect; using namespace QskAspect;
const QSizeF sizeBullet = bulletSize( Bullet ); const qreal sizeBullet = metric( Bullet | Size );
const QSizeF sizeCurrent = bulletSize( Highlighted ); const qreal sizeCurrent = metric( Highlighted | Size );
const qreal spacing = metric( Panel | Spacing ); const qreal spacing = metric( Panel | Spacing );
const int n = m_data->count; const int n = m_data->count;
@ -115,39 +115,33 @@ QSizeF QskPageIndicator::contentsSizeHint() const
{ {
if ( n > 0 ) if ( n > 0 )
{ {
w += qMax( sizeCurrent.width(), sizeBullet.width() ); w += qMax( sizeCurrent, sizeBullet );
if ( n > 1 ) if ( n > 1 )
w += ( n - 1 ) * ( sizeBullet.width() + spacing ); w += ( n - 1 ) * ( sizeBullet + spacing );
} }
h = qMax( sizeCurrent.height(), sizeBullet.height() ); h = qMax( sizeCurrent, sizeBullet );
} }
else else
{ {
if ( n > 0 ) if ( n > 0 )
{ {
h += qMax( sizeCurrent.height(), sizeBullet.height() ); h += qMax( sizeCurrent, sizeBullet );
if ( n > 1 ) if ( n > 1 )
h += ( n - 1 ) * ( sizeBullet.height() + spacing ); h += ( n - 1 ) * ( sizeBullet + spacing );
} }
w = qMax( sizeCurrent.width(), sizeBullet.width() ); w = qMax( sizeCurrent, sizeBullet );
} }
const QSizeF minSize( const QSizeF minSize(
metric( Panel | QskAspect::MinimumWidth ), metric( Panel | MinimumWidth ),
metric( Panel | QskAspect::MinimumHeight ) ); metric( Panel | MinimumHeight ) );
return outerBoxSize( Panel, QSizeF( w, h ) ).expandedTo( minSize ); return outerBoxSize( Panel, QSizeF( w, h ) ).expandedTo( minSize );
} }
QSizeF QskPageIndicator::bulletSize( QskAspect::Subcontrol subControl ) const
{
const qreal dim = metric( subControl | QskAspect::Size );
return QSizeF( dim, dim );
}
#include "moc_QskPageIndicator.cpp" #include "moc_QskPageIndicator.cpp"

View File

@ -36,8 +36,6 @@ public:
virtual QSizeF contentsSizeHint() const override; virtual QSizeF contentsSizeHint() const override;
QSizeF bulletSize( QskAspect::Subcontrol ) const;
Q_SIGNALS: Q_SIGNALS:
void countChanged(); void countChanged();
void currentIndexChanged(); void currentIndexChanged();

View File

@ -54,11 +54,8 @@ QSGNode* QskPageIndicatorSkinlet::updateSubNode( const QskSkinnable* skinnable,
QRectF QskPageIndicatorSkinlet::bulletRect( QRectF QskPageIndicatorSkinlet::bulletRect(
const QskPageIndicator* indicator, const QRectF& rect, int index ) const const QskPageIndicator* indicator, const QRectF& rect, int index ) const
{ {
#if 1 const qreal szNormal = indicator->metric( QskPageIndicator::Bullet | QskAspect::Size );
// ignoring, that width/height might differ !!! const qreal szHighlighted = indicator->metric( QskPageIndicator::Highlighted | QskAspect::Size );
const qreal szNormal = indicator->bulletSize( QskPageIndicator::Bullet ).width();
const qreal szHighlighted = indicator->bulletSize( QskPageIndicator::Highlighted ).width();
#endif
// scale bullet size if we are in between a transition: // scale bullet size if we are in between a transition:
qreal indexDiff = qAbs( indicator->currentIndex() - index ); qreal indexDiff = qAbs( indicator->currentIndex() - index );
@ -82,29 +79,27 @@ QRectF QskPageIndicatorSkinlet::bulletRect(
w = rect.width(); w = rect.width();
h = ( indicator->count() - 1 ) * ( szNormal + spacing ) + szHighlighted; h = ( indicator->count() - 1 ) * ( szNormal + spacing ) + szHighlighted;
} }
QRectF r( 0, 0, w, h ); QRectF r( 0, 0, w, h );
r.moveCenter( rect.center() ); r.moveCenter( rect.center() );
// x-adjust (in horizontal mode) when not scrolling:
const qreal s = ( index > indicator->currentIndex() ) ? szHighlighted : szNormal; const qreal s = ( index > indicator->currentIndex() ) ? szHighlighted : szNormal;
// adapt x-adjust while scrolling:
qreal s2; qreal s2;
// scrolling from or to this bullet:
if ( indexDiff < 1 && index >= indicator->currentIndex() ) if ( indexDiff < 1 && index >= indicator->currentIndex() )
{ {
// scrolling from or to this bullet:
s2 = szNormal + qAbs( szHighlighted - szNormal ) * indexDiff; s2 = szNormal + qAbs( szHighlighted - szNormal ) * indexDiff;
} }
// wrapping case:
else if ( ( indicator->currentIndex() > ( indicator->count() - 1 ) && else if ( ( indicator->currentIndex() > ( indicator->count() - 1 ) &&
index > ( indicator->currentIndex() - indicator->count() + 1 ) ) ) index > ( indicator->currentIndex() - indicator->count() + 1 ) ) )
{ {
// wrapping case:
qreal wrappingDiff = indexDiff; qreal wrappingDiff = indexDiff;
while ( wrappingDiff > 1 ) while ( wrappingDiff > 1 )
wrappingDiff -= 1; wrappingDiff -= 1;
s2 = szNormal + qAbs( szHighlighted - szNormal ) * wrappingDiff; s2 = szNormal + qAbs( szHighlighted - szNormal ) * wrappingDiff;
} }
// unrelated bullet:
else else
{ {
s2 = s; s2 = s;