00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qpixmap.h>
00013 #include <qstring.h>
00014 #include <qpainter.h>
00015 #include <qiconview.h>
00016
00017
00018 #include "item.h"
00019
00020
00021 Item::Item( QIconView* parent, QPixmap icon, QString text ) : QIconViewItem(parent, text, icon)
00022 {
00023 mousedOver = false;
00024 }
00025
00026 void Item::paintItem( QPainter* p, const QColorGroup&)
00027 {
00028 p->save();
00029 QRect r = rect();
00030
00031
00032 if(isSelected())
00033 {
00034
00035 p->fillRect( r, QColor(193, 210, 238) );
00036
00037
00038 p->setPen( QColor(49, 106, 197) );
00039 p->drawRect(r);
00040 }
00041
00042 else if(mousedOver)
00043 {
00044
00045 p->fillRect( r, QColor(224, 232, 246) );
00046
00047
00048 p->setPen( QColor(152, 180, 226) );
00049 p->drawRect(r);
00050 }
00051
00052 p->restore();
00053
00054 p->drawPixmap( x() , y() + ( height() - pixmap()->height() ) / 2, *pixmap());
00055
00056 int align = AlignLeft | WordBreak | BreakAnywhere;
00057 p->drawText( textRect( FALSE ), align, text());
00058 }
00059
00060 void Item::setMousedOver(bool val)
00061 { mousedOver = val; }
00062
00063 void Item::setTextWidth(int w)
00064 {
00065 QRect pr = pixmapRect();
00066 pr.moveBy( 3, 3 );
00067 setPixmapRect( pr );
00068
00069 QRect tr = textRect();
00070 tr.moveBy( 3, 3 );
00071 tr.setRight( tr.left() + w);
00072 setTextRect( tr );
00073
00074 int newW = pixmapRect().width() + 6 + w;
00075 int newH = QMAX( textRect().height(), pixmapRect().height() ) + 6;
00076
00077 setItemRect( QRect( rect().topLeft(), QSize(newW, newH)) );
00078 }
00079