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 | 47d455dd55be855e4cc691c32f687f723d9247ee (patch) | |
tree | 52e236aaa2576bdb3840ebede26619692fed6d7d /kpovmodeler/pmcomment.cpp | |
download | tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.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/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpovmodeler/pmcomment.cpp')
-rw-r--r-- | kpovmodeler/pmcomment.cpp | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/kpovmodeler/pmcomment.cpp b/kpovmodeler/pmcomment.cpp new file mode 100644 index 00000000..e4783ae5 --- /dev/null +++ b/kpovmodeler/pmcomment.cpp @@ -0,0 +1,174 @@ +/* +************************************************************************** + description + -------------------- + copyright : (C) 2000-2001 by Andreas Zehender + 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 "pmcomment.h" +#include "pmxmlhelper.h" + +#include "pmcommentedit.h" +#include "pmmemento.h" + +#include <qtextstream.h> +#include <klocale.h> + +PMDefinePropertyClass( PMComment, PMCommentProperty ); + +PMMetaObject* PMComment::s_pMetaObject = 0; +PMObject* createNewComment( PMPart* part ) +{ + return new PMComment( part ); +} + +const unsigned int c_maxDescriptionLength = 25; + +PMComment::PMComment( PMPart* part ) + : Base( part ) +{ +} + +PMComment::PMComment( PMPart* part, const QString& t ) + : Base( part ) +{ + m_text = t; +} + +PMComment::PMComment( const PMComment& c ) + : Base( c ) +{ + m_text = c.m_text; +} + +PMComment::~PMComment( ) +{ +} + +QString PMComment::description( ) const +{ + if( !m_text.isEmpty( ) ) + { + QString copy = m_text; + QTextStream str( ©, IO_ReadOnly ); + QString tmp, desc; + bool stop = false; + bool truncated = false; + + while( !str.atEnd( ) && !stop ) + { + str >> tmp; + if( desc.length( ) + tmp.length( ) + 1 <= c_maxDescriptionLength ) + { + if( !desc.isEmpty( ) ) + desc += " "; + desc += tmp; + } + else + { + if( desc.isEmpty( ) ) + { + desc = tmp.left( c_maxDescriptionLength ); + if( tmp.length( ) > c_maxDescriptionLength ) + truncated = true; + } + else + truncated = true; + stop = true; + } + } + if( truncated ) + desc += "..."; + return desc; + } + return i18n( "comment" ); +} + +void PMComment::setText( const QString& text ) +{ + if( text != m_text ) + { + if( m_pMemento ) + { + m_pMemento->addData( s_pMetaObject, PMTextID, m_text ); + m_pMemento->setDescriptionChanged( ); + } + m_text = text; + } +} + +PMMetaObject* PMComment::metaObject( ) const +{ + if( !s_pMetaObject ) + { + s_pMetaObject = new PMMetaObject( "Comment", Base::metaObject( ), + createNewComment ); + s_pMetaObject->addProperty( + new PMCommentProperty( "text", &PMComment::setText, &PMComment::text ) ); + } + return s_pMetaObject; +} + +void PMComment::cleanUp( ) const +{ + if( s_pMetaObject ) + { + delete s_pMetaObject; + s_pMetaObject = 0; + } + Base::cleanUp( ); +} + +void PMComment::serialize( QDomElement& e, QDomDocument& doc ) const +{ + QDomText t = doc.createTextNode( m_text ); + e.appendChild( t ); +} + +void PMComment::readAttributes( const PMXMLHelper& h ) +{ + QDomNode e = h.element( ).firstChild( ); + if( e.isText( ) ) + m_text = e.toText( ).data( ); +} + +PMDialogEditBase* PMComment::editWidget( QWidget* parent ) const +{ + return new PMCommentEdit( parent ); +} + +void PMComment::restoreMemento( PMMemento* s ) +{ + PMMementoDataIterator it( s ); + PMMementoData* data; + + for( ; it.current( ); ++it ) + { + data = it.current( ); + if( data->objectType( ) == s_pMetaObject ) + { + switch( data->valueID( ) ) + { + case PMTextID: + setText( data->stringData( ) ); + break; + default: + kdError( PMArea ) << "Wrong ID in PMComment::restoreMemento\n"; + break; + } + } + } + Base::restoreMemento( s ); +} + |