Skip to content

Commit

Permalink
completed dropmenu in audio controls area
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Zanetti committed Sep 24, 2011
1 parent b2f3ded commit c3d223d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/audiocontrols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ AudioControls::AudioControls( QWidget* parent )
connect( &m_dropAreaCollapseTimer, SIGNAL( timeout() ), this, SLOT( collapseDropMenu() ) );

connect( ui->metaDataDropArea, SIGNAL( dropReceived( QDropEvent* ) ), this, SLOT( dropReceived( QDropEvent* ) ) );
connect( ui->metaDataDropArea, SIGNAL( mouseLeft() ), &m_dropAreaCollapseTimer, SLOT( start() ) );

DropMenuEntry *trackEntry = new DropMenuEntry( QPixmap(":/data/images/drop-song.png" ).scaledToWidth( 32, Qt::SmoothTransformation ),
"Track",
Expand Down Expand Up @@ -611,6 +612,21 @@ AudioControls::dragEnterEvent( QDragEnterEvent* e )

m_dropAreaCollapseTimer.stop();

DropJob::DropFlags flags = DropJob::DropFlagsNone;

if ( e->mimeData()->hasFormat( "application/tomahawk.query.list" )
|| e->mimeData()->hasFormat( "application/tomahawk.result.list" )
|| e->mimeData()->hasFormat( "application/tomahawk.result" ) )
flags = DropJob::DropFlagsAll;

if ( e->mimeData()->hasFormat( "application/tomahawk.metadata.album" ) )
flags = DropJob::DropFlagAlbum | DropJob::DropFlagArtist | DropJob::DropFlagLocal | DropJob::DropFlagTop10;

if ( e->mimeData()->hasFormat( "application/tomahawk.metadata.artist" ) )
flags = DropJob::DropFlagArtist | DropJob::DropFlagLocal | DropJob::DropFlagTop10;

ui->metaDataDropArea->setFilter( flags );

if( !m_dropAreaExpanded )
{
m_dragAnimation->stop();
Expand All @@ -635,6 +651,7 @@ AudioControls::dragMoveEvent( QDragMoveEvent* /* e */ )
void
AudioControls::dragLeaveEvent( QDragLeaveEvent * )
{
qDebug() << "******************************** dragLeaveEvent" << ui->metaDataDropArea->hovered();
if( !ui->metaDataDropArea->hovered() )
m_dropAreaCollapseTimer.start();
}
Expand All @@ -643,6 +660,10 @@ AudioControls::dragLeaveEvent( QDragLeaveEvent * )
void
AudioControls::collapseDropMenu()
{
// Check if the menu is hovered now...
if( ui->metaDataDropArea->hovered() )
return;

m_dropAreaExpanded = false;

m_dragAnimation->stop();
Expand Down
12 changes: 12 additions & 0 deletions src/libtomahawk/utils/dropmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ DropMenu::addEntry( DropMenuEntry *entry, bool isDefault )
m_defaultEntry = entry;
}

void
DropMenu::setFilter(DropJob::DropFlags shownEntries)
{
foreach( DropMenuEntry *entry, m_entries )
{
if( ( entry->dropFlags() & shownEntries ) != DropJob::DropFlagsNone )
entry->setVisible( true );
else
entry->setVisible( false );
}
}

bool
DropMenu::hovered() const
Expand Down Expand Up @@ -67,6 +78,7 @@ DropMenu::entryLeft( DropMenuEntry *entry )
entry->setActive( false );
m_defaultEntry->setActive( true );
m_activeEntry = m_defaultEntry;
emit mouseLeft();
}


Expand Down
3 changes: 3 additions & 0 deletions src/libtomahawk/utils/dropmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class DLLEXPORT DropMenu: public QWidget

void addEntry( DropMenuEntry *entry, bool isDefault = false );

void setFilter( DropJob::DropFlags shownEntries );


/** @brief Returns true if the mouse is somewhere over the contained entries */
bool hovered() const;
Expand All @@ -26,6 +28,7 @@ class DLLEXPORT DropMenu: public QWidget

signals:
void dropReceived( QDropEvent *event );
void mouseLeft();

private slots:
void entryHovered( DropMenuEntry* entry );
Expand Down

0 comments on commit c3d223d

Please sign in to comment.