From c0edc3a989669884141e4609b36a1fc60ac5c447 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 4 Sep 2011 01:37:01 +0200 Subject: [PATCH] initial try on a dragndrop menu for audiocontrols --- src/audiocontrols.cpp | 93 ++++++++ src/audiocontrols.h | 10 + src/audiocontrols.ui | 483 ++++++++++++++++++++++-------------------- 3 files changed, 355 insertions(+), 231 deletions(-) diff --git a/src/audiocontrols.cpp b/src/audiocontrols.cpp index 604c27833..5df690327 100644 --- a/src/audiocontrols.cpp +++ b/src/audiocontrols.cpp @@ -148,6 +148,61 @@ AudioControls::AudioControls( QWidget* parent ) ui->stackedLayout->setSizeConstraint( QLayout::SetFixedSize ); onPlaybackStopped(); // initial state + + + m_dragAnimation = new QPropertyAnimation( this, "dropAreaSize", this ); + m_dragAnimation->setDuration( 500 ); + m_dragAnimation->setEasingCurve( QEasingCurve::OutExpo ); + connect( m_dragAnimation, SIGNAL( finished() ), SLOT(dragAnimationFinished())); + + QGridLayout *dropMenuLayout = new QGridLayout; + ui->metaDataDropArea->setLayout( dropMenuLayout ); + + QLabel* dropTrackImage = new QLabel; + dropTrackImage->setAlignment( Qt::AlignHCenter ); + dropTrackImage->setPixmap( QPixmap(":/data/images/drop-song.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); + dropMenuLayout->addWidget( dropTrackImage, 0, 0 ); + + QLabel* dropAlbumImage = new QLabel; + dropAlbumImage->setAlignment( Qt::AlignHCenter ); + dropAlbumImage->setPixmap( QPixmap( ":/data/images/drop-album.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); + dropMenuLayout->addWidget( dropAlbumImage, 0, 1 ); + + QLabel* dropArtistImage = new QLabel; + dropArtistImage->setAlignment( Qt::AlignHCenter ); + dropArtistImage->setPixmap( QPixmap( ":/data/images/drop-all-songs.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); + dropMenuLayout->addWidget( dropArtistImage, 0, 2 ); + + QLabel* dropLocalImage = new QLabel; + dropLocalImage->setAlignment( Qt::AlignHCenter ); + dropLocalImage->setPixmap( QPixmap( ":/data/images/drop-local-songs.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); + dropMenuLayout->addWidget( dropLocalImage, 0, 3 ); + + QLabel* dropTop10Image = new QLabel; + dropTop10Image->setAlignment( Qt::AlignHCenter ); + dropTop10Image->setPixmap( QPixmap( ":/data/images/drop-top-songs.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); + dropMenuLayout->addWidget( dropTop10Image, 0, 4 ); + + QLabel* dropAllText = new QLabel( "Track" ); + dropAllText->setAlignment( Qt::AlignHCenter ); + dropMenuLayout->addWidget( dropAllText, 1, 0 ); + + QLabel* dropAlbumText = new QLabel( "Album" ); + dropAlbumText->setAlignment( Qt::AlignHCenter ); + dropMenuLayout->addWidget( dropAlbumText, 1, 1 ); + + QLabel* dropArtistText = new QLabel( "Artist" ); + dropArtistText->setAlignment( Qt::AlignHCenter ); + dropMenuLayout->addWidget( dropArtistText, 1, 2 ); + + QLabel* dropLocalText = new QLabel( "Local" ); + dropLocalText->setAlignment( Qt::AlignHCenter ); + dropMenuLayout->addWidget( dropLocalText, 1, 3 ); + + QLabel* dropTop10Text = new QLabel( "Top 10" ); + dropTop10Text->setAlignment( Qt::AlignHCenter ); + dropMenuLayout->addWidget( dropTop10Text, 1, 4 ); + } @@ -521,7 +576,14 @@ void AudioControls::dragEnterEvent( QDragEnterEvent* e ) { if ( DropJob::acceptsMimeData( e->mimeData() ) ) + { e->acceptProposedAction(); + + m_dragAnimation->setStartValue( 0 ); + m_dragAnimation->setEndValue( ui->metaDataArea->height() ); + m_dragAnimation->setDirection( QAbstractAnimation::Forward ); + m_dragAnimation->start(); + } } @@ -533,6 +595,18 @@ AudioControls::dragMoveEvent( QDragMoveEvent* /* e */ ) } +void +AudioControls::dragLeaveEvent( QDragLeaveEvent * ) +{ + ui->metaDataInfoArea->setMaximumHeight( 1000 ); + ui->metaDataDropArea->setMaximumHeight( 0 ); + + m_dragAnimation->setDirection( QAbstractAnimation::Backward ); + m_dragAnimation->start(); + +} + + void AudioControls::dropEvent( QDropEvent* e ) { @@ -595,3 +669,22 @@ AudioControls::onLoveButtonClicked( bool checked ) } } + +void +AudioControls::dragAnimationFinished() +{ + +} + +int +AudioControls::dropAreaSize() +{ + return ui->metaDataDropArea->maximumHeight(); +} + +void +AudioControls::setDropAreaSize( int size ) +{ + ui->metaDataDropArea->setMaximumHeight( size ); + ui->metaDataInfoArea->setMaximumHeight( ui->metaDataArea->height() - size ); +} diff --git a/src/audiocontrols.h b/src/audiocontrols.h index 7fc47eb92..06da6a324 100644 --- a/src/audiocontrols.h +++ b/src/audiocontrols.h @@ -21,6 +21,7 @@ #include #include +#include #include "result.h" #include "playlistinterface.h" @@ -37,6 +38,7 @@ namespace Ui class AudioControls : public QWidget { Q_OBJECT +Q_PROPERTY( int dropAreaSize READ dropAreaSize WRITE setDropAreaSize ) public: AudioControls( QWidget* parent = 0 ); @@ -54,8 +56,12 @@ protected: void changeEvent( QEvent* e ); void dragEnterEvent ( QDragEnterEvent* ); void dragMoveEvent ( QDragMoveEvent* ); + void dragLeaveEvent( QDragLeaveEvent * ); void dropEvent ( QDropEvent* ); + int dropAreaSize(); + void setDropAreaSize( int size ); + private slots: void onPlaybackStarted( const Tomahawk::result_ptr& result ); void onPlaybackLoading( const Tomahawk::result_ptr& result ); @@ -82,6 +88,8 @@ private slots: void socialActionsLoaded(); + void dragAnimationFinished(); + private: Ui::AudioControls *ui; @@ -93,6 +101,8 @@ private: QTimeLine m_sliderTimeLine; qint64 m_seekMsecs; + + QPropertyAnimation *m_dragAnimation; }; #endif // AUDIOCONTROLS_H diff --git a/src/audiocontrols.ui b/src/audiocontrols.ui index 8b4ea01ca..4636d8e60 100644 --- a/src/audiocontrols.ui +++ b/src/audiocontrols.ui @@ -84,14 +84,14 @@ 0 - + Play - + Pause @@ -125,248 +125,269 @@ - - - 16777215 - 74 - - - - - 10 - - - 0 - - - 12 - - + + 0 - - - - 0 - 0 - - - - - 58 - 58 - - + - 58 - 58 + 16777215 + 0 - - TextLabel - - - Qt::AlignCenter - - - - 4 + + + + 16777215 + 74 + - - 6 - - - 2 - - - - - 0 - - - 0 - - - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 0 - 16 - - - - PointingHandCursor - - - Artist - - - - - - - - 0 - 0 - - - - - 0 - 16 - - - - PointingHandCursor - - - Album - - - - - - - - - Qt::Horizontal - - - - 4 - 8 - - - - - - - - - - - 0 - 0 - - - - PointingHandCursor - - - love - - - - - - - Qt::Vertical - - - - 20 - 13 - - - - - - - - - - - 7 - - - - Owner - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - 0 - - - - - - - - - Qt::Vertical - - - - 20 - 4 - - - - - - - - 4 - - - - - Time - - - - - - - - 0 - 20 - - - - - 16777215 - 20 - - - - Qt::Horizontal - - - - - - - Time Left - - - - - - + + + 10 + + + 0 + + + 12 + + + 0 + + + + + + 0 + 0 + + + + + 58 + 58 + + + + + 58 + 58 + + + + TextLabel + + + Qt::AlignCenter + + + + + + + 4 + + + 6 + + + 2 + + + + + 0 + + + 0 + + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 16 + + + + PointingHandCursor + + + Artist + + + + + + + + 0 + 0 + + + + + 0 + 16 + + + + PointingHandCursor + + + Album + + + + + + + + + Qt::Horizontal + + + + 4 + 8 + + + + + + + + + + + 0 + 0 + + + + PointingHandCursor + + + love + + + + + + + Qt::Vertical + + + + 20 + 13 + + + + + + + + + + + 7 + + + + Owner + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + 0 + + + + + + + + + Qt::Vertical + + + + 20 + 4 + + + + + + + + 4 + + + + + Time + + + + + + + + 0 + 20 + + + + + 16777215 + 20 + + + + Qt::Horizontal + + + + + + + Time Left + + + + + + + + + + metaDataInfoArea + metaDataDropArea