plvitem.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003-2004 by David Saxton                               *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "plvitem.h"
00012 #include "variant.h"
00013 
00014 #include <klistview.h>
00015 #include <qpainter.h>
00016 #include <qvariant.h>
00017 
00018 //BEGIN class PLVItem
00019 PLVItem::PLVItem(KListView *listview, const QString &id, Variant *data)
00020         : KListViewItem(listview, data->editorCaption())
00021 {
00022         p_data = data;
00023         m_id = id;
00024         setText(1,p_data->displayString() );
00025         
00026         connect(data,SIGNAL(valueChanged(QVariant, QVariant )),this,SLOT(updateData(QVariant )));
00027         
00028         //setHeight(100);
00029 }
00030 
00031 
00032 PLVItem::~PLVItem()
00033 {
00034 }
00035 
00036 void PLVItem::updateData(QVariant /*value*/)
00037 {
00038         if (!p_data)
00039                 return;
00040         setText(1,p_data->displayString() );
00041 }
00042 
00043 
00044 int PLVItem::width ( const QFontMetrics & fm, const QListView * lv, int c ) const
00045 {
00046         if ( c == 0 )
00047                 return 100;
00048 //              return KListViewItem::width( fm, lv, c );
00049         else
00050                 return 200;
00051 }
00052 //END class PLVitem
00053 
00054 
00055 
00056 //BEGIN class PLVColorItem
00057 PLVColorItem::PLVColorItem(KListView *listview, const QString &id, Variant *data)
00058         : PLVItem(listview,id,data)
00059 {
00060 }
00061 
00062 
00063 PLVColorItem::~PLVColorItem()
00064 {
00065 }
00066 
00067 void PLVColorItem::paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align )
00068 {
00069         if (!p_data)
00070                 return;
00071         // we only draw column 1 "Data" ourselves, otherwise
00072         // we leave it up to KDE
00073         if (column == 1)
00074         {
00075                 p->setBackgroundColor( p_data->value().toColor() );
00076                 QBrush brush( p_data->value().toColor() );
00077                 p->fillRect(QRect(0,0,listView()->columnWidth(1),KListViewItem::height()),brush);
00078         }
00079         else
00080                 KListViewItem::paintCell(p,cg,column,width,align);
00081 }
00082 
00083 void PLVColorItem::updateData(QVariant value)
00084 {
00085         listView()->triggerUpdate();
00086         PLVItem::updateData(value);
00087 }
00088 //END class PLVColorItem
00089 
00090 #include "plvitem.moc"

Generated on Tue May 8 17:05:32 2007 for KTechLab by  doxygen 1.5.1