diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp index 6c7176710..4c84907b3 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp @@ -197,6 +197,13 @@ EchonestGenerator::dynamicFetched() Q_ASSERT( qobject_cast< QNetworkReply* >( sender() ) ); QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() ); + m_steeredSinceLastTrack = false; + m_steerData.first = Echonest::DynamicPlaylist::Steer; + m_steerData.second = QString(); + + if( m_steerer ) + m_steerer->resetSteering( true ); + try { Echonest::Song song = m_dynPlaylist->parseNextSong( reply ); @@ -282,8 +289,12 @@ EchonestGenerator::queryFromSong(const Echonest::Song& song) QWidget* EchonestGenerator::steeringWidget() { - if( !m_steerer ) + if( !m_steerer ) { m_steerer = new EchonestSteerer(); + + connect( m_steerer, SIGNAL( steerField( QString ) ), this, SLOT( steerField( QString ) ) ); + connect( m_steerer, SIGNAL( steerDescription( QString ) ), this, SLOT( steerDescription( QString ) ) ); + } return m_steerer; } diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestSteerer.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestSteerer.cpp index f5b2978f6..1c6f32182 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestSteerer.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestSteerer.cpp @@ -15,6 +15,9 @@ ****************************************************************************************/ #include "dynamic/echonest/EchonestSteerer.h" + +#include "utils/tomahawkutils.h" + #include #include #include @@ -22,6 +25,7 @@ #include #include #include +#include using namespace Tomahawk; @@ -30,16 +34,18 @@ using namespace Tomahawk; EchonestSteerer::EchonestSteerer( QWidget* parent ) : QWidget( parent ) , m_layout( new QHBoxLayout ) - , m_steerTop( 0 ) - , m_steerBottom( 0 ) , m_amplifier( 0 ) , m_field( 0 ) , m_description( 0 ) , m_textL( new QVBoxLayout ) + , m_steerTop( 0 ) + , m_steerBottom( 0 ) + , m_reset( 0 ) , m_expanding( true ) { m_layout->setContentsMargins( 8, 8, 8, 8 ); + m_textL->setSpacing( 0 ); m_steerTop = new QLabel( tr( "Steer this station:" ), this ); QFont f = m_steerTop->font(); @@ -79,6 +85,13 @@ EchonestSteerer::EchonestSteerer( QWidget* parent ) m_description->setPlaceholderText( tr( "Enter a description" ) ); m_description->hide(); + m_reset = initButton( this ); + m_reset->setIcon( QIcon( RESPATH "images/view-refresh.png" ) ); + m_reset->setToolTip( tr( "Reset all steering commands" ) ); + m_layout->addWidget( m_reset ); + + connect( m_reset, SIGNAL( clicked( bool )), this, SLOT(resetSteering(bool))); + setLayout( m_layout ); setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); @@ -88,7 +101,6 @@ EchonestSteerer::EchonestSteerer( QWidget* parent ) m_resizeAnim.setUpdateInterval( 8 ); connect( &m_resizeAnim, SIGNAL( frameChanged( int ) ), this, SLOT( resizeFrame( int ) ) ); - connect( &m_resizeAnim, SIGNAL( finished() ), this, SLOT( resizeFinished() ) ); resize( sizeHint() ); } @@ -119,6 +131,7 @@ void EchonestSteerer::changed() { 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(); emit steerField( steer ); @@ -138,18 +151,25 @@ EchonestSteerer::changed() 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(); + if( !m_description->text().isEmpty() ) { + QString steer = m_description->text() + m_amplifier->itemData( m_amplifier->currentIndex() ).toString(); + emit steerDescription( steer ); + } - 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; + if( !m_layout->indexOf( m_description ) > 0 ) { + // animate to expand + m_layout->insertWidget( m_layout->count() - 1, 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; + } } } @@ -164,9 +184,24 @@ EchonestSteerer::resizeFrame( int width ) } void -EchonestSteerer::resizeFinished() +EchonestSteerer::resetSteering( bool automatic ) { -// resize( m_layout->sizeHint() ); -// update(); + m_field->setCurrentIndex( 0 ); + m_amplifier->setCurrentIndex( 0 ); + + if( !automatic ) + changed(); } + +QToolButton* +EchonestSteerer::initButton( QWidget* parent ) +{ + QToolButton* btn = new QToolButton( parent ); + btn->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); + btn->setIconSize( QSize( 14, 14 ) ); + btn->setToolButtonStyle( Qt::ToolButtonIconOnly ); + btn->setAutoRaise( true ); + btn->setContentsMargins( 0, 0, 0, 0 ); + return btn; +} diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestSteerer.h b/src/libtomahawk/playlist/dynamic/echonest/EchonestSteerer.h index bcbe5e5e2..24b795e19 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestSteerer.h +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestSteerer.h @@ -20,6 +20,7 @@ #include #include +class QToolButton; class QLabel; class QComboBox; class QVBoxLayout; @@ -32,11 +33,15 @@ namespace Tomahawk class EchonestSteerer : public QWidget { Q_OBJECT + public: EchonestSteerer( QWidget* parent = 0 ); virtual void paintEvent(QPaintEvent* ); +public slots: + void resetSteering( bool automatic = false ); + signals: void steerField( const QString& field ); void steerDescription( const QString& desc ); @@ -46,20 +51,25 @@ private slots: void changed(); void resizeFrame( int ); - void resizeFinished(); private: + QToolButton* initButton( QWidget* parent ); + QHBoxLayout* m_layout; - QLabel* m_steerTop; - QLabel* m_steerBottom; QComboBox* m_amplifier; QComboBox* m_field; QLineEdit* m_description; + // text on the left QVBoxLayout* m_textL; + QLabel* m_steerTop; + QLabel* m_steerBottom; + // icons on the right + QToolButton* m_reset; + // animations QTimeLine m_resizeAnim; bool m_expanding;