summaryrefslogtreecommitdiffstats
path: root/amarok/src/starmanager.cpp
blob: adeb866524ddc96fd0a5e94ad0dcbf2a2e390f3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
// C++ Implementation: starmanager
//
// Description: helper to give correct stars
//
//
// Author: Jeff Mitchell <kde-dev@emailgoeshere.com>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include "amarok.h"
#include "amarokconfig.h"
#include "collectionbrowser.h"
#include "contextbrowser.h"
#include "debug.h"
#include "metabundle.h"
#include "playlist.h"
#include "starmanager.h"

#include <kiconeffect.h>

#include <tqfile.h>
#include <tqimage.h>
#include <tqpixmap.h>

#include <kstandarddirs.h>   //TDEGlobal::dirs()

StarManager* StarManager::instance()
{
    static StarManager sm;
    return &sm;
}


StarManager::StarManager()
{
    if( AmarokConfig::customRatingsColors() )
        AmarokConfig::setCustomRatingsColors( false );
    m_colors[0] = AmarokConfig::starColorOne();
    m_colors[1] = AmarokConfig::starColorTwo();
    m_colors[2] = AmarokConfig::starColorThree();
    m_colors[3] = AmarokConfig::starColorFour();
    m_colors[4] = AmarokConfig::starColorFive();
    m_halfStarColor = AmarokConfig::starColorHalf();
    m_margin = 1;
    m_height = 20;
    reinitStars();
}

StarManager::~StarManager() {}

void
StarManager::reinitStars( int height, int margin )
{
    if( height != -1 ) {
        m_height = height;
    }
    if( margin != -1 ) {
        m_margin = margin;
    }

    int hval = m_height + m_margin * 2 - 4 + ( ( m_height % 2 ) ? 1 : 0 );
    TQImage star = TQImage( locate( "data", "amarok/images/star.png" ) ).smoothScale( hval, hval, TQ_ScaleMin );
    TQImage fullStar = TQImage( locate( "data", "amarok/images/star.png" ) );
    m_star = star.copy();
    m_fullStar = fullStar.copy();
    m_starPix.convertFromImage( star );
    m_fullStarPix.convertFromImage( fullStar );
    m_greyedStar = star.copy();
    TDEIconEffect::toGray( m_greyedStar, 1.0 );
    m_greyedStarPix.convertFromImage( m_greyedStar );
    TQImage half = TQImage( locate( "data", "amarok/images/smallstar.png" ) ).smoothScale( hval, hval, TQ_ScaleMin );
    TQImage fullHalf = TQImage( locate( "data", "amarok/images/smallstar.png" ) );
    m_halfStar = half.copy();
    m_fullHalfStar = fullHalf.copy();
    if( AmarokConfig::customRatingsColors() ) {
        TDEIconEffect::colorize( m_halfStar, m_halfStarColor, 1.0 );
    }
    m_halfStarPix.convertFromImage( m_halfStar );
    m_fullHalfStarPix.convertFromImage( m_fullHalfStar );

    TQImage tempstar;
    TQImage temphalfstar;
    for( int i = 0; i < 5; i++ )
    {
        tempstar = star.copy();
        temphalfstar = half.copy();
        if( AmarokConfig::customRatingsColors() )
        {
            TDEIconEffect::colorize( tempstar, m_colors[i], 1.0 );
            if( !AmarokConfig::fixedHalfStarColor() )
                TDEIconEffect::colorize( temphalfstar, m_colors[i], 1.0 );
        }
        m_images[i] = tempstar.copy();
        m_halfimages[i] = temphalfstar.copy();
        m_pixmaps[i].convertFromImage( tempstar );
        m_halfpixmaps[i].convertFromImage( temphalfstar );
        tempstar.reset();
        temphalfstar.reset();
    }
    if( Playlist::instance() ) Playlist::instance()->qscrollview()->viewport()->update();
    if( CollectionView::instance() &&
            CollectionView::instance()->viewMode() == CollectionView::modeFlatView )
        CollectionView::instance()->triggerUpdate();
    // FIXME
    // Not ideal but should work sufficiently for now
    emit ratingsColorsChanged(TQString::null);
}

TQPixmap*
StarManager::getStar( int num, bool full )
{
    if(full)
	return &m_fullStarPix;
    else if( num < 1 || num > 5 )
        return &m_starPix;
    else
        return &m_pixmaps[num - 1];
}

TQImage&
StarManager::getStarImage( int num, bool full )
{
    if(full)
        return m_fullStar;
    else if( num < 1 || num > 5 )
        return m_star;
    else
        return m_images[num - 1];
}

TQPixmap*
StarManager::getHalfStar( int num, bool full )
{
    if( full )
        return &m_fullHalfStarPix;
    else if( AmarokConfig::fixedHalfStarColor() || num == -1 )
        return &m_halfStarPix;
    else
        return &m_halfpixmaps[num - 1];
}

TQImage&
StarManager::getHalfStarImage( int num, bool full )
{
    if( full )
        return m_fullHalfStar;
    else if( AmarokConfig::fixedHalfStarColor() || num == -1 )
        return m_halfStar;
    else
        return m_halfimages[num - 1];
}

bool
StarManager::setColor( int starNum, const TQColor &color )
{
    if( starNum < 1 || starNum > 5 )
        return false;
    m_colors[starNum - 1] = color;
    return true;
}

bool
StarManager::setHalfColor( const TQColor &color )
{
    m_halfStarColor = color;
    return true;
}

#include "starmanager.moc"