1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-17 11:30:49 +02:00

add some animation goodness

This commit is contained in:
Leo Franchi
2011-01-28 17:40:42 -05:00
parent b94233f0f7
commit 4cdd3f6956
3 changed files with 61 additions and 4 deletions

View File

@@ -26,6 +26,8 @@
#include <QStackedLayout> #include <QStackedLayout>
#include <QToolButton> #include <QToolButton>
#include <QAction> #include <QAction>
#include <QEasingCurve>
#include <QTimeLine>
using namespace Tomahawk; using namespace Tomahawk;
@@ -51,6 +53,14 @@ Tomahawk::CollapsibleControls::~CollapsibleControls()
void void
CollapsibleControls::init() CollapsibleControls::init()
{ {
m_timeline = new QTimeLine( 300, this );
m_timeline->setUpdateInterval( 8 );
m_timeline->setEasingCurve( QEasingCurve::OutBack );
m_animHeight = -1;
connect( m_timeline, SIGNAL( frameChanged( int ) ), this, SLOT( onAnimationStep( int ) ) );
connect( m_timeline, SIGNAL( finished() ), this, SLOT( onAnimationFinished() ) );
m_layout = new QStackedLayout; m_layout = new QStackedLayout;
setContentsMargins( 0, 0, 0, 0 ); setContentsMargins( 0, 0, 0, 0 );
m_layout->setContentsMargins( 0, 0, 0, 0 ); m_layout->setContentsMargins( 0, 0, 0, 0 );
@@ -62,8 +72,8 @@ CollapsibleControls::init()
m_summaryWidget = new QWidget( this ); m_summaryWidget = new QWidget( this );
// TODO replace // TODO replace
// m_summaryWidget->setMinimumHeight( 24 ); m_summaryWidget->setMinimumHeight( 24 );
// m_summaryWidget->setMaximumHeight( 24 ); m_summaryWidget->setMaximumHeight( 24 );
m_summaryWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); m_summaryWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
QHBoxLayout* summaryLayout = new QHBoxLayout; QHBoxLayout* summaryLayout = new QHBoxLayout;
m_summaryWidget->setLayout( summaryLayout ); m_summaryWidget->setLayout( summaryLayout );
@@ -107,10 +117,49 @@ CollapsibleControls::setControls( const dynplaylist_ptr& playlist, bool isLocal
void void
CollapsibleControls::toggleCollapse() CollapsibleControls::toggleCollapse()
{ {
qDebug() << "TOGGLING SIZEHINTS:" << m_controls->height() << m_summaryWidget->sizeHint();
m_timeline->setFrameRange( m_summaryWidget->sizeHint().height(), m_controls->height() );
if( m_layout->currentWidget() == m_controls ) { if( m_layout->currentWidget() == m_controls ) {
m_summary->setText( m_dynplaylist->generator()->sentenceSummary() ); m_summary->setText( m_dynplaylist->generator()->sentenceSummary() );
m_layout->setCurrentWidget( m_summaryWidget ); m_controls->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
m_timeline->setDirection( QTimeLine::Backward );
m_timeline->start();
} else { } else {
m_summaryWidget->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
m_layout->setCurrentWidget( m_controls ); m_layout->setCurrentWidget( m_controls );
m_timeline->setDirection( QTimeLine::Forward );
m_timeline->start();
}
}
void
CollapsibleControls::onAnimationStep( int step )
{
resize( width(), step );
m_animHeight = step;
setMaximumHeight( m_animHeight );
}
void
CollapsibleControls::onAnimationFinished()
{
setMaximumHeight( m_animHeight );
m_animHeight = -1;
if( m_layout->currentWidget() == m_controls && m_timeline->direction() == QTimeLine::Backward ) {
m_layout->setCurrentWidget( m_summaryWidget );
}
}
QSize CollapsibleControls::sizeHint() const
{
if( m_animHeight >= 0 ) {
return QSize( QWidget::sizeHint().width(), m_animHeight );
} else {
return QWidget::sizeHint();
} }
} }

View File

@@ -21,6 +21,7 @@
#include <QWidget> #include <QWidget>
class QTimeLine;
class QToolButton; class QToolButton;
class QLabel; class QLabel;
class QStackedLayout; class QStackedLayout;
@@ -41,12 +42,15 @@ public:
void setControls( const dynplaylist_ptr& playlist, bool isLocal ); void setControls( const dynplaylist_ptr& playlist, bool isLocal );
QList< DynamicControlWrapper* > controls() const; QList< DynamicControlWrapper* > controls() const;
virtual QSize sizeHint() const;
signals: signals:
void controlsChanged(); void controlsChanged();
void controlChanged( const Tomahawk::dyncontrol_ptr& control ); void controlChanged( const Tomahawk::dyncontrol_ptr& control );
private slots: private slots:
void toggleCollapse(); void toggleCollapse();
void onAnimationStep( int );
void onAnimationFinished();
private: private:
void init(); void init();
@@ -58,6 +62,10 @@ private:
QWidget* m_summaryWidget; QWidget* m_summaryWidget;
QLabel* m_summary; QLabel* m_summary;
QToolButton* m_summaryExpand; QToolButton* m_summaryExpand;
// animations!
QTimeLine* m_timeline;
int m_animHeight;
}; };
} }

View File

@@ -90,7 +90,7 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
m_view = new DynamicView( this ); m_view = new DynamicView( this );
m_view->setModel( m_model ); m_view->setModel( m_model );
m_view->setContentsMargins( 0, 0, 0, 0 ); m_view->setContentsMargins( 0, 0, 0, 0 );
m_layout->addWidget( m_view ); m_layout->addWidget( m_view, 1 );
loadDynamicPlaylist( playlist ); loadDynamicPlaylist( playlist );