kdeprint Library API Documentation

driveritem.cpp

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License version 2 as published by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 00018 **/ 00019 00020 #include "driveritem.h" 00021 #include "driver.h" 00022 00023 #include <qpainter.h> 00024 #include <kiconloader.h> 00025 #include <kdebug.h> 00026 00027 DriverItem::DriverItem(QListView *parent, DrBase *item) 00028 : QListViewItem(parent), m_item(item), m_conflict(false) 00029 { 00030 setOpen(depth() < 3); 00031 setPixmap(0,SmallIcon("fileprint")); 00032 updateText(); 00033 } 00034 00035 DriverItem::DriverItem(QListViewItem *parent, QListViewItem *after, DrBase *item) 00036 : QListViewItem(parent, after), m_item(item), m_conflict(false) 00037 { 00038 setOpen(depth() < 3); 00039 if (item) setPixmap(0,SmallIcon((item->isOption() ? "document" : "folder"))); 00040 updateText(); 00041 } 00042 00043 void DriverItem::updateText() 00044 { 00045 if (m_item) 00046 { 00047 QString s(m_item->get("text")); 00048 if (m_item->isOption()) 00049 s.append(QString::fromLatin1(": <%1>").arg(m_item->prettyText())); 00050 if (m_item->type() == DrBase::List) 00051 { 00052 // remove all children: something has changed (otherwise this 00053 // function would not be called), so it make sense to remove 00054 // those children in all cases. 00055 while (firstChild()) 00056 delete firstChild(); 00057 DrBase *ch = static_cast<DrListOption*>(m_item)->currentChoice(); 00058 if (ch && ch->type() == DrBase::ChoiceGroup) 00059 { 00060 // add new children 00061 static_cast<DrChoiceGroup*>(ch)->createItem(this); 00062 setOpen(true); 00063 } 00064 } 00065 setText(0,s); 00066 } 00067 else 00068 setText(0,"ERROR"); 00069 widthChanged(); 00070 } 00071 00072 void DriverItem::paintCell(QPainter *p, const QColorGroup& cg, int, int width, int) 00073 { 00074 // background 00075 p->fillRect(0, 0, width, height(), cg.base()); 00076 00077 // highlight rectangle 00078 if (isSelected()) 00079 p->fillRect(0, 0, /*2+p->fontMetrics().width(text(0))+(pixmap(0) ? pixmap(0)->width()+2 : 0)*/ width, height(), (m_conflict ? red : cg.highlight())); 00080 00081 // draw pixmap 00082 int w(0); 00083 if (pixmap(0) && !pixmap(0)->isNull()) 00084 { 00085 int h((height()-pixmap(0)->height())/2); 00086 p->drawPixmap(w,h,*pixmap(0)); 00087 w += (pixmap(0)->width()+2); 00088 } 00089 00090 // draw Text 00091 if (!m_item || !m_item->isOption() || isSelected()) 00092 { 00093 p->setPen((isSelected() ? cg.highlightedText() : (m_conflict ? red : cg.text()))); 00094 p->drawText(w,0,width-w,height(),Qt::AlignLeft|Qt::AlignVCenter,text(0)); 00095 } 00096 else 00097 { 00098 int w1(0); 00099 QString s(m_item->get("text") + ": <"); 00100 w1 = p->fontMetrics().width(s); 00101 p->setPen(cg.text()); 00102 p->drawText(w,0,w1,height(),Qt::AlignLeft|Qt::AlignVCenter,s); 00103 w += w1; 00104 p->setPen((m_conflict ? red : darkGreen)); 00105 s = m_item->prettyText(); 00106 w1 = p->fontMetrics().width(s); 00107 p->drawText(w,0,w1,height(),Qt::AlignLeft|Qt::AlignVCenter,s); 00108 w += w1; 00109 p->setPen(cg.text()); 00110 s = QString::fromLatin1(">"); 00111 w1 = p->fontMetrics().width(s); 00112 p->drawText(w,0,w1,height(),Qt::AlignLeft|Qt::AlignVCenter,s); 00113 } 00114 } 00115 00116 bool DriverItem::updateConflict() 00117 { 00118 m_conflict = false; 00119 if (m_item) 00120 { 00121 if (!m_item->isOption()) 00122 { 00123 DriverItem *item = (DriverItem*)firstChild(); 00124 while (item) 00125 { 00126 if (item->updateConflict()) 00127 m_conflict = true; 00128 item = (DriverItem*)item->nextSibling(); 00129 } 00130 } 00131 else 00132 { 00133 m_conflict = (m_item->conflict()); 00134 } 00135 } 00136 repaint(); 00137 return m_conflict; 00138 } 00139 00140 void DriverItem::updateTextRecursive() 00141 { 00142 if ( m_item->isOption() ) 00143 updateText(); 00144 00145 DriverItem *item = static_cast<DriverItem*>( firstChild() ); 00146 while ( item ) 00147 { 00148 item->updateTextRecursive(); 00149 item = static_cast<DriverItem*>( item->nextSibling() ); 00150 } 00151 }
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 20 09:49:59 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003