diff --git a/core/annotations.cpp b/core/annotations.cpp index 511ba5f59..83be68bad 100644 --- a/core/annotations.cpp +++ b/core/annotations.cpp @@ -49,6 +49,9 @@ Annotation * AnnotationUtils::createAnnotation( const QDomElement & annElement ) case Annotation::AInk: annotation = new InkAnnotation( annElement ); break; + case Annotation::ACaret: + annotation = new CaretAnnotation( annElement ); + break; } // return created annotation @@ -2027,3 +2030,79 @@ void InkAnnotationPrivate::translate( const NormalizedPoint &coord ) } } } + +/** CaretAnnotation [Annotation] */ + +class Okular::CaretAnnotationPrivate : public Okular::AnnotationPrivate +{ + public: + CaretAnnotationPrivate() + : AnnotationPrivate(), m_symbol( "None" ) + { + } + + QString m_symbol; +}; + +CaretAnnotation::CaretAnnotation() + : Annotation( *new CaretAnnotationPrivate() ) +{ +} + +CaretAnnotation::CaretAnnotation( const QDomNode & node ) + : Annotation( *new CaretAnnotationPrivate(), node ) +{ + Q_D( CaretAnnotation ); + // loop through the whole children looking for a 'caret' element + QDomNode subNode = node.firstChild(); + while( subNode.isElement() ) + { + QDomElement e = subNode.toElement(); + subNode = subNode.nextSibling(); + if ( e.tagName() != "caret" ) + continue; + + // parse the attributes + if ( e.hasAttribute( "symbol" ) ) + d->m_symbol = e.attribute( "symbol" ); + + // loading complete + break; + } +} + +CaretAnnotation::~CaretAnnotation() +{ +} + +void CaretAnnotation::setCaretSymbol( const QString &symbol ) +{ + Q_D( CaretAnnotation ); + d->m_symbol = symbol; +} + +QString CaretAnnotation::caretSymbol() const +{ + Q_D( const CaretAnnotation ); + return d->m_symbol; +} + +Annotation::SubType CaretAnnotation::subType() const +{ + return ACaret; +} + +void CaretAnnotation::store( QDomNode & node, QDomDocument & document ) const +{ + Q_D( const CaretAnnotation ); + // recurse to parent objects storing properties + Annotation::store( node, document ); + + // create [caret] element + QDomElement caretElement = document.createElement( "caret" ); + node.appendChild( caretElement ); + + // append the optional attributes + if ( d->m_symbol != "None" ) + caretElement.setAttribute( "symbol", d->m_symbol ); +} diff --git a/core/annotations.h b/core/annotations.h index 064acce78..4839c4165 100644 --- a/core/annotations.h +++ b/core/annotations.h @@ -35,6 +35,7 @@ class GeomAnnotationPrivate; class HighlightAnnotationPrivate; class StampAnnotationPrivate; class InkAnnotationPrivate; +class CaretAnnotationPrivate; /** * @short Helper class for (recursive) annotation retrieval/storage. @@ -101,6 +102,7 @@ class OKULAR_EXPORT Annotation AHighlight = 4, ///< A highlight annotation AStamp = 5, ///< A stamp annotation AInk = 6, ///< An ink annotation + ACaret = 8, ///< A caret annotation A_BASE = 0 ///< The annotation base class }; @@ -1191,6 +1193,50 @@ class OKULAR_EXPORT InkAnnotation : public Annotation Q_DISABLE_COPY( InkAnnotation ) }; +class OKULAR_EXPORT CaretAnnotation : public Annotation +{ + public: + /** + * Creates a new caret annotation. + */ + CaretAnnotation(); + + /** + * Creates a new caret annotation from the xml @p description + */ + explicit CaretAnnotation( const QDomNode &description ); + + /** + * Destroys the caret annotation. + */ + ~CaretAnnotation(); + + /** + * Sets the @p symbol for the caret annotation. + */ + void setCaretSymbol( const QString &symbol ); + + /** + * Returns the symbol of the annotation. + */ + QString caretSymbol() const; + + /** + * 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( CaretAnnotation ) + Q_DISABLE_COPY( CaretAnnotation ) +}; + } #endif