1 //Maintainer: Max Howell <max.howell@methylblue.com>
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.
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
22 #include <q3valuevector.h>
24 #include <Q3ValueList>
35 class PlaylistItem
: public MetaBundle
, public K3ListViewItem
37 typedef MetaBundle super
;
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
;
48 PlaylistItem( Q3ListView
*, Q3ListViewItem
* ); //used by PlaylistLoader
49 PlaylistItem( const MetaBundle
&, Q3ListViewItem
*, bool enabled
= true );
52 /// pass 'raw' data here, for example "92" for Length, and not "1:32"
53 virtual void setText( int column
, const QString
& );
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
; }
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()
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;
110 virtual void aboutToChange( const Q3ValueList
<int> &columns
);
111 virtual void reactToChanges( const Q3ValueList
<int> &columns
);
114 friend class Playlist
;
117 struct paintCacheItem
{
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
);
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
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
;
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
>
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; }