[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegraphics/okular/core
From:       Pino Toscano <pino () kde ! org>
Date:       2008-05-31 21:13:16
Message-ID: 1212268396.276967.17697.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 814998 by pino:

Load and save in the XML document info all the properties of the various View's, that \
are specific to each document. At the moment, they are the zoom mode and level of the \
                page view.
BUG: 155752


 M  +87 -0     document.cpp  
 M  +2 -0      document_p.h  


--- trunk/KDE/kdegraphics/okular/core/document.cpp #814997:814998
@@ -384,6 +384,27 @@
                         setRotationInternal( newrotation, false );
                     }
                 }
+                else if ( infoElement.tagName() == "views" )
+                {
+                    QDomNode viewNode = infoNode.firstChild();
+                    while ( viewNode.isElement() )
+                    {
+                        QDomElement viewElement = viewNode.toElement();
+                        if ( viewElement.tagName() == "view" )
+                        {
+                            const QString viewName = viewElement.attribute( "name" \
); +                            Q_FOREACH ( View * view, m_views )
+                            {
+                                if ( view->name() == viewName )
+                                {
+                                    loadViewsInfo( view, viewElement );
+                                    break;
+                                }
+                            }
+                        }
+                        viewNode = viewNode.nextSibling();
+                    }
+                }
                 infoNode = infoNode.nextSibling();
             }
         }
@@ -392,6 +413,62 @@
     } // </documentInfo>
 }
 
+void DocumentPrivate::loadViewsInfo( View *view, const QDomElement &e )
+{
+    QDomNode viewNode = e.firstChild();
+    while ( viewNode.isElement() )
+    {
+        QDomElement viewElement = viewNode.toElement();
+
+        if ( viewElement.tagName() == "zoom" )
+        {
+            const QString valueString = viewElement.attribute( "value" );
+            bool newzoom_ok = true;
+            const double newzoom = !valueString.isEmpty() ? valueString.toDouble( \
&newzoom_ok ) : 1.0; +            if ( newzoom_ok && newzoom != 0
+                 && view->supportsCapability( View::Zoom )
+                 && ( view->capabilityFlags( View::Zoom ) & ( View::CapabilityRead & \
View::CapabilitySerializable ) ) ) +            {
+                view->setCapability( View::Zoom, newzoom );
+            }
+            const QString modeString = viewElement.attribute( "mode" );
+            bool newmode_ok = true;
+            const int newmode = !modeString.isEmpty() ? modeString.toInt( \
&newmode_ok ) : 2; +            if ( newmode_ok
+                 && view->supportsCapability( View::ZoomModality )
+                 && ( view->capabilityFlags( View::ZoomModality ) & ( \
View::CapabilityRead & View::CapabilitySerializable ) ) ) +            {
+                view->setCapability( View::ZoomModality, newmode );
+            }
+        }
+
+        viewNode = viewNode.nextSibling();
+    }
+}
+
+void DocumentPrivate::saveViewsInfo( View *view, QDomElement &e ) const
+{
+    if ( view->supportsCapability( View::Zoom )
+         && ( view->capabilityFlags( View::Zoom ) & ( View::CapabilityRead & \
View::CapabilitySerializable ) ) +         && view->supportsCapability( \
View::ZoomModality ) +         && ( view->capabilityFlags( View::ZoomModality ) & ( \
View::CapabilityRead & View::CapabilitySerializable ) ) ) +    {
+        QDomElement zoomEl = e.ownerDocument().createElement( "zoom" );
+        e.appendChild( zoomEl );
+        bool ok = true;
+        const double zoom = view->capability( View::Zoom ).toDouble( &ok );
+        if ( ok && zoom != 0 )
+        {
+            zoomEl.setAttribute( "value", zoom );
+        }
+        const int mode = view->capability( View::ZoomModality ).toInt( &ok );
+        if ( ok )
+        {
+            zoomEl.setAttribute( "mode", mode );
+        }
+    }
+}
+
 QString DocumentPrivate::giveAbsolutePath( const QString & fileName ) const
 {
     if ( !QDir::isRelativePath( fileName ) )
@@ -562,6 +639,16 @@
                 ++backIterator;
             }
         }
+        // create views root node
+        QDomElement viewsNode = doc.createElement( "views" );
+        generalInfo.appendChild( viewsNode );
+        Q_FOREACH ( View * view, m_views )
+        {
+            QDomElement viewEntry = doc.createElement( "view" );
+            viewEntry.setAttribute( "name", view->name() );
+            viewsNode.appendChild( viewEntry );
+            saveViewsInfo( view, viewEntry );
+        }
 
         // 3. Save DOM to XML file
         QString xml = doc.toString();
--- trunk/KDE/kdegraphics/okular/core/document_p.h #814997:814998
@@ -93,6 +93,8 @@
         qulonglong getTotalMemory();
         qulonglong getFreeMemory();
         void loadDocumentInfo();
+        void loadViewsInfo( View *view, const QDomElement &e );
+        void saveViewsInfo( View *view, QDomElement &e ) const;
         QString giveAbsolutePath( const QString & fileName ) const;
         bool openRelativeFile( const QString & fileName );
         Generator * loadGeneratorLibrary( const KService::Ptr &service );


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic