| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2007 Jeff Mitchell <kde-dev@emailgoeshere.com> * |
| 3 |
* * |
| 4 |
* This program is free software; you can redistribute it and/or modify it under * |
| 5 |
* the terms of the GNU General Public License as published by the Free Software * |
| 6 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 7 |
* version. * |
| 8 |
* * |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 10 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 11 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 12 |
* * |
| 13 |
* You should have received a copy of the GNU General Public License along with * |
| 14 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 15 |
****************************************************************************************/ |
| 16 |
|
| 17 |
#include "StarManager.h" |
| 18 |
|
| 19 |
#include "core/support/Amarok.h" |
| 20 |
#include <config-amarok.h> |
| 21 |
#include "core/support/Debug.h" |
| 22 |
#include "MainWindow.h" |
| 23 |
|
| 24 |
#include <KIconEffect> |
| 25 |
#include <KStandardDirs> //KGlobal::dirs() |
| 26 |
|
| 27 |
#include <QImage> |
| 28 |
#include <QPixmap> |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
StarManager* StarManager::s_instance = 0; |
| 33 |
|
| 34 |
|
| 35 |
StarManager* StarManager::instance() |
| 36 |
{ |
| 37 |
return s_instance ? s_instance : new StarManager( The::mainWindow() ); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
StarManager::StarManager( QObject* parent ) |
| 42 |
: QObject( parent ) |
| 43 |
{ |
| 44 |
DEBUG_BLOCK |
| 45 |
|
| 46 |
s_instance = this; |
| 47 |
|
| 48 |
/*if( AmarokConfig::customRatingsColors() ) |
| 49 |
AmarokConfig::setCustomRatingsColors( false ); |
| 50 |
m_colors[0] = AmarokConfig::starColorOne(); |
| 51 |
m_colors[1] = AmarokConfig::starColorTwo(); |
| 52 |
m_colors[2] = AmarokConfig::starColorThree(); |
| 53 |
m_colors[3] = AmarokConfig::starColorFour(); |
| 54 |
m_colors[4] = AmarokConfig::starColorFive(); |
| 55 |
m_halfStarColor = AmarokConfig::starColorHalf();*/ |
| 56 |
m_margin = 1; |
| 57 |
m_height = 20; |
| 58 |
reinitStars(); |
| 59 |
} |
| 60 |
|
| 61 |
StarManager::~StarManager() |
| 62 |
{ |
| 63 |
DEBUG_BLOCK |
| 64 |
} |
| 65 |
|
| 66 |
void |
| 67 |
StarManager::reinitStars( int height, int margin ) |
| 68 |
{ |
| 69 |
if( height != -1 ) |
| 70 |
m_height = height; |
| 71 |
if( margin != -1 ) |
| 72 |
m_margin = margin; |
| 73 |
|
| 74 |
int hval = m_height + m_margin * 2 - 4 + ( ( m_height % 2 ) ? 1 : 0 ); |
| 75 |
QImage star = QImage( KStandardDirs::locate( "data", "amarok/images/star.png" ) ).scaled( hval, hval, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); |
| 76 |
m_star = star.copy(); |
| 77 |
m_starPix = QPixmap::fromImage( star ); |
| 78 |
m_greyedStar = star.copy(); |
| 79 |
KIconEffect::toGray( m_greyedStar, 1.0 ); |
| 80 |
m_greyedStarPix = QPixmap::fromImage( m_greyedStar ); |
| 81 |
QImage half = QImage( KStandardDirs::locate( "data", "amarok/images/smallstar.png" ) ).scaled( hval, hval, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); |
| 82 |
m_halfStar = half.copy(); |
| 83 |
/*if( AmarokConfig::customRatingsColors() ) |
| 84 |
KIconEffect::colorize( m_halfStar, m_halfStarColor, 1.0 );*/ |
| 85 |
m_halfStarPix = QPixmap::fromImage( m_halfStar ); |
| 86 |
|
| 87 |
QImage tempstar; |
| 88 |
QImage temphalfstar; |
| 89 |
for( int i = 0; i < 5; i++ ) |
| 90 |
{ |
| 91 |
tempstar = star.copy(); |
| 92 |
temphalfstar = half.copy(); |
| 93 |
/*if( AmarokConfig::customRatingsColors() ) |
| 94 |
{ |
| 95 |
KIconEffect::colorize( tempstar, m_colors[i], 1.0 ); |
| 96 |
if( !AmarokConfig::fixedHalfStarColor() ) |
| 97 |
KIconEffect::colorize( temphalfstar, m_colors[i], 1.0 ); |
| 98 |
}*/ |
| 99 |
m_images[i] = tempstar.copy(); |
| 100 |
m_halfimages[i] = temphalfstar.copy(); |
| 101 |
m_pixmaps[i] = QPixmap::fromImage( tempstar ); |
| 102 |
m_halfpixmaps[i] = QPixmap::fromImage( temphalfstar ); |
| 103 |
tempstar = QImage(); |
| 104 |
temphalfstar = QImage(); |
| 105 |
} |
| 106 |
//TODO:PORT |
| 107 |
// if( Playlist::instance() ) Playlist::instance()->qscrollview()->viewport()->update(); |
| 108 |
/*PORT 2.0 |
| 109 |
if( CollectionView::instance() && |
| 110 |
CollectionView::instance()->viewMode() == CollectionView::modeFlatView ) |
| 111 |
CollectionView::instance()->triggerUpdate(); */ |
| 112 |
emit ratingsColorsChanged(); |
| 113 |
} |
| 114 |
|
| 115 |
QPixmap* |
| 116 |
StarManager::getStar( int num ) |
| 117 |
{ |
| 118 |
if( num < 1 || num > 5 ) |
| 119 |
return &m_starPix; |
| 120 |
else |
| 121 |
return &m_pixmaps[num - 1]; |
| 122 |
} |
| 123 |
|
| 124 |
QImage& |
| 125 |
StarManager::getStarImage( int num ) |
| 126 |
{ |
| 127 |
if( num < 1 || num > 5 ) |
| 128 |
return m_star; |
| 129 |
else |
| 130 |
return m_images[num - 1]; |
| 131 |
} |
| 132 |
|
| 133 |
QPixmap* |
| 134 |
StarManager::getHalfStar( int num ) |
| 135 |
{ |
| 136 |
/*if( AmarokConfig::fixedHalfStarColor() || num == -1 ) |
| 137 |
return &m_halfStarPix; |
| 138 |
else*/ |
| 139 |
if( num < 1 || num > 5 ) |
| 140 |
return &m_starPix; |
| 141 |
else |
| 142 |
return &m_halfpixmaps[num - 1]; |
| 143 |
} |
| 144 |
|
| 145 |
QImage& |
| 146 |
StarManager::getHalfStarImage( int num ) |
| 147 |
{ |
| 148 |
/*if( AmarokConfig::fixedHalfStarColor() || num == -1 ) |
| 149 |
return m_halfStar; |
| 150 |
else*/ |
| 151 |
return m_halfimages[num - 1]; |
| 152 |
} |
| 153 |
|
| 154 |
bool |
| 155 |
StarManager::setColor( int starNum, const QColor &color ) |
| 156 |
{ |
| 157 |
if( starNum < 1 || starNum > 5 ) |
| 158 |
return false; |
| 159 |
m_colors[starNum - 1] = color; |
| 160 |
return true; |
| 161 |
} |
| 162 |
|
| 163 |
bool |
| 164 |
StarManager::setHalfColor( const QColor &color ) |
| 165 |
{ |
| 166 |
m_halfStarColor = color; |
| 167 |
return true; |
| 168 |
} |
| 169 |
|
| 170 |
#include "StarManager.moc" |