diff --git a/libs/flake/KoShape.cpp b/libs/flake/KoShape.cpp index a9c5f5d7b5655ed7e4bf6d87b9a86f6851eb5484..0b99e9e461a876389c82635e737ea2d1810f5c48 100644 --- a/libs/flake/KoShape.cpp +++ b/libs/flake/KoShape.cpp @@ -34,6 +34,7 @@ #include "KoShapeSavingContext.h" #include "KoShapeLoadingContext.h" #include "KoViewConverter.h" +#include "KoLineBorder.h" #include #include @@ -596,6 +597,7 @@ void KoShape::setName( const QString & name ) { // loading & saving methods void KoShape::saveOdfConnections(KoShapeSavingContext &context) const { // TODO save "draw-glue-point" elements (9.2.19) + Q_UNUSED( context ); } QString KoShape::style( KoShapeSavingContext &context ) const @@ -657,6 +659,7 @@ bool KoShape::loadOdfAttributes( const KoXmlElement & element, KoShapeLoadingCon } setBackground( loadOdfFill( element, context ) ); + setBorder( loadOdfStroke( element, context ) ); } if ( attributes & OdfSize ) { @@ -708,6 +711,70 @@ QBrush KoShape::loadOdfFill( const KoXmlElement & element, KoShapeLoadingContext return QBrush(); } +KoShapeBorderModel * KoShape::loadOdfStroke( const KoXmlElement & element, KoShapeLoadingContext & context ) +{ + KoStyleStack &styleStack = context.koLoadingContext().styleStack(); + QString stroke; + if( element.hasAttributeNS( KoXmlNS::draw, "style-name" ) ) + { + // fill the style stack with the shapes style + context.koLoadingContext().fillStyleStack( element, KoXmlNS::draw, "style-name", "graphic" ); + styleStack.setTypeProperties( "graphic" ); + if( styleStack.hasProperty( KoXmlNS::draw, "stroke" ) ) + stroke = styleStack.property( KoXmlNS::draw, "stroke" ); + } + else if( element.hasAttributeNS( KoXmlNS::draw, "style-name" ) ) + { + // fill the style stack with the shapes style + context.koLoadingContext().fillStyleStack( element, KoXmlNS::presentation, "style-name", "presentation" ); + styleStack.setTypeProperties( "presentation" ); + if ( styleStack.hasProperty( KoXmlNS::presentation, "stroke" ) ) + stroke = styleStack.property( KoXmlNS::presentation, "stroke" ); + } + + KoLineBorder * border = 0; + + if( stroke == "solid" ) + { + border = new KoLineBorder(); + } + else if( stroke == "dash" ) + { + border = new KoLineBorder(); + if( styleStack.hasProperty( KoXmlNS::draw, "stroke-dash" ) ) + { + QString dashStyleName = styleStack.property( KoXmlNS::draw, "stroke-dash" ); + // TODO load dashes + } + } + else + return 0; + + if ( styleStack.hasProperty( KoXmlNS::svg, "stroke-color" ) ) + border->setColor( styleStack.property( KoXmlNS::svg, "stroke-color" ) ); + if ( styleStack.hasProperty( KoXmlNS::svg, "stroke-opacity" ) ) + { + QColor color = border->color(); + QString opacity = styleStack.property( KoXmlNS::svg, "stroke-opacity" ); + color.setAlphaF( opacity.toDouble() ); + border->setColor( color ); + } + if( styleStack.hasProperty( KoXmlNS::svg, "stroke-width" ) ) + border->setLineWidth( KoUnit::parseValue( styleStack.property( KoXmlNS::svg, "stroke-width" ) ) ); + if( styleStack.hasProperty( KoXmlNS::draw, "stroke-linejoin" ) ) + { + QString join = styleStack.property( KoXmlNS::draw, "stroke-linejoin" ); + if( join == "bevel" ) + border->setJoinStyle( Qt::BevelJoin ); + else if( join == "round" ) + border->setJoinStyle( Qt::RoundJoin ); + else + border->setJoinStyle( Qt::MiterJoin ); + } + + return border; +} + QMatrix KoShape::parseOdfTransform( const QString &transform ) { QMatrix matrix; diff --git a/libs/flake/KoShape.h b/libs/flake/KoShape.h index 651a59360d892511d7863bdf897bdad8ba397750..dfef4e7057d3c6f2a8c76c1faafb643a851a1b82 100644 --- a/libs/flake/KoShape.h +++ b/libs/flake/KoShape.h @@ -647,6 +647,9 @@ protected: /// Loads the fill style QBrush loadOdfFill( const KoXmlElement & element, KoShapeLoadingContext & context ); + /// Loads the stroke style + KoShapeBorderModel * loadOdfStroke( const KoXmlElement & element, KoShapeLoadingContext & context ); + /* ** end loading saving */