mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-23 01:09:42 +01:00
* Properly center spinner.
This commit is contained in:
parent
246d935c04
commit
5d977d1ca7
@ -28,6 +28,9 @@
|
||||
#include <QtGui/QPaintEvent>
|
||||
#include <QtGui/QShowEvent>
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
|
||||
AnimatedSpinner::AnimatedSpinner( QWidget *parent )
|
||||
: QWidget( parent )
|
||||
, m_showHide( new QTimeLine )
|
||||
@ -89,11 +92,11 @@ AnimatedSpinner::init()
|
||||
size = m_pixmap.size();
|
||||
|
||||
/// Radius is best-fit line with points (13x13, 2), (28x28, 5), (48x48, 10)
|
||||
m_radius = qRound( ( 23. * ( size.width() - 5.) ) / 100. );
|
||||
m_armLength = size.width()/2 - m_radius;
|
||||
m_radius = qRound( ( 23. * ( size.width() - 5. ) ) / 100. );
|
||||
m_armLength = size.width() / 2 - m_radius;
|
||||
|
||||
/// Arm width is best-fit line with points (13x13, 1), (28x28, 2), (48x48, 5)
|
||||
m_armWidth = qRound( (116.*size.width() - 781.)/1000. );
|
||||
m_armWidth = qRound( ( 116. * size.width() - 781. ) / 1000. );
|
||||
m_border = 2;
|
||||
m_armRect = QRect( m_radius, 0, m_armLength, m_armWidth );
|
||||
|
||||
@ -107,7 +110,7 @@ AnimatedSpinner::paintEvent( QPaintEvent* event )
|
||||
Q_UNUSED( event );
|
||||
if ( m_autoCenter && parentWidget() )
|
||||
{
|
||||
QPoint center = parentWidget()->contentsRect().center();
|
||||
QPoint center = parentWidget()->contentsRect().center() - QPoint( sizeHint().width() / 2, sizeHint().height() / 2 );
|
||||
if ( center != pos() )
|
||||
{
|
||||
move( center );
|
||||
@ -143,8 +146,7 @@ AnimatedSpinner::drawFrame( QPainter* p, const QRect& rect )
|
||||
p->setOpacity( (qreal)m_showHide->currentValue() );
|
||||
}
|
||||
|
||||
p->setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
p->setRenderHint( QPainter::Antialiasing, true );
|
||||
p->translate( rect.center() + QPoint( 0, 1 ) ); // center
|
||||
|
||||
const qreal stepRadius = (360 + 2*m_armWidth) / segmentCount();
|
||||
@ -207,19 +209,17 @@ AnimatedSpinner::hideFinished()
|
||||
QSize
|
||||
AnimatedSpinner::sizeHint() const
|
||||
{
|
||||
return QSize(48, 48);
|
||||
return QSize( 48, 48 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AnimatedSpinner::frameChanged( int frame )
|
||||
{
|
||||
|
||||
if ( m_currentIndex == frame || frame > segmentCount()-1 )
|
||||
if ( m_currentIndex == frame || frame > segmentCount() - 1 )
|
||||
return;
|
||||
|
||||
m_currentIndex = frame;
|
||||
|
||||
Q_ASSERT( frame >= 0 && frame < m_colors.size() );
|
||||
|
||||
// calculate colors, save a factor from 1 to 0 behind the current item
|
||||
@ -251,7 +251,7 @@ AnimatedSpinner::colorForSegment( int seg ) const
|
||||
// Base color is 101, 101, 101
|
||||
Q_ASSERT( seg < m_colors.size() );
|
||||
const int comp = 101 + m_colors[seg] * ( 126 );
|
||||
return QColor(comp, comp, comp, 255);
|
||||
return QColor( comp, comp, comp, 255 );
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user