Make playlist items use the full width available to them and adjust correctly when...
[amarok.git] / src / StarManager.cpp
blob6a6622f3ecb71cb318e8e61020f3ff7dc7bba7c7
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"
25 #include "playlist.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 if( Playlist::instance() ) Playlist::instance()->qscrollview()->viewport()->update();
100 /*PORT 2.0
101 if( CollectionView::instance() &&
102 CollectionView::instance()->viewMode() == CollectionView::modeFlatView )
103 CollectionView::instance()->triggerUpdate(); */
104 emit ratingsColorsChanged();
107 QPixmap*
108 StarManager::getStar( int num )
110 if( num < 1 || num > 5 )
111 return &m_starPix;
112 else
113 return &m_pixmaps[num - 1];
116 QImage&
117 StarManager::getStarImage( int num )
119 if( num < 1 || num > 5 )
120 return m_star;
121 else
122 return m_images[num - 1];
125 QPixmap*
126 StarManager::getHalfStar( int num )
128 /*if( AmarokConfig::fixedHalfStarColor() || num == -1 )
129 return &m_halfStarPix;
130 else*/
131 return &m_halfpixmaps[num - 1];
134 QImage&
135 StarManager::getHalfStarImage( int num )
137 /*if( AmarokConfig::fixedHalfStarColor() || num == -1 )
138 return m_halfStar;
139 else*/
140 return m_halfimages[num - 1];
143 bool
144 StarManager::setColor( int starNum, const QColor &color )
146 if( starNum < 1 || starNum > 5 )
147 return false;
148 m_colors[starNum - 1] = color;
149 return true;
152 bool
153 StarManager::setHalfColor( const QColor &color )
155 m_halfStarColor = color;
156 return true;
159 #include "StarManager.moc"