Commit 9023b05e authored by Enrico Ros's avatar Enrico Ros

Document, Page:

  Changed loadDocumentInfo/saveDocumentInfo semantics. Document settings
  are saved by Document, but page related stuff (bookmark state,
  annotations, ...) are loaded/saved by the KPDFPage itself.
Annotation:
  Better usage of dom entities (QDomElement(s) -> QDomNode(s)). Added const
  modifier to 'saveSettings' methods.
Part:
  Use setCheckedState for the show/hide left panel menu entry. Use icon
  too. Bumped .rc revision.

svn path=/branches/kpdf_annotations/kdegraphics/kpdf/; revision=397236
parent 664d4415
......@@ -30,7 +30,7 @@ Annotation::Annotation( const QDomElement & /*node*/ )
{
}
void Annotation::store( QDomElement & /*node*/, QDomDocument & /*document*/ )
void Annotation::store( QDomNode & /*node*/, QDomDocument & /*document*/ ) const
{
}
......@@ -52,7 +52,7 @@ MarkupAnnotation::MarkupAnnotation( const QDomElement & node )
// ... load stuff ...
}
void MarkupAnnotation::store( QDomElement & node, QDomDocument & document )
void MarkupAnnotation::store( QDomNode & node, QDomDocument & document ) const
{
// ... save stuff ...
Annotation::store( node, document );
......@@ -72,7 +72,7 @@ PopupAnnotation::PopupAnnotation( const QDomElement & node )
// ... load stuff ...
}
void PopupAnnotation::store( QDomElement & node, QDomDocument & document )
void PopupAnnotation::store( QDomNode & node, QDomDocument & document ) const
{
// ... save stuff ...
Annotation::store( node, document );
......@@ -94,7 +94,7 @@ TextAnnotation::TextAnnotation( const QDomElement & node )
// ... load stuff ...
}
void TextAnnotation::store( QDomElement & node, QDomDocument & document )
void TextAnnotation::store( QDomNode & node, QDomDocument & document ) const
{
// ... save stuff ...
MarkupAnnotation::store( node, document );
......@@ -116,7 +116,7 @@ LineAnnotation::LineAnnotation( const QDomElement & node )
// ... load stuff ...
}
void LineAnnotation::store( QDomElement & node, QDomDocument & document )
void LineAnnotation::store( QDomNode & node, QDomDocument & document ) const
{
// ... save stuff ...
MarkupAnnotation::store( node, document );
......@@ -136,7 +136,7 @@ GeomAnnotation::GeomAnnotation( const QDomElement & node )
// ... load stuff ...
}
void GeomAnnotation::store( QDomElement & node, QDomDocument & document )
void GeomAnnotation::store( QDomNode & node, QDomDocument & document ) const
{
// ... save stuff ...
MarkupAnnotation::store( node, document );
......@@ -156,7 +156,7 @@ HighlightAnnotation::HighlightAnnotation( const QDomElement & node )
// ... load stuff ...
}
void HighlightAnnotation::store( QDomElement & node, QDomDocument & document )
void HighlightAnnotation::store( QDomNode & node, QDomDocument & document ) const
{
// ... save stuff ...
MarkupAnnotation::store( node, document );
......@@ -176,7 +176,7 @@ StampAnnotation::StampAnnotation( const QDomElement & node )
// ... load stuff ...
}
void StampAnnotation::store( QDomElement & node, QDomDocument & document )
void StampAnnotation::store( QDomNode & node, QDomDocument & document ) const
{
// ... save stuff ...
MarkupAnnotation::store( node, document );
......@@ -196,8 +196,10 @@ InkAnnotation::InkAnnotation( const QDomElement & node )
// ... load stuff ...
}
void InkAnnotation::store( QDomElement & node, QDomDocument & document )
void InkAnnotation::store( QDomNode & node, QDomDocument & document ) const
{
// ... save stuff ...
// recurse saving parent's attributes
MarkupAnnotation::store( node, document );
// save local attributes
}
......@@ -180,7 +180,7 @@ Unused / Incomplete :
struct Annotation
{
// enum definitions
enum SubType { APopup, AText, ALine, AGeom, AHighlight, AStamp, AInk, AMedia };
enum SubType { APopup, AText, ALine, AGeom, AHighlight, AStamp, AInk };
enum Flags { Hidden, NoOpenable, Print, Locked, ReadOnly };
// struct definitions
......@@ -215,7 +215,7 @@ struct Annotation
// read values from XML node
Annotation( const QDomElement & node );
// store custom config to XML node
virtual void store( QDomElement & node, QDomDocument & document );
virtual void store( QDomNode & parentNode, QDomDocument & document ) const;
};
struct MarkupAnnotation : public Annotation
......@@ -247,7 +247,7 @@ struct MarkupAnnotation : public Annotation
// read values from XML node
MarkupAnnotation( const QDomElement & node );
// store custom config to XML node
virtual void store( QDomElement & node, QDomDocument & document );
virtual void store( QDomNode & parentNode, QDomDocument & document ) const;
};
struct PopupAnnotation : public Annotation
......@@ -262,7 +262,7 @@ struct PopupAnnotation : public Annotation
// common functions
PopupAnnotation();
PopupAnnotation( const QDomElement & node );
void store( QDomElement & node, QDomDocument & document );
void store( QDomNode & parentNode, QDomDocument & document ) const;
};
struct TextAnnotation : public MarkupAnnotation
......@@ -284,7 +284,7 @@ struct TextAnnotation : public MarkupAnnotation
// common functions
TextAnnotation();
TextAnnotation( const QDomElement & node );
void store( QDomElement & node, QDomDocument & document );
void store( QDomNode & parentNode, QDomDocument & document ) const;
};
struct LineAnnotation : public MarkupAnnotation
......@@ -306,7 +306,7 @@ struct LineAnnotation : public MarkupAnnotation
// common functions
LineAnnotation();
LineAnnotation( const QDomElement & node );
void store( QDomElement & node, QDomDocument & document );
void store( QDomNode & parentNode, QDomDocument & document ) const;
};
struct GeomAnnotation : public MarkupAnnotation
......@@ -322,7 +322,7 @@ struct GeomAnnotation : public MarkupAnnotation
// common functions
GeomAnnotation();
GeomAnnotation( const QDomElement & node );
void store( QDomElement & node, QDomDocument & document );
void store( QDomNode & parentNode, QDomDocument & document ) const;
};
struct HighlightAnnotation : public MarkupAnnotation
......@@ -337,7 +337,7 @@ struct HighlightAnnotation : public MarkupAnnotation
// common functions
HighlightAnnotation();
HighlightAnnotation( const QDomElement & node );
void store( QDomElement & node, QDomDocument & document );
void store( QDomNode & parentNode, QDomDocument & document ) const;
};
struct StampAnnotation : public MarkupAnnotation
......@@ -351,7 +351,7 @@ struct StampAnnotation : public MarkupAnnotation
// common functions
StampAnnotation();
StampAnnotation( const QDomElement & node );
void store( QDomElement & node, QDomDocument & document );
void store( QDomNode & parentNode, QDomDocument & document ) const;
};
struct InkAnnotation : public MarkupAnnotation
......@@ -365,7 +365,7 @@ struct InkAnnotation : public MarkupAnnotation
// common functions
InkAnnotation();
InkAnnotation( const QDomElement & node );
void store( QDomElement & node, QDomDocument & document );
void store( QDomNode & parentNode, QDomDocument & document ) const;
};
#endif
......@@ -1238,26 +1238,28 @@ void KPDFDocument::loadDocumentInfo()
{
QString catName = topLevelNode.toElement().tagName();
// Get bookmarks list from DOM
if ( catName == "bookmarkList" )
// Restore page attributes (bookmark, annotations, ...) from the DOM
if ( catName == "pageList" )
{
QDomNode n = topLevelNode.firstChild();
QDomElement e;
int pageNumber;
bool ok;
while ( n.isElement() )
QDomNode pageNode = topLevelNode.firstChild();
while ( pageNode.isElement() )
{
e = n.toElement();
if (e.tagName() == "page")
QDomElement pageElement = pageNode.toElement();
if ( pageElement.hasAttribute( "number" ) )
{
pageNumber = e.text().toInt(&ok);
// get page number (node's attribute)
bool ok;
int pageNumber = pageElement.attribute( "number" ).toInt( &ok );
// pass the domElement to the right page, to read config data from
if ( ok && pageNumber >= 0 && pageNumber < (int)pages_vector.count() )
pages_vector[ pageNumber ]->setBookmark( true );
pages_vector[ pageNumber ]->restoreLocalContents( pageElement );
}
n = n.nextSibling();
pageNode = pageNode.nextSibling();
}
} // </bookmarkList>
// Get 'general info' from the DOM
}
// Restore 'general info' from the DOM
else if ( catName == "generalInfo" )
{
QDomNode infoNode = topLevelNode.firstChild();
......@@ -1296,7 +1298,8 @@ void KPDFDocument::loadDocumentInfo()
}
infoNode = infoNode.nextSibling();
}
} // </generalInfo>
}
topLevelNode = topLevelNode.nextSibling();
} // </documentInfo>
}
......@@ -1305,7 +1308,7 @@ QString KPDFDocument::giveAbsolutePath( const QString & fileName )
{
if ( !d->url.isValid() )
return QString::null;
return d->url.upURL().url() + fileName;
}
......@@ -1330,31 +1333,23 @@ void KPDFDocument::saveDocumentInfo() const
QFile infoFile( d->xmlFileName );
if (infoFile.open( IO_WriteOnly | IO_Truncate) )
{
// Create DOM
// 1. Create DOM
QDomDocument doc( "documentInfo" );
QDomElement root = doc.createElement( "documentInfo" );
doc.appendChild( root );
// Add bookmark list to DOM
QDomElement bookmarkList = doc.createElement( "bookmarkList" );
root.appendChild( bookmarkList );
// 2.1. Save page attributes (bookmark state, annotations, ... ) to DOM
QDomElement pageList = doc.createElement( "pageList" );
root.appendChild( pageList );
// <page list><page number='x'>.... </page> save pages that hold data
QValueVector< KPDFPage * >::const_iterator pIt = pages_vector.begin(), pEnd = pages_vector.end();
for ( ; pIt != pEnd; ++pIt )
(*pIt)->saveLocalContents( pageList, doc );
for ( uint i = 0; i < pages_vector.count() ; i++ )
{
if ( pages_vector[i]->hasBookmark() )
{
QDomElement page = doc.createElement( "page" );
page.appendChild( doc.createTextNode( QString::number(i) ) );
bookmarkList.appendChild( page );
}
}
// Add general info to DOM
// 2.2. Save document info (current viewport, history, ... ) to DOM
QDomElement generalInfo = doc.createElement( "generalInfo" );
root.appendChild( generalInfo );
// <general info><history> ... </history> saves history up to 10 viewports
// <general info><history> ... </history> save history up to 10 viewports
QValueList< DocumentViewport >::iterator backIterator = d->viewportIterator;
if ( backIterator != d->viewportHistory.end() )
{
......@@ -1380,7 +1375,7 @@ void KPDFDocument::saveDocumentInfo() const
}
}
// Save DOM to XML file
// 3. Save DOM to XML file
QString xml = doc.toString();
QTextStream os( &infoFile );
os << xml;
......
......@@ -11,6 +11,7 @@
#include <qpixmap.h>
#include <qstring.h>
#include <qmap.h>
#include <qdom.h>
#include <kdebug.h>
// local includes
......@@ -293,6 +294,116 @@ void KPDFPage::deleteAnnotations()
m_annotations.clear();
}
void KPDFPage::restoreLocalContents( const QDomNode & pageNode )
{
// iterate over all chilren (bookmark, annotationList, ...)
QDomNode childNode = pageNode.firstChild();
while ( childNode.isElement() )
{
QDomElement childElement = childNode.toElement();
childNode = childNode.nextSibling();
// parse annotationList child element
if ( childElement.tagName() == "annotationList" )
{
// iterate over all annotations
QDomNode annotationNode = childElement.firstChild();
while( annotationNode.isElement() )
{
// get annotation element and advance to next annot
QDomElement annotElement = annotationNode.toElement();
annotationNode = annotationNode.nextSibling();
if ( !annotElement.hasAttribute( "type" ) )
continue;
// build annotation of given type
Annotation * annotation = 0;
int typeNumber = annotElement.attribute( "type" ).toInt();
switch ( typeNumber )
{
case Annotation::APopup:
annotation = new PopupAnnotation( annotElement );
break;
case Annotation::AText:
annotation = new TextAnnotation( annotElement );
break;
case Annotation::ALine:
annotation = new LineAnnotation( annotElement );
break;
case Annotation::AGeom:
annotation = new GeomAnnotation( annotElement );
break;
case Annotation::AHighlight:
annotation = new HighlightAnnotation( annotElement );
break;
case Annotation::AStamp:
annotation = new StampAnnotation( annotElement );
break;
case Annotation::AInk:
annotation = new InkAnnotation( annotElement );
break;
}
// append annotation to the list or show warning
if ( annotation )
m_annotations.append( annotation );
else
kdWarning() << "can't restore Annotation of type '" << typeNumber << "from XML." << endl;
}
}
// parse bookmark child element
else if ( childElement.tagName() == "bookmark" )
m_bookmarked = true;
}
}
void KPDFPage::saveLocalContents( QDomNode & parentNode, QDomDocument & document )
{
// only add a node if there is some stuff to write into
if ( m_bookmarked || !m_annotations.isEmpty() )
{
// create the page node and set the 'number' attribute
QDomElement pageElement = document.createElement( "page" );
parentNode.appendChild( pageElement );
pageElement.setAttribute( "number", m_number );
// add bookmark info if is bookmarked
if ( m_bookmarked )
{
// create the pageElement's 'bookmark' child
QDomElement bookmarkElement = document.createElement( "bookmark" );
pageElement.appendChild( bookmarkElement );
// add attributes to the element
//bookmarkElement.setAttribute( "name", bookmark name );
}
// add annotations info if has got any
if ( !m_annotations.isEmpty() )
{
// create the annotationList
QDomElement annotListElement = document.createElement( "annotationList" );
pageElement.appendChild( annotListElement );
// add every annotation to the annotationList
QValueList< Annotation * >::iterator aIt = m_annotations.begin(), aEnd = m_annotations.end();
for ( ; aIt != aEnd; ++aIt )
{
// get annotation
const Annotation * a = *aIt;
// create annotation element and set type
QDomElement annotElement = document.createElement( "annotation" );
annotListElement.appendChild( annotElement );
annotElement.setAttribute( "type", (uint)a->subType() );
// add children and attributes to annotation element
a->store( annotElement, document );
}
}
}
}
/** class NormalizedPoint **/
NormalizedPoint::NormalizedPoint()
......
......@@ -15,6 +15,8 @@
class QPixmap;
class QRect;
class QDomNode;
class QDomDocument;
class TextPage;
class KPDFPageTransition;
class NormalizedRect;
......@@ -73,6 +75,10 @@ class KPDFPage
void deleteHighlights( int s_id = -1 );
void deleteAnnotations();
// operations to save/restore page state (by KPDFDocument)
void restoreLocalContents( const QDomNode & pageNode );
void saveLocalContents( QDomNode & parentNode, QDomDocument & document );
private:
friend class PagePainter;
int m_number, m_rotation;
......
......@@ -116,10 +116,6 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
m_splitter = new QSplitter( parentWidget, widgetName );
m_splitter->setOpaqueResize( true );
setWidget( m_splitter );
m_showLeftPanel = new KToggleAction( i18n( "Show &left panel"), 0, this, SLOT( slotShowLeftPanel() ), actionCollection(), "show_leftpanel" );
m_showLeftPanel->setShortcut( "CTRL+L" );
m_showLeftPanel->setChecked( Settings::showLeftPanel() );
// widgets: [left panel] | []
m_leftPanel = new QWidget( m_splitter );
......@@ -151,8 +147,6 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
m_toolBox->addItem( thumbsBox, QIconSet(SmallIcon("thumbnail")), i18n("Thumbnails") );
m_toolBox->setCurrentItem( thumbsBox );
slotShowLeftPanel();
/* // [left toolbox: Annotations] | []
QFrame * editFrame = new QFrame( m_toolBox );
int iIdx = m_toolBox->addItem( editFrame, QIconSet(SmallIcon("pencil")), i18n("Annotations") );
......@@ -230,6 +224,12 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
m_printPreview = KStdAction::printPreview( this, SLOT( slotPrintPreview() ), ac );
m_printPreview->setEnabled( false );
m_showLeftPanel = new KToggleAction( i18n( "Show &left panel"), "show_side_panel", 0, this, SLOT( slotShowLeftPanel() ), ac, "show_leftpanel" );
m_showLeftPanel->setShortcut( "CTRL+L" );
m_showLeftPanel->setCheckedState( i18n("Hide &left panel") );
m_showLeftPanel->setChecked( Settings::showLeftPanel() );
slotShowLeftPanel();
m_showProperties = new KAction(i18n("&Properties"), "info", 0, this, SLOT(slotShowProperties()), ac, "properties");
m_showProperties->setEnabled( false );
......@@ -381,8 +381,8 @@ bool Part::closeURL()
void Part::slotShowLeftPanel()
{
bool showLeft = m_showLeftPanel->isChecked();
Settings::setShowLeftPanel(showLeft);
// show/hide left qtoolbox
Settings::setShowLeftPanel( showLeft );
// show/hide left panel
m_leftPanel->setShown( showLeft );
// this needs to be hidden explicitly to disable thumbnails gen
m_thumbnailList->setShown( showLeft );
......
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="kpdf_part" version="18">
<kpartgui name="kpdf_part" version="19">
<MenuBar>
<Menu name="file"><text>&amp;File</text>
<Action name="save" group="file_save"/>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment