From 095d8fc384e1aa16079e2a8f8f9911f3513449a6 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 13 Apr 2008 16:34:33 +0000 Subject: [PATCH] Add support in the Okular core for File Attachment annotations. (Although, they cannot be (de)serialized to XML.) CCBUG: 155072 svn path=/trunk/KDE/kdegraphics/okular/; revision=796467 --- core/annotations.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++ core/annotations.h | 38 ++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/core/annotations.cpp b/core/annotations.cpp index 6a06752a6..c8a89995f 100644 --- a/core/annotations.cpp +++ b/core/annotations.cpp @@ -15,6 +15,7 @@ #include // local includes +#include "document.h" #include "page_p.h" using namespace Okular; @@ -2145,3 +2146,87 @@ void CaretAnnotation::store( QDomNode & node, QDomDocument & document ) const if ( d->m_symbol != None ) caretElement.setAttribute( "symbol", caretSymbolToString( d->m_symbol ) ); } + +/** FileAttachmentAnnotation [Annotation] */ + +class Okular::FileAttachmentAnnotationPrivate : public Okular::AnnotationPrivate +{ + public: + FileAttachmentAnnotationPrivate() + : AnnotationPrivate(), icon( "PushPin" ), embfile( 0 ) + { + } + ~FileAttachmentAnnotationPrivate() + { + delete embfile; + } + + // data fields + QString icon; + EmbeddedFile *embfile; +}; + +FileAttachmentAnnotation::FileAttachmentAnnotation() + : Annotation( *new FileAttachmentAnnotationPrivate() ) +{ +} + +FileAttachmentAnnotation::FileAttachmentAnnotation( const QDomNode & node ) + : Annotation( *new FileAttachmentAnnotationPrivate(), node ) +{ + // loop through the whole children looking for a 'fileattachment' element + QDomNode subNode = node.firstChild(); + while( subNode.isElement() ) + { + QDomElement e = subNode.toElement(); + subNode = subNode.nextSibling(); + if ( e.tagName() != "fileattachment" ) + continue; + + // loading complete + break; + } +} + +FileAttachmentAnnotation::~FileAttachmentAnnotation() +{ +} + +void FileAttachmentAnnotation::store( QDomNode & node, QDomDocument & document ) const +{ + // recurse to parent objects storing properties + Annotation::store( node, document ); + + // create [fileattachment] element + QDomElement fileAttachmentElement = document.createElement( "fileattachment" ); + node.appendChild( fileAttachmentElement ); +} + +Annotation::SubType FileAttachmentAnnotation::subType() const +{ + return AFileAttachment; +} + +QString FileAttachmentAnnotation::fileIconName() const +{ + Q_D( const FileAttachmentAnnotation ); + return d->icon; +} + +void FileAttachmentAnnotation::setFileIconName( const QString &icon ) +{ + Q_D( FileAttachmentAnnotation ); + d->icon = icon; +} + +EmbeddedFile* FileAttachmentAnnotation::embeddedFile() const +{ + Q_D( const FileAttachmentAnnotation ); + return d->embfile; +} + +void FileAttachmentAnnotation::setEmbeddedFile( EmbeddedFile *ef ) +{ + Q_D( FileAttachmentAnnotation ); + d->embfile = ef; +} diff --git a/core/annotations.h b/core/annotations.h index 9cb562636..05d030b51 100644 --- a/core/annotations.h +++ b/core/annotations.h @@ -27,6 +27,7 @@ class Annotation; class AnnotationObjectRect; class AnnotationPrivate; class Document; +class EmbeddedFile; class Page; class PagePrivate; class TextAnnotationPrivate; @@ -36,6 +37,7 @@ class HighlightAnnotationPrivate; class StampAnnotationPrivate; class InkAnnotationPrivate; class CaretAnnotationPrivate; +class FileAttachmentAnnotationPrivate; /** * @short Helper class for (recursive) annotation retrieval/storage. @@ -103,6 +105,7 @@ class OKULAR_EXPORT Annotation AStamp = 5, ///< A stamp annotation AInk = 6, ///< An ink annotation ACaret = 8, ///< A caret annotation + AFileAttachment = 9, ///< A file attachment annotation A_BASE = 0 ///< The annotation base class }; @@ -1286,6 +1289,41 @@ class OKULAR_EXPORT CaretAnnotation : public Annotation Q_DISABLE_COPY( CaretAnnotation ) }; +class OKULAR_EXPORT FileAttachmentAnnotation : public Annotation +{ + public: + /** + * Creates a new file attachment annotation. + */ + FileAttachmentAnnotation(); + explicit FileAttachmentAnnotation( const QDomNode &node ); + /** + * Destroys the file attachment annotation. + */ + virtual ~FileAttachmentAnnotation(); + + QString fileIconName() const; + void setFileIconName( const QString &icon ); + + EmbeddedFile* embeddedFile() const; + void setEmbeddedFile( EmbeddedFile *ef ); + + /** + * Returns the sub type of the caret annotation. + */ + SubType subType() const; + + /** + * Stores the caret annotation as xml in @p document + * under the given parent @p node. + */ + void store( QDomNode &node, QDomDocument &document ) const; + + private: + Q_DECLARE_PRIVATE( FileAttachmentAnnotation ) + Q_DISABLE_COPY( FileAttachmentAnnotation ) +}; + } #endif