make PlaylistModel observe albums for changes to the cover image (needed for services...
[amarok.git] / src / playlist / PlaylistGraphicsView.cpp
blob8d8311bb3a43d17957d9dd3fb314dedece75e495
1 /***************************************************************************
2 * copyright : (C) 2007 Ian Monroe <ian@monroe.nu> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License version 2 *
6 * as published by the Free Software Foundation. *
7 ***************************************************************************/
9 #include "debug.h"
10 #include "PlaylistModel.h"
11 #include "PlaylistGraphicsItem.h"
12 #include "PlaylistGraphicsView.h"
14 #include <QModelIndex>
15 #include <QGraphicsScene>
17 PlaylistNS::GraphicsView::GraphicsView( QWidget* parent, PlaylistNS::Model* model )
18 : QGraphicsView( parent )
19 , m_model( model )
21 DEBUG_BLOCK
22 setScene( new QGraphicsScene() );
23 rowsInserted( QModelIndex(), 0, m_model->rowCount() - 1);
24 connect( m_model, SIGNAL( modelReset() ), this, SLOT( modelReset() ) );
25 connect( m_model, SIGNAL( rowsInserted( const QModelIndex&, int, int ) ), this, SLOT( rowsInserted( const QModelIndex &, int, int ) ) );
26 connect( m_model, SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ), this, SLOT( rowsRemoved( const QModelIndex&, int, int ) ) );
27 show();
30 void
31 PlaylistNS::GraphicsView::rowsInserted( const QModelIndex& parent, int start, int end )
33 Q_UNUSED( parent );
34 for( int i = start; i <= end; i++ )
36 PlaylistNS::GraphicsItem* item = new PlaylistNS::GraphicsItem();
37 item->setPos( 0.0, PlaylistNS::GraphicsItem::height() * i );
38 scene()->addItem( item );
39 m_tracks.insert( i, item );
43 void
44 PlaylistNS::GraphicsView::rowsRemoved(const QModelIndex& parent, int start, int end )
46 Q_UNUSED( parent );
47 for( int i = end; i >= start; i-- )
48 delete m_tracks.takeAt( i );
51 void
52 PlaylistNS::GraphicsView::modelReset()
54 foreach( PlaylistNS::GraphicsItem* it, m_tracks )
56 delete it;
58 m_tracks.clear();
61 #include "PlaylistGraphicsView.moc"