Make playlist items use the full width available to them and adjust correctly when...
[amarok.git] / src / colorgenerator.h
blob9bfacbe633db343db0c40a7fbeaf51b490e7ec7b
1 /***************************************************************************
2 copyright : (C) 2004 by amarok squad
3 email : amarok@kde.org
4 ***************************************************************************/
6 /***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
10 * *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 *
19 * USA *
20 ***************************************************************************/
22 #ifndef COLORGENERATOR_H
23 #define COLORGENERATOR_H
25 #include "debug.h"
27 namespace Amarok {
30 class Color : public QColor
32 static const int CONTRAST = 130;
33 static const int SATURATION_TARGET = 30;
35 public:
36 Color( const QColor &c ) : QColor( c )
38 DEBUG_BLOCK
40 int h,s1,s,v1,v;
41 getHsv( &h, &s1, &v1 );
43 debug() << "Initial Color Properties: s:" << s1 << " v:" << v1 << endl;
45 //we want the new colour to be low saturation
46 //TODO what if s is less than SATURATION_TARGET to start with
47 s = s1 - CONTRAST;
48 v = v1;
50 if ( s < SATURATION_TARGET ) {
51 int remainingContrast = SATURATION_TARGET - s;
52 s = SATURATION_TARGET;
54 debug() << "Unapplied Contrast: " << remainingContrast << endl;
56 //we only add to the value to avoid the dreaded "grey-gradient"
57 v += remainingContrast;
59 if ( v > 255 ) {
60 int error = v - 255;
61 debug() << "Over-compensation: " << error << endl;
63 //if the error is significant then this must be a pretty bright colour
64 //it would look better if the gradient was dark
65 if( error > CONTRAST/2 )
66 v = v1 - error;
67 else
68 v = 255;
72 setHsv( h, s, v );
74 debug() << "Final Colour Properties: s:" << s << " v:" << v << endl;
80 #endif