Commit e20f3983 authored by Johannes Simon's avatar Johannes Simon

Split up KoShape::OdfAttribute enum values into their equivalents from ODF...

Split up KoShape::OdfAttribute enum values into their equivalents from ODF 9.2.15 "Common Drawing Shape Attributes", and provide former values like 'OdfMandatories' as masks of these.

svn path=/trunk/koffice/; revision=865423
parent 317679a9
......@@ -826,40 +826,57 @@ void KoShape::loadStyle( const KoXmlElement & element, KoShapeLoadingContext &co
bool KoShape::loadOdfAttributes( const KoXmlElement & element, KoShapeLoadingContext &context, int attributes )
{
if ( attributes & OdfSize ) {
QPointF pos;
pos.setX( KoUnit::parseValue( element.attributeNS( KoXmlNS::svg, "x", QString() ) ) );
pos.setY( KoUnit::parseValue( element.attributeNS( KoXmlNS::svg, "y", QString() ) ) );
if ( attributes & OdfPosition ) {
QPointF pos( position() );
if ( element.hasAttributeNS( KoXmlNS::svg, "x" ) )
pos.setX( KoUnit::parseValue( element.attributeNS( KoXmlNS::svg, "x", QString() ) ) );
if ( element.hasAttributeNS( KoXmlNS::svg, "y" ) )
pos.setY( KoUnit::parseValue( element.attributeNS( KoXmlNS::svg, "y", QString() ) ) );
setPosition( pos );
}
QSizeF size;
size.setWidth( KoUnit::parseValue( element.attributeNS( KoXmlNS::svg, "width", QString() ) ) );
size.setHeight( KoUnit::parseValue( element.attributeNS( KoXmlNS::svg, "height", QString() ) ) );
setSize( size );
if ( attributes & OdfSize ) {
QSizeF s( size() );
if ( element.hasAttributeNS( KoXmlNS::svg, "width" ) )
s.setWidth( KoUnit::parseValue( element.attributeNS( KoXmlNS::svg, "width", QString() ) ) );
if ( element.hasAttributeNS( KoXmlNS::svg, "height" ) )
s.setHeight( KoUnit::parseValue( element.attributeNS( KoXmlNS::svg, "height", QString() ) ) );
setSize( s );
}
if ( attributes & OdfMandatories ) {
if ( attributes & OdfLayer ) {
if ( element.hasAttributeNS( KoXmlNS::draw, "layer" ) ) {
KoShapeLayer * layer = context.layer( element.attributeNS( KoXmlNS::draw, "layer" ) );
if ( layer ) {
setParent( layer );
}
}
}
if ( attributes & OdfId ) {
if ( element.hasAttributeNS( KoXmlNS::draw, "id" ) ) {
QString id = element.attributeNS( KoXmlNS::draw, "id" );
if ( !id.isNull() ) {
context.addShapeId( this, id );
}
}
}
if ( attributes & OdfZIndex ) {
if ( element.hasAttributeNS( KoXmlNS::draw, "z-index" ) ) {
context.addShapeZIndex( this, element.attributeNS( KoXmlNS::draw, "z-index" ).toInt() );
}
setZIndex( context.zIndex() );
}
if ( attributes & OdfName ) {
if ( element.hasAttributeNS( KoXmlNS::draw, "name" ) ) {
setName( element.attributeNS( KoXmlNS::draw, "name" ) );
}
}
if ( attributes & OdfStyle ) {
loadStyle( element, context );
}
......@@ -1067,7 +1084,7 @@ QMatrix KoShape::parseOdfTransform( const QString &transform )
void KoShape::saveOdfAttributes(KoShapeSavingContext &context, int attributes) const
{
if (attributes & OdfMandatories) {
if ( attributes & OdfStyle ) {
KoGenStyle style;
// all items that should be written to 'draw:frame' and any other 'draw:' object that inherits this shape
if ( context.isSet( KoShapeSavingContext::PresentationShape ) ) {
......@@ -1078,29 +1095,40 @@ void KoShape::saveOdfAttributes(KoShapeSavingContext &context, int attributes) c
style = KoGenStyle( KoGenStyle::StyleGraphicAuto, "graphic" );
context.xmlWriter().addAttribute( "draw:style-name", saveStyle( style, context ) );
}
}
if ( attributes & OdfId ) {
if ( context.isSet( KoShapeSavingContext::DrawId ) )
{
context.xmlWriter().addAttribute( "draw:id", context.drawId( this ) );
}
}
if ( attributes & OdfName ) {
if ( ! name().isEmpty() )
context.xmlWriter().addAttribute( "draw:name", name() );
}
if ( attributes & OdfLayer ) {
if (d->parent && dynamic_cast<KoShapeLayer*> (d->parent))
context.xmlWriter().addAttribute("draw:layer", d->parent->name());
}
if (attributes & OdfSize) {
QSizeF s( size() );
if ( attributes & OdfSize ) {
const QSizeF s( size() );
context.xmlWriter().addAttributePt( "svg:width", s.width() );
context.xmlWriter().addAttributePt( "svg:height", s.height() );
// the position is hidden in the transformation
context.xmlWriter().addAttributePt( "svg:x", 0.0 );
context.xmlWriter().addAttributePt( "svg:y", 0.0 );
}
if (attributes & OdfTransformation) {
// The position is implicitly stored in the transformation matrix
// if the transformation is saved as well
if ( (attributes & OdfPosition) && !(attributes & OdfTransformation) ) {
const QPointF p( position() );
context.xmlWriter().addAttributePt( "svg:x", p.x() );
context.xmlWriter().addAttributePt( "svg:y", p.y() );
}
if ( attributes & OdfTransformation ) {
QMatrix matrix = absoluteTransformation(0);
if ( ! matrix.isIdentity() )
{
......
......@@ -755,12 +755,21 @@ protected:
enum OdfAttribute {
OdfTransformation = 1, ///< Store transformation information
OdfSize = 2, ///< Store size information
OdfAdditionalAttributes = 4, ///< Store additional attributes of shape
OdfMandatories = 8, ///< Id, z-index, layer and style
OdfCommonChildElements = 16, ///< event actions and connection points
OdfPosition = 8, ///< Store position
OdfAdditionalAttributes = 4, ///< Store additional attributes of the shape
OdfCommonChildElements = 16, ///< Event actions and connection points
OdfLayer = 64, ///< Store layer name
OdfStyle = 128, ///< Store the style
OdfId = 256, ///< Store the unique ID
OdfName = 512, ///< Store the name of the shape
OdfZIndex = 1024, ///< This only loads the z-index; when saving, it is reflected by the order of the shapes.
/// A mask for all mandatory attributes
OdfMandatories = OdfLayer | OdfStyle | OdfId | OdfName | OdfZIndex,
/// A mask for geometry attributes
OdfGeometry = OdfPosition | OdfSize,
/// A mask for all the attributes
OdfAllAttributes = OdfTransformation | OdfSize | OdfAdditionalAttributes | OdfMandatories | OdfCommonChildElements
OdfAllAttributes = OdfTransformation | OdfGeometry | OdfAdditionalAttributes | OdfMandatories | OdfCommonChildElements
};
/**
......
......@@ -47,7 +47,7 @@ KoRectangleShape::~KoRectangleShape()
bool KoRectangleShape::loadOdf( const KoXmlElement & element, KoShapeLoadingContext & context )
{
loadOdfAttributes( element, context, OdfMandatories | OdfSize | OdfAdditionalAttributes | OdfCommonChildElements );
loadOdfAttributes( element, context, OdfMandatories | OdfGeometry | OdfAdditionalAttributes | OdfCommonChildElements );
if( element.hasAttributeNS( KoXmlNS::svg, "rx" ) && element.hasAttributeNS( KoXmlNS::svg, "ry" ) )
{
......
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