Chop ::paint into more managable pieces ( using big axe ) as it was getting really...
[amarok.git] / src / playlist / PlaylistGraphicsItem.h
blob3bfafdbf216e9354cbe6f0935f4f7e4ae65ed724
1 /***************************************************************************
2 * copyright : (C) 2007 Ian Monroe <ian@monroe.nu>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License or (at your option) version 3 or any later version
8 * accepted by the membership of KDE e.V. (or its successor approved
9 * by the membership of KDE e.V.), which shall act as a proxy
10 * defined in Section 14 of version 3 of the license.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **************************************************************************/
22 #ifndef AMAROK_PLAYLISTGRAPHICSITEM_H
23 #define AMAROK_PLAYLISTGRAPHICSITEM_H
26 #include "Meta.h"
27 #include <QGraphicsItem>
28 #include <QSvgRenderer>
30 class QFontMetricsF;
32 namespace Playlist
34 /**
35 * A lazy-loading QGraphicsItem to display one track in the playlist.
36 * If a user drags 20000 tracks into the playlist, 20000 GraphicsItem's
37 * will be created. However only the tracks that are visible will query
38 * the model for their information, the rest will take up very little memory
39 * and really aren't associated with a particular track yet.
40 * On a paint operation the GraphicsItem will be "active" by creating an ActiveItems.
41 * Do not add any data members to GraphicsItem, you should be able to add them to
42 * ActiveItems instead.
44 class GraphicsItem : public QGraphicsItem
46 class ActiveItems;
48 public:
49 GraphicsItem();
50 ~GraphicsItem();
51 ///Be sure to read ::paint rules in-method
52 void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget );
53 QRectF boundingRect() const;
54 void setupItem();
55 void refresh();
56 void play();
58 void setRow( int row );
59 const QRectF imageLocation() const { return QRectF( MARGIN, MARGIN, ALBUM_WIDTH, ALBUM_WIDTH ); }
61 const bool hasImage() const;
62 void showImage() const;
63 void fetchImage();
64 void unsetImage();
65 void dataChanged();
67 const int groupMode() const { return m_groupMode; }
69 protected:
70 void dragEnterEvent( QGraphicsSceneDragDropEvent *event );
71 void dropEvent( QGraphicsSceneDragDropEvent * event );
72 void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* event );
73 void mousePressEvent( QGraphicsSceneMouseEvent* event );
74 void mouseMoveEvent( QGraphicsSceneMouseEvent* event );
75 void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
76 void hoverEnterEvent ( QGraphicsSceneHoverEvent * event );
78 private:
79 void init( Meta::TrackPtr track );
80 void resize( Meta::TrackPtr track, int totalWidth );
81 QString findArtistForCurrentAlbum() const;
84 void paintSingleTrack ( QPainter* painter, const QStyleOptionGraphicsItem* option, bool active );
85 void paintHead ( QPainter* painter, const QStyleOptionGraphicsItem* option, bool active );
86 void paintCollapsedHead ( QPainter* painter, const QStyleOptionGraphicsItem* option, bool active );
87 void paintBody( QPainter* painter, const QStyleOptionGraphicsItem* option, bool active, bool alternate );
88 void paintTail( QPainter* painter, const QStyleOptionGraphicsItem* option, bool active, bool alternate );
89 void paintCollapsed( );
91 QPixmap getCachedSvg( QString name, int width, int height );
92 void handleActiveOverlay( QRectF rect, bool active );
94 ActiveItems* m_items;
95 qreal m_height;
96 int m_groupMode;
97 int m_currentRow;
98 bool m_groupModeChanged;
99 bool m_collapsible;
100 bool m_dataChanged;
102 static const qreal ALBUM_WIDTH;
103 static const qreal MARGIN;
104 static QFontMetricsF* s_fm;
105 static QSvgRenderer * s_svgRenderer;
109 #endif