mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
* Added PlayableCover. A QLabel that you can set artists, albums or queries on and which shows a play button when hovered.
This commit is contained in:
@@ -149,6 +149,7 @@ set( libGuiSources
|
|||||||
widgets/ComboBox.cpp
|
widgets/ComboBox.cpp
|
||||||
widgets/ToggleButton.cpp
|
widgets/ToggleButton.cpp
|
||||||
widgets/FadingPixmap.cpp
|
widgets/FadingPixmap.cpp
|
||||||
|
widgets/PlayableCover.cpp
|
||||||
widgets/SocialPlaylistWidget.cpp
|
widgets/SocialPlaylistWidget.cpp
|
||||||
widgets/SourceTreePopupDialog.cpp
|
widgets/SourceTreePopupDialog.cpp
|
||||||
widgets/infowidgets/SourceInfoWidget.cpp
|
widgets/infowidgets/SourceInfoWidget.cpp
|
||||||
|
108
src/libtomahawk/widgets/PlayableCover.cpp
Normal file
108
src/libtomahawk/widgets/PlayableCover.cpp
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2011 - 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "PlayableCover.h"
|
||||||
|
|
||||||
|
#include "audio/AudioEngine.h"
|
||||||
|
#include "widgets/ImageButton.h"
|
||||||
|
#include "utils/TomahawkUtils.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
|
||||||
|
PlayableCover::PlayableCover( QWidget* parent )
|
||||||
|
: QLabel( parent )
|
||||||
|
{
|
||||||
|
setMouseTracking( true );
|
||||||
|
|
||||||
|
m_button = new ImageButton( this );
|
||||||
|
m_button->setPixmap( RESPATH "images/play-rest.png" );
|
||||||
|
m_button->setPixmap( RESPATH "images/play-pressed.png", QIcon::Off, QIcon::Active );
|
||||||
|
m_button->setFixedSize( 48, 48 );
|
||||||
|
m_button->setContentsMargins( 0, 0, 0, 0 );
|
||||||
|
m_button->setFocusPolicy( Qt::NoFocus );
|
||||||
|
m_button->installEventFilter( this );
|
||||||
|
m_button->hide();
|
||||||
|
|
||||||
|
connect( m_button, SIGNAL( clicked( bool ) ), SLOT( onClicked() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PlayableCover::~PlayableCover()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayableCover::enterEvent( QEvent* event )
|
||||||
|
{
|
||||||
|
QLabel::enterEvent( event );
|
||||||
|
|
||||||
|
m_button->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayableCover::leaveEvent( QEvent* event )
|
||||||
|
{
|
||||||
|
QLabel::leaveEvent( event );
|
||||||
|
|
||||||
|
m_button->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayableCover::resizeEvent( QResizeEvent* event )
|
||||||
|
{
|
||||||
|
QLabel::resizeEvent( event );
|
||||||
|
m_button->move( contentsRect().center() - QPoint( 23, 23 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayableCover::onClicked()
|
||||||
|
{
|
||||||
|
if ( m_artist )
|
||||||
|
AudioEngine::instance()->playItem( m_artist );
|
||||||
|
else if ( m_album )
|
||||||
|
AudioEngine::instance()->playItem( m_album );
|
||||||
|
else if ( m_query )
|
||||||
|
AudioEngine::instance()->playItem( Tomahawk::playlistinterface_ptr(), m_query );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayableCover::setArtist( const Tomahawk::artist_ptr& artist )
|
||||||
|
{
|
||||||
|
m_artist = artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayableCover::setAlbum( const Tomahawk::album_ptr& album )
|
||||||
|
{
|
||||||
|
m_album = album;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayableCover::setQuery( const Tomahawk::query_ptr& query )
|
||||||
|
{
|
||||||
|
m_query = query;
|
||||||
|
}
|
66
src/libtomahawk/widgets/PlayableCover.h
Normal file
66
src/libtomahawk/widgets/PlayableCover.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2011 - 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PLAYABLEPIXMAP_H
|
||||||
|
#define PLAYABLEPIXMAP_H
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPaintEvent>
|
||||||
|
#include <QResizeEvent>
|
||||||
|
|
||||||
|
#include "Artist.h"
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
class ImageButton;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class PlayableCover
|
||||||
|
* \brief QLabel which shows a play/pause button on hovering.
|
||||||
|
*/
|
||||||
|
class DLLEXPORT PlayableCover : public QLabel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
PlayableCover( QWidget* parent = 0 );
|
||||||
|
virtual ~PlayableCover();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void setArtist( const Tomahawk::artist_ptr& artist );
|
||||||
|
virtual void setAlbum( const Tomahawk::album_ptr& album );
|
||||||
|
virtual void setQuery( const Tomahawk::query_ptr& query );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void resizeEvent( QResizeEvent* event );
|
||||||
|
|
||||||
|
void leaveEvent( QEvent* event );
|
||||||
|
void enterEvent( QEvent* event );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onClicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPixmap m_pixmap;
|
||||||
|
|
||||||
|
ImageButton* m_button;
|
||||||
|
Tomahawk::artist_ptr m_artist;
|
||||||
|
Tomahawk::album_ptr m_album;
|
||||||
|
Tomahawk::query_ptr m_query;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user