summaryrefslogtreecommitdiffstats
path: root/kdeprint/driveritem.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch)
tree5ac38a06f3dde268dc7927dc155896926aaf7012 /kdeprint/driveritem.cpp
downloadtdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz
tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdeprint/driveritem.cpp')
-rw-r--r--kdeprint/driveritem.cpp151
1 files changed, 151 insertions, 0 deletions
diff --git a/kdeprint/driveritem.cpp b/kdeprint/driveritem.cpp
new file mode 100644
index 000000000..026c369a6
--- /dev/null
+++ b/kdeprint/driveritem.cpp
@@ -0,0 +1,151 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ **/
+
+#include "driveritem.h"
+#include "driver.h"
+
+#include <qpainter.h>
+#include <kiconloader.h>
+#include <kdebug.h>
+
+DriverItem::DriverItem(QListView *parent, DrBase *item)
+: QListViewItem(parent), m_item(item), m_conflict(false)
+{
+ setOpen(depth() < 3);
+ setPixmap(0,SmallIcon("fileprint"));
+ updateText();
+}
+
+DriverItem::DriverItem(QListViewItem *parent, QListViewItem *after, DrBase *item)
+: QListViewItem(parent, after), m_item(item), m_conflict(false)
+{
+ setOpen(depth() < 3);
+ if (item) setPixmap(0,SmallIcon((item->isOption() ? "document" : "folder")));
+ updateText();
+}
+
+void DriverItem::updateText()
+{
+ if (m_item)
+ {
+ QString s(m_item->get("text"));
+ if (m_item->isOption())
+ s.append(QString::fromLatin1(": <%1>").arg(m_item->prettyText()));
+ if (m_item->type() == DrBase::List)
+ {
+ // remove all children: something has changed (otherwise this
+ // function would not be called), so it make sense to remove
+ // those children in all cases.
+ while (firstChild())
+ delete firstChild();
+ DrBase *ch = static_cast<DrListOption*>(m_item)->currentChoice();
+ if (ch && ch->type() == DrBase::ChoiceGroup)
+ {
+ // add new children
+ static_cast<DrChoiceGroup*>(ch)->createItem(this);
+ setOpen(true);
+ }
+ }
+ setText(0,s);
+ }
+ else
+ setText(0,"ERROR");
+ widthChanged();
+}
+
+void DriverItem::paintCell(QPainter *p, const QColorGroup& cg, int, int width, int)
+{
+ // background
+ p->fillRect(0, 0, width, height(), cg.base());
+
+ // highlight rectangle
+ if (isSelected())
+ p->fillRect(0, 0, /*2+p->fontMetrics().width(text(0))+(pixmap(0) ? pixmap(0)->width()+2 : 0)*/ width, height(), (m_conflict ? red : cg.highlight()));
+
+ // draw pixmap
+ int w(0);
+ if (pixmap(0) && !pixmap(0)->isNull())
+ {
+ int h((height()-pixmap(0)->height())/2);
+ p->drawPixmap(w,h,*pixmap(0));
+ w += (pixmap(0)->width()+2);
+ }
+
+ // draw Text
+ if (!m_item || !m_item->isOption() || isSelected())
+ {
+ p->setPen((isSelected() ? cg.highlightedText() : (m_conflict ? red : cg.text())));
+ p->drawText(w,0,width-w,height(),Qt::AlignLeft|Qt::AlignVCenter,text(0));
+ }
+ else
+ {
+ int w1(0);
+ QString s(m_item->get("text") + ": <");
+ w1 = p->fontMetrics().width(s);
+ p->setPen(cg.text());
+ p->drawText(w,0,w1,height(),Qt::AlignLeft|Qt::AlignVCenter,s);
+ w += w1;
+ p->setPen((m_conflict ? red : darkGreen));
+ s = m_item->prettyText();
+ w1 = p->fontMetrics().width(s);
+ p->drawText(w,0,w1,height(),Qt::AlignLeft|Qt::AlignVCenter,s);
+ w += w1;
+ p->setPen(cg.text());
+ s = QString::fromLatin1(">");
+ w1 = p->fontMetrics().width(s);
+ p->drawText(w,0,w1,height(),Qt::AlignLeft|Qt::AlignVCenter,s);
+ }
+}
+
+bool DriverItem::updateConflict()
+{
+ m_conflict = false;
+ if (m_item)
+ {
+ if (!m_item->isOption())
+ {
+ DriverItem *item = (DriverItem*)firstChild();
+ while (item)
+ {
+ if (item->updateConflict())
+ m_conflict = true;
+ item = (DriverItem*)item->nextSibling();
+ }
+ }
+ else
+ {
+ m_conflict = (m_item->conflict());
+ }
+ }
+ repaint();
+ return m_conflict;
+}
+
+void DriverItem::updateTextRecursive()
+{
+ if ( m_item->isOption() )
+ updateText();
+
+ DriverItem *item = static_cast<DriverItem*>( firstChild() );
+ while ( item )
+ {
+ item->updateTextRecursive();
+ item = static_cast<DriverItem*>( item->nextSibling() );
+ }
+}