1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-18 20:04:00 +02:00

initial try on a dragndrop menu for audiocontrols

This commit is contained in:
Michael Zanetti
2011-09-04 01:37:01 +02:00
parent 5dfb3ccc5c
commit c0edc3a989
3 changed files with 355 additions and 231 deletions

View File

@@ -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 );
}

View File

@@ -21,6 +21,7 @@
#include <QWidget>
#include <QTimeLine>
#include <QPropertyAnimation>
#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

View File

@@ -84,14 +84,14 @@
<property name="spacing">
<number>0</number>
</property>
<item>
<item row="0" column="0">
<widget class="ImageButton" name="playPauseButton">
<property name="text">
<string>Play</string>
</property>
</widget>
</item>
<item>
<item row="0" column="0">
<widget class="ImageButton" name="pauseButton">
<property name="text">
<string>Pause</string>
@@ -125,6 +125,22 @@
</item>
<item>
<widget class="QWidget" name="metaDataArea" native="true">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="metaDataDropArea" native="true">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="metaDataInfoArea" native="true">
<property name="maximumSize">
<size>
<width>16777215</width>
@@ -184,7 +200,7 @@
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,0,0">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,0,0,0">
<property name="topMargin">
<number>0</number>
</property>
@@ -369,6 +385,11 @@
</layout>
</widget>
</item>
</layout>
<zorder>metaDataInfoArea</zorder>
<zorder>metaDataDropArea</zorder>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_4" native="true">
<property name="sizePolicy">