mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-14 04:51:53 +02:00
Merge remote branch 'origin/master' into dynamic
Conflicts: src/libtomahawk/widgets/overlaywidget.cpp
This commit is contained in:
commit
0879079371
@ -110,7 +110,6 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi )
|
||||
|
||||
qDebug() << Q_FUNC_INFO << ql.length();
|
||||
|
||||
if ( ql.count() )
|
||||
emit tracks( ql, m_collection );
|
||||
emit tracks( ql, m_collection );
|
||||
emit done( m_collection );
|
||||
}
|
||||
|
@ -159,7 +159,10 @@ void
|
||||
CollectionFlatModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection )
|
||||
{
|
||||
if ( !tracks.count() )
|
||||
{
|
||||
emit trackCountChanged( rowCount( QModelIndex() ) );
|
||||
return;
|
||||
}
|
||||
|
||||
int c = rowCount( QModelIndex() );
|
||||
QPair< int, int > crows;
|
||||
|
@ -32,6 +32,15 @@ CollectionView::~CollectionView()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CollectionView::setModel( TrackModel* model )
|
||||
{
|
||||
TrackView::setModel( model );
|
||||
|
||||
connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CollectionView::dragEnterEvent( QDragEnterEvent* event )
|
||||
{
|
||||
@ -74,14 +83,13 @@ CollectionView::onCustomContextMenu( const QPoint& pos )
|
||||
|
||||
|
||||
void
|
||||
CollectionView::paintEvent( QPaintEvent* event )
|
||||
CollectionView::onTrackCountChanged( unsigned int tracks )
|
||||
{
|
||||
TrackView::paintEvent( event );
|
||||
QPainter painter( viewport() );
|
||||
|
||||
if ( !model()->trackCount() )
|
||||
if ( tracks == 0 )
|
||||
{
|
||||
overlay()->setText( tr( "This collection is empty." ) );
|
||||
overlay()->paint( &painter );
|
||||
overlay()->show();
|
||||
}
|
||||
else
|
||||
overlay()->hide();
|
||||
}
|
||||
|
@ -15,12 +15,14 @@ public:
|
||||
explicit CollectionView( QWidget* parent = 0 );
|
||||
~CollectionView();
|
||||
|
||||
virtual void setModel( TrackModel* model );
|
||||
|
||||
private slots:
|
||||
void onCustomContextMenu( const QPoint& pos );
|
||||
void onTrackCountChanged( unsigned int tracks );
|
||||
|
||||
protected:
|
||||
virtual void dragEnterEvent( QDragEnterEvent* event );
|
||||
void paintEvent( QPaintEvent* event );
|
||||
|
||||
private:
|
||||
void setupMenus();
|
||||
|
@ -20,22 +20,12 @@
|
||||
#include "trackmodel.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
DynamicView::DynamicView( QWidget* parent )
|
||||
: PlaylistView( parent )
|
||||
{
|
||||
m_showTimer.setInterval( 5000 );
|
||||
m_showTimer.setSingleShot( true );
|
||||
|
||||
m_fadeOut = new QPropertyAnimation( overlay(), "opacity" );
|
||||
m_fadeOut->setDuration( 500 );
|
||||
m_fadeOut->setEndValue( 0 );
|
||||
m_fadeOut->setEasingCurve( QEasingCurve::InOutQuad );
|
||||
|
||||
connect( &m_showTimer, SIGNAL( timeout() ), m_fadeOut, SLOT( start() ) );
|
||||
|
||||
}
|
||||
|
||||
@ -44,27 +34,33 @@ DynamicView::~DynamicView()
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
DynamicView::setModel( TrackModel* model)
|
||||
{
|
||||
PlaylistView::setModel( model );
|
||||
|
||||
connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicView::showMessageTimeout( const QString& title, const QString& body )
|
||||
{
|
||||
m_title = title;
|
||||
m_body = body;
|
||||
m_showTimer.start();
|
||||
viewport()->update();
|
||||
|
||||
overlay()->setText( QString( "%1:\n\n%2" ).arg( m_title, m_body ) );
|
||||
overlay()->show( 5 );
|
||||
}
|
||||
|
||||
void
|
||||
DynamicView::paintEvent( QPaintEvent* event )
|
||||
DynamicView::onTrackCountChanged( unsigned int tracks )
|
||||
{
|
||||
QPainter painter( viewport() );
|
||||
if ( m_showTimer.isActive() || m_fadeOut->state() == QPropertyAnimation::Running )
|
||||
if ( tracks == 0 )
|
||||
{
|
||||
overlay()->setText( QString( "%1:\n\n%2" ).arg( m_title, m_body ) );
|
||||
overlay()->paint( &painter );
|
||||
} else if( !model()->trackCount() ) {
|
||||
overlay()->setText( tr( "Add some filters above, and press Generate to get started!" ) );
|
||||
overlay()->paint( &painter );
|
||||
} else {
|
||||
PlaylistView::paintEvent( event );
|
||||
overlay()->show();
|
||||
}
|
||||
else
|
||||
overlay()->hide();
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <QTimer>
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
class TrackModel;
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
@ -31,11 +32,13 @@ public:
|
||||
explicit DynamicView( QWidget* parent = 0 );
|
||||
virtual ~DynamicView();
|
||||
|
||||
virtual void setModel( TrackModel* model );
|
||||
|
||||
public slots:
|
||||
void showMessageTimeout( const QString& title, const QString& body );
|
||||
|
||||
protected:
|
||||
virtual void paintEvent( QPaintEvent* event );
|
||||
private slots:
|
||||
void onTrackCountChanged( unsigned int );
|
||||
|
||||
private:
|
||||
QTimer m_showTimer;
|
||||
|
@ -90,8 +90,8 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist )
|
||||
emit endInsertRows();
|
||||
}
|
||||
|
||||
qDebug() << rowCount( QModelIndex() );
|
||||
emit loadingFinished();
|
||||
emit trackCountChanged( rowCount( QModelIndex() ) );
|
||||
}
|
||||
|
||||
|
||||
@ -194,7 +194,10 @@ void
|
||||
PlaylistModel::onTracksInserted( unsigned int row, const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection )
|
||||
{
|
||||
if ( !tracks.count() )
|
||||
{
|
||||
emit trackCountChanged( rowCount( QModelIndex() ) );
|
||||
return;
|
||||
}
|
||||
|
||||
int c = row;
|
||||
QPair< int, int > crows;
|
||||
@ -220,7 +223,6 @@ PlaylistModel::onTracksInserted( unsigned int row, const QList<Tomahawk::query_p
|
||||
|
||||
emit endInsertRows();
|
||||
emit trackCountChanged( rowCount( QModelIndex() ) );
|
||||
qDebug() << rowCount( QModelIndex() );
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,8 +30,9 @@ void
|
||||
PlaylistView::setModel( TrackModel* model )
|
||||
{
|
||||
TrackView::setModel( model );
|
||||
|
||||
setColumnHidden( 5, true ); // Hide age column per default
|
||||
|
||||
connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
|
||||
}
|
||||
|
||||
|
||||
@ -110,14 +111,13 @@ PlaylistView::deleteItems()
|
||||
|
||||
|
||||
void
|
||||
PlaylistView::paintEvent( QPaintEvent* event )
|
||||
PlaylistView::onTrackCountChanged( unsigned int tracks )
|
||||
{
|
||||
TrackView::paintEvent( event );
|
||||
QPainter painter( viewport() );
|
||||
|
||||
if ( !model()->trackCount() )
|
||||
if ( tracks == 0 )
|
||||
{
|
||||
overlay()->setText( tr( "This playlist is currently empty. Add some tracks to it and enjoy the music!" ) );
|
||||
overlay()->paint( &painter );
|
||||
overlay()->show();
|
||||
}
|
||||
else
|
||||
overlay()->hide();
|
||||
}
|
||||
|
@ -15,14 +15,14 @@ public:
|
||||
explicit PlaylistView( QWidget* parent = 0 );
|
||||
~PlaylistView();
|
||||
|
||||
void setModel( TrackModel* model );
|
||||
virtual void setModel( TrackModel* model );
|
||||
|
||||
protected:
|
||||
void keyPressEvent( QKeyEvent* event );
|
||||
void paintEvent( QPaintEvent* event );
|
||||
|
||||
private slots:
|
||||
void onCustomContextMenu( const QPoint& pos );
|
||||
void onTrackCountChanged( unsigned int tracks );
|
||||
|
||||
void addItemsToPlaylist();
|
||||
void deleteItems();
|
||||
|
@ -251,13 +251,6 @@ TrackView::paintEvent( QPaintEvent* event )
|
||||
QTreeView::paintEvent( event );
|
||||
QPainter painter( viewport() );
|
||||
|
||||
if ( !proxyModel()->filter().isEmpty() && !proxyModel()->trackCount() &&
|
||||
model()->trackCount() )
|
||||
{
|
||||
m_overlay->setText( tr( "Sorry, your filter '%1' did not match any results." ).arg( proxyModel()->filter() ) );
|
||||
m_overlay->paint( &painter );
|
||||
}
|
||||
|
||||
if ( m_dragging )
|
||||
{
|
||||
// draw drop indicator
|
||||
@ -289,6 +282,16 @@ TrackView::onFilterChanged( const QString& )
|
||||
{
|
||||
if ( selectedIndexes().count() )
|
||||
scrollTo( selectedIndexes().at( 0 ), QAbstractItemView::PositionAtCenter );
|
||||
|
||||
if ( !proxyModel()->filter().isEmpty() && !proxyModel()->trackCount() &&
|
||||
model()->trackCount() )
|
||||
{
|
||||
m_overlay->setText( tr( "Sorry, your filter '%1' did not match any results." ).arg( proxyModel()->filter() ) );
|
||||
m_overlay->show();
|
||||
}
|
||||
else
|
||||
if ( model()->trackCount() )
|
||||
m_overlay->hide();
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
TrackHeader* header() const { return m_header; }
|
||||
OverlayWidget* overlay() const { return m_overlay; }
|
||||
|
||||
void setModel( TrackModel* model );
|
||||
virtual void setModel( TrackModel* model );
|
||||
|
||||
QModelIndex contextMenuIndex() const { return m_contextMenuIndex; }
|
||||
void setContextMenuIndex( const QModelIndex& idx ) { m_contextMenuIndex = idx; }
|
||||
|
@ -4,18 +4,24 @@
|
||||
#include <QPainter>
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
#define CORNER_ROUNDNESS 32.0
|
||||
#define FADEIN_DURATION 500
|
||||
#define CORNER_ROUNDNESS 16.0
|
||||
#define FADING_DURATION 500
|
||||
#define FONT_SIZE 18
|
||||
#define OPACITY 0.80
|
||||
#define OPACITY 0.86
|
||||
|
||||
|
||||
OverlayWidget::OverlayWidget( QAbstractItemView* parent )
|
||||
: QWidget() // this is on purpose!
|
||||
OverlayWidget::OverlayWidget( QWidget* parent )
|
||||
: QWidget( parent ) // this is on purpose!
|
||||
, m_opacity( 0.00 )
|
||||
, m_parent( parent )
|
||||
{
|
||||
resize( 380, 220 );
|
||||
setAttribute( Qt::WA_TranslucentBackground, true );
|
||||
|
||||
setOpacity( m_opacity );
|
||||
|
||||
m_timer.setSingleShot( true );
|
||||
connect( &m_timer, SIGNAL( timeout() ), this, SLOT( hide() ) );
|
||||
}
|
||||
|
||||
|
||||
@ -28,77 +34,67 @@ void
|
||||
OverlayWidget::setOpacity( qreal opacity )
|
||||
{
|
||||
m_opacity = opacity;
|
||||
m_parent->viewport()->update();
|
||||
|
||||
if ( m_opacity == 0.00 && !isHidden() )
|
||||
{
|
||||
QWidget::hide();
|
||||
}
|
||||
else if ( m_opacity > 0.00 && isHidden() )
|
||||
{
|
||||
QWidget::show();
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OverlayWidget::setText( const QString& text )
|
||||
{
|
||||
if ( text == m_text )
|
||||
return;
|
||||
|
||||
if ( isEnabled() )
|
||||
{
|
||||
QPropertyAnimation* animation = new QPropertyAnimation( this, "opacity" );
|
||||
animation->setDuration( FADEIN_DURATION );
|
||||
animation->setStartValue( 0.00 );
|
||||
animation->setEndValue( OPACITY );
|
||||
animation->start();
|
||||
}
|
||||
else
|
||||
m_opacity = OPACITY;
|
||||
|
||||
m_text = text;
|
||||
m_pixmap = QPixmap();
|
||||
}
|
||||
|
||||
|
||||
QPixmap
|
||||
OverlayWidget::pixmap()
|
||||
{
|
||||
if ( m_pixmap.isNull() )
|
||||
{
|
||||
QPixmap p( contentsRect().size() );
|
||||
p.fill( Qt::transparent );
|
||||
render( &p );
|
||||
|
||||
m_pixmap = p;
|
||||
}
|
||||
|
||||
return m_pixmap;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OverlayWidget::paint( QPainter* painter )
|
||||
OverlayWidget::show( int timeoutSecs )
|
||||
{
|
||||
if ( !isEnabled() )
|
||||
return;
|
||||
QPropertyAnimation* animation = new QPropertyAnimation( this, "opacity" );
|
||||
animation->setDuration( FADING_DURATION );
|
||||
animation->setStartValue( 0.00 );
|
||||
animation->setEndValue( OPACITY );
|
||||
animation->start();
|
||||
|
||||
if( timeoutSecs > 0 )
|
||||
m_timer.start( timeoutSecs * 1000 );
|
||||
}
|
||||
|
||||
pixmap(); // cache the image
|
||||
|
||||
QRect center( QPoint( ( painter->viewport().width() - m_pixmap.width() ) / 2,
|
||||
( painter->viewport().height() - m_pixmap.height() ) / 2 ), m_pixmap.size() );
|
||||
|
||||
painter->save();
|
||||
painter->setOpacity( m_opacity );
|
||||
painter->drawPixmap( center, m_pixmap );
|
||||
painter->restore();
|
||||
void
|
||||
OverlayWidget::hide()
|
||||
{
|
||||
QPropertyAnimation* animation = new QPropertyAnimation( this, "opacity" );
|
||||
animation->setDuration( FADING_DURATION );
|
||||
animation->setEndValue( 0.00 );
|
||||
animation->start();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OverlayWidget::paintEvent( QPaintEvent* event )
|
||||
{
|
||||
QPoint center( ( m_parent->width() - width() ) / 2, ( m_parent->height() - height() ) / 2 );
|
||||
move( center );
|
||||
|
||||
QPainter p( this );
|
||||
QRect r = contentsRect();
|
||||
|
||||
p.setBackgroundMode( Qt::TransparentMode );
|
||||
p.setRenderHint( QPainter::Antialiasing );
|
||||
p.setOpacity( m_opacity );
|
||||
|
||||
p.setPen( palette().shadow().color() );
|
||||
p.setBrush( palette().shadow() );
|
||||
QPen pen( palette().dark().color(), .5 );
|
||||
p.setPen( pen );
|
||||
p.setBrush( palette().highlight() );
|
||||
|
||||
p.drawRoundedRect( r, CORNER_ROUNDNESS, CORNER_ROUNDNESS );
|
||||
|
||||
@ -110,6 +106,6 @@ OverlayWidget::paintEvent( QPaintEvent* event )
|
||||
f.setBold( true );
|
||||
|
||||
p.setFont( f );
|
||||
p.setPen( palette().light().color() );
|
||||
p.setPen( palette().highlightedText().color() );
|
||||
p.drawText( r.adjusted( 16, 16, -16, -16 ), text(), to );
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QAbstractItemView>
|
||||
|
||||
#include "dllmacro.h"
|
||||
#include <QTimer>
|
||||
|
||||
class DLLEXPORT OverlayWidget : public QWidget
|
||||
{
|
||||
@ -12,18 +13,18 @@ Q_OBJECT
|
||||
Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
|
||||
|
||||
public:
|
||||
OverlayWidget( QAbstractItemView* parent );
|
||||
OverlayWidget( QWidget* parent );
|
||||
~OverlayWidget();
|
||||
|
||||
QPixmap pixmap();
|
||||
|
||||
qreal opacity() const { return m_opacity; }
|
||||
void setOpacity( qreal opacity );
|
||||
|
||||
QString text() const { return m_text; }
|
||||
void setText( const QString& text );
|
||||
|
||||
void paint( QPainter* painter );
|
||||
public slots:
|
||||
void show( int timeoutSecs = 0 );
|
||||
void hide();
|
||||
|
||||
protected:
|
||||
// void changeEvent( QEvent* e );
|
||||
@ -31,10 +32,10 @@ protected:
|
||||
|
||||
private:
|
||||
QString m_text;
|
||||
QPixmap m_pixmap;
|
||||
qreal m_opacity;
|
||||
|
||||
QAbstractItemView* m_parent;
|
||||
QWidget* m_parent;
|
||||
QTimer m_timer;
|
||||
};
|
||||
|
||||
#endif // WELCOMEWIDGET_H
|
||||
#endif // OVERLAYWIDGET_H
|
||||
|
@ -56,6 +56,14 @@ WelcomeWidget::updatePlaylists()
|
||||
ui->playlistWidget->addItem( item );
|
||||
item->setData( Qt::DisplayRole, playlist->title() );
|
||||
}
|
||||
|
||||
if ( !playlists.count() )
|
||||
{
|
||||
ui->playlistWidget->overlay()->setText( tr( "You have not played any playlists yet." ) );
|
||||
ui->playlistWidget->overlay()->show();
|
||||
}
|
||||
else
|
||||
ui->playlistWidget->overlay()->hide();
|
||||
}
|
||||
|
||||
|
||||
@ -178,3 +186,10 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
PlaylistWidget::PlaylistWidget( QWidget* parent )
|
||||
: QListWidget( parent )
|
||||
{
|
||||
m_overlay = new OverlayWidget( this );
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "dllmacro.h"
|
||||
|
||||
class PlaylistModel;
|
||||
class OverlayWidget;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
@ -60,6 +61,18 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class DLLEXPORT PlaylistWidget : public QListWidget
|
||||
{
|
||||
public:
|
||||
PlaylistWidget( QWidget* parent = 0 );
|
||||
|
||||
OverlayWidget* overlay() const { return m_overlay; }
|
||||
|
||||
private:
|
||||
OverlayWidget* m_overlay;
|
||||
};
|
||||
|
||||
|
||||
class DLLEXPORT WelcomeWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -41,7 +41,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="playlistWidget"/>
|
||||
<widget class="PlaylistWidget" name="playlistWidget"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
@ -66,6 +66,11 @@
|
||||
<extends>QTreeView</extends>
|
||||
<header>playlist/playlistview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>PlaylistWidget</class>
|
||||
<extends>QListWidget</extends>
|
||||
<header>widgets/welcomewidget.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
@ -140,6 +140,9 @@ Scrobbler::scrobble()
|
||||
{
|
||||
Q_ASSERT( QThread::currentThread() == thread() );
|
||||
|
||||
if ( !m_scrobbler || m_track.isNull() )
|
||||
return;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << m_track.toString();
|
||||
m_scrobbler->cache( m_track );
|
||||
m_scrobbler->submit();
|
||||
|
Loading…
x
Reference in New Issue
Block a user