[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/libs/flake
From: Jan Hambrecht <jaham () gmx ! net>
Date: 2007-08-31 20:05:57
Message-ID: 1188590757.729586.23212.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 707032 by jaham:
Added fill rule property to the path shape and restructured
the shape style loading and saving to make saving of the
fill rule possible.
M +47 -4 KoPathShape.cpp
M +9 -0 KoPathShape.h
M +31 -38 KoShape.cpp
M +19 -3 KoShape.h
--- trunk/koffice/libs/flake/KoPathShape.cpp #707031:707032
@@ -25,25 +25,39 @@
#include "KoShapeBorderModel.h"
#include "KoViewConverter.h"
#include "KoPathShapeLoader.h"
+#include "KoShapeSavingContext.h"
+#include "KoShapeLoadingContext.h"
-#include "KoShapeSavingContext.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 @@
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 @@
{
applyConversion( painter, converter );
QPainterPath path( outline() );
-
+ path.setFillRule( d->fillRule );
+
painter.setBrush( background() );
painter.drawPath( path );
//paintDebug( painter );
@@ -1129,3 +1162,13 @@
return d;
}
+
+Qt::FillRule KoPathShape::fillRule() const
+{
+ return d->fillRule;
+}
+
+void KoPathShape::setFillRule( Qt::FillRule fillRule )
+{
+ d->fillRule = fillRule;
+}
--- trunk/koffice/libs/flake/KoPathShape.h #707031:707032
@@ -442,6 +442,11 @@
/// 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 @@
#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;
--- trunk/koffice/libs/flake/KoShape.cpp #707031:707032
@@ -627,16 +627,8 @@
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 @@
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 @@
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 @@
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 @@
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::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 ) )
{
--- trunk/koffice/libs/flake/KoShape.h #707031:707032
@@ -49,6 +49,7 @@
class KoShapeSavingContext;
class KoCanvasBase;
class KoShapeLoadingContext;
+class KoGenStyle;
/**
*
@@ -660,22 +661,37 @@
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 );
/// 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 */
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic