[poppler] qt4/src qt5/src

Albert Astals Cid aacid at kemper.freedesktop.org
Fri Nov 25 16:43:21 UTC 2016


 qt4/src/poppler-link-private.h       |   57 +++++++++++++++++++
 qt4/src/poppler-link.cc              |   33 +++++------
 qt4/src/poppler-link.h               |   34 ++++++++++-
 qt4/src/poppler-optcontent-private.h |    3 -
 qt4/src/poppler-optcontent.cc        |  103 ++++++++++++++++++++++-------------
 qt4/src/poppler-optcontent.h         |    8 ++
 qt4/src/poppler-page.cc              |   11 +++
 qt5/src/poppler-link-private.h       |   57 +++++++++++++++++++
 qt5/src/poppler-link.cc              |   33 +++++------
 qt5/src/poppler-link.h               |   34 ++++++++++-
 qt5/src/poppler-optcontent-private.h |    3 -
 qt5/src/poppler-optcontent.cc        |  103 ++++++++++++++++++++++-------------
 qt5/src/poppler-optcontent.h         |    8 ++
 qt5/src/poppler-page.cc              |   11 +++
 14 files changed, 382 insertions(+), 116 deletions(-)

New commits:
commit bc11784e143d462d62d3f63fc61e58b4b9640da7
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Nov 25 17:42:27 2016 +0100

    Qt: Support OCG state change links

diff --git a/qt4/src/poppler-link-private.h b/qt4/src/poppler-link-private.h
new file mode 100644
index 0000000..7b03c1c
--- /dev/null
+++ b/qt4/src/poppler-link-private.h
@@ -0,0 +1,57 @@
+/* poppler-link-private.h: qt interface to poppler
+ * Copyright (C) 2016, Albert Astals Cid <aacid at kde.org>
+ *
+ * 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, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _POPPLER_LINK_PRIVATE_H_
+#define _POPPLER_LINK_PRIVATE_H_
+
+class LinkOCGState;
+
+namespace Poppler {
+
+class LinkPrivate
+{
+public:
+    LinkPrivate( const QRectF &area )
+        : linkArea( area )
+    {
+    }
+
+    virtual ~LinkPrivate()
+    {
+    }
+
+    QRectF linkArea;
+};
+
+
+
+class LinkOCGStatePrivate : public LinkPrivate
+{
+public:
+    LinkOCGStatePrivate( const QRectF &area, ::LinkOCGState *plocg )
+        : LinkPrivate( area )
+        , popplerLinkOCGState( plocg )
+    {
+    }
+
+    ::LinkOCGState *popplerLinkOCGState;
+};
+
+}
+
+#endif
diff --git a/qt4/src/poppler-link.cc b/qt4/src/poppler-link.cc
index b810c55..4715f25 100644
--- a/qt4/src/poppler-link.cc
+++ b/qt4/src/poppler-link.cc
@@ -23,6 +23,7 @@
  */
 
 #include <poppler-qt4.h>
+#include <poppler-link-private.h>
 #include <poppler-private.h>
 #include <poppler-media.h>
 
@@ -70,24 +71,6 @@ class LinkDestinationPrivate : public QSharedData
 		changeZoom = false;
 	}
 
-class LinkPrivate
-{
-	public:
-		LinkPrivate( const QRectF &area );
-		virtual ~LinkPrivate();
-
-		QRectF linkArea;
-};
-
-	LinkPrivate::LinkPrivate( const QRectF &area )
-		: linkArea( area )
-	{
-	}
-
-	LinkPrivate::~LinkPrivate()
-	{
-	}
-
 class LinkGotoPrivate : public LinkPrivate
 {
 	public:
@@ -710,4 +693,18 @@ class LinkMoviePrivate : public LinkPrivate
 
 		return false;
 	}
+
+	LinkOCGState::LinkOCGState( LinkOCGStatePrivate *ocgp )
+		: Link ( *ocgp )
+	{
+	}
+
+	LinkOCGState::~LinkOCGState()
+	{
+	}
+
+	Link::LinkType LinkOCGState::linkType() const
+	{
+		return OCGState;
+	}
 }
diff --git a/qt4/src/poppler-link.h b/qt4/src/poppler-link.h
index 2c4bb55..d90b698 100644
--- a/qt4/src/poppler-link.h
+++ b/qt4/src/poppler-link.h
@@ -1,5 +1,5 @@
 /* poppler-link.h: qt interface to poppler
- * Copyright (C) 2006, 2013, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2006, 2013, 2016, Albert Astals Cid <aacid at kde.org>
  * Copyright (C) 2007-2008, 2010, Pino Toscano <pino at kde.org>
  * Copyright (C) 2010, 2012, Guillermo Amaral <gamaral at kdab.com>
  * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
@@ -31,6 +31,8 @@
 
 struct Ref;
 class MediaRendition;
+class MovieAnnotation;
+class ScreenAnnotation;
 
 namespace Poppler {
 
@@ -45,6 +47,7 @@ class LinkMoviePrivate;
 class LinkDestinationData;
 class LinkDestinationPrivate;
 class LinkRenditionPrivate;
+class LinkOCGStatePrivate;
 class MediaRendition;
 class SoundObject;
 
@@ -170,6 +173,8 @@ class POPPLER_QT4_EXPORT LinkDestination
  */
 class POPPLER_QT4_EXPORT Link
 {
+	friend class OptContentModel;
+
 	public:
 		/// \cond PRIVATE
 		Link( const QRectF &linkArea );
@@ -190,7 +195,8 @@ class POPPLER_QT4_EXPORT Link
 		    Sound,    ///< A link representing a sound to be played
 		    Movie,    ///< An action to be executed on a movie
 		    Rendition,    ///< A rendition link \since 0.20
-		    JavaScript    ///< A JavaScript code to be interpreted \since 0.10
+		    JavaScript,   ///< A JavaScript code to be interpreted \since 0.10
+		    OCGState      ///< An Optional Content Group state change \since 0.50
 		};
 
 		/**
@@ -606,6 +612,30 @@ class POPPLER_QT4_EXPORT LinkMovie : public Link
 		Q_DISABLE_COPY( LinkMovie )
 };
 
+/**
+ * OCGState: an optional content group state change.
+ *
+ * \since 0.50
+ */
+class POPPLER_QT4_EXPORT LinkOCGState : public Link
+{
+	public:
+		/**
+		 * Create a new OCGState link. This is only used by Poppler::Page.
+		 */
+		LinkOCGState( LinkOCGStatePrivate *ocgp );
+		/**
+		 * Destructor.
+		 */
+		~LinkOCGState();
+
+		LinkType linkType() const;
+
+	private:
+		Q_DECLARE_PRIVATE( LinkOCGState )
+		Q_DISABLE_COPY( LinkOCGState )
+};
+
 }
 
 #endif
diff --git a/qt4/src/poppler-optcontent-private.h b/qt4/src/poppler-optcontent-private.h
index 98eda07..25bae04 100644
--- a/qt4/src/poppler-optcontent-private.h
+++ b/qt4/src/poppler-optcontent-private.h
@@ -2,6 +2,7 @@
  *
  * Copyright (C) 2007, Brad Hards <bradh at kde.org>
  * Copyright (C) 2008, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2016, Albert Astals Cid <aacid at kde.org>
  *
  * 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
@@ -60,7 +61,7 @@ namespace Poppler
 
     QString name() const { return m_name; }
     ItemState state() const { return m_stateBackup; }
-    bool setState(ItemState state, QSet<OptContentItem *> &changedItems);
+    void setState(ItemState state, bool obeyRadioGroups, QSet<OptContentItem *> &changedItems);
 
     QList<OptContentItem*> childList() { return m_children; }
 
diff --git a/qt4/src/poppler-optcontent.cc b/qt4/src/poppler-optcontent.cc
index 431f0ee..84a4d62 100644
--- a/qt4/src/poppler-optcontent.cc
+++ b/qt4/src/poppler-optcontent.cc
@@ -3,7 +3,7 @@
  * Copyright (C) 2007, Brad Hards <bradh at kde.org>
  * Copyright (C) 2008, 2014, Pino Toscano <pino at kde.org>
  * Copyright (C) 2008, Carlos Garcia Campos <carlosgc at gnome.org>
- * Copyright (C) 2015, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2015, 2016, Albert Astals Cid <aacid at kde.org>
  *
  * 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
@@ -25,11 +25,13 @@
 #include "poppler-optcontent-private.h"
 
 #include "poppler-private.h"
+#include "poppler-link-private.h"
 
 #include <QtCore/QDebug>
 #include <QtCore/QtAlgorithms>
 
 #include "poppler/OptionalContent.h"
+#include "poppler/Link.h"
 
 namespace Poppler
 {
@@ -63,7 +65,7 @@ namespace Poppler
       OptContentItem *thisItem = itemsInGroup.at(i);
       if (thisItem != itemToSetOn) {
         QSet<OptContentItem *> newChangedItems;
-        thisItem->setState(OptContentItem::Off, newChangedItems);
+        thisItem->setState(OptContentItem::Off, false /*obeyRadioGroups*/, newChangedItems);
         changedItems += newChangedItems;
       }
     }
@@ -111,31 +113,33 @@ namespace Poppler
   }
 
 
-  bool OptContentItem::setState(ItemState state, QSet<OptContentItem *> &changedItems)
+  void OptContentItem::setState(ItemState state, bool obeyRadioGroups, QSet<OptContentItem *> &changedItems)
   {
+    if (state == m_state)
+        return;
+
     m_state = state;
     m_stateBackup = m_state;
     changedItems.insert(this);
     QSet<OptContentItem *> empty;
     Q_FOREACH (OptContentItem *child, m_children) {
       ItemState oldState = child->m_stateBackup;
-      child->setState(state == OptContentItem::On ? child->m_stateBackup : OptContentItem::Off, empty);
+      child->setState(state == OptContentItem::On ? child->m_stateBackup : OptContentItem::Off, true /*obeyRadioGroups*/, empty);
       child->m_enabled = state == OptContentItem::On;
       child->m_stateBackup = oldState;
     }
-    if (!m_group) {
-      return false;
+    if (!m_group || !obeyRadioGroups) {
+      return;
     }
     if ( state == OptContentItem::On ) {
       m_group->setState( OptionalContentGroup::On );
       for (int i = 0; i < m_rbGroups.size(); ++i) {
-	RadioButtonGroup *rbgroup = m_rbGroups.at(i);
+        RadioButtonGroup *rbgroup = m_rbGroups.at(i);
         changedItems += rbgroup->setItemOn( this );
       }
     } else if ( state == OptContentItem::Off ) {
       m_group->setState( OptionalContentGroup::Off );
     }
-    return true;
   }
 
   void OptContentItem::addChild( OptContentItem *child )
@@ -353,36 +357,20 @@ namespace Poppler
       case Qt::CheckStateRole:
       {
         const bool newvalue = value.toBool();
-        if (newvalue) {
-          if (node->state() != OptContentItem::On) {
-            QSet<OptContentItem *> changedItems;
-            node->setState(OptContentItem::On, changedItems);
-            changedItems += node->recurseListChildren(false);
-            QModelIndexList indexes;
-            Q_FOREACH (OptContentItem *item, changedItems) {
-              indexes.append(d->indexFromItem(item, 0));
-            }
-            qStableSort(indexes);
-            Q_FOREACH (const QModelIndex &changedIndex, indexes) {
-              emit dataChanged(changedIndex, changedIndex);
-            }
-            return true;
+        QSet<OptContentItem *> changedItems;
+        node->setState(newvalue ? OptContentItem::On : OptContentItem::Off, true /*obeyRadioGroups*/, changedItems);
+
+        if (!changedItems.isEmpty()) {
+          changedItems += node->recurseListChildren(false);
+          QModelIndexList indexes;
+          Q_FOREACH (OptContentItem *item, changedItems) {
+            indexes.append(d->indexFromItem(item, 0));
           }
-        } else {
-          if (node->state() != OptContentItem::Off) {
-            QSet<OptContentItem *> changedItems;
-            node->setState(OptContentItem::Off, changedItems);
-            changedItems += node->recurseListChildren(false);
-            QModelIndexList indexes;
-            Q_FOREACH (OptContentItem *item, changedItems) {
-              indexes.append(d->indexFromItem(item, 0));
-            }
-            qStableSort(indexes);
-            Q_FOREACH (const QModelIndex &changedIndex, indexes) {
-              emit dataChanged(changedIndex, changedIndex);
-            }
-            return true;
+          qStableSort(indexes);
+          Q_FOREACH (const QModelIndex &changedIndex, indexes) {
+            emit dataChanged(changedIndex, changedIndex);
           }
+          return true;
         }
         break;
       }
@@ -406,6 +394,49 @@ namespace Poppler
     return QAbstractItemModel::headerData( section, orientation, role );
   }
 
+  void OptContentModel::applyLink( LinkOCGState *link )
+  {
+    ::LinkOCGState *popplerLinkOCGState = static_cast<LinkOCGStatePrivate*>(link->d_ptr)->popplerLinkOCGState;
+
+    QSet<OptContentItem *> changedItems;
+
+    GooList *statesList = popplerLinkOCGState->getStateList();
+    for (int i = 0; i < statesList->getLength(); ++i) {
+        ::LinkOCGState::StateList *stateList = (::LinkOCGState::StateList*)statesList->get(i);
+
+        GooList *refsList = stateList->list;
+        for (int j = 0; j < refsList->getLength(); ++j) {
+            Ref *ref = (Ref *)refsList->get(j);
+            OptContentItem *item = d->itemFromRef(QString::number(ref->num));
+
+            if (stateList->st == ::LinkOCGState::On) {
+              item->setState(OptContentItem::On, popplerLinkOCGState->getPreserveRB(), changedItems);
+            } else if (stateList->st == ::LinkOCGState::Off) {
+              item->setState(OptContentItem::Off, popplerLinkOCGState->getPreserveRB(), changedItems);
+            } else {
+              OptContentItem::ItemState newState = item->state() == OptContentItem::On ? OptContentItem::Off : OptContentItem::On;
+              item->setState(newState, popplerLinkOCGState->getPreserveRB(), changedItems);
+            }
+        }
+    }
+
+    if (!changedItems.isEmpty()) {
+      QSet<OptContentItem *> aux;
+      Q_FOREACH (OptContentItem *item, aux) {
+        changedItems += item->recurseListChildren(false);
+      }
+
+      QModelIndexList indexes;
+      Q_FOREACH (OptContentItem *item, changedItems) {
+        indexes.append(d->indexFromItem(item, 0));
+      }
+      qStableSort(indexes);
+      Q_FOREACH (const QModelIndex &changedIndex, indexes) {
+        emit dataChanged(changedIndex, changedIndex);
+      }
+    }
+  }
+
   void OptContentModelPrivate::addChild( OptContentItem *parent, OptContentItem *child )
   {
     parent->addChild( child );
diff --git a/qt4/src/poppler-optcontent.h b/qt4/src/poppler-optcontent.h
index 3f47853..7232bb4 100644
--- a/qt4/src/poppler-optcontent.h
+++ b/qt4/src/poppler-optcontent.h
@@ -2,6 +2,7 @@
  *
  * Copyright (C) 2007, Brad Hards <bradh at kde.org>
  * Copyright (C) 2008, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2016, Albert Astals Cid <aacid at kde.org>
  *
  * 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
@@ -24,6 +25,7 @@
 #include <QtCore/QAbstractListModel>
 
 #include "poppler-export.h"
+#include "poppler-link.h"
 
 class OCGs;
 
@@ -65,6 +67,12 @@ namespace Poppler
 
     virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
 
+    /**
+     * Applies the Optional Contentn Changes specified by that link.
+     * \since 0.50
+     */
+    void applyLink( LinkOCGState *link );
+
     private:
     OptContentModel( OCGs *optContent, QObject *parent = 0);
 
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index 9e466da..fb6a036 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -1,7 +1,7 @@
 /* poppler-page.cc: qt interface to poppler
  * Copyright (C) 2005, Net Integration Technologies, Inc.
  * Copyright (C) 2005, Brad Hards <bradh at frogmouth.net>
- * Copyright (C) 2005-2015, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2005-2016, Albert Astals Cid <aacid at kde.org>
  * Copyright (C) 2005, Stefan Kebekus <stefan.kebekus at math.uni-koeln.de>
  * Copyright (C) 2006-2011, Pino Toscano <pino at kde.org>
  * Copyright (C) 2008 Carlos Garcia Campos <carlosgc at gnome.org>
@@ -59,6 +59,7 @@
 #include "poppler-page-transition-private.h"
 #include "poppler-page-private.h"
 #include "poppler-link-extractor-private.h"
+#include "poppler-link-private.h"
 #include "poppler-annotation-private.h"
 #include "poppler-form.h"
 #include "poppler-media.h"
@@ -210,6 +211,14 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo
     }
     break;
 
+    case actionOCGState:
+    {
+      ::LinkOCGState *plocg = (::LinkOCGState *)a;
+
+      LinkOCGStatePrivate *locgp = new LinkOCGStatePrivate( linkArea, plocg );
+      popplerLink = new LinkOCGState( locgp );
+    }
+
     case actionUnknown:
     break;
   }
diff --git a/qt5/src/poppler-link-private.h b/qt5/src/poppler-link-private.h
new file mode 100644
index 0000000..7b03c1c
--- /dev/null
+++ b/qt5/src/poppler-link-private.h
@@ -0,0 +1,57 @@
+/* poppler-link-private.h: qt interface to poppler
+ * Copyright (C) 2016, Albert Astals Cid <aacid at kde.org>
+ *
+ * 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, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _POPPLER_LINK_PRIVATE_H_
+#define _POPPLER_LINK_PRIVATE_H_
+
+class LinkOCGState;
+
+namespace Poppler {
+
+class LinkPrivate
+{
+public:
+    LinkPrivate( const QRectF &area )
+        : linkArea( area )
+    {
+    }
+
+    virtual ~LinkPrivate()
+    {
+    }
+
+    QRectF linkArea;
+};
+
+
+
+class LinkOCGStatePrivate : public LinkPrivate
+{
+public:
+    LinkOCGStatePrivate( const QRectF &area, ::LinkOCGState *plocg )
+        : LinkPrivate( area )
+        , popplerLinkOCGState( plocg )
+    {
+    }
+
+    ::LinkOCGState *popplerLinkOCGState;
+};
+
+}
+
+#endif
diff --git a/qt5/src/poppler-link.cc b/qt5/src/poppler-link.cc
index 60d9439..477f228 100644
--- a/qt5/src/poppler-link.cc
+++ b/qt5/src/poppler-link.cc
@@ -23,6 +23,7 @@
  */
 
 #include <poppler-qt5.h>
+#include <poppler-link-private.h>
 #include <poppler-private.h>
 #include <poppler-media.h>
 
@@ -70,24 +71,6 @@ class LinkDestinationPrivate : public QSharedData
 		changeZoom = false;
 	}
 
-class LinkPrivate
-{
-	public:
-		LinkPrivate( const QRectF &area );
-		virtual ~LinkPrivate();
-
-		QRectF linkArea;
-};
-
-	LinkPrivate::LinkPrivate( const QRectF &area )
-		: linkArea( area )
-	{
-	}
-
-	LinkPrivate::~LinkPrivate()
-	{
-	}
-
 class LinkGotoPrivate : public LinkPrivate
 {
 	public:
@@ -705,4 +688,18 @@ class LinkMoviePrivate : public LinkPrivate
 
 		return false;
 	}
+
+	LinkOCGState::LinkOCGState( LinkOCGStatePrivate *ocgp )
+		: Link ( *ocgp )
+	{
+	}
+
+	LinkOCGState::~LinkOCGState()
+	{
+	}
+
+	Link::LinkType LinkOCGState::linkType() const
+	{
+		return OCGState;
+	}
 }
diff --git a/qt5/src/poppler-link.h b/qt5/src/poppler-link.h
index 172effa..1ada9d3 100644
--- a/qt5/src/poppler-link.h
+++ b/qt5/src/poppler-link.h
@@ -1,5 +1,5 @@
 /* poppler-link.h: qt interface to poppler
- * Copyright (C) 2006, 2013, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2006, 2013, 2016, Albert Astals Cid <aacid at kde.org>
  * Copyright (C) 2007-2008, 2010, Pino Toscano <pino at kde.org>
  * Copyright (C) 2010, 2012, Guillermo Amaral <gamaral at kdab.com>
  * Copyright (C) 2012, Tobias Koenig <tokoe at kdab.com>
@@ -32,6 +32,8 @@
 
 struct Ref;
 class MediaRendition;
+class MovieAnnotation;
+class ScreenAnnotation;
 
 namespace Poppler {
 
@@ -46,6 +48,7 @@ class LinkMoviePrivate;
 class LinkDestinationData;
 class LinkDestinationPrivate;
 class LinkRenditionPrivate;
+class LinkOCGStatePrivate;
 class MediaRendition;
 class SoundObject;
 
@@ -171,6 +174,8 @@ class POPPLER_QT5_EXPORT LinkDestination
  */
 class POPPLER_QT5_EXPORT Link
 {
+	friend class OptContentModel;
+
 	public:
 		/// \cond PRIVATE
 		Link( const QRectF &linkArea );
@@ -191,7 +196,8 @@ class POPPLER_QT5_EXPORT Link
 		    Sound,    ///< A link representing a sound to be played
 		    Movie,    ///< An action to be executed on a movie
 		    Rendition,    ///< A rendition link \since 0.20
-		    JavaScript    ///< A JavaScript code to be interpreted \since 0.10
+		    JavaScript,   ///< A JavaScript code to be interpreted \since 0.10
+		    OCGState      ///< An Optional Content Group state change \since 0.50
 		};
 
 		/**
@@ -597,6 +603,30 @@ class POPPLER_QT5_EXPORT LinkMovie : public Link
 		Q_DISABLE_COPY( LinkMovie )
 };
 
+/**
+ * OCGState: an optional content group state change.
+ *
+ * \since 0.50
+ */
+class POPPLER_QT5_EXPORT LinkOCGState : public Link
+{
+	public:
+		/**
+		 * Create a new OCGState link. This is only used by Poppler::Page.
+		 */
+		LinkOCGState( LinkOCGStatePrivate *ocgp );
+		/**
+		 * Destructor.
+		 */
+		~LinkOCGState();
+
+		LinkType linkType() const;
+
+	private:
+		Q_DECLARE_PRIVATE( LinkOCGState )
+		Q_DISABLE_COPY( LinkOCGState )
+};
+
 }
 
 #endif
diff --git a/qt5/src/poppler-optcontent-private.h b/qt5/src/poppler-optcontent-private.h
index 98eda07..25bae04 100644
--- a/qt5/src/poppler-optcontent-private.h
+++ b/qt5/src/poppler-optcontent-private.h
@@ -2,6 +2,7 @@
  *
  * Copyright (C) 2007, Brad Hards <bradh at kde.org>
  * Copyright (C) 2008, Pino Toscano <pino at kde.org>
+ * Copyright (C) 2016, Albert Astals Cid <aacid at kde.org>
  *
  * 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
@@ -60,7 +61,7 @@ namespace Poppler
 
     QString name() const { return m_name; }
     ItemState state() const { return m_stateBackup; }
-    bool setState(ItemState state, QSet<OptContentItem *> &changedItems);
+    void setState(ItemState state, bool obeyRadioGroups, QSet<OptContentItem *> &changedItems);
 
     QList<OptContentItem*> childList() { return m_children; }
 
diff --git a/qt5/src/poppler-optcontent.cc b/qt5/src/poppler-optcontent.cc
index e2fd66e..53364ef 100644
--- a/qt5/src/poppler-optcontent.cc
+++ b/qt5/src/poppler-optcontent.cc
@@ -3,7 +3,7 @@
  * Copyright (C) 2007, Brad Hards <bradh at kde.org>
  * Copyright (C) 2008, 2014, Pino Toscano <pino at kde.org>
  * Copyright (C) 2008, Carlos Garcia Campos <carlosgc at gnome.org>
- * Copyright (C) 2015, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2015, 2016, Albert Astals Cid <aacid at kde.org>
  *
  * 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
@@ -25,11 +25,13 @@
 #include "poppler-optcontent-private.h"
 
 #include "poppler-private.h"
+#include "poppler-link-private.h"
 
 #include <QtCore/QDebug>
 #include <QtCore/QtAlgorithms>
 
 #include "poppler/OptionalContent.h"
+#include "poppler/Link.h"
 
 namespace Poppler
 {
@@ -63,7 +65,7 @@ namespace Poppler
       OptContentItem *thisItem = itemsInGroup.at(i);
       if (thisItem != itemToSetOn) {
         QSet<OptContentItem *> newChangedItems;
-        thisItem->setState(OptContentItem::Off, newChangedItems);
+        thisItem->setState(OptContentItem::Off, false /*obeyRadioGroups*/, newChangedItems);
         changedItems += newChangedItems;
       }
     }
@@ -111,31 +113,33 @@ namespace Poppler
   }
 
 
-  bool OptContentItem::setState(ItemState state, QSet<OptContentItem *> &changedItems)
+  void OptContentItem::setState(ItemState state, bool obeyRadioGroups, QSet<OptContentItem *> &changedItems)
   {
+    if (state == m_state)
+        return;
+
     m_state = state;
     m_stateBackup = m_state;
     changedItems.insert(this);
     QSet<OptContentItem *> empty;
     Q_FOREACH (OptContentItem *child, m_children) {
       ItemState oldState = child->m_stateBackup;
-      child->setState(state == OptContentItem::On ? child->m_stateBackup : OptContentItem::Off, empty);
+      child->setState(state == OptContentItem::On ? child->m_stateBackup : OptContentItem::Off, true /*obeyRadioGroups*/, empty);
       child->m_enabled = state == OptContentItem::On;
       child->m_stateBackup = oldState;
     }
-    if (!m_group) {
-      return false;
+    if (!m_group || !obeyRadioGroups) {
+      return;
     }
     if ( state == OptContentItem::On ) {
       m_group->setState( OptionalContentGroup::On );
       for (int i = 0; i < m_rbGroups.size(); ++i) {
-	RadioButtonGroup *rbgroup = m_rbGroups.at(i);
+        RadioButtonGroup *rbgroup = m_rbGroups.at(i);
         changedItems += rbgroup->setItemOn( this );
       }
     } else if ( state == OptContentItem::Off ) {
       m_group->setState( OptionalContentGroup::Off );
     }
-    return true;
   }
 
   void OptContentItem::addChild( OptContentItem *child )
@@ -354,36 +358,20 @@ namespace Poppler
       case Qt::CheckStateRole:
       {
         const bool newvalue = value.toBool();
-        if (newvalue) {
-          if (node->state() != OptContentItem::On) {
-            QSet<OptContentItem *> changedItems;
-            node->setState(OptContentItem::On, changedItems);
-            changedItems += node->recurseListChildren(false);
-            QModelIndexList indexes;
-            Q_FOREACH (OptContentItem *item, changedItems) {
-              indexes.append(d->indexFromItem(item, 0));
-            }
-            qStableSort(indexes);
-            Q_FOREACH (const QModelIndex &changedIndex, indexes) {
-              emit dataChanged(changedIndex, changedIndex);
-            }
-            return true;
+        QSet<OptContentItem *> changedItems;
+        node->setState(newvalue ? OptContentItem::On : OptContentItem::Off, true /*obeyRadioGroups*/, changedItems);
+
+        if (!changedItems.isEmpty()) {
+          changedItems += node->recurseListChildren(false);
+          QModelIndexList indexes;
+          Q_FOREACH (OptContentItem *item, changedItems) {
+            indexes.append(d->indexFromItem(item, 0));
           }
-        } else {
-          if (node->state() != OptContentItem::Off) {
-            QSet<OptContentItem *> changedItems;
-            node->setState(OptContentItem::Off, changedItems);
-            changedItems += node->recurseListChildren(false);
-            QModelIndexList indexes;
-            Q_FOREACH (OptContentItem *item, changedItems) {
-              indexes.append(d->indexFromItem(item, 0));
-            }
-            qStableSort(indexes);
-            Q_FOREACH (const QModelIndex &changedIndex, indexes) {
-              emit dataChanged(changedIndex, changedIndex);
-            }
-            return true;
+          qStableSort(indexes);
+          Q_FOREACH (const QModelIndex &changedIndex, indexes) {
+            emit dataChanged(changedIndex, changedIndex);
           }
+          return true;
         }
         break;
       }
@@ -407,6 +395,49 @@ namespace Poppler
     return QAbstractItemModel::headerData( section, orientation, role );
   }
 
+  void OptContentModel::applyLink( LinkOCGState *link )
+  {
+    ::LinkOCGState *popplerLinkOCGState = static_cast<LinkOCGStatePrivate*>(link->d_ptr)->popplerLinkOCGState;
+
+    QSet<OptContentItem *> changedItems;
+
+    GooList *statesList = popplerLinkOCGState->getStateList();
+    for (int i = 0; i < statesList->getLength(); ++i) {
+        ::LinkOCGState::StateList *stateList = (::LinkOCGState::StateList*)statesList->get(i);
+
+        GooList *refsList = stateList->list;
+        for (int j = 0; j < refsList->getLength(); ++j) {
+            Ref *ref = (Ref *)refsList->get(j);
+            OptContentItem *item = d->itemFromRef(QString::number(ref->num));
+
+            if (stateList->st == ::LinkOCGState::On) {
+              item->setState(OptContentItem::On, popplerLinkOCGState->getPreserveRB(), changedItems);
+            } else if (stateList->st == ::LinkOCGState::Off) {
+              item->setState(OptContentItem::Off, popplerLinkOCGState->getPreserveRB(), changedItems);
+            } else {
+              OptContentItem::ItemState newState = item->state() == OptContentItem::On ? OptContentItem::Off : OptContentItem::On;
+              item->setState(newState, popplerLinkOCGState->getPreserveRB(), changedItems);
+            }
+        }
+    }
+
+    if (!changedItems.isEmpty()) {
+      QSet<OptContentItem *> aux;
+      Q_FOREACH (OptContentItem *item, aux) {
+        changedItems += item->recurseListChildren(false);
+      }
+
+      QModelIndexList indexes;
+      Q_FOREACH (OptContentItem *item, changedItems) {
+        indexes.append(d->indexFromItem(item, 0));
+      }
+      qStableSort(indexes);
+      Q_FOREACH (const QModelIndex &changedIndex, indexes) {
+        emit dataChanged(changedIndex, changedIndex);
+      }
+    }
+  }
+
   void OptContentModelPrivate::addChild( OptContentItem *parent, OptContentItem *child )
   {
     parent->addChild( child );
diff --git a/qt5/src/poppler-optcontent.h b/qt5/src/poppler-optcontent.h
index ad75da8..25fdbaf 100644
--- a/qt5/src/poppler-optcontent.h
+++ b/qt5/src/poppler-optcontent.h
@@ -3,6 +3,7 @@
  * Copyright (C) 2007, Brad Hards <bradh at kde.org>
  * Copyright (C) 2008, Pino Toscano <pino at kde.org>
  * Copyright (C) 2013, Anthony Granger <grangeranthony at gmail.com>
+ * Copyright (C) 2016, Albert Astals Cid <aacid at kde.org>
  *
  * 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
@@ -25,6 +26,7 @@
 #include <QtCore/QAbstractListModel>
 
 #include "poppler-export.h"
+#include "poppler-link.h"
 
 class OCGs;
 
@@ -66,6 +68,12 @@ namespace Poppler
 
     virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
 
+    /**
+     * Applies the Optional Contentn Changes specified by that link.
+     * \since 0.50
+     */
+    void applyLink( LinkOCGState *link );
+
     private:
     OptContentModel( OCGs *optContent, QObject *parent = 0);
 
diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc
index 937b3b3..029716e 100644
--- a/qt5/src/poppler-page.cc
+++ b/qt5/src/poppler-page.cc
@@ -1,7 +1,7 @@
 /* poppler-page.cc: qt interface to poppler
  * Copyright (C) 2005, Net Integration Technologies, Inc.
  * Copyright (C) 2005, Brad Hards <bradh at frogmouth.net>
- * Copyright (C) 2005-2015, Albert Astals Cid <aacid at kde.org>
+ * Copyright (C) 2005-2016, Albert Astals Cid <aacid at kde.org>
  * Copyright (C) 2005, Stefan Kebekus <stefan.kebekus at math.uni-koeln.de>
  * Copyright (C) 2006-2011, Pino Toscano <pino at kde.org>
  * Copyright (C) 2008 Carlos Garcia Campos <carlosgc at gnome.org>
@@ -59,6 +59,7 @@
 #include "poppler-page-transition-private.h"
 #include "poppler-page-private.h"
 #include "poppler-link-extractor-private.h"
+#include "poppler-link-private.h"
 #include "poppler-annotation-private.h"
 #include "poppler-form.h"
 #include "poppler-media.h"
@@ -210,6 +211,14 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo
     }
     break;
 
+    case actionOCGState:
+    {
+      ::LinkOCGState *plocg = (::LinkOCGState *)a;
+
+      LinkOCGStatePrivate *locgp = new LinkOCGStatePrivate( linkArea, plocg );
+      popplerLink = new LinkOCGState( locgp );
+    }
+
     case actionUnknown:
     break;
   }


More information about the poppler mailing list