mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
Show and animate steering description
This commit is contained in:
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
#define ANIM_DURATION 300
|
||||||
|
|
||||||
EchonestSteerer::EchonestSteerer( QWidget* parent )
|
EchonestSteerer::EchonestSteerer( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
, m_layout( new QHBoxLayout )
|
, m_layout( new QHBoxLayout )
|
||||||
@@ -34,6 +36,7 @@ EchonestSteerer::EchonestSteerer( QWidget* parent )
|
|||||||
, m_field( 0 )
|
, m_field( 0 )
|
||||||
, m_description( 0 )
|
, m_description( 0 )
|
||||||
, m_textL( new QVBoxLayout )
|
, m_textL( new QVBoxLayout )
|
||||||
|
, m_expanding( true )
|
||||||
|
|
||||||
{
|
{
|
||||||
m_layout->setContentsMargins( 8, 8, 8, 8 );
|
m_layout->setContentsMargins( 8, 8, 8, 8 );
|
||||||
@@ -73,11 +76,20 @@ EchonestSteerer::EchonestSteerer( QWidget* parent )
|
|||||||
connect( m_field, SIGNAL( currentIndexChanged( int ) ), this, SLOT( changed() ) );
|
connect( m_field, SIGNAL( currentIndexChanged( int ) ), this, SLOT( changed() ) );
|
||||||
|
|
||||||
m_description = new QLineEdit( this );
|
m_description = new QLineEdit( this );
|
||||||
|
m_description->setPlaceholderText( tr( "Enter a description" ) );
|
||||||
m_description->hide();
|
m_description->hide();
|
||||||
|
|
||||||
setLayout( m_layout );
|
setLayout( m_layout );
|
||||||
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
||||||
|
|
||||||
|
m_resizeAnim.setDuration( ANIM_DURATION );
|
||||||
|
m_resizeAnim.setEasingCurve( QEasingCurve::InOutQuad );
|
||||||
|
m_resizeAnim.setDirection( QTimeLine::Forward );
|
||||||
|
m_resizeAnim.setUpdateInterval( 8 );
|
||||||
|
|
||||||
|
connect( &m_resizeAnim, SIGNAL( frameChanged( int ) ), this, SLOT( resizeFrame( int ) ) );
|
||||||
|
connect( &m_resizeAnim, SIGNAL( finished() ), this, SLOT( resizeFinished() ) );
|
||||||
|
|
||||||
resize( sizeHint() );
|
resize( sizeHint() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +121,52 @@ EchonestSteerer::changed()
|
|||||||
if( m_field->itemData( m_field->currentIndex() ).toString() != "desc" ) {
|
if( m_field->itemData( m_field->currentIndex() ).toString() != "desc" ) {
|
||||||
QString steer = m_field->itemData( m_field->currentIndex() ).toString() + m_amplifier->itemData( m_amplifier->currentIndex() ).toString();
|
QString steer = m_field->itemData( m_field->currentIndex() ).toString() + m_amplifier->itemData( m_amplifier->currentIndex() ).toString();
|
||||||
emit steerField( steer );
|
emit steerField( steer );
|
||||||
} else {
|
|
||||||
|
|
||||||
|
// if description was shown, animate to shrink
|
||||||
|
if( m_layout->indexOf( m_description ) > 0 ) {
|
||||||
|
m_expanding = false;
|
||||||
|
int start = width();
|
||||||
|
int end = start - m_layout->spacing() - m_description->sizeHint().width();;
|
||||||
|
|
||||||
|
m_layout->removeWidget( m_description );
|
||||||
|
m_description->hide();
|
||||||
|
m_layout->setStretchFactor( m_textL, 1 );
|
||||||
|
|
||||||
|
m_resizeAnim.setFrameRange( start, end );
|
||||||
|
m_resizeAnim.start();
|
||||||
|
|
||||||
|
qDebug() << "COLLAPSING FROM" << start << "TO" << end;
|
||||||
|
}
|
||||||
|
} else { // description, so put in the description field
|
||||||
|
// animate to expand
|
||||||
|
m_layout->addWidget( m_description, 1 );
|
||||||
|
m_layout->setStretchFactor( m_textL, 0 );
|
||||||
|
m_description->show();
|
||||||
|
|
||||||
|
m_expanding = true;
|
||||||
|
int start = width();
|
||||||
|
int end = start + m_layout->spacing() + m_description->sizeHint().width();
|
||||||
|
m_resizeAnim.setFrameRange( start, end );
|
||||||
|
m_resizeAnim.start();
|
||||||
|
|
||||||
|
qDebug() << "EXPANDING FROM" << start << "TO" << end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
EchonestSteerer::resizeFrame( int width )
|
||||||
|
{
|
||||||
|
qDebug() << "RESIZING TO:" << width;
|
||||||
|
resize( width, sizeHint().height() );
|
||||||
|
update();
|
||||||
|
|
||||||
|
emit resized();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
EchonestSteerer::resizeFinished()
|
||||||
|
{
|
||||||
|
// resize( m_layout->sizeHint() );
|
||||||
|
// update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
#define ECHONEST_STEERER_H
|
#define ECHONEST_STEERER_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QTimeLine>
|
||||||
|
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
@@ -40,9 +41,13 @@ signals:
|
|||||||
void steerField( const QString& field );
|
void steerField( const QString& field );
|
||||||
void steerDescription( const QString& desc );
|
void steerDescription( const QString& desc );
|
||||||
|
|
||||||
|
void resized();
|
||||||
private slots:
|
private slots:
|
||||||
void changed();
|
void changed();
|
||||||
|
|
||||||
|
void resizeFrame( int );
|
||||||
|
void resizeFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHBoxLayout* m_layout;
|
QHBoxLayout* m_layout;
|
||||||
QLabel* m_steerTop;
|
QLabel* m_steerTop;
|
||||||
@@ -55,6 +60,9 @@ private:
|
|||||||
|
|
||||||
QVBoxLayout* m_textL;
|
QVBoxLayout* m_textL;
|
||||||
|
|
||||||
|
// animations
|
||||||
|
QTimeLine m_resizeAnim;
|
||||||
|
bool m_expanding;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@@ -186,6 +186,12 @@ DynamicWidget::sizeHint() const
|
|||||||
|
|
||||||
void
|
void
|
||||||
DynamicWidget::resizeEvent(QResizeEvent* )
|
DynamicWidget::resizeEvent(QResizeEvent* )
|
||||||
|
{
|
||||||
|
layoutSteerer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DynamicWidget::layoutSteerer()
|
||||||
{
|
{
|
||||||
if( m_runningOnDemand && m_steering ) {
|
if( m_runningOnDemand && m_steering ) {
|
||||||
int x = ( width() / 2 ) - ( m_steering->size().width() / 2 );
|
int x = ( width() / 2 ) - ( m_steering->size().width() / 2 );
|
||||||
@@ -223,6 +229,8 @@ DynamicWidget::generateOrStart()
|
|||||||
m_steering->setParent( this );
|
m_steering->setParent( this );
|
||||||
m_steering->move( x, y );
|
m_steering->move( x, y );
|
||||||
m_steering->show();
|
m_steering->show();
|
||||||
|
|
||||||
|
connect( m_steering, SIGNAL( resized() ), this, SLOT( layoutSteerer() ) );
|
||||||
}
|
}
|
||||||
} else { // stop
|
} else { // stop
|
||||||
m_model->stopOnDemand();
|
m_model->stopOnDemand();
|
||||||
|
@@ -74,6 +74,7 @@ private slots:
|
|||||||
void controlsChanged();
|
void controlsChanged();
|
||||||
void controlChanged( const Tomahawk::dyncontrol_ptr& control );
|
void controlChanged( const Tomahawk::dyncontrol_ptr& control );
|
||||||
|
|
||||||
|
void layoutSteerer();
|
||||||
private:
|
private:
|
||||||
void applyModeChange( int mode );
|
void applyModeChange( int mode );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user