1
/***************************************************************************
2
 *   Copyright (c) 2008  Nikolaj Hald Nielsen <nhnFreespirit@gmail.com>    *
3
 *                                                                         *
4
 *   This program is free software; you can redistribute it and/or modify  *
5
 *   it under the terms of the GNU General Public License as published by  *
6
 *   the Free Software Foundation; either version 2 of the License, or     *
7
 *   (at your option) any later version.                                   *
8
 *                                                                         *
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.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18
 ***************************************************************************/
19
 
20
#include "PaletteHandler.h"
21
22
#include "App.h"
23
#include "Debug.h"
24
#include "MainWindow.h"
25
26
#include <kglobal.h>
27
28
29
namespace The {
30
    static PaletteHandler* s_PaletteHandler_instance = 0;
31
32
    PaletteHandler* paletteHandler()
33
    {
34
        if( !s_PaletteHandler_instance )
35
            s_PaletteHandler_instance = new PaletteHandler();
36
37
        return s_PaletteHandler_instance;
38
    }
39
}
40
41
42
PaletteHandler::PaletteHandler( QObject* parent )
43
    : QObject( parent )
44
{}
45
46
47
PaletteHandler::~PaletteHandler()
48
{
49
    DEBUG_BLOCK
50
51
    The::s_PaletteHandler_instance = 0;
52
}
53
54
void
55
PaletteHandler::setPalette( const QPalette & palette )
56
{
57
    m_palette = palette;
58
    emit( newPalette( m_palette ) );
59
}
60
61
void
62
PaletteHandler::updateItemView( QAbstractItemView * view )
63
{
64
65
    QPalette p = m_palette;
66
67
    QColor c = p.color( QPalette::Base );
68
    c.setAlpha( 0 );
69
    p.setColor( QPalette::Base, c );
70
71
    c = p.color( QPalette::AlternateBase );
72
    c.setAlpha( 77 );
73
    p.setColor( QPalette::AlternateBase, c );
74
75
    view->setPalette( p );
76
    
77
}
78
79
QPalette
80
PaletteHandler::palette()
81
{
82
    return m_palette;
83
}
84
85
QColor
86
PaletteHandler::highlightColor()
87
{
88
    QColor highlight = App::instance()->palette().highlight().color();
89
    qreal saturation = highlight.saturationF();
90
    saturation *= 0.5;
91
    highlight.setHsvF( highlight.hueF(), saturation, highlight.valueF(), highlight.alphaF() );
92
93
    return highlight;
94
}
95
96
QColor
97
PaletteHandler::highlightColor( qreal saturationPercent, qreal valuePercent )
98
{
99
    QColor highlight = QColor( App::instance()->palette().highlight().color() );
100
    qreal saturation = highlight.saturationF();
101
    saturation *= saturationPercent;
102
    qreal value = highlight.valueF();
103
    value *= valuePercent;
104
    highlight.setHsvF( highlight.hueF(), saturation, value, highlight.alphaF() );
105
106
    return highlight;
107
}
108
109
    
110
#include "PaletteHandler.moc"