File indexing completed on 2024-05-05 04:49:29

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Jeff Mitchell <kde-dev@emailgoeshere.com>                         *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef AMAROK_STAR_MANAGER_H
0018 #define AMAROK_STAR_MANAGER_H
0019 
0020 #include <QImage>
0021 #include <QPixmap>
0022 
0023 /**
0024  * TODO: only used in Osd.cpp, remove! We can paint stars using KRatingWidget
0025  */
0026 class StarManager : public QObject
0027 {
0028     Q_OBJECT
0029 
0030     public:
0031         static StarManager *instance();
0032 
0033         QPixmap* getStar( int num );
0034         QPixmap* getGreyStar() { return &m_greyedStarPix; }
0035         QPixmap* getHalfStar( int num = -1 );
0036         QImage& getStarImage( int num );
0037         QImage& getGreyStarImage() { return m_greyedStar; }
0038         QImage& getHalfStarImage( int num = -1 );
0039 
0040         bool setColor( int starNum, const QColor &color );
0041         bool setHalfColor( const QColor &color );
0042 
0043         void reinitStars( int height = -1, int margin = -1 );
0044 
0045     Q_SIGNALS:
0046         void ratingsColorsChanged();
0047 
0048     private:
0049         explicit StarManager( QObject* parent );
0050         ~StarManager() override;
0051 
0052         static StarManager* s_instance;
0053 
0054         int m_height;
0055         int m_margin;
0056 
0057         //cached stars...why both?  For faster conversion when drawing context browser
0058         QPixmap m_starPix;
0059         QImage m_star;
0060         QPixmap m_greyedStarPix;
0061         QImage m_greyedStar;
0062         QPixmap m_halfStarPix;
0063         QImage m_halfStar;
0064 
0065         QImage m_images[5];
0066         QImage m_halfimages[5];
0067         QPixmap m_pixmaps[5];
0068         QPixmap m_halfpixmaps[5];
0069 
0070         QColor m_colors[5];
0071         QColor m_halfStarColor;
0072 };
0073 
0074 #endif
0075