author | ulf69 <ulf69> | 2004-09-15 17:53:22 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-09-15 17:53:22 (UTC) |
commit | d3925ba5bd25224bc4a60d3d6a107c464994a1ea (patch) (side-by-side diff) | |
tree | 60f69da1d2b79ee3081e7ef5c09a46470ca6eda0 /pwmanager/pwmanager/commentbox.cpp | |
parent | ce83a3479d23b9e8a59c745ccd0a0b14f64ef4e8 (diff) | |
download | kdepimpi-d3925ba5bd25224bc4a60d3d6a107c464994a1ea.zip kdepimpi-d3925ba5bd25224bc4a60d3d6a107c464994a1ea.tar.gz kdepimpi-d3925ba5bd25224bc4a60d3d6a107c464994a1ea.tar.bz2 |
initial revision
Diffstat (limited to 'pwmanager/pwmanager/commentbox.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | pwmanager/pwmanager/commentbox.cpp | 238 |
1 files changed, 238 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/commentbox.cpp b/pwmanager/pwmanager/commentbox.cpp new file mode 100644 index 0000000..280b139 --- a/dev/null +++ b/pwmanager/pwmanager/commentbox.cpp @@ -0,0 +1,238 @@ +/*************************************************************************** + * * + * copyright (C) 2004 by Michael Buesch * + * email: mbuesch@freenet.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License version 2 * + * as published by the Free Software Foundation. * + * * + ***************************************************************************/ + +/*************************************************************************** + * copyright (C) 2004 by Ulf Schenk + * This file is originaly based on version 1.0.1 of pwmanager + * and was modified to run on embedded devices that run microkde + * + * $Id$ + **************************************************************************/ + +#include "commentbox.h" +#include "pwmexception.h" +#include "htmlgen.h" + +#include <klocale.h> + +#ifndef PWM_EMBEDDED +#include <khtml_part.h> +#include <khtmlview.h> +#include <qtextedit.h> +#else +#include <qmultilineedit.h> +#endif + +CommentBox::CommentBox(QWidget *_parentWidget) +{ + PWM_ASSERT(_parentWidget); + parentWidget = _parentWidget; + textDta = 0; +#ifndef PWM_EMBEDDED + htmlDta = 0; +#endif + mode = mode_notSet; +} + +CommentBox::~CommentBox() +{ + clearText(); + clearHtml(); +} + +void CommentBox::clear() +{ + clearText(); + clearHtml(); + mode = mode_notSet; +} + +void CommentBox::clearText() +{ + delete_ifnot_null(textDta); +} + +void CommentBox::clearHtml() +{ +#ifndef PWM_EMBEDDED + delete_ifnot_null(htmlDta); +#endif +} + +void CommentBox::setText(const QString &text) +{ + switchTo(mode_text); + PWM_ASSERT(textDta); + textDta->setText(i18n("Comment") + ": " + text); + if (!textDta->isVisible()) + textDta->show(); +} + +bool CommentBox::getText(QString *text) +{ + if (mode != mode_text) + return false; + PWM_ASSERT(text); + if (!textDta) { + *text = ""; + return true; + } + *text = textDta->text(); + return true; +} + +void CommentBox::setHtml(QString code) +{ +#ifndef PWM_EMBEDDED + switchTo(mode_html); + PWM_ASSERT(htmlDta); + if (!HtmlGen::replaceSSDummy(&code)) + printWarn("CommentBox::setHtml(): replaceSSDummy() failed!"); + htmlDta->begin(); + htmlDta->write(code); + htmlDta->end(); + htmlDta->show(); +#endif +} + +void CommentBox::setContent(const QString &dta) +{ + // if there's no data, hide the comment-box + if (dta.isEmpty()) { + clear(); + return; + } +#ifndef PWM_EMBEDDED + if (HtmlGen::isHtml(dta)) { + setHtml(dta); + return; + } +#endif + // we assume it's plain text + setText(dta); +} + +void CommentBox::switchTo(commentBoxMode newMode) +{ + if (newMode == mode) + return; + + // cleanup old mode + switch (mode) { + case mode_text: + clearText(); + break; + case mode_html: + clearHtml(); + break; + default: + break; + } + + // setup new mode + switch (newMode) { + case mode_text: +#ifndef PWM_EMBEDDED + textDta = new QTextEdit(parentWidget); + textDta->setTextFormat(Qt::PlainText); +#else + textDta = new QMultiLineEdit(parentWidget); +#endif + textDta->setReadOnly(true); + textDta->show(); + break; + case mode_html: +#ifndef PWM_EMBEDDED + htmlDta = new KHTMLPart(parentWidget, 0, + parentWidget); + htmlDta->show(); +#endif + break; + default: + BUG(); + break; + } + + mode = newMode; +} + +void CommentBox::show() +{ + switch (mode) { + case mode_text: + PWM_ASSERT(textDta); + textDta->show(); + break; + case mode_html: +#ifndef PWM_EMBEDDED + PWM_ASSERT(htmlDta); + htmlDta->show(); +#endif + break; + default: + break; + } +} + +void CommentBox::hide() +{ + switch (mode) { + case mode_text: + PWM_ASSERT(textDta); + textDta->hide(); + break; + case mode_html: +#ifndef PWM_EMBEDDED + PWM_ASSERT(htmlDta); + htmlDta->hide(); +#endif + break; + default: + break; + } +} + +void CommentBox::resize(const QSize &size) +{ + switch (mode) { + case mode_text: + PWM_ASSERT(textDta); + textDta->resize(size); + break; + case mode_html: +#ifndef PWM_EMBEDDED + PWM_ASSERT(htmlDta); + htmlDta->view()->resize(size); +#endif + break; + default: + break; + } +} + +QSize CommentBox::size() +{ + switch (mode) { + case mode_text: + PWM_ASSERT(textDta); + return textDta->size(); + break; + case mode_html: +#ifndef PWM_EMBEDDED + PWM_ASSERT(htmlDta); + return htmlDta->view()->size(); +#endif + break; + default: + break; + } + return QSize(); +} |