extragear/multimedia/amarok/src/context/applets/albums

Seb Ruiz ruiz at kde.org
Tue Sep 2 15:24:39 CEST 2008


SVN commit 856266 by seb:

Give the Albums applet a makeover. Modelled off the collection browser view, and responds to hover events and presents itself much more nicely. Usability has improved, imo, although the SVG colour choices seem to cause it to blend into the background a bit. Some contrast is needed I think.
RFC compared to the previous version please.
CCMAIL:amarok-devel at kde.org


 M  +22 -7     Albums.cpp  
 M  +88 -55    AlbumsView.cpp  
 M  +3 -17     AlbumsView.h  


--- trunk/extragear/multimedia/amarok/src/context/applets/albums/Albums.cpp #856265:856266
@@ -125,32 +125,47 @@
         return;
     
     m_names = data[ "names" ].toList();
-    m_trackCounts = data[ "trackCounts" ].toList();;
+    m_trackCounts = data[ "trackCounts" ].toList();
     m_covers = data[ "covers" ].toList();;
     m_albumsTracks = data[ "albumsTracks" ].toList();
     
     kDebug() << "Albums::dataUpdated. count: " << m_albumCount << " names " << m_names.count();
 
-    m_model->clear();    
+    m_model->clear();
        
     int row = 0;
     
     foreach( const QVariant &albumName, m_names )
     {
         QStandardItem *albumItem = new QStandardItem();
-        albumItem->setData( albumName.toString(), AlbumRoles::AlbumName );
-        
+
+        QString displayText = albumName.toString();
+
         if( m_trackCounts.size() > 0 )
-            albumItem->setData( m_trackCounts[row].toString(), AlbumRoles::TrackCount );
+            displayText += "\n" + m_trackCounts[row].toString();
 
+        albumItem->setText( displayText );
+
         if( m_covers.size() > 0 )
-            albumItem->setData( m_covers[row].value<QPixmap>(), AlbumRoles::AlbumCover );
+        {
+            QPixmap cover = m_covers[row].value<QPixmap>();
+            albumItem->setIcon( QIcon( cover ) );
+        }
+        else
+            albumItem->setIcon( KIcon( "media-album-cover" ) );
         
+        QSize sizeHint = albumItem->sizeHint();
+        sizeHint.setHeight( 80 );
+        albumItem->setSizeHint( sizeHint );
+        
         int childRow = 0;
         foreach( const QVariant &trackName, m_albumsTracks[row].toList() )
         {
+            QString text = QString( "%1 - " ).arg( childRow + 1 ) + trackName.toString();
+
             QStandardItem *trackItem = new QStandardItem();
-            trackItem->setData( trackName.toString(), AlbumRoles::TrackName );
+            trackItem->setText( text );
+
             albumItem->setChild( childRow, trackItem );
             childRow++;
         }
--- trunk/extragear/multimedia/amarok/src/context/applets/albums/AlbumsView.cpp #856265:856266
@@ -1,5 +1,6 @@
 /*******************************************************************************
 * copyright              : (C) 2008 William Viana Soares <vianasw at gmail.com>   *
+*                        : (C) 2008 Seb Ruiz <ruiz at kde.org>                    *
 *                                                                              *
 ********************************************************************************/
 
@@ -14,45 +15,107 @@
 
 #include "AlbumsView.h"
 #include "Debug.h"
+#include "SvgHandler.h"
 
+#include <QHeaderView>
+#include <QPainter>
+#include <QStyleOptionViewItem>
 #include <QTreeView>
-#include <QHeaderView>
-#include <QItemDelegate>
 
 #include <KIconLoader>
 
-#include "AlbumsDelegate.h"
+class AlbumsTreeView : public QTreeView
+{
+    public:
+        AlbumsTreeView( QWidget * parent = 0 ) : QTreeView( parent )
+        {
+            setAttribute( Qt::WA_NoSystemBackground );
+            viewport()->setAutoFillBackground( false );
+    
+            setFrameStyle( QFrame::NoFrame );
+            setHeaderHidden( true );
+            setIconSize( QSize(60,60) );
 
+            // setAnimated( true ); // looks TERRIBLE
 
+            setRootIsDecorated( false );
+            setMouseTracking( true );
+    
+            setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
+            setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); // Scrolling per item is really not smooth and looks terrible
+            
+            setAlternatingRowColors( true );
+            //transparency
+            QPalette p = palette();
+            QColor c = p.color( QPalette::Base );
+            c.setAlpha( 0 );
+            p.setColor( QPalette::Base, c );
+            
+            //HACK ALERT, make a workaround, for now, for the alternating row color issue
+            c = Qt::white;
+            c.setAlpha( 31 );
+            p.setColor( QPalette::AlternateBase, c );
+            
+            setPalette( p );
+        }
+
+    protected:
+        void drawRow( QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
+        {
+            const QStyleOptionViewItemV4 opt = option;
+
+            const bool alternate = opt.features & QStyleOptionViewItemV2::Alternate;
+
+            const int width = option.rect.width();
+            const int height = option.rect.height();
+
+            if( height > 0 )
+            {
+                painter->save();
+                QPixmap background;
+
+                if ( !alternate )
+                    background = The::svgHandler()->renderSvgWithDividers( "service_list_item", width, height, "service_list_item" );
+                else
+                    background = The::svgHandler()->renderSvgWithDividers( "alt_service_list_item", width, height, "alt_service_list_item" );
+
+                painter->drawPixmap( option.rect.topLeft().x(), option.rect.topLeft().y(), background );
+
+                painter->restore();
+            }
+    
+            QTreeView::drawRow( painter, option, index ); 
+        }
+};
+
 AlbumsView::AlbumsView( QGraphicsWidget *parent )
     : QGraphicsProxyWidget( parent )
 {
-    QTreeView* native = new QTreeView;
-    setWidget( native );
-    native->setAttribute( Qt::WA_NoSystemBackground );
-    native->viewport()->setAutoFillBackground( false );
-    native->setFrameStyle( QFrame::NoFrame );
-    native->setHeaderHidden( true );
+    AlbumsTreeView* treeView = new AlbumsTreeView;
+    setWidget( treeView );
+    
+    connect( treeView, SIGNAL(       clicked( const QModelIndex & ) ), this, SLOT( itemClicked( const QModelIndex & ) ) );
+    connect( treeView, SIGNAL( doubleClicked( const QModelIndex & ) ), this, SLOT( itemClicked( const QModelIndex & ) ) );
 
-    // native->setAnimated( true ); // causes flickering
+    treeView->show();
+}
 
-    native->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
-    native->setIconSize( QSize( KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium ) );
-    native->setRootIsDecorated( true );
-    native->setMouseTracking( true );
-    native->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); // Scrolling per item is really not smooth and looks terrible
+void
+AlbumsView::setModel( QAbstractItemModel *model )
+{
+    nativeWidget()->setModel( model );                                                                                               
+}
 
-    AlbumsDelegate *delegate = new AlbumsDelegate( native );
-    native->setItemDelegate( delegate );
-    connect( native, SIGNAL(       clicked( const QModelIndex & ) ), this, SLOT( itemClicked( const QModelIndex & ) ) );
-    connect( native, SIGNAL( doubleClicked( const QModelIndex & ) ), this, SLOT( itemClicked( const QModelIndex & ) ) );
-//     connect( native, SIGNAL( entered( const QModelIndex & ) ), delegate, SLOT( highlightRow( const QModelIndex & ) ) );
-
-    native->show();
+QAbstractItemModel *
+AlbumsView::model()
+{
+    return nativeWidget()->model();
 }
 
-AlbumsView::~AlbumsView()
+QTreeView*
+AlbumsView::nativeWidget() const
 {
+    return static_cast<QTreeView*>( widget() );
 }
 
 void
@@ -81,45 +144,15 @@
 */
 
 void
-AlbumsView::setModel( QAbstractItemModel *model )
-{
-    nativeWidget()->setModel( model );
-}
-
-QAbstractItemModel *
-AlbumsView::model()
-{
-    return nativeWidget()->model();
-}
-
-void
-AlbumsView::setStyleSheet( const QString &stylesheet )
-{
-    widget()->setStyleSheet( stylesheet );
-}
-
-QString
-AlbumsView::styleSheet()
-{
-    return widget()->styleSheet();
-}
-
-QTreeView*
-AlbumsView::nativeWidget() const
-{
-    return static_cast<QTreeView*>( widget() );
-}
-
-void
 AlbumsView::resizeEvent( QGraphicsSceneResizeEvent *event )
 {
     QGraphicsProxyWidget::resizeEvent( event );
 
     const int newWidth = size().width() / nativeWidget()->header()->count();
 
-    for ( int i = 0; i < nativeWidget()->header()->count(); ++i ) {
+    for( int i = 0; i < nativeWidget()->header()->count(); ++i )
         nativeWidget()->header()->resizeSection( i, newWidth );
-    }
+
     nativeWidget()->setColumnWidth( 0, 100 );
 }
 
--- trunk/extragear/multimedia/amarok/src/context/applets/albums/AlbumsView.h #856265:856266
@@ -1,5 +1,6 @@
 /*******************************************************************************
 * copyright              : (C) 2008 William Viana Soares <vianasw at gmail.com>   *
+*                        : (C) 2008 Seb Ruiz <ruiz at kde.org>                    *
 *                                                                              *
 ********************************************************************************/
 
@@ -16,7 +17,7 @@
 #ifndef AMAROK_ALBUMSVIEW_H
 #define AMAROK_ALBUMSVIEW_H
 
-#include <QtGui/QGraphicsProxyWidget>
+#include <QGraphicsProxyWidget>
 
 class QTreeView;
 class QAbstractItemModel;
@@ -25,15 +26,12 @@
 class AlbumsView : public QGraphicsProxyWidget
 {
     Q_OBJECT
-
     Q_PROPERTY( QAbstractItemModel* model READ model WRITE setModel )
-    Q_PROPERTY( QGraphicsWidget* parentWidget READ parentWidget )
-    Q_PROPERTY( QString styleSheet READ styleSheet WRITE setStyleSheet )
     Q_PROPERTY( QTreeView* nativeWidget READ nativeWidget )
 
 public:
     explicit AlbumsView( QGraphicsWidget *parent = 0 );
-    ~AlbumsView();
+    ~AlbumsView() { }
 
     /**
      * Sets a model for this weather view
@@ -48,18 +46,6 @@
     QAbstractItemModel *model();
 
     /**
-     * Sets the stylesheet used to control the visual display of this AlbumsView
-     *
-     * @arg stylesheet a CSS string
-     */
-    void setStyleSheet( const QString &stylesheet );
-
-    /**
-     * @return the stylesheet currently used with this widget
-     */
-    QString styleSheet();
-
-    /**
      * @return the native widget wrapped by this AlbumsView
      */
     QTreeView* nativeWidget() const;


More information about the Amarok-devel mailing list