mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
* Polished AlbumView / Model.
This commit is contained in:
@@ -125,6 +125,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
|
|||||||
playlist/albumitem.cpp
|
playlist/albumitem.cpp
|
||||||
playlist/albummodel.cpp
|
playlist/albummodel.cpp
|
||||||
playlist/albumproxymodel.cpp
|
playlist/albumproxymodel.cpp
|
||||||
|
playlist/albumitemdelegate.cpp
|
||||||
playlist/albumview.cpp
|
playlist/albumview.cpp
|
||||||
|
|
||||||
sourcetree/sourcesmodel.cpp
|
sourcetree/sourcesmodel.cpp
|
||||||
@@ -255,6 +256,7 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui}
|
|||||||
playlist/albumitem.h
|
playlist/albumitem.h
|
||||||
playlist/albummodel.h
|
playlist/albummodel.h
|
||||||
playlist/albumproxymodel.h
|
playlist/albumproxymodel.h
|
||||||
|
playlist/albumitemdelegate.h
|
||||||
playlist/albumview.h
|
playlist/albumview.h
|
||||||
|
|
||||||
sourcetree/sourcesmodel.h
|
sourcetree/sourcesmodel.h
|
||||||
|
@@ -55,13 +55,13 @@
|
|||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>0</width>
|
<width>0</width>
|
||||||
<height>210</height>
|
<height>192</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>16777215</width>
|
<width>16777215</width>
|
||||||
<height>210</height>
|
<height>192</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
65
src/playlist/albumitemdelegate.cpp
Normal file
65
src/playlist/albumitemdelegate.cpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#include "albumitemdelegate.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QAbstractItemView>
|
||||||
|
|
||||||
|
#include "tomahawk/query.h"
|
||||||
|
#include "tomahawk/result.h"
|
||||||
|
#include "tomahawk/tomahawkapp.h"
|
||||||
|
|
||||||
|
#include "playlist/albumitem.h"
|
||||||
|
#include "playlist/albumproxymodel.h"
|
||||||
|
|
||||||
|
|
||||||
|
AlbumItemDelegate::AlbumItemDelegate( QAbstractItemView* parent, AlbumProxyModel* proxy )
|
||||||
|
: QStyledItemDelegate( (QObject*)parent )
|
||||||
|
, m_view( parent )
|
||||||
|
, m_model( proxy )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QSize
|
||||||
|
AlbumItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||||
|
{
|
||||||
|
QSize size = QStyledItemDelegate::sizeHint( option, index );
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||||
|
{
|
||||||
|
AlbumItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) );
|
||||||
|
if ( !item )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QStyleOptionViewItemV4 opt = option;
|
||||||
|
initStyleOption( &opt, QModelIndex() );
|
||||||
|
APP->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );
|
||||||
|
|
||||||
|
if ( option.state & QStyle::State_Selected )
|
||||||
|
{
|
||||||
|
opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
painter->setRenderHint( QPainter::Antialiasing );
|
||||||
|
painter->setPen( opt.palette.color( QPalette::Text ) );
|
||||||
|
|
||||||
|
painter->drawPixmap( option.rect.adjusted( 4, 4, -4, -38 ), item->cover );
|
||||||
|
|
||||||
|
QTextOption to;
|
||||||
|
to.setAlignment( Qt::AlignHCenter );
|
||||||
|
QFont font = opt.font;
|
||||||
|
QFont boldFont = opt.font;
|
||||||
|
boldFont.setBold( true );
|
||||||
|
|
||||||
|
painter->drawText( option.rect.adjusted( 0, option.rect.height() - 16, 0, -2 ), item->album()->artist()->name(), to );
|
||||||
|
|
||||||
|
painter->setFont( boldFont );
|
||||||
|
painter->drawText( option.rect.adjusted( 0, option.rect.height() - 32, 0, -18 ), item->album()->name(), to );
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
|
}
|
26
src/playlist/albumitemdelegate.h
Normal file
26
src/playlist/albumitemdelegate.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef ALBUMITEMDELEGATE_H
|
||||||
|
#define ALBUMITEMDELEGATE_H
|
||||||
|
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
class AlbumProxyModel;
|
||||||
|
|
||||||
|
class AlbumItemDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
AlbumItemDelegate( QAbstractItemView* parent = 0, AlbumProxyModel* proxy = 0 );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
|
||||||
|
// QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QAbstractItemView* m_view;
|
||||||
|
AlbumProxyModel* m_model;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ALBUMITEMDELEGATE_H
|
@@ -20,7 +20,7 @@ AlbumModel::AlbumModel( QObject* parent )
|
|||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" )
|
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" )
|
||||||
.scaled( QSize( 64, 64 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
.scaled( QSize( 120, 120 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ AlbumModel::data( const QModelIndex& index, int role ) const
|
|||||||
|
|
||||||
if ( role == Qt::SizeHintRole )
|
if ( role == Qt::SizeHintRole )
|
||||||
{
|
{
|
||||||
return QSize( 90, 90 );
|
return QSize( 116, 150 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole )
|
if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole )
|
||||||
@@ -110,7 +110,7 @@ AlbumModel::data( const QModelIndex& index, int role ) const
|
|||||||
switch( index.column() )
|
switch( index.column() )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return album->name();
|
return album->name() + "<br/>Test\nTest2";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ AlbumModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const Tomah
|
|||||||
albumitem->cover = m_defaultCover;
|
albumitem->cover = m_defaultCover;
|
||||||
albumitem->index = createIndex( m_rootItem->children.count() - 1, 0, albumitem );
|
albumitem->index = createIndex( m_rootItem->children.count() - 1, 0, albumitem );
|
||||||
|
|
||||||
QString imgurl = "http://ws.audioscrobbler.com/2.0/?method=album.imageredirect&artist=%1&album=%2&size=medium&api_key=7a90f6672a04b809ee309af169f34b8b";
|
QString imgurl = "http://ws.audioscrobbler.com/2.0/?method=album.imageredirect&artist=%1&album=%2&size=large&api_key=7a90f6672a04b809ee309af169f34b8b";
|
||||||
QNetworkRequest req( imgurl.arg( album->artist()->name() ).arg( album->name() ) );
|
QNetworkRequest req( imgurl.arg( album->artist()->name() ).arg( album->name() ) );
|
||||||
req.setAttribute( QNetworkRequest::User, (qlonglong)albumitem );
|
req.setAttribute( QNetworkRequest::User, (qlonglong)albumitem );
|
||||||
QNetworkReply* reply = APP->nam()->get( req );
|
QNetworkReply* reply = APP->nam()->get( req );
|
||||||
@@ -288,7 +288,7 @@ AlbumModel::onCoverArtDownloaded()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ai->setCover( pm.scaled( QSize( 64, 64 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
|
ai->setCover( pm.scaled( QSize( 150, 150 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include "audioengine.h"
|
#include "audioengine.h"
|
||||||
#include "tomahawksettings.h"
|
#include "tomahawksettings.h"
|
||||||
|
|
||||||
|
#include "albumitemdelegate.h"
|
||||||
#include "albummodel.h"
|
#include "albummodel.h"
|
||||||
#include "albumproxymodel.h"
|
#include "albumproxymodel.h"
|
||||||
#include "playlistmanager.h"
|
#include "playlistmanager.h"
|
||||||
@@ -27,11 +28,12 @@ AlbumView::AlbumView( QWidget* parent )
|
|||||||
setDropIndicatorShown( false );
|
setDropIndicatorShown( false );
|
||||||
setDragDropOverwriteMode( false );
|
setDragDropOverwriteMode( false );
|
||||||
setUniformItemSizes( true );
|
setUniformItemSizes( true );
|
||||||
setSpacing( 8 );
|
setSpacing( 20 );
|
||||||
|
setWordWrap( true );
|
||||||
|
|
||||||
setResizeMode( Adjust );
|
setResizeMode( Adjust );
|
||||||
setViewMode( IconMode );
|
setViewMode( IconMode );
|
||||||
setIconSize( QSize( 64, 64 ) );
|
// setIconSize( QSize( 64, 64 ) );
|
||||||
|
|
||||||
setProxyModel( new AlbumProxyModel( this ) );
|
setProxyModel( new AlbumProxyModel( this ) );
|
||||||
|
|
||||||
@@ -49,8 +51,7 @@ void
|
|||||||
AlbumView::setProxyModel( AlbumProxyModel* model )
|
AlbumView::setProxyModel( AlbumProxyModel* model )
|
||||||
{
|
{
|
||||||
m_proxyModel = model;
|
m_proxyModel = model;
|
||||||
// m_delegate = new PlaylistItemDelegate( this, m_proxyModel );
|
setItemDelegate( new AlbumItemDelegate( this, m_proxyModel ) );
|
||||||
// setItemDelegate( m_delegate );
|
|
||||||
|
|
||||||
QListView::setModel( m_proxyModel );
|
QListView::setModel( m_proxyModel );
|
||||||
}
|
}
|
||||||
|
@@ -38,12 +38,17 @@ PlaylistView::setupMenus()
|
|||||||
{
|
{
|
||||||
m_itemMenu.clear();
|
m_itemMenu.clear();
|
||||||
|
|
||||||
|
unsigned int i = 0;
|
||||||
|
foreach( const QModelIndex& idx, selectedIndexes() )
|
||||||
|
if ( idx.column() == 0 )
|
||||||
|
i++;
|
||||||
|
|
||||||
m_playItemAction = m_itemMenu.addAction( tr( "&Play" ) );
|
m_playItemAction = m_itemMenu.addAction( tr( "&Play" ) );
|
||||||
m_addItemsToQueueAction = m_itemMenu.addAction( tr( "Add to &Queue" ) );
|
m_addItemsToQueueAction = m_itemMenu.addAction( tr( "Add to &Queue" ) );
|
||||||
m_itemMenu.addSeparator();
|
m_itemMenu.addSeparator();
|
||||||
m_addItemsToPlaylistAction = m_itemMenu.addAction( tr( "&Add to Playlist" ) );
|
m_addItemsToPlaylistAction = m_itemMenu.addAction( tr( "&Add to Playlist" ) );
|
||||||
m_itemMenu.addSeparator();
|
m_itemMenu.addSeparator();
|
||||||
m_deleteItemsAction = m_itemMenu.addAction( tr( "&Delete Item" ) );
|
m_deleteItemsAction = m_itemMenu.addAction( i > 1 ? tr( "&Delete Items" ) : tr( "&Delete Item" ) );
|
||||||
|
|
||||||
if ( model() )
|
if ( model() )
|
||||||
m_deleteItemsAction->setEnabled( !model()->isReadOnly() );
|
m_deleteItemsAction->setEnabled( !model()->isReadOnly() );
|
||||||
|
Reference in New Issue
Block a user