Commit 8fcaa2a4 authored by Jan Hambrecht's avatar Jan Hambrecht

Added fill rule property to the path shape and restructured

the shape style loading and saving to make saving of the 
fill rule possible.


svn path=/trunk/koffice/; revision=707032
parent f84ef49b
......@@ -25,25 +25,39 @@
#include "KoShapeBorderModel.h"
#include "KoViewConverter.h"
#include "KoPathShapeLoader.h"
#include "KoShapeSavingContext.h"
#include "KoShapeLoadingContext.h"
#include <KoXmlReader.h>
#include <KoXmlWriter.h>
#include <KoXmlNS.h>
#include <KoUnit.h>
#include <KoGenStyle.h>
#include <KoStyleStack.h>
#include <KoOasisLoadingContext.h>
#include <KDebug>
#include <QtGui/QPainter>
class KoPathShape::Private
{
public:
Private() : fillRule( Qt::OddEvenFill )
{
}
Qt::FillRule fillRule;
};
KoPathShape::KoPathShape()
: d(0) // while we don't actually have any private data, just leave it as this.
: d( new Private() ) // while we don't actually have any private data, just leave it as this.
{
}
KoPathShape::~KoPathShape()
{
clear();
//delete d;
delete d;
}
void KoPathShape::saveOdf( KoShapeSavingContext & context ) const
......@@ -119,6 +133,24 @@ bool KoPathShape::loadOdf( const KoXmlElement & element, KoShapeLoadingContext &
return true;
}
QString KoPathShape::saveStyle( KoGenStyle &style, KoShapeSavingContext &context ) const
{
style.addProperty( "svg:fill-rule", d->fillRule == Qt::OddEvenFill ? "evenodd" : "nonzero" );
return KoShape::saveStyle( style, context );
}
void KoPathShape::loadStyle( const KoXmlElement & element, KoShapeLoadingContext &context )
{
KoShape::loadStyle( element, context );
KoStyleStack &styleStack = context.koLoadingContext().styleStack();
if ( styleStack.hasProperty( KoXmlNS::svg, "fill-rule" ) )
{
QString rule = styleStack.property( KoXmlNS::svg, "fill-rule" );
d->fillRule = rule == "nonzero" ? Qt::WindingFill : Qt::OddEvenFill;
}
}
QRectF KoPathShape::loadOdfViewbox( const KoXmlElement & element ) const
{
QRectF viewbox;
......@@ -180,7 +212,8 @@ void KoPathShape::paint( QPainter &painter, const KoViewConverter &converter )
{
applyConversion( painter, converter );
QPainterPath path( outline() );
path.setFillRule( d->fillRule );
painter.setBrush( background() );
painter.drawPath( path );
//paintDebug( painter );
......@@ -1129,3 +1162,13 @@ QString KoPathShape::toString( const QMatrix &matrix ) const
return d;
}
Qt::FillRule KoPathShape::fillRule() const
{
return d->fillRule;
}
void KoPathShape::setFillRule( Qt::FillRule fillRule )
{
d->fillRule = fillRule;
}
......@@ -442,6 +442,11 @@ public:
/// Returns a odf/svg string represenatation of the path data with the given matrix applied.
QString toString( const QMatrix &matrix ) const;
/// Returns the fill rule for the path object
Qt::FillRule fillRule() const;
/// Sets the fill rule to be used for painting the background
void setFillRule( Qt::FillRule fillRule );
private:
// TODO move all the private methods to live on the d pointer object
void map( const QMatrix &matrix );
......@@ -462,6 +467,10 @@ private:
#ifndef NDEBUG
void paintDebug( QPainter &painter );
#endif
/// reimplemented
virtual QString saveStyle( KoGenStyle &style, KoShapeSavingContext &context ) const;
/// reimplemented
virtual void loadStyle( const KoXmlElement & element, KoShapeLoadingContext &context );
protected:
QRectF handleRect( const QPointF &p, double radius ) const;
......
......@@ -627,16 +627,8 @@ void KoShape::saveOdfConnections(KoShapeSavingContext &context) const {
Q_UNUSED( context );
}
QString KoShape::style( KoShapeSavingContext &context ) const
QString KoShape::saveStyle( KoGenStyle &style, KoShapeSavingContext &context ) const
{
KoGenStyle style;
if ( context.isSet( KoShapeSavingContext::PresentationShape ) ) {
style = KoGenStyle( KoGenStyle::StylePresentationAuto, "presentation" );
}
else {
style = KoGenStyle( KoGenStyle::StyleGraphicAuto, "graphic" );
}
// and fill the style
KoShapeBorderModel * b = border();
if ( b )
......@@ -649,6 +641,12 @@ QString KoShape::style( KoShapeSavingContext &context ) const
return styleWriter.addFillStyle( style, background() );
}
void KoShape::loadStyle( const KoXmlElement & element, KoShapeLoadingContext &context )
{
setBackground( loadOdfFill( element, context ) );
setBorder( loadOdfStroke( element, context ) );
}
bool KoShape::loadOdfAttributes( const KoXmlElement & element, KoShapeLoadingContext &context, int attributes )
{
if ( attributes & OdfSize ) {
......@@ -688,8 +686,7 @@ bool KoShape::loadOdfAttributes( const KoXmlElement & element, KoShapeLoadingCon
if( element.hasAttributeNS( KoXmlNS::draw, "name" ) )
setName( element.attributeNS( KoXmlNS::draw, "name" ) );
setBackground( loadOdfFill( element, context ) );
setBorder( loadOdfStroke( element, context ) );
loadStyle( element, context );
}
if( attributes & OdfTransformation )
......@@ -702,27 +699,34 @@ bool KoShape::loadOdfAttributes( const KoXmlElement & element, KoShapeLoadingCon
return true;
}
QBrush KoShape::loadOdfFill( const KoXmlElement & element, KoShapeLoadingContext & context )
QString KoShape::getStyleProperty( const char *property, const KoXmlElement & element, KoShapeLoadingContext & context )
{
KoStyleStack &styleStack = context.koLoadingContext().styleStack();
QString fill;
QString value;
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, "fill" ) )
fill = styleStack.property( KoXmlNS::draw, "fill" );
if( styleStack.hasProperty( KoXmlNS::draw, property ) )
value = styleStack.property( KoXmlNS::draw, property );
}
else if( element.hasAttributeNS( KoXmlNS::presentation, "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, "fill" ) )
fill = styleStack.property( KoXmlNS::presentation, "fill" );
if ( styleStack.hasProperty( KoXmlNS::presentation, property ) )
value = styleStack.property( KoXmlNS::presentation, property );
}
return value;
}
QBrush KoShape::loadOdfFill( const KoXmlElement & element, KoShapeLoadingContext & context )
{
KoStyleStack &styleStack = context.koLoadingContext().styleStack();
QString fill = getStyleProperty( "fill", element, context );
if ( fill == "solid" || fill == "hatch" )
return KoOasisStyles::loadOasisFillStyle( styleStack, fill, context.koLoadingContext().oasisStyles() );
else if( fill == "gradient" )
......@@ -736,24 +740,7 @@ QBrush KoShape::loadOdfFill( const KoXmlElement & element, KoShapeLoadingContext
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::presentation, "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" );
}
QString stroke = getStyleProperty( "stroke", element, context );
if( stroke == "solid" || stroke == "dash" )
{
QPen pen = KoOasisStyles::loadOasisStrokeStyle( styleStack, stroke, context.koLoadingContext().oasisStyles() );
......@@ -850,10 +837,16 @@ void KoShape::saveOdfFrameAttributes(KoShapeSavingContext &context) const {
void KoShape::saveOdfAttributes(KoShapeSavingContext &context, int attributes) const {
if(attributes & OdfMandatories) {
KoGenStyle style;
// all items that should be written to 'draw:frame' and any other 'draw:' object that inherits this shape
context.xmlWriter().addAttribute( context.isSet( KoShapeSavingContext::PresentationShape ) ?
"presentation:style-name": "draw:style-name",
style( context ) );
if ( context.isSet( KoShapeSavingContext::PresentationShape ) ) {
style = KoGenStyle( KoGenStyle::StylePresentationAuto, "presentation" );
context.xmlWriter().addAttribute( "presentation:style-name", saveStyle( style, context ) );
}
else {
style = KoGenStyle( KoGenStyle::StyleGraphicAuto, "graphic" );
context.xmlWriter().addAttribute( "draw:style-name", saveStyle( style, context ) );
}
if ( context.isSet( KoShapeSavingContext::DrawId ) )
{
......
......@@ -49,6 +49,7 @@ class KoShapeApplicationData;
class KoShapeSavingContext;
class KoCanvasBase;
class KoShapeLoadingContext;
class KoGenStyle;
/**
*
......@@ -660,15 +661,25 @@ protected:
void saveOdfConnections( KoShapeSavingContext &context ) const;
/**
* @brief Get the style used for the shape
* @brief Saves the style used for the shape
*
* This method calls fillStyle and add then the style to the context
* This method fills the given style object with the border and
* background properties and then adds the style to the context.
*
* @param style the style object to fill
* @param context used for saving
* @return the name of the style
* @see saveOdf
*/
QString style( KoShapeSavingContext &context ) const;
virtual QString saveStyle( KoGenStyle &style, KoShapeSavingContext &context ) const;
/**
* Loads the stroke and fill style from the given element.
*
* @param element the xml element to load the style from
* @param context the loading context used for loading
*/
virtual void loadStyle( const KoXmlElement & element, KoShapeLoadingContext &context );
/// Loads the fill style
QBrush loadOdfFill( const KoXmlElement & element, KoShapeLoadingContext & context );
......@@ -676,6 +687,11 @@ protected:
/// Loads the stroke style
KoShapeBorderModel * loadOdfStroke( const KoXmlElement & element, KoShapeLoadingContext & context );
/**
* Fills the style stack and returns the value of the given style property (e.g fill, stroke).
*/
QString getStyleProperty( const char *property, const KoXmlElement & element, KoShapeLoadingContext & context );
/* ** end loading saving */
......
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