00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef EXCEPTLISTITEM_H
00032 #define EXCEPTLISTITEM_H
00033
00034 #include <qlistview.h>
00035 #include <qpixmap.h>
00036 #include <qimage.h>
00037 #include <qpainter.h>
00038
00039 class ExceptListItem : public QListViewItem {
00040 public:
00041 ExceptListItem ( QListView *lv, QListViewItem *after, const QString &t, bool nostyle = true, bool nofont = true, bool nodeco = true ) : QListViewItem ( lv, after )
00042 {
00043 m_text = t;
00044
00045 m_nofont = nofont;
00046 m_nostyle = nostyle;
00047 m_nodeco = nodeco;
00048
00049 init ( );
00050 }
00051
00052 virtual ~ExceptListItem ( )
00053 {
00054 }
00055
00056 static void overlay ( QImage &img, const QImage &ovl )
00057 {
00058 if (( img. size ( ) != ovl. size ( )) ||
00059 ( img. depth ( ) != ovl. depth ( )))
00060 return;
00061
00062 for ( int y = 0; y != img. height ( ); y++ ) {
00063 QRgb *iline = (QRgb *) img. scanLine ( y );
00064 QRgb *oline = (QRgb *) ovl. scanLine ( y );
00065
00066 for ( int x = 0; x != img. width ( ); x++ ) {
00067 QRgb i = *iline;
00068 QRgb o = *oline;
00069
00070 *iline = qRgba (( qRed ( i ) + qRed ( o )) / 2,
00071 ( qGreen ( i ) + qGreen ( o )) / 2,
00072 ( qBlue ( i ) + qBlue ( o )) / 2,
00073 ( qAlpha ( i ) + qAlpha ( o )) / 2 );
00074 iline++;
00075 oline++;
00076 }
00077 }
00078 }
00079
00080 static void init ( )
00081 {
00082 static bool init = false;
00083
00084 if ( init )
00085 return;
00086
00087 QImage noimg = Opie::Core::OResource::loadImage ( "appearance/no.png", Opie::Core::OResource::SmallIcon );
00088 QImage fontimg = Opie::Core::OResource::loadImage ( "appearance/font.png", Opie::Core::OResource::SmallIcon );
00089 QImage styleimg = Opie::Core::OResource::loadImage ( "appearance/style.png", Opie::Core::OResource::SmallIcon );
00090 QImage decoimg = Opie::Core::OResource::loadImage ( "appearance/deco.png", Opie::Core::OResource::SmallIcon );
00091
00092 s_fontpix [0] = new QPixmap ( );
00093 s_fontpix [0]-> convertFromImage ( fontimg );
00094 overlay ( fontimg, noimg );
00095 s_fontpix [1] = new QPixmap ( );
00096 s_fontpix [1]-> convertFromImage ( fontimg );
00097
00098 s_stylepix [0] = new QPixmap ( );
00099 s_stylepix [0]-> convertFromImage ( styleimg );
00100 overlay ( styleimg, noimg );
00101 s_stylepix [1] = new QPixmap ( );
00102 s_stylepix [1]-> convertFromImage ( styleimg );
00103
00104 s_decopix [0] = new QPixmap ( );
00105 s_decopix [0]-> convertFromImage ( decoimg );
00106 overlay ( decoimg, noimg );
00107 s_decopix [1] = new QPixmap ( );
00108 s_decopix [1]-> convertFromImage ( decoimg );
00109
00110 init = true;
00111 }
00112
00113 bool noFont ( ) const
00114 {
00115 return m_nofont;
00116 }
00117
00118 bool noStyle ( ) const
00119 {
00120 return m_nostyle;
00121 }
00122
00123 bool noDeco ( ) const
00124 {
00125 return m_nodeco;
00126 }
00127
00128 void setNoDeco ( bool b )
00129 {
00130 if ( b != m_nodeco ) {
00131 m_nodeco = b;
00132 repaint ( );
00133 }
00134 }
00135
00136 void setNoStyle ( bool b )
00137 {
00138 if ( b != m_nostyle ) {
00139 m_nostyle = b;
00140 repaint ( );
00141 }
00142 }
00143
00144 void setNoFont ( bool b )
00145 {
00146 if ( b != m_nofont ) {
00147 m_nofont = b;
00148 repaint ( );
00149 }
00150 }
00151
00152 QString pattern ( ) const
00153 {
00154 return m_text;
00155 }
00156
00157 void setPattern ( const QString &s )
00158 {
00159 if ( s != m_text ) {
00160 m_text = s;
00161 widthChanged ( 3 );
00162 repaint ( );
00163 }
00164 }
00165
00166 QString text ( int i ) const
00167 {
00168 if ( i == 3 )
00169 return m_text;
00170 else
00171 return QString::null;
00172
00173 }
00174
00175 const QPixmap *pixmap ( int i ) const
00176 {
00177 if ( i == 0 )
00178 return (const QPixmap *) s_stylepix [m_nostyle ? 1 : 0];
00179 else if ( i == 1 )
00180 return (const QPixmap *) s_fontpix [m_nofont ? 1 : 0];
00181 else if ( i == 2 )
00182 return (const QPixmap *) s_decopix [m_nodeco ? 1 : 0];
00183 else
00184 return 0;
00185 }
00186
00187 private:
00188 QString m_text;
00189 bool m_nofont;
00190 bool m_nostyle;
00191 bool m_nodeco;
00192
00193 static QPixmap *s_stylepix [2];
00194 static QPixmap *s_fontpix [2];
00195 static QPixmap *s_decopix [2];
00196 };
00197
00198 QPixmap *ExceptListItem::s_stylepix [2] = { 0, 0 };
00199 QPixmap *ExceptListItem::s_fontpix [2] = { 0, 0 };
00200 QPixmap *ExceptListItem::s_decopix [2] = { 0, 0 };
00201
00202 #endif