diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 84da08d7b7fcda12c85caeb5a10b4903770a6f69 (patch) | |
tree | 2a6aea76f2dfffb4cc04bb907c4725af94f70e72 /ksig/siglistviewitem.cpp | |
download | tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.tar.gz tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.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/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ksig/siglistviewitem.cpp')
-rw-r--r-- | ksig/siglistviewitem.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/ksig/siglistviewitem.cpp b/ksig/siglistviewitem.cpp new file mode 100644 index 0000000..6744f87 --- /dev/null +++ b/ksig/siglistviewitem.cpp @@ -0,0 +1,108 @@ +/*************************************************************************** + siglistviewitem.cpp - description + ------------------- + begin : Fri Jul 12 2002 + copyright : (C) 2002 by Scott Wheeler + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "siglistviewitem.h" + +#include <klocale.h> +#include <kdebug.h> + +#include <qregexp.h> + +//////////////////////////////////////////////////////////////////////////////// +// public members +//////////////////////////////////////////////////////////////////////////////// + +SigListViewItem::~SigListViewItem() +{ + // remove the element from the tree + element.parentNode().removeChild(element); +} + +QString SigListViewItem::text() const +{ + return(elementText); +} + +void SigListViewItem::setText(const QString &t) +{ + if(t != elementText) { + elementText = t; + dirty = true; + refreshText(); + } +} + +void SigListViewItem::refreshText() +{ + if(!text().isEmpty()) + KListViewItem::setText(0, text().simplifyWhiteSpace()); + else + KListViewItem::setText(0, emptySigString); +} + +void SigListViewItem::nodeToText(const QDomNode &n, QString &s) +{ + QDomNodeList children = n.childNodes(); + + for(uint i = 0; i < children.count(); i++) { + if(children.item(i).isText()) + s.append(children.item(i).toText().data()); + else { + nodeToText(children.item(i), s); + if(children.item(i).isElement() && children.item(i).toElement().tagName() == "p") { + s.append("\n"); + } + } + } +} + +//////////////////////////////////////////////////////////////////////////////// +// private members +//////////////////////////////////////////////////////////////////////////////// + +SigListViewItem::SigListViewItem(QListView *parent, QDomDocument document, QDomElement signatureElement) : KListViewItem(parent) +{ + emptySigString = i18n("<empty signature>"); + + doc = document; + element = signatureElement; + nodeToText(element, elementText); + elementText.replace(QRegExp("\n$"), ""); + + dirty = false; + refreshText(); +} + +void SigListViewItem::render() +{ + if(dirty) { + QDomNodeList children = element.childNodes(); + + while(!element.firstChild().isNull()) + element.removeChild(element.firstChild()); + + // create new children + QStringList lines = QStringList::split("\n", elementText, true); + + for(QStringList::Iterator it = lines.begin(); it != lines.end(); it++) { + QDomElement p = doc.createElement("p"); + element.appendChild(p); + p.appendChild(doc.createTextNode(*it)); + } + dirty = false; + } +} |