diff --git a/conf/widgetannottools.cpp b/conf/widgetannottools.cpp index a23170ba4..c76956245 100644 --- a/conf/widgetannottools.cpp +++ b/conf/widgetannottools.cpp @@ -165,9 +165,8 @@ void WidgetAnnotTools::slotAdd( bool ) if ( t.exec() != QDialog::Accepted ) return; - QDomDocument entryParser; - entryParser.setContent( t.toolXml() ); - QDomElement toolElement = entryParser.documentElement(); + QDomDocument rootDoc = t.toolXml(); + QDomElement toolElement = rootDoc.documentElement(); QString itemText = t.name(); @@ -179,7 +178,7 @@ void WidgetAnnotTools::slotAdd( bool ) // Create list entry and attach XML string as data QListWidgetItem * listEntry = new QListWidgetItem( itemText, m_list ); - listEntry->setData( ToolXmlRole, qVariantFromValue( entryParser.toString(-1) ) ); + listEntry->setData( ToolXmlRole, qVariantFromValue( rootDoc.toString(-1) ) ); listEntry->setIcon( PageViewAnnotator::makeToolPixmap( toolElement ) ); // Select and scroll @@ -269,9 +268,18 @@ QString NewAnnotToolDialog::name() const return m_name->text(); } -QString NewAnnotToolDialog::toolXml() const +QDomDocument NewAnnotToolDialog::toolXml() const { const QByteArray toolType = m_type->itemData( m_type->currentIndex() ).toByteArray(); + + QDomDocument doc; + QDomElement toolElement = doc.createElement( "tool" ); + QDomElement engineElement = doc.createElement( "engine" ); + QDomElement annotationElement = doc.createElement( "annotation" ); + doc.appendChild( toolElement ); + toolElement.appendChild( engineElement ); + engineElement.appendChild( annotationElement ); + const QString color = m_stubann->style().color().name(); const double opacity = m_stubann->style().opacity(); const double width = m_stubann->style().width(); @@ -279,123 +287,134 @@ QString NewAnnotToolDialog::toolXml() const if ( toolType == "note-linked" ) { Okular::TextAnnotation * ta = static_cast( m_stubann ); - return QString( "" - "" - "" - "" - "" ).arg( color ).arg( opacity ).arg( ta->textIcon() ); + toolElement.setAttribute( "type", "note-linked" ); + engineElement.setAttribute( "type", "PickPoint" ); + engineElement.setAttribute( "color", color ); + engineElement.setAttribute( "hoverIcon", "tool-note" ); + annotationElement.setAttribute( "type", "Text" ); + annotationElement.setAttribute( "color", color ); + annotationElement.setAttribute( "icon", ta->textIcon() ); } else if ( toolType == "note-inline" ) { Okular::TextAnnotation * ta = static_cast( m_stubann ); - Q_UNUSED( ta ); - return QString( "" - "" - "" - "" - "" ).arg( color ).arg( opacity ); + toolElement.setAttribute( "type", "note-inline" ); + engineElement.setAttribute( "type", "PickPoint" ); + engineElement.setAttribute( "color", color ); + engineElement.setAttribute( "hoverIcon", "tool-note-inline" ); + engineElement.setAttribute( "block", "true" ); + annotationElement.setAttribute( "type", "FreeText" ); + annotationElement.setAttribute( "color", color ); + // TODO: Font } else if ( toolType == "ink" ) { - Okular::InkAnnotation * ia = static_cast( m_stubann ); - Q_UNUSED( ia ); - return QString( "" - "" - "" - "" - "").arg( color ).arg( opacity ).arg( width ); + toolElement.setAttribute( "type", "ink" ); + engineElement.setAttribute( "type", "SmoothLine" ); + engineElement.setAttribute( "color", color ); + annotationElement.setAttribute( "type", "Ink" ); + annotationElement.setAttribute( "color", color ); + annotationElement.setAttribute( "width", width ); } else if ( toolType == "straight-line" ) { Okular::LineAnnotation * la = static_cast( m_stubann ); - - QString lineExt; + toolElement.setAttribute( "type", "straight-line" ); + engineElement.setAttribute( "type", "PolyLine" ); + engineElement.setAttribute( "color", color ); + engineElement.setAttribute( "points", "2" ); + annotationElement.setAttribute( "type", "Line" ); + annotationElement.setAttribute( "color", color ); + annotationElement.setAttribute( "width", width ); if ( la->lineLeadingForwardPoint() != 0 || la->lineLeadingBackwardPoint() != 0 ) - lineExt = QString( "leadFwd=\"%1\" leadBack=\"%2\"" ).arg( la->lineLeadingForwardPoint() ).arg( la->lineLeadingBackwardPoint() ); - - return QString( "" - "" - "" - "" - "" ).arg( color ).arg( opacity ).arg( width ) - .arg( lineExt ); + { + annotationElement.setAttribute( "leadFwd", la->lineLeadingForwardPoint() ); + annotationElement.setAttribute( "leadBack", la->lineLeadingBackwardPoint() ); + } } else if ( toolType == "polygon" ) { Okular::LineAnnotation * la = static_cast( m_stubann ); - - QString innerColor; + toolElement.setAttribute( "type", "polygon" ); + engineElement.setAttribute( "type", "PolyLine" ); + engineElement.setAttribute( "color", color ); + engineElement.setAttribute( "points", "-1" ); + annotationElement.setAttribute( "type", "Line" ); + annotationElement.setAttribute( "color", color ); + annotationElement.setAttribute( "width", width ); if ( la->lineInnerColor().isValid() ) - innerColor = QString( "innerColor=\"%1\"" ).arg( la->lineInnerColor().name() ); - - return QString( "" - "" - "" - "" - "" ).arg( color ).arg( opacity ).arg( width ) - .arg( innerColor ); + { + annotationElement.setAttribute( "innerColor", la->lineInnerColor().name() ); + } } else if ( toolType == "text-markup" ) { Okular::HighlightAnnotation * ha = static_cast( m_stubann ); - QString toolType, annotationType; switch ( ha->highlightType() ) { case Okular::HighlightAnnotation::Highlight: - toolType = "highlight"; - annotationType = "Highlight"; + toolElement.setAttribute( "type", "highlight" ); + annotationElement.setAttribute( "type", "Highlight" ); break; case Okular::HighlightAnnotation::Squiggly: - toolType = "squiggly"; - annotationType = "Squiggly"; + toolElement.setAttribute( "type", "squiggly" ); + annotationElement.setAttribute( "type", "Squiggly" ); break; case Okular::HighlightAnnotation::Underline: - toolType = "underline"; - annotationType = "Underline"; + toolElement.setAttribute( "type", "underline" ); + annotationElement.setAttribute( "type", "Underline" ); break; case Okular::HighlightAnnotation::StrikeOut: - toolType = "strikeout"; - annotationType = "StrikeOut"; + toolElement.setAttribute( "type", "strikeout" ); + annotationElement.setAttribute( "type", "StrikeOut" ); break; } - return QString( "" - "" - "" - "" - "").arg( color ).arg( opacity ) - .arg( toolType ).arg( annotationType ); + engineElement.setAttribute( "type", "TextSelector" ); + engineElement.setAttribute( "color", color ); + annotationElement.setAttribute( "color", color ); } else if ( toolType == "geometrical-shape" ) { Okular::GeomAnnotation * ga = static_cast( m_stubann ); - const bool isCircle = (ga->geometricalType() == Okular::GeomAnnotation::InscribedCircle); - QString innerColor; + if ( ga->geometricalType() == Okular::GeomAnnotation::InscribedCircle ) + { + toolElement.setAttribute( "type", "ellipse" ); + annotationElement.setAttribute( "type", "GeomCircle" ); + } + else + { + toolElement.setAttribute( "type", "rectangle" ); + annotationElement.setAttribute( "type", "GeomSquare" ); + } + + engineElement.setAttribute( "type", "PickPoint" ); + engineElement.setAttribute( "color", color ); + engineElement.setAttribute( "block", "true" ); + annotationElement.setAttribute( "color", color ); + annotationElement.setAttribute( "width", width ); + if ( ga->geometricalInnerColor().isValid() ) - innerColor = QString( "innerColor=\"%1\"" ).arg( ga->geometricalInnerColor().name() ); - - return QString( "" - "" - "" - "" - "").arg( color ).arg( opacity ).arg( width ) - .arg( isCircle ? "ellipse" : "rectangle" ) - .arg( isCircle ? "GeomCircle" : "GeomSquare" ) - .arg( innerColor ); + annotationElement.setAttribute( "innerColor", ga->geometricalInnerColor().name() ); } else if ( toolType == "stamp" ) { Okular::StampAnnotation * sa = static_cast( m_stubann ); - return QString( "" - "" - "" - "" - "" ).arg( sa->stampIconName() ); // FIXME: Check bad strings + toolElement.setAttribute( "type", "stamp" ); + engineElement.setAttribute( "type", "PickPoint" ); + engineElement.setAttribute( "hoverIcon", sa->stampIconName() ); + engineElement.setAttribute( "size", "64" ); + engineElement.setAttribute( "block", "true" ); + annotationElement.setAttribute( "type", "Stamp" ); + annotationElement.setAttribute( "icon", sa->stampIconName() ); } - return QString(); // This should never happen + if ( opacity != 1 ) + annotationElement.setAttribute( "opacity", opacity ); + + return doc; } void NewAnnotToolDialog::rebuildAppearanceBox() @@ -482,9 +501,8 @@ void NewAnnotToolDialog::rebuildAppearanceBox() void NewAnnotToolDialog::updateDefaultName() { - QDomDocument entryParser; - entryParser.setContent( toolXml() ); - QDomElement toolElement = entryParser.documentElement(); + QDomDocument doc = toolXml(); + QDomElement toolElement = doc.documentElement(); m_name->setPlaceholderText( PageViewAnnotator::defaultToolName( toolElement ) ); } diff --git a/conf/widgetannottools.h b/conf/widgetannottools.h index 297b0624f..3f37a179d 100644 --- a/conf/widgetannottools.h +++ b/conf/widgetannottools.h @@ -11,6 +11,7 @@ #define _WIDGETANNOTTOOLS_H_ #include +#include #include class KLineEdit; @@ -66,7 +67,7 @@ class NewAnnotToolDialog : public KDialog NewAnnotToolDialog( QWidget *parent = 0 ); ~NewAnnotToolDialog(); QString name() const; - QString toolXml() const; + QDomDocument toolXml() const; private: void rebuildAppearanceBox();