1 /***************************************************************************
2 * copyright : (C) 2007 Ian Monroe <ian@monroe.nu> *
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 ***************************************************************************/
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
)
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 ) ) );
31 PlaylistNS::GraphicsView::rowsInserted( const QModelIndex
& parent
, int start
, int end
)
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
);
44 PlaylistNS::GraphicsView::rowsRemoved(const QModelIndex
& parent
, int start
, int end
)
47 for( int i
= end
; i
>= start
; i
-- )
48 delete m_tracks
.takeAt( i
);
52 PlaylistNS::GraphicsView::modelReset()
54 foreach( PlaylistNS::GraphicsItem
* it
, m_tracks
)
61 #include "PlaylistGraphicsView.moc"