Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

groupIcon.cpp

Go to the documentation of this file.
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 "groupIcon.h"
00019 #include "groupsWidget.h"
00020 
00021 //==============================================
00022 GroupIcon::GroupIcon( QIconView* parent, QPixmap icon, 
00023                       QString text, QWidget* settingsWidget) :
00024                       QIconViewItem(parent, text, icon)
00025 {
00026   this->parent = parent;
00027   this->settingsWidget = settingsWidget;
00028   mousedOver = false;
00029   
00030   //initialize item rectangle
00031   initializeItemRect();
00032 }
00033 //==============================================
00034 void GroupIcon::paintItem( QPainter* p, const QColorGroup&)
00035 {
00036   p->save();
00037   QRect r = rect();
00038 
00039   //if selected paint dark blue background and outline
00040   if(isSelected())
00041   {
00042     //Draw Selected Color (dark blue)
00043     p->fillRect( r, QColor(193, 210, 238) );
00044 
00045     //draw selection rectangle (darker blue)
00046     p->setPen( QColor(49, 106, 197) );
00047     p->drawRect(r);
00048   }
00049   //else if pseudo selected paint ligher blue background with outline
00050   else if(mousedOver)
00051   {
00052     //Draw Pseudo Selected Color (light blue)
00053     p->fillRect( r, QColor(224, 232, 246) );
00054 
00055     //draw selection rectangle (darker blue)
00056     p->setPen( QColor(152, 180, 226) );
00057     p->drawRect(r);
00058   }
00059 
00060   p->restore();
00061 
00062   p->drawPixmap( x()+3 , y() + ( height() - pixmap()->height() ) / 2, *pixmap());
00063 
00064   int align = AlignLeft | WordBreak | BreakAnywhere;
00065   p->drawText( textRect( FALSE ), align, text());
00066 }
00067 //==============================================
00068 void GroupIcon::paintFocus( QPainter*, const QColorGroup&) { }
00069 //==============================================
00070 QWidget* GroupIcon::getSettingsWidget() { return settingsWidget; }
00071 //==============================================
00072 void GroupIcon::setMousedOver(bool val) { mousedOver = val; }
00073 //==============================================
00074 void GroupIcon::initializeItemRect()
00075 {
00076   //reset pixmap rect
00077   QRect pr = pixmapRect();
00078   int prWidth  = pr.width();
00079   int prHeight = pr.height();
00080   pr.setTopLeft( QPoint(3,3) );
00081   pr.setBottomRight( QPoint(pr.left()+prWidth, pr.top()+prHeight) );
00082   setPixmapRect( pr );
00083   
00084   //reset text rect
00085   int textWidth = ((GroupsWidget*)parent)->getTextWidth();
00086   QRect tr = textRect();
00087   tr.setTop( pixmapRect().top() );
00088   tr.setBottom( pixmapRect().bottom() );
00089   tr.setLeft( pixmapRect().right() + 2 );
00090   tr.setRight( tr.left() + textWidth );
00091   setTextRect( tr );
00092   
00093   //reset item rect using pixmap and text rect dimensions
00094   int itemW = 3 + pixmapRect().width() + (tr.left() - pr.right()) + textRect().width() + 3;
00095   int itemH = 3 + pixmapRect().height() + 3;
00096   setItemRect( QRect( pixmapRect().left() - 3, pixmapRect().top() - 3, itemW, itemH ) );
00097 }
00098 //==============================================

Generated on Wed May 4 11:10:13 2005 for AlbumShaper by  doxygen 1.3.9.1