Just as a relaxing sunday evening project, try to create a simple, alternate playlist...
[amarok.git] / src / playlist / PlaylistGraphicsItem.h
blob8e53cce4c8f1991e71034e561fad8b492d1dac41
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 #ifndef AMAROK_PLAYLISTGRAPHICSITEM_H
10 #define AMAROK_PLAYLISTGRAPHICSITEM_H
13 #include "meta.h"
14 #include <QGraphicsItem>
16 class QFontMetricsF;
18 namespace Playlist
20 /**
21 * A lazy-loading QGraphicsItem to display one track in the playlist.
22 * If a user drags 20000 tracks into the playlist, 20000 GraphicsItem's
23 * will be created. However only the tracks that are visible will query
24 * the model for their information, the rest will take up very little memory
25 * and really aren't associated with a particular track yet.
26 * On a paint operation the GraphicsItem will be "active" by creating an ActiveItems.
27 * Do not add any data members to GraphicsItem, you should be able to add them to
28 * ActiveItems instead.
30 class GraphicsItem : public QGraphicsItem
32 class ActiveItems;
34 public:
35 GraphicsItem();
36 ~GraphicsItem();
37 ///Be sure to read ::paint rules in-method
38 void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget );
39 QRectF boundingRect() const;
40 void setupItem();
41 static qreal height() { return s_height; }
42 void refresh();
43 void play();
45 protected:
46 void dragEnterEvent( QGraphicsSceneDragDropEvent *event );
47 void dropEvent( QGraphicsSceneDragDropEvent * event );
48 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* event );
49 void mousePressEvent( QGraphicsSceneMouseEvent* event );
50 void mouseMoveEvent( QGraphicsSceneMouseEvent* event );
51 void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
53 private:
54 void init( Meta::TrackPtr track );
55 void resize( Meta::TrackPtr track, int totalWidth );
56 int getRow() const { return int( ( mapToScene( 0.0, 0.0 ).y() ) / s_height ); }
60 ActiveItems* m_items;
61 static const qreal ALBUM_WIDTH;
62 static const qreal MARGIN;
63 static qreal s_height;
64 static QFontMetricsF* s_fm;
68 #endif