add mp3 and ogg torrent url info to JamendoAlbum
[amarok.git] / src / StarManager.cpp
blob3d5357aede8e8d8cec48fbe5e0e46a35cb8246ed
1 /*
2 Copyright (C) 2007 Jeff Mitchell <kde-dev@emailgoeshere.com>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "StarManager.h"
21 #include "amarok.h"
22 #include "config-amarok.h"
23 #include "debug.h"
24 #include "metabundle.h"
27 #include <KIconEffect>
28 #include <KStandardDirs> //KGlobal::dirs()
30 #include <QFile>
31 #include <QImage>
32 #include <QPixmap>
35 StarManager* StarManager::instance()
37 static StarManager sm;
38 return &sm;
42 StarManager::StarManager()
44 /*if( AmarokConfig::customRatingsColors() )
45 AmarokConfig::setCustomRatingsColors( false );
46 m_colors[0] = AmarokConfig::starColorOne();
47 m_colors[1] = AmarokConfig::starColorTwo();
48 m_colors[2] = AmarokConfig::starColorThree();
49 m_colors[3] = AmarokConfig::starColorFour();
50 m_colors[4] = AmarokConfig::starColorFive();
51 m_halfStarColor = AmarokConfig::starColorHalf();*/
52 m_margin = 1;
53 m_height = 20;
54 reinitStars();
57 StarManager::~StarManager() {}
59 void
60 StarManager::reinitStars( int height, int margin )
62 if( height != -1 )
63 m_height = height;
64 if( margin != -1 )
65 m_margin = margin;
67 int hval = m_height + m_margin * 2 - 4 + ( ( m_height % 2 ) ? 1 : 0 );
68 QImage star = QImage( KStandardDirs::locate( "data", "amarok/images/star.png" ) ).scaled( hval, hval, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
69 m_star = star.copy();
70 m_starPix = QPixmap::fromImage( star );
71 m_greyedStar = star.copy();
72 KIconEffect::toGray( m_greyedStar, 1.0 );
73 m_greyedStarPix = QPixmap::fromImage( m_greyedStar );
74 QImage half = QImage( KStandardDirs::locate( "data", "amarok/images/smallstar.png" ) ).scaled( hval, hval, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
75 m_halfStar = half.copy();
76 /*if( AmarokConfig::customRatingsColors() )
77 KIconEffect::colorize( m_halfStar, m_halfStarColor, 1.0 );*/
78 m_halfStarPix = QPixmap::fromImage( m_halfStar );
80 QImage tempstar;
81 QImage temphalfstar;
82 for( int i = 0; i < 5; i++ )
84 tempstar = star.copy();
85 temphalfstar = half.copy();
86 /*if( AmarokConfig::customRatingsColors() )
88 KIconEffect::colorize( tempstar, m_colors[i], 1.0 );
89 if( !AmarokConfig::fixedHalfStarColor() )
90 KIconEffect::colorize( temphalfstar, m_colors[i], 1.0 );
91 }*/
92 m_images[i] = tempstar.copy();
93 m_halfimages[i] = temphalfstar.copy();
94 m_pixmaps[i] = QPixmap::fromImage( tempstar );
95 m_halfpixmaps[i] = QPixmap::fromImage( temphalfstar );
96 tempstar = QImage();
97 temphalfstar = QImage();
99 //TODO:PORT
100 // if( Playlist::instance() ) Playlist::instance()->qscrollview()->viewport()->update();
101 /*PORT 2.0
102 if( CollectionView::instance() &&
103 CollectionView::instance()->viewMode() == CollectionView::modeFlatView )
104 CollectionView::instance()->triggerUpdate(); */
105 emit ratingsColorsChanged();
108 QPixmap*
109 StarManager::getStar( int num )
111 if( num < 1 || num > 5 )
112 return &m_starPix;
113 else
114 return &m_pixmaps[num - 1];
117 QImage&
118 StarManager::getStarImage( int num )
120 if( num < 1 || num > 5 )
121 return m_star;
122 else
123 return m_images[num - 1];
126 QPixmap*
127 StarManager::getHalfStar( int num )
129 /*if( AmarokConfig::fixedHalfStarColor() || num == -1 )
130 return &m_halfStarPix;
131 else*/
132 return &m_halfpixmaps[num - 1];
135 QImage&
136 StarManager::getHalfStarImage( int num )
138 /*if( AmarokConfig::fixedHalfStarColor() || num == -1 )
139 return m_halfStar;
140 else*/
141 return m_halfimages[num - 1];
144 bool
145 StarManager::setColor( int starNum, const QColor &color )
147 if( starNum < 1 || starNum > 5 )
148 return false;
149 m_colors[starNum - 1] = color;
150 return true;
153 bool
154 StarManager::setHalfColor( const QColor &color )
156 m_halfStarColor = color;
157 return true;
160 #include "StarManager.moc"