summaryrefslogtreecommitdiffstats
path: root/amarok/src/playlistitem.h
blob: 16f01caa6a5b7a4a1f9949fff0492342c9db3863 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//Maintainer: Max Howell <max.howell@methylblue.com>
//Copyright:  GPL v2

//NOTE please show restraint when adding data members to this class!
//     some users have playlists with 20,000 items or more in, one 32 bit int adds up rapidly!
//     -- on second thought, 80KB isn't all that much. be careful with TQStrings, though.


#ifndef PLAYLISTITEM_H
#define PLAYLISTITEM_H

#include "metabundle.h" //baseclass
#include "amarok_export.h"

#include <tdelistview.h> //baseclass
#include <kurl.h>      //stack allocated

#include <tqcolor.h>    //stack allocated
#include <tqfont.h>     //stack allocated
#include <tqmap.h>
#include <tqpixmap.h>
#include <tqvaluevector.h>

class TQColorGroup;
class TQDomNode;
class TQImage;
class TQListViewItem;
class TQPainter;
class MetaBundle;
class Playlist;
class PlaylistAlbum;

class LIBAMAROK_EXPORT PlaylistItem : public MetaBundle, public TDEListViewItem
{
    typedef MetaBundle super;
    public:
        /// Indicates that the current-track pixmap has changed. Animation must be redrawn.
        static void setPixmapChanged() { s_pixmapChanged = true; }

        /// For the glow colouration stuff
        static double glowIntensity;
        static TQColor glowText;
        static TQColor glowBase;

    public:
        PlaylistItem( TQListView*, TQListViewItem* ); //used by PlaylistLoader
        PlaylistItem( const MetaBundle&, TQListViewItem*, bool enabled = true );
        ~PlaylistItem();

        /// pass 'raw' data here, for example "92" for Length, and not "1:32"
        virtual void setText( int column, const TQString& );

        /**
        * @return The text of the column @p column, formatted for display purposes.
        * (For example, if the Length is 92, "1:32".)
        */
        virtual TQString text( int column ) const;

        void filter( const TQString &expression ); //makes visible depending on whether it matches

        bool isCurrent() const;

        bool isQueued() const;
        int queuePosition() const;

        bool isEnabled() const { return m_enabled; }
        bool isDynamicEnabled() const { return m_dynamicEnabled; }
        bool isFilestatusEnabled() const { return m_filestatusEnabled; }
        void setEnabled();
        void setDynamicEnabled( bool enabled );
        void setFilestatusEnabled( bool enabled );
        void setAllCriteriaEnabled( bool enabled );

        void setSelected( bool selected );
        void setVisible( bool visible );

        void setEditing( int column );
        bool isEditing( int column ) const;
        bool anyEditing() const;
        void setIsBeingRenamed( bool renaming ) { m_isBeingRenamed = renaming; }
        bool isBeingRenamed() const { return m_isBeingRenamed; }
        void setDeleteAfterEditing( bool dae ) { m_deleteAfterEdit = dae; }
        bool deleteAfterEditing() const { return m_deleteAfterEdit; }
        void setIsNew( bool is ) { m_isNew = is; }

        /// convenience functions
        Playlist *listView() const { return reinterpret_cast<Playlist*>( TDEListViewItem::listView() ); }
        PlaylistItem *nextSibling() const { return static_cast<PlaylistItem*>( TDEListViewItem::nextSibling() ); }

        static int ratingAtPoint( int x );
        static int ratingColumnWidth();

        /// like TQWidget::update()
        void update() const;

        //updates only the area of a specific column, avoids flickering of the current item marker
        void updateColumn( int column ) const;

        virtual void setup(); // from TQListViewItem

        virtual bool operator== ( const PlaylistItem & item ) const;
        virtual bool operator< ( const PlaylistItem & item ) const;

        PlaylistItem *nextInAlbum() const;
        PlaylistItem *prevInAlbum() const;

    protected:
        virtual void aboutToChange( const TQValueList<int> &columns );
        virtual void reactToChanges( const TQValueList<int> &columns );

    private:
        friend class Playlist;


        struct paintCacheItem {
            int width;
            int height;
            TQString text;
            TQFont font;
            TQColor color;
            bool selected;
            TQMap<TQString, TQPixmap> map;
        };

        virtual void paintCell( TQPainter*, const TQColorGroup&, int, int, int );
        void drawRating( TQPainter *p );
        void drawRating( TQPainter *p, int stars, int greystars, bool half );
        void drawMood( TQPainter *p, int width, int height );
        virtual void moodbarJobEvent( int newState );

        // Used for sorting
        virtual int compare( TQListViewItem*, int, bool ) const;

        /**
        * Paints a focus indicator on the rectangle (current item). We disable it
        * over the currentTrack, cause it would look like crap and flicker.
        */
        void paintFocus( TQPainter*, const TQColorGroup&, const TQRect& );

        static void imageTransparency( TQImage& image, float factor );

        AtomicString artist_album() const; // returns a placeholder 'artist' for compilations

        void refAlbum();
        void derefAlbum();

        void decrementTotals();
        void incrementTotals();

        void incrementCounts();
        void decrementCounts();
        void incrementLengths();
        void decrementLengths();

        int totalIncrementAmount() const;

        PlaylistAlbum *m_album;
        bool m_enabled;
        bool m_dynamicEnabled;
        bool m_filestatusEnabled;
        bool m_deleteAfterEdit;
        bool m_isBeingRenamed;
        bool m_isNew; //New items will be assigned a different color

        static bool s_pixmapChanged;
        static const TQString &editingText();
};

class PLItemList: public TQPtrList<PlaylistItem>
{
    public:
        PLItemList() : TQPtrList<PlaylistItem>() { }
        PLItemList( const TQPtrList<PlaylistItem> &list ) : TQPtrList<PlaylistItem>( list ) { }
        PLItemList( PlaylistItem *item ) : TQPtrList<PlaylistItem>() { append( item ); }

        inline PLItemList &operator<<( PlaylistItem *item ) { append( item ); return *this; }
};


#endif