KDevelop API Documentation

filecreate_listitem.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Julian Rockey                                   *
00003  *   linux@jrockey.com                                                     *
00004  *   thanks: Roberto Raggi for QSimpleRichText stuff                       *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  ***************************************************************************/
00011 
00012 
00013 #include "filecreate_listitem.h"
00014 
00015 #include <kglobal.h>
00016 #include <kiconloader.h>
00017 
00018 #include <qsimplerichtext.h>
00019 #include <qpixmap.h>
00020 
00021 namespace FileCreate {
00022 
00023   ListItem::ListItem(QListView * listview, const FileType * filetype) :
00024     KListViewItem(listview), m_filetype(filetype),
00025     m_filetypeRenderer(NULL)
00026   {
00027     init();
00028   }
00029 
00030 
00031   ListItem::ListItem(ListItem * listitem, const FileType * filetype) :
00032     KListViewItem(listitem), m_filetype(filetype),
00033     m_filetypeRenderer(NULL)
00034   {
00035     init();
00036   }
00037 
00038   ListItem::~ListItem()
00039   {
00040     if (m_filetypeRenderer) delete m_filetypeRenderer;
00041   }
00042 
00043   void ListItem::setup()
00044   {
00045     if (m_filetypeRenderer) delete m_filetypeRenderer;
00046     m_filetypeRenderer = new QSimpleRichText( text(1), listView()->font() );
00047     m_filetypeRenderer->setWidth(listView()->columnWidth(1));
00048     setHeight(m_filetypeRenderer->height());
00049     KListViewItem::setup();
00050   }
00051 
00052   void ListItem::setHeight( int height )
00053   {
00054     KListViewItem::setHeight( QMAX(QMAX(height,m_iconHeight), m_filetypeRenderer->height() ) );
00055   }
00056 
00057   void ListItem::prepareResize() {
00058     if (m_filetypeRenderer) {
00059       m_filetypeRenderer->setWidth(listView()->columnWidth(1));
00060       setHeight(m_filetypeRenderer->height());
00061     }
00062   }
00063 
00064   void ListItem::paintCell( QPainter* p, const QColorGroup& cg, int column, int width, int align )
00065   {
00066 
00067     QBrush brush( isSelected() ? cg.highlight() : backgroundColor() );
00068 
00069     if( column == 1 ){
00070 //       m_filetypeRenderer->setWidth(width);
00071 //       setHeight(m_filetypeRenderer->height());
00072       m_filetypeRenderer->draw( p, 0, 0, QRect(0, 0, width, height()), cg, &brush );
00073       return;
00074     }
00075 
00076     KListViewItem::paintCell( p, cg, column, width, align );
00077   }
00078 
00079   void ListItem::init()
00080   {
00081     m_iconHeight = 0;
00082     setText(0, m_filetype->ext()!="" ? QString("." + m_filetype->ext()) : QString("") );
00083     setText(1, "<qt><b>"+m_filetype->name()+"</b>. " + m_filetype->descr() );
00084 
00085     KIconLoader * loader = KGlobal::iconLoader();
00086     QPixmap iconPix = loader->loadIcon(m_filetype->icon(), KIcon::Desktop,
00087                                        KIcon::SizeMedium,
00088                                        KIcon::DefaultState, NULL,
00089                                        true);
00090     if (!iconPix.isNull()) {
00091       setPixmap(0, iconPix);
00092       m_iconHeight = iconPix.height();
00093     }
00094 
00095   }
00096 
00097 
00098 
00099 }
00100 
00101 
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:40 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003