summaryrefslogtreecommitdiff
path: root/noncore/settings/appearance2/exceptlistitem.h
blob: 7b4fa4860f0c7809c9dd61e7d1c67de75d4a3413 (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
               =.            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 EXCEPTLISTITEM_H
#define EXCEPTLISTITEM_H

#include <qlistview.h>
#include <qpixmap.h>
#include <qimage.h>
#include <qpainter.h>

class ExceptListItem : public QListViewItem {
public:
	ExceptListItem ( QListView *lv, QListViewItem *after, const QString &t, bool nostyle = true, bool nofont = true, bool nodeco = true ) : QListViewItem ( lv, after )
	{
		m_text = t;
		
		m_nofont = nofont;
		m_nostyle = nostyle;
		m_nodeco = nodeco;
		
		init ( );
	}
	
	virtual ~ExceptListItem ( )
	{
	}
	
	static void overlay ( QImage &img, const QImage &ovl )
	{
		if (( img. size ( ) != ovl. size ( )) || 
		    ( img. depth ( ) != ovl. depth ( )))
			return;
		
		for ( int y = 0; y != img. height ( ); y++ ) {
			QRgb *iline = (QRgb *) img. scanLine ( y );
			QRgb *oline = (QRgb *) ovl. scanLine ( y );
			
			for ( int x = 0; x != img. width ( ); x++ ) {
				QRgb i = *iline;
				QRgb o = *oline;
			
				*iline = qRgba (( qRed ( i ) + qRed ( o )) / 2,
				                ( qGreen ( i ) + qGreen ( o )) / 2,
				                ( qBlue ( i ) + qBlue ( o )) / 2,
				                ( qAlpha ( i ) + qAlpha ( o )) / 2 );
				iline++;
				oline++;
			}
		}
	}
	
	static void init ( )
	{
		static bool init = false;
		
		if ( init ) 
			return;
	
		QImage noimg    = Resource::loadImage ( "appearance/no.png" );
		QImage fontimg  = Resource::loadImage ( "appearance/font.png" );
		QImage styleimg = Resource::loadImage ( "appearance/style.png" );
		QImage decoimg  = Resource::loadImage ( "appearance/deco.png" );

		s_fontpix [0] = new QPixmap ( );
		s_fontpix [0]-> convertFromImage ( fontimg );
		overlay ( fontimg, noimg );
		s_fontpix [1] = new QPixmap ( );
		s_fontpix [1]-> convertFromImage ( fontimg );

		s_stylepix [0] = new QPixmap ( );
		s_stylepix [0]-> convertFromImage ( styleimg );
		overlay ( styleimg, noimg );
		s_stylepix [1] = new QPixmap ( );
		s_stylepix [1]-> convertFromImage ( styleimg );

		s_decopix [0] = new QPixmap ( );
		s_decopix [0]-> convertFromImage ( decoimg );
		overlay ( decoimg, noimg );
		s_decopix [1] = new QPixmap ( );
		s_decopix [1]-> convertFromImage ( decoimg );

		init = true;
	}
	
	bool noFont ( ) const
	{
		return m_nofont;
	}

	bool noStyle ( ) const
	{
		return m_nostyle;
	}

	bool noDeco ( ) const
	{
		return m_nodeco;
	}

	void setNoDeco ( bool b )
	{
		if ( b != m_nodeco ) {
			m_nodeco = b;
			repaint ( );
		}
	}

	void setNoStyle ( bool b )
	{
		if ( b != m_nostyle ) {
			m_nostyle = b;
			repaint ( );
		}
	}

	void setNoFont ( bool b )
	{
		if ( b != m_nofont ) {
			m_nofont = b;
			repaint ( );
		}
	}
	
	QString pattern ( ) const 
	{
		return m_text;
	}
	
	void setPattern ( const QString &s )
	{
		if ( s != m_text ) {
			m_text = s;
			widthChanged ( 3 );
			repaint ( );
		}
	}

	QString text ( int i ) const
	{
		if ( i == 3 )
			return m_text;
		else
			return QString::null;
	
	}
	
	const QPixmap *pixmap ( int i ) const
	{
		if ( i == 0 )
			return (const QPixmap *) s_stylepix [m_nostyle ? 1 : 0];
		else if ( i == 1 )
			return (const QPixmap *) s_fontpix [m_nofont ? 1 : 0];
		else if ( i == 2 )
			return (const QPixmap *) s_decopix [m_nodeco ? 1 : 0];
		else
			return 0;
	}

private:
	QString m_text;
	bool m_nofont;
	bool m_nostyle;
	bool m_nodeco;
	
	static QPixmap *s_stylepix [2];
	static QPixmap *s_fontpix [2];
	static QPixmap *s_decopix [2];
};

QPixmap *ExceptListItem::s_stylepix [2] = { 0, 0 };
QPixmap *ExceptListItem::s_fontpix [2] = { 0, 0 };
QPixmap *ExceptListItem::s_decopix [2] = { 0, 0 };

#endif