AlbumShaper
1.0a3
|
00001 //============================================== 00002 // copyright : (C) 2003-2005 by Will Stokes 00003 //============================================== 00004 // This program is free software; you can redistribute it 00005 // and/or modify it under the terms of the GNU General 00006 // Public License as published by the Free Software 00007 // Foundation; either version 2 of the License, or 00008 // (at your option) any later version. 00009 //============================================== 00010 00011 //Systemwide includes 00012 #include <qpixmap.h> 00013 #include <qstring.h> 00014 #include <qpainter.h> 00015 #include <qiconview.h> 00016 00017 //Projectwide includes 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 //if selected paint dark blue background and outline 00032 if(isSelected()) 00033 { 00034 //Draw Selected Color (dark blue) 00035 p->fillRect( r, QColor(193, 210, 238) ); 00036 00037 //draw selection rectangle (darker blue) 00038 p->setPen( QColor(49, 106, 197) ); 00039 p->drawRect(r); 00040 } 00041 //else if pseudo selected paint ligher blue background with outline 00042 else if(mousedOver) 00043 { 00044 //Draw Pseudo Selected Color (light blue) 00045 p->fillRect( r, QColor(224, 232, 246) ); 00046 00047 //draw selection rectangle (darker blue) 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 //==============================================