diff --git a/qt4/src/poppler-annotation-private.h b/qt4/src/poppler-annotation-private.h index 2ee7d77..68c1b8e 100644 --- a/qt4/src/poppler-annotation-private.h +++ b/qt4/src/poppler-annotation-private.h @@ -31,6 +31,7 @@ class Annot; class AnnotPath; +class Link; class Page; class PDFRectangle; @@ -100,6 +101,8 @@ class AnnotationPrivate : public QSharedData static void removeAnnotationFromPage(::Page *pdfPage, const Annotation * ann); Ref pdfObjectReference() const; + + Link* additionalAction( Annotation::AdditionalActionsType type ) const; }; } diff --git a/qt4/src/poppler-annotation.cc b/qt4/src/poppler-annotation.cc index d4f12d4..3068d6b 100644 --- a/qt4/src/poppler-annotation.cc +++ b/qt4/src/poppler-annotation.cc @@ -42,6 +42,7 @@ #include #include #include +#include /* Almost all getters directly query the underlying poppler annotation, with * the exceptions of link, file attachment, sound, movie and screen annotations, @@ -455,7 +456,8 @@ QList AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentD case Annot::typeUnknown: continue; // special case for ignoring unknown annotations case Annot::typeWidget: - continue; // handled as forms or some other way + annotation = new WidgetAnnotation(); + break; default: { #define CASE_FOR_TYPE( thetype ) \ @@ -493,6 +495,42 @@ Ref AnnotationPrivate::pdfObjectReference() const return pdfAnnot->getRef(); } +Link* AnnotationPrivate::additionalAction( Annotation::AdditionalActionsType type ) const +{ + if ( pdfAnnot->getType() != Annot::typeScreen && pdfAnnot->getType() != Annot::typeWidget ) + return 0; + + Annot::AdditionalActionsType actionType = Annot::actionCursorEntering; + switch ( type ) + { + case Annotation::CursorEnteringAction: actionType = Annot::actionCursorEntering; break; + case Annotation::CursorLeavingAction: actionType = Annot::actionCursorLeaving; break; + case Annotation::MousePressedAction: actionType = Annot::actionMousePressed; break; + case Annotation::MouseReleasedAction: actionType = Annot::actionMouseReleased; break; + case Annotation::FocusInAction: actionType = Annot::actionFocusIn; break; + case Annotation::FocusOutAction: actionType = Annot::actionFocusOut; break; + case Annotation::PageOpeningAction: actionType = Annot::actionPageOpening; break; + case Annotation::PageClosingAction: actionType = Annot::actionPageClosing; break; + case Annotation::PageVisibleAction: actionType = Annot::actionPageVisible; break; + case Annotation::PageInvisibleAction: actionType = Annot::actionPageInvisible; break; + } + + ::LinkAction *linkAction = 0; + if ( pdfAnnot->getType() == Annot::typeScreen ) + linkAction = static_cast( pdfAnnot )->getAdditionalAction( actionType ); + else if ( pdfAnnot->getType() == Annot::typeWidget ) + linkAction = static_cast( pdfAnnot )->getAdditionalAction( actionType ); + + Link *link = 0; + + if ( linkAction ) + link = PageData::convertLinkActionToLink( linkAction, parentDoc, QRectF() ); + + delete linkAction; + + return link; +} + void AnnotationPrivate::addAnnotationToPage(::Page *pdfPage, DocumentData *doc, const Annotation * ann) { if (ann->d_ptr->pdfAnnot != 0) @@ -4261,6 +4299,64 @@ void ScreenAnnotation::setScreenTitle( const QString &title ) d->title = title; } +Link* ScreenAnnotation::additionalAction( AdditionalActionsType type ) const +{ + Q_D( const ScreenAnnotation ); + return d->additionalAction( type ); +} + +/** WidgetAnnotation [Annotation] */ +class WidgetAnnotationPrivate : public AnnotationPrivate +{ + public: + Annotation * makeAlias(); + Annot* createNativeAnnot(::Page *destPage, DocumentData *doc); +}; + +Annotation * WidgetAnnotationPrivate::makeAlias() +{ + return new WidgetAnnotation(*this); +} + +Annot* WidgetAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) +{ + return 0; // Not implemented +} + +WidgetAnnotation::WidgetAnnotation(WidgetAnnotationPrivate &dd) + : Annotation( dd ) +{} + +WidgetAnnotation::WidgetAnnotation() + : Annotation( *new WidgetAnnotationPrivate() ) +{ +} + +WidgetAnnotation::~WidgetAnnotation() +{ +} + +void WidgetAnnotation::store( QDomNode & node, QDomDocument & document ) const +{ + // store base annotation properties + storeBaseAnnotationProperties( node, document ); + + // create [widget] element + QDomElement widgetElement = document.createElement( "widget" ); + node.appendChild( widgetElement ); +} + +Annotation::SubType WidgetAnnotation::subType() const +{ + return AWidget; +} + +Link* WidgetAnnotation::additionalAction( AdditionalActionsType type ) const +{ + Q_D( const WidgetAnnotation ); + return d->additionalAction( type ); +} + //BEGIN utility annotation functions QColor convertAnnotColor( AnnotColor *color ) { diff --git a/qt4/src/poppler-annotation.h b/qt4/src/poppler-annotation.h index e511ec0..85669e0 100644 --- a/qt4/src/poppler-annotation.h +++ b/qt4/src/poppler-annotation.h @@ -55,6 +55,7 @@ class FileAttachmentAnnotationPrivate; class SoundAnnotationPrivate; class MovieAnnotationPrivate; class ScreenAnnotationPrivate; +class WidgetAnnotationPrivate; class EmbeddedFile; class Link; class SoundObject; @@ -112,7 +113,7 @@ class POPPLER_QT4_EXPORT Annotation // WARNING!!! oKular uses that very same values so if you change them notify the author! enum SubType { AText = 1, ALine = 2, AGeom = 3, AHighlight = 4, AStamp = 5, AInk = 6, ALink = 7, ACaret = 8, AFileAttachment = 9, ASound = 10, - AMovie = 11, AScreen = 12 /** \since 0.20 */, A_BASE = 0 }; + AMovie = 11, AScreen = 12 /** \since 0.20 */, AWidget = 13 /** \since 0.22 */, A_BASE = 0 }; enum Flag { Hidden = 1, FixedSize = 2, FixedRotation = 4, DenyPrint = 8, DenyWrite = 16, DenyDelete = 32, ToggleHidingOnMouse = 64, External = 128 }; enum LineStyle { Solid = 1, Dashed = 2, Beveled = 4, Inset = 8, Underline = 16 }; @@ -272,6 +273,28 @@ class POPPLER_QT4_EXPORT Annotation */ virtual ~Annotation(); + /** + * Describes the flags from an annotations 'AA' dictionary. + * + * This flag is used by the additionalAction() method for ScreenAnnotation + * and WidgetAnnotation. + * + * \since 0.22 + */ + enum AdditionalActionsType + { + CursorEnteringAction, ///< Performed when the cursor enters the annotation's active area + CursorLeavingAction, ///< Performed when the cursor exists the annotation's active area + MousePressedAction, ///< Performed when the mouse button is pressed inside the annotation's active area + MouseReleasedAction, ///< Performed when the mouse button is released inside the annotation's active area + FocusInAction, ///< Performed when the annotation receives the input focus + FocusOutAction, ///< Performed when the annotation loses the input focus + PageOpeningAction, ///< Performed when the page containing the annotation is opened + PageClosingAction, ///< Performed when the page containing the annotation is closed + PageVisibleAction, ///< Performed when the page containing the annotation becomes visible + PageInvisibleAction ///< Performed when the page containing the annotation becomes invisible + }; + protected: /// \cond PRIVATE Annotation( AnnotationPrivate &dd ); @@ -840,6 +863,14 @@ class POPPLER_QT4_EXPORT ScreenAnnotation : public Annotation */ void setScreenTitle( const QString &title ); + /** + * Returns the additional action of the given @p type fo the annotation or + * @c 0 if no action has been defined. + * + * \since 0.22 + */ + Link* additionalAction( AdditionalActionsType type ) const; + private: ScreenAnnotation(); ScreenAnnotation( ScreenAnnotationPrivate &dd ); @@ -848,6 +879,41 @@ class POPPLER_QT4_EXPORT ScreenAnnotation : public Annotation Q_DISABLE_COPY( ScreenAnnotation ) }; +/** + * \short Widget annotation. + * + * The widget annotation represents a widget (form field) on a page. + * + * \note This class is just provided for consistency of the annotation API, + * use the FormField classes to get all the form-related information. + * + * \since 0.22 + */ +class POPPLER_QT4_EXPORT WidgetAnnotation : public Annotation +{ + friend class AnnotationPrivate; + + public: + virtual ~WidgetAnnotation(); + + virtual SubType subType() const; + + /** + * Returns the additional action of the given @p type fo the annotation or + * @c 0 if no action has been defined. + * + * \since 0.22 + */ + Link* additionalAction( AdditionalActionsType type ) const; + + private: + WidgetAnnotation(); + WidgetAnnotation( WidgetAnnotationPrivate &dd ); + virtual void store( QDomNode &parentNode, QDomDocument &document ) const; // stub + Q_DECLARE_PRIVATE( WidgetAnnotation ) + Q_DISABLE_COPY( WidgetAnnotation ) +}; + } #endif