File indexing completed on 2024-05-05 04:48:33

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  * Copyright (c) 2009 Mark Kretschmann <kretschmann@kde.org>                            *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Pulic License for more details.              *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef MOODBARMANAGER_H
0019 #define MOODBARMANAGER_H
0020 
0021 #include "amarok_export.h"
0022 #include "core/meta/forward_declarations.h"
0023 
0024 #include <KImageCache>
0025 
0026 #include <QColor>
0027 #include <QMap>
0028 #include <QObject>
0029 
0030 class QUrl;
0031 class QPalette;
0032 class MoodbarManager;
0033 
0034 namespace The {
0035     AMAROK_EXPORT MoodbarManager* moodbarManager();
0036 }
0037 
0038 typedef QVector<QColor> MoodbarColorList;
0039 
0040 class AMAROK_EXPORT  MoodbarManager : public QObject
0041 {
0042 
0043 Q_OBJECT
0044 
0045 friend MoodbarManager* The::moodbarManager();
0046 
0047 public:
0048     enum Style
0049     {
0050         SystemColours,
0051         Angry,
0052         Frozen,
0053         Happy,
0054         Normal
0055     };
0056     ~MoodbarManager() override;
0057 
0058     bool hasMoodbar( Meta::TrackPtr track );
0059     QPixmap getMoodbar( Meta::TrackPtr track, int width, int height, bool rtl = false );
0060 
0061 Q_SIGNALS:
0062     void moodbarReady( const QPixmap &pixmap );
0063     void moodbarCreationFailed( const QString &error );
0064     void moodbarStyleChanged();
0065 
0066 private Q_SLOTS:
0067     void paletteChanged( const QPalette &palette );
0068 
0069 private:
0070     MoodbarManager();
0071 
0072     MoodbarColorList readMoodFile( const QUrl &moodFileUrl );
0073     QPixmap drawMoodbar( const MoodbarColorList &data, int width, int height, bool rtl );
0074     QString moodPath( const QString &trackPath ) const;
0075 
0076     //let this class take care of caching everything as needed, otherwise things get pretty complex pretty fast.
0077     QMap<Meta::TrackPtr, bool> m_hasMoodMap;
0078     QMap<Meta::TrackPtr, QString> m_moodFileMap;
0079     QMap<Meta::TrackPtr, MoodbarColorList> m_moodDataMap;
0080 
0081     KImageCache * m_cache;
0082 
0083     int m_lastPaintMode;
0084 };
0085 
0086 #endif // MOODBARMANAGER_H