From 793babcd12fc0b4f029c1198da20771909edc242 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 1 Dec 2011 07:21:53 +0100 Subject: [PATCH] * Fixed TWK-418: Context menu for now playing track. --- src/audiocontrols.cpp | 12 +++++++----- src/libtomahawk/contextmenu.cpp | 18 +++++++++--------- src/libtomahawk/contextmenu.h | 1 - src/libtomahawk/playlist/artistview.cpp | 1 + src/libtomahawk/playlist/artistview.h | 6 +++++- src/libtomahawk/playlist/playlistmodel.cpp | 4 ++-- src/libtomahawk/widgets/querylabel.cpp | 21 +++++++++++++++++++++ src/libtomahawk/widgets/querylabel.h | 9 +++++++++ 8 files changed, 54 insertions(+), 18 deletions(-) diff --git a/src/audiocontrols.cpp b/src/audiocontrols.cpp index f231ef02d..ff0d3413f 100644 --- a/src/audiocontrols.cpp +++ b/src/audiocontrols.cpp @@ -111,8 +111,8 @@ AudioControls::AudioControls( QWidget* parent ) connect( ui->volumeLowButton, SIGNAL( clicked() ), AudioEngine::instance(), SLOT( lowerVolume() ) ); connect( ui->volumeHighButton, SIGNAL( clicked() ), AudioEngine::instance(), SLOT( raiseVolume() ) ); - connect( ui->playPauseButton, SIGNAL( clicked() ), this, SIGNAL( playPressed() ) ); - connect( ui->pauseButton, SIGNAL( clicked() ), this, SIGNAL( pausePressed() ) ); + connect( ui->playPauseButton, SIGNAL( clicked() ), SIGNAL( playPressed() ) ); + connect( ui->pauseButton, SIGNAL( clicked() ), SIGNAL( pausePressed() ) ); connect( ui->repeatButton, SIGNAL( clicked() ), SLOT( onRepeatClicked() ) ); connect( ui->shuffleButton, SIGNAL( clicked() ), SLOT( onShuffleClicked() ) ); @@ -208,11 +208,11 @@ AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result ) m_sliderTimeLine.setFrameRange( 0, duration ); m_sliderTimeLine.setCurrentTime( 0 ); m_seekMsecs = -1; - + ui->seekSlider->setVisible( true ); m_noTimeChange = false; - + Tomahawk::InfoSystem::InfoStringHash trackInfo; trackInfo["artist"] = result->artist()->name(); trackInfo["album"] = result->album()->name(); @@ -291,9 +291,10 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result ) result->loadSocialActions(); - connect( result.data(), SIGNAL( socialActionsLoaded() ), this, SLOT( socialActionsLoaded() ) ); + connect( result.data(), SIGNAL( socialActionsLoaded() ), SLOT( socialActionsLoaded() ) ); } + void AudioControls::socialActionsLoaded() { @@ -324,6 +325,7 @@ AudioControls::onPlaybackPaused() m_sliderTimeLine.setPaused( true ); } + void AudioControls::onPlaybackResumed() { diff --git a/src/libtomahawk/contextmenu.cpp b/src/libtomahawk/contextmenu.cpp index 73752e0bb..b13540db0 100644 --- a/src/libtomahawk/contextmenu.cpp +++ b/src/libtomahawk/contextmenu.cpp @@ -39,8 +39,11 @@ ContextMenu::ContextMenu( QWidget* parent ) m_supportedActions = ActionPlay | ActionQueue | ActionCopyLink; } + ContextMenu::~ContextMenu() -{} +{ +} + void ContextMenu::clear() @@ -50,23 +53,22 @@ ContextMenu::clear() m_queries.clear(); m_albums.clear(); m_artists.clear(); - } + unsigned int ContextMenu::itemCount() const { return m_queries.count() + m_artists.count() + m_albums.count(); } + void ContextMenu::setQueries( const QList& queries ) { - if ( queries.isEmpty() ) return; - QMenu::clear(); m_queries.clear(); m_queries << queries; @@ -87,11 +89,8 @@ ContextMenu::setQueries( const QList& queries ) if ( m_supportedActions & ActionDelete ) m_sigmap->setMapping( addAction( queries.count() > 1 ? tr( "&Delete Items" ) : tr( "&Delete Item" ) ), ActionDelete ); - - foreach ( QAction* action, actions() ) { - connect( action, SIGNAL( triggered() ), m_sigmap, SLOT( map() ) ); } } @@ -107,7 +106,6 @@ ContextMenu::setQuery( const Tomahawk::query_ptr& query ) } - void ContextMenu::setAlbums( const QList& albums ) { @@ -185,6 +183,7 @@ ContextMenu::setArtist( const Tomahawk::artist_ptr& artist ) setArtists( artists ); } + void ContextMenu::onTriggered( int action ) { @@ -205,7 +204,8 @@ ContextMenu::onTriggered( int action ) -void ContextMenu::addToQueue() +void +ContextMenu::addToQueue() { foreach ( const query_ptr& query, m_queries ) { diff --git a/src/libtomahawk/contextmenu.h b/src/libtomahawk/contextmenu.h index 56f0406d7..af272262a 100644 --- a/src/libtomahawk/contextmenu.h +++ b/src/libtomahawk/contextmenu.h @@ -39,7 +39,6 @@ public: ActionQueue = 2, ActionDelete = 4, ActionCopyLink = 8 - }; explicit ContextMenu( QWidget* parent = 0 ); diff --git a/src/libtomahawk/playlist/artistview.cpp b/src/libtomahawk/playlist/artistview.cpp index cd02c3266..3c93e00a0 100644 --- a/src/libtomahawk/playlist/artistview.cpp +++ b/src/libtomahawk/playlist/artistview.cpp @@ -28,6 +28,7 @@ #include "dynamic/widgets/LoadingSpinner.h" #include "widgets/overlaywidget.h" +#include "contextmenu.h" #include "tomahawksettings.h" #include "treeheader.h" #include "treeitemdelegate.h" diff --git a/src/libtomahawk/playlist/artistview.h b/src/libtomahawk/playlist/artistview.h index 934edbea4..9e82571b4 100644 --- a/src/libtomahawk/playlist/artistview.h +++ b/src/libtomahawk/playlist/artistview.h @@ -23,12 +23,16 @@ #include #include -#include "contextmenu.h" #include "treeproxymodel.h" #include "viewpage.h" #include "dllmacro.h" +namespace Tomahawk +{ + class ContextMenu; +}; + class TreeHeader; class LoadingSpinner; class OverlayWidget; diff --git a/src/libtomahawk/playlist/playlistmodel.cpp b/src/libtomahawk/playlist/playlistmodel.cpp index d35aa017c..d9a0747d6 100644 --- a/src/libtomahawk/playlist/playlistmodel.cpp +++ b/src/libtomahawk/playlist/playlistmodel.cpp @@ -149,7 +149,7 @@ PlaylistModel::append( const Tomahawk::album_ptr& album ) return; connect( album.data(), SIGNAL( tracksAdded( QList ) ), - SLOT( onTracksAdded( QList ) ) ); + SLOT( append( QList ) ) ); if ( rowCount( QModelIndex() ) == 0 ) { @@ -169,7 +169,7 @@ PlaylistModel::append( const Tomahawk::artist_ptr& artist ) return; connect( artist.data(), SIGNAL( tracksAdded( QList ) ), - SLOT( onTracksAdded( QList ) ) ); + SLOT( append( QList ) ) ); if ( rowCount( QModelIndex() ) == 0 ) { diff --git a/src/libtomahawk/widgets/querylabel.cpp b/src/libtomahawk/widgets/querylabel.cpp index 0877f9ffe..131204e95 100644 --- a/src/libtomahawk/widgets/querylabel.cpp +++ b/src/libtomahawk/widgets/querylabel.cpp @@ -27,12 +27,15 @@ #include "artist.h" #include "album.h" #include "query.h" +#include "contextmenu.h" #include "utils/tomahawkutilsgui.h" #include "utils/logger.h" #define BOXMARGIN 2 #define DASH " - " +using namespace Tomahawk; + QueryLabel::QueryLabel( QWidget* parent, Qt::WindowFlags flags ) : QFrame( parent, flags ) @@ -76,6 +79,9 @@ QueryLabel::~QueryLabel() void QueryLabel::init() { + m_contextMenu = new ContextMenu( this ); + m_contextMenu->setSupportedActions( ContextMenu::ActionQueue | ContextMenu::ActionCopyLink ); + m_hoverType = None; setContentsMargins( 0, 0, 0, 0 ); setMouseTracking( true ); @@ -250,6 +256,7 @@ QueryLabel::setAlignment( Qt::Alignment alignment ) } } + void QueryLabel::setTextPen( const QPen & pen ) { @@ -257,12 +264,14 @@ QueryLabel::setTextPen( const QPen & pen ) m_textPen = pen; } + QPen QueryLabel::textPen() const { return m_textPen; } + Qt::TextElideMode QueryLabel::elideMode() const { @@ -280,12 +289,14 @@ QueryLabel::setElideMode( Qt::TextElideMode mode ) } } + QFont QueryLabel::font() const { return m_font; } + void QueryLabel::setFont( const QFont& font ) { @@ -304,6 +315,7 @@ QueryLabel::updateLabel() update(); } + void QueryLabel::setExtraContentsMargins( int left, int top, int right, int bottom ) { @@ -476,6 +488,15 @@ QueryLabel::changeEvent( QEvent* event ) } +void +QueryLabel::contextMenuEvent( QContextMenuEvent* event ) +{ + m_contextMenu->clear(); + m_contextMenu->setQuery( m_query ); + m_contextMenu->exec( event->globalPos() ); +} + + void QueryLabel::mousePressEvent( QMouseEvent* event ) { diff --git a/src/libtomahawk/widgets/querylabel.h b/src/libtomahawk/widgets/querylabel.h index ef3b758f0..3f8ef2828 100644 --- a/src/libtomahawk/widgets/querylabel.h +++ b/src/libtomahawk/widgets/querylabel.h @@ -28,6 +28,11 @@ #include "typedefs.h" #include "dllmacro.h" +namespace Tomahawk +{ + class ContextMenu; +}; + class DLLEXPORT QueryLabel : public QFrame { Q_OBJECT @@ -98,6 +103,8 @@ signals: void queryChanged( const Tomahawk::query_ptr& query ); protected: + virtual void contextMenuEvent( QContextMenuEvent* event ); + virtual void mousePressEvent( QMouseEvent* event ); virtual void mouseReleaseEvent( QMouseEvent* event ); virtual void mouseMoveEvent( QMouseEvent* event ); @@ -117,6 +124,8 @@ private: Tomahawk::result_ptr m_result; Tomahawk::query_ptr m_query; + Tomahawk::ContextMenu* m_contextMenu; + Qt::Alignment m_align; Qt::TextElideMode m_mode;