summaryrefslogtreecommitdiff
path: root/noncore/settings/appearance2/colorlistitem.h
blob: f8d5c45d58d2779f762964c7bd3d7e32c0eafd78 (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
/*
               =.            This file is part of the OPIE Project
             .=l.            Copyright (c)  2002 Robert Griebl <sandman@handhelds.org>
           .>+-=
 _;:,     .>    :=|.         This file is free software; you can
.> <`_,   >  .   <=          redistribute it and/or modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU General Public
.="- .-=="i,     .._         License as published by the Free Software
 - .   .-<_>     .<>         Foundation; either version 2 of the License,
     ._= =}       :          or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s.       This file is distributed in the hope that
     +  .  -:.       =       it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . .    without even the implied warranty of
    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU General
..}^=.=       =       ;      Public License for more details.
++=   -.     .`     .:       
 :     =  ...= . :.=-        You should have received a copy of the GNU
 -.   .:....=;==+<;          General Public License along with this file;
  -_. . .   )=.  =           see the file COPYING. If not, write to the
    --        :-=`           Free Software Foundation, Inc.,
                             59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.

*/

#ifndef COLORLISTITEM_H
#define COLORLISTITEM_H

#include <qlistbox.h>
#include <qpalette.h>
#include <qapplication.h>

#include <qpe/config.h>

class Appearance;

class ColorListItem : public QListBoxText {
public:
	ColorListItem ( const QString &t, Config &cfg ) : QListBoxText ( t ) 
	{
		m_colors = new QColor [s_colorcount];
		load ( cfg );
	}

	virtual ~ColorListItem ( )
	{
		delete [] m_colors;
	}
	
	QPalette palette ( )
	{
		return m_palette;
	}

	bool load ( Config &cfg )
	{
		for ( int i = 0; i < s_colorcount; i++ ) 
			m_colors [i] = QColor ( cfg. readEntry ( s_colorlut [i]. m_key, s_colorlut [i]. m_def ));
			
		buildPalette ( );
		return true;
	}
	
	void buildPalette ( )
	{
		m_palette = QPalette ( m_colors [r2i(QColorGroup::Button)], m_colors [r2i(QColorGroup::Background)] );
		m_palette. setColor ( QColorGroup::Highlight, m_colors [r2i(QColorGroup::Highlight)] );
		m_palette. setColor ( QColorGroup::HighlightedText, m_colors [r2i(QColorGroup::HighlightedText)] );
		m_palette. setColor ( QColorGroup::Text, m_colors [r2i(QColorGroup::Text)] );
		m_palette. setColor ( QPalette::Active, QColorGroup::ButtonText, m_colors [r2i(QColorGroup::ButtonText)] );
		m_palette. setColor ( QColorGroup::Base, m_colors [r2i(QColorGroup::Base)] );
		m_palette. setColor ( QPalette::Disabled, QColorGroup::Text, m_palette. color ( QPalette::Active, QColorGroup::Background ). dark ( ));
	}
	
	bool save ( Config &cfg )
	{
		for ( int i = 0; i < s_colorcount; i++ ) 
			cfg. writeEntry ( s_colorlut [i]. m_key, m_colors [i]. name ( ));
		return true;
	}

	QColor color ( QColorGroup::ColorRole role )
	{
		int i = r2i ( role );
		return i >= 0 ? m_colors [i] : QColor ( );
	}
	
	void setColor ( QColorGroup::ColorRole role, QColor c )
	{
		int i = r2i ( role );
		if ( i >= 0 ) {
			m_colors [i] = c;
			buildPalette ( );
		}
	}
	
	QString label ( QColorGroup::ColorRole role )
	{
		int i = r2i ( role );
		return i >= 0 ? qApp-> translate ( "Appearance", s_colorlut [i]. m_label ) : QString::null;
	}
		
private:
	QPalette m_palette;	
	QColor *m_colors;
	
	static struct colorlut {
		QColorGroup::ColorRole m_role;
		const char *           m_key;
		const char *           m_def;		
		const char *           m_label;
	} const s_colorlut [];
	static const int s_colorcount;

	static int r2i ( QColorGroup::ColorRole role )
	{
		for ( int i = 0; i < s_colorcount; i++ ) {
			if ( s_colorlut [i]. m_role == role )
				return i;
		}
		return -1;
	}
};

// from etc/colors/Liquid.scheme
const ColorListItem::colorlut ColorListItem::s_colorlut [] = {
	{ QColorGroup::Base,            "Base",            "#FFFFFF", QT_TRANSLATE_NOOP( "Appearance", "Base" )             },
	{ QColorGroup::Background,      "Background",      "#E0E0E0", QT_TRANSLATE_NOOP( "Appearance", "Background" )       },
	{ QColorGroup::Button,          "Button",          "#96c8fa", QT_TRANSLATE_NOOP( "Appearance", "Button" )           },
	{ QColorGroup::ButtonText,      "ButtonText",      "#000000", QT_TRANSLATE_NOOP( "Appearance", "Button Text" )      }, 
	{ QColorGroup::Highlight,       "Highlight",       "#73adef", QT_TRANSLATE_NOOP( "Appearance", "Highlight" )        },
	{ QColorGroup::HighlightedText, "HighlightedText", "#FFFFFF", QT_TRANSLATE_NOOP( "Appearance", "Highlighted Text" ) },
	{ QColorGroup::Text,            "Text",            "#000000", QT_TRANSLATE_NOOP( "Appearance", "Text" )             }
};

const int ColorListItem::s_colorcount =  sizeof( s_colorlut ) / sizeof ( s_colorlut [0] );


#endif