[poppler] qt4/src

Albert Astals Cid aacid at kemper.freedesktop.org
Tue Sep 11 07:41:31 PDT 2012


 qt4/src/poppler-annotation-private.h |    3 +
 qt4/src/poppler-annotation.cc        |   99 ++++++++++++++++++++++++++++++++++-
 qt4/src/poppler-annotation.h         |   68 +++++++++++++++++++++++-
 3 files changed, 168 insertions(+), 2 deletions(-)

New commits:
commit e79b70ec13ab4d2cce8f245d150fa9329b436658
Author: Tobias Koenig <tokoe at kdab.com>
Date:   Tue Sep 11 16:39:55 2012 +0200

    Make 'additional actions' available in Annotation API of Qt4 frontend
    
    Bug #53589

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..c93c5b7 100644
--- a/qt4/src/poppler-annotation.cc
+++ b/qt4/src/poppler-annotation.cc
@@ -3,6 +3,7 @@
  * Copyright (C) 2006, 2008, 2010 Pino Toscano <pino at kde.org>
  * Copyright (C) 2012, Guillermo A. Amaral B. <gamaral at kde.org>
  * Copyright (C) 2012, Fabio D'Urso <fabiodurso at hotmail.it>
+ * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
  * Adapting code from
  *   Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
  *
@@ -42,6 +43,7 @@
 #include <Gfx.h>
 #include <Error.h>
 #include <FileSpec.h>
+#include <Link.h>
 
 /* Almost all getters directly query the underlying poppler annotation, with
  * the exceptions of link, file attachment, sound, movie and screen annotations,
@@ -455,7 +457,8 @@ QList<Annotation*> 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 +496,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<AnnotScreen*>( pdfAnnot )->getAdditionalAction( actionType );
+    else
+        linkAction = static_cast<AnnotWidget*>( 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 +4300,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


More information about the poppler mailing list