make PlaylistModel observe albums for changes to the cover image (needed for services...
[amarok.git] / src / playlistitem.h
blobd68ac7d608c40df34473e3b0884c1dbcfeb73f51
1 //Maintainer: Max Howell <max.howell@methylblue.com>
2 //Copyright: GPL v2
4 //NOTE please show restraint when adding data members to this class!
5 // some users have playlists with 20,000 items or more in, one 32 bit int adds up rapidly!
6 // -- on second thought, 80KB isn't all that much. be careful with QStrings, though.
9 #ifndef PLAYLISTITEM_H
10 #define PLAYLISTITEM_H
12 #include "metabundle.h" //baseclass
13 #include "amarok_export.h"
15 #include <k3listview.h> //baseclass
16 #include <kurl.h> //stack allocated
18 #include <qcolor.h> //stack allocated
19 #include <qfont.h> //stack allocated
20 #include <qmap.h>
21 #include <QPixmap>
22 #include <q3valuevector.h>
23 //Added by qt3to4:
24 #include <Q3ValueList>
25 #include <Q3PtrList>
27 class QColorGroup;
28 class QImage;
29 class Q3ListViewItem;
30 class QPainter;
31 class MetaBundle;
32 class Playlist;
33 class PlaylistAlbum;
35 class PlaylistItem : public MetaBundle, public K3ListViewItem
37 typedef MetaBundle super;
38 public:
39 /// Indicates that the current-track pixmap has changed. Animation must be redrawn.
40 static void setPixmapChanged() { s_pixmapChanged = true; }
42 /// For the glow colouration stuff
43 static double glowIntensity;
44 static QColor glowText;
45 static QColor glowBase;
47 public:
48 PlaylistItem( Q3ListView*, Q3ListViewItem* ); //used by PlaylistLoader
49 PlaylistItem( const MetaBundle&, Q3ListViewItem*, bool enabled = true );
50 ~PlaylistItem();
52 /// pass 'raw' data here, for example "92" for Length, and not "1:32"
53 virtual void setText( int column, const QString& );
55 /**
56 * @return The text of the column @p column, formatted for display purposes.
57 * (For example, if the Length is 92, "1:32".)
59 virtual QString text( int column ) const;
61 void filter( const QString &expression ); //makes visible depending on whether it matches
63 bool isCurrent() const;
65 bool isQueued() const;
66 int queuePosition() const;
68 bool isEnabled() const { return m_enabled; }
69 bool isDynamicEnabled() const { return m_dynamicEnabled; }
70 bool isFilestatusEnabled() const { return m_filestatusEnabled; }
71 void setEnabled();
72 void setDynamicEnabled( bool enabled );
73 void setFilestatusEnabled( bool enabled );
74 void setAllCriteriaEnabled( bool enabled );
76 void setSelected( bool selected );
77 void setVisible( bool visible );
79 void setEditing( int column );
80 bool isEditing( int column ) const;
81 bool anyEditing() const;
82 void setIsBeingRenamed( bool renaming ) { m_isBeingRenamed = renaming; }
83 bool isBeingRenamed() const { return m_isBeingRenamed; }
84 void setDeleteAfterEditing( bool dae ) { m_deleteAfterEdit = dae; }
85 bool deleteAfterEditing() const { return m_deleteAfterEdit; }
86 void setIsNew( bool is ) { m_isNew = is; }
88 /// convenience functions
89 Playlist *listView() const { return reinterpret_cast<Playlist*>( K3ListViewItem::listView() ); }
90 PlaylistItem *nextSibling() const { return static_cast<PlaylistItem*>( K3ListViewItem::nextSibling() ); }
92 static int ratingAtPoint( int x );
93 static int ratingColumnWidth();
95 /// like QWidget::update()
96 void update() const;
98 //updates only the area of a specific column, avoids flickering of the current item marker
99 void updateColumn( int column ) const;
101 virtual void setup(); // from QListViewItem
103 virtual bool operator== ( const PlaylistItem & item ) const;
104 virtual bool operator< ( const PlaylistItem & item ) const;
106 PlaylistItem *nextInAlbum() const;
107 PlaylistItem *prevInAlbum() const;
109 protected:
110 virtual void aboutToChange( const Q3ValueList<int> &columns );
111 virtual void reactToChanges( const Q3ValueList<int> &columns );
113 private:
114 friend class Playlist;
117 struct paintCacheItem {
118 int width;
119 int height;
120 QString text;
121 QFont font;
122 QColor color;
123 bool selected;
124 QMap<QString, QPixmap> map;
127 virtual void paintCell( QPainter*, const QColorGroup&, int, int, int );
128 void drawRating( QPainter *p );
129 void drawRating( QPainter *p, int stars, int greystars, bool half );
130 void drawMood( QPainter *p, int width, int height );
131 virtual void moodbarJobEvent( int newState );
133 // Used for sorting
134 virtual int compare( Q3ListViewItem*, int, bool ) const;
137 * Paints a focus indicator on the rectangle (current item). We disable it
138 * over the currentTrack, cause it would look like crap and flicker.
140 void paintFocus( QPainter*, const QColorGroup&, const QRect& );
142 static void imageTransparency( QImage& image, float factor );
144 AtomicString artist_album() const; // returns a placeholder 'artist' for compilations
146 void refAlbum();
147 void derefAlbum();
149 void decrementTotals();
150 void incrementTotals();
152 void incrementCounts();
153 void decrementCounts();
154 void incrementLengths();
155 void decrementLengths();
157 int totalIncrementAmount() const;
159 PlaylistAlbum *m_album;
160 bool m_enabled;
161 bool m_dynamicEnabled;
162 bool m_filestatusEnabled;
163 bool m_deleteAfterEdit;
164 bool m_isBeingRenamed;
165 bool m_isNew; //New items will be assigned a different color
167 static bool s_pixmapChanged;
168 static const QString &editingText();
171 class PLItemList: public Q3PtrList<PlaylistItem>
173 public:
174 PLItemList() : Q3PtrList<PlaylistItem>() { }
175 PLItemList( const Q3PtrList<PlaylistItem> &list ) : Q3PtrList<PlaylistItem>( list ) { }
176 PLItemList( PlaylistItem *item ) : Q3PtrList<PlaylistItem>() { append( item ); }
178 inline PLItemList &operator<<( PlaylistItem *item ) { append( item ); return *this; }
182 #endif