1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 07:19:42 +01:00

* Center overlay widgets before showing them the first time.

This commit is contained in:
Christian Muehlhaeuser 2011-11-27 01:11:21 +01:00
parent b86c0f5c5e
commit 956243e570
3 changed files with 20 additions and 25 deletions

View File

@ -37,7 +37,7 @@ LoadingSpinner::LoadingSpinner( QWidget* parent )
m_showHide->setDuration( 300 );
m_showHide->setStartFrame( 0 );
m_showHide->setEndFrame( 100 );
m_showHide->setUpdateInterval( 20 );
m_showHide->setUpdateInterval( 20 );
connect( m_showHide, SIGNAL( frameChanged( int ) ), this, SLOT( update() ) );
connect( m_showHide, SIGNAL( finished() ), this, SLOT( hideFinished() ) );
@ -45,6 +45,7 @@ LoadingSpinner::LoadingSpinner( QWidget* parent )
connect( m_anim, SIGNAL( frameChanged( int ) ), this, SLOT( update() ) );
resize( 31, 31 );
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
hide();
}
@ -99,34 +100,24 @@ LoadingSpinner::sizeHint() const
}
void
LoadingSpinner::resizeEvent( QResizeEvent* )
{
reposition();
}
void
LoadingSpinner::reposition()
{
if( !parentWidget() )
return;
int x = ( parentWidget()->width() / 2 ) - ( width() / 2 );
int y = ( parentWidget()->height() / 2 ) - ( height() / 2 );
move( x, y );
resize( 31, 31 );
}
void
LoadingSpinner::paintEvent( QPaintEvent* ev )
{
Q_UNUSED( ev );
if ( !parentWidget() )
return;
QPoint center( ( parentWidget()->width() / 2 ) - ( width() / 2 ), ( parentWidget()->height() / 2 ) - ( height() / 2 ) );
if ( center != pos() )
{
move( center );
return;
}
QPainter p( this );
// qDebug() << "FADING" << ( m_showHide->state() == QTimeLine::Running ) << "at frame:" << m_showHide->currentValue();
if( m_showHide->state() == QTimeLine::Running )
if ( m_showHide->state() == QTimeLine::Running )
{ // showing or hiding
p.setOpacity( (qreal)m_showHide->currentValue() );
}

View File

@ -36,7 +36,6 @@ public:
virtual QSize sizeHint() const;
virtual void paintEvent( QPaintEvent* );
virtual void resizeEvent( QResizeEvent* );
public slots:
void fadeIn();

View File

@ -123,8 +123,13 @@ void
OverlayWidget::paintEvent( QPaintEvent* event )
{
Q_UNUSED( event );
QPoint center( ( m_parent->width() - width() ) / 2, ( m_parent->height() - height() ) / 2 );
move( center );
if ( center != pos() )
{
move( center );
return;
}
QPainter p( this );
QRect r = contentsRect();