Commit 12dddc4b authored by Thorsten Zachmann's avatar Thorsten Zachmann

o Started to implement saving of shapes in flake to OpenDocument.

  This is still work in progress so please be patient a bit longer to let
  the api take shape.

svn path=/trunk/koffice/; revision=635461
parent 45346a40
......@@ -55,6 +55,7 @@ set(flake_SRCS
KoToolManager.cpp
KoToolRegistry.cpp
KoToolProxy.cpp
KoShapeSavingContext.cpp
commands/KoShapeGroupCommand.cpp
commands/KoShapeAlignCommand.cpp
commands/KoShapeBackgroundCommand.cpp
......
/* This file is part of the KDE project
* Copyright (C) 2006 Thomas Zander <zander@kde.org>
* Copyright (C) 2006 Jan Hambrecht <jaham@gmx.net>
* Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -24,6 +25,8 @@
#include <QPainterPath>
#include <KoGenStyle.h>
KoLineBorder::KoLineBorder()
: m_color(Qt::black)
{
......@@ -37,6 +40,15 @@ KoLineBorder::KoLineBorder(double lineWidth, QColor color)
m_pen.setJoinStyle(Qt::MiterJoin);
}
void KoLineBorder::fillStyle( KoGenStyle &style, KoShapeSavingContext &context )
{
Q_UNUSED( context );
// TODO implement all possibilities
style.addProperty( "draw:stroke", "solid" );
style.addProperty( "svg:stroke-color", color().name() );
style.addPropertyPt( "svg:stroke-width", lineWidth() );
}
KoInsets* KoLineBorder::borderInsets(const KoShape *shape, KoInsets &insets) {
Q_UNUSED(shape);
double lineWidth = m_pen.widthF();
......
/* This file is part of the KDE project
* Copyright (C) 2006 Thomas Zander <zander@kde.org>
* Copyright (C) 2006 Jan Hambrecht <jaham@gmx.net>
* Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -69,6 +70,7 @@ public:
/// Stes the color
void setColor( const QColor & color );
virtual void fillStyle( KoGenStyle &style, KoShapeSavingContext &context );
virtual KoInsets* borderInsets(const KoShape *shape, KoInsets &insets);
virtual bool hasTransparency();
virtual void paintBorder(KoShape *shape, QPainter &painter, const KoViewConverter &converter);
......
/* This file is part of the KDE project Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
Copyright (C) 2006 Casper Boemann Rasmussen <cbr@boemann.dk>
Copyright (C) 2006 Thomas Zander <zander@kde.org>
Copyright (C) 2006-2007 Thorsten Zachmann <zachmann@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -27,12 +28,19 @@
#include "KoShapeManager.h"
#include "KoShapeUserData.h"
#include "KoShapeApplicationData.h"
#include "KoShapeSavingContext.h"
#include "KoViewConverter.h"
#include <KoXmlWriter.h>
#include <KoGenStyles.h>
#include <KoGenStyle.h>
#include <QPainter>
#include <QVariant>
#include <QPainterPath>
#include <kdebug.h>
class KoShapePrivate {
public:
KoShapePrivate()
......@@ -124,6 +132,66 @@ void KoShape::paintDecorations(QPainter &painter, const KoViewConverter &convert
}*/
}
bool KoShape::saveOdf( KoShapeSavingContext & context )
{
const char * tag = odfTagName();
if ( tag[0] == '\0' )
{
kWarning(30006) << "No support for shape yet. Not saving!" << endl;
}
else
{
context.xmlWriter().startElement( tag );
context.xmlWriter().addAttribute( context.isSet( KoShapeSavingContext::PresentationShape ) ?
"presentation:style-name": "draw:style-name",
getStyle( context ) );
if ( context.isSet( KoShapeSavingContext::DrawId ) )
{
context.xmlWriter().addAttribute( "draw:id", context.drawId( this ) );
}
saveOdfData( context );
context.xmlWriter().endElement();
}
return true;
}
QString KoShape::getStyle( KoShapeSavingContext &context )
{
KoGenStyle style;
if ( context.isSet( KoShapeSavingContext::PresentationShape ) )
style = KoGenStyle( KoGenStyle::STYLE_PRESENTATIONAUTO, "presentation" );
else
style = KoGenStyle( KoGenStyle::STYLE_GRAPHICAUTO, "graphic" );
fillStyle( style, context );
if ( KoShapeSavingContext::AutoStyleInStyleXml )
style.setAutoStyleInStylesDotXml( true );
return context.mainStyles().lookup( style, context.isSet( KoShapeSavingContext::PresentationShape ) ? "pr" : "gr" );
}
void KoShape::fillStyle( KoGenStyle &style, KoShapeSavingContext &context )
{
KoShapeBorderModel * b = border();
if ( b )
{
b->fillStyle( style, context );
}
QBrush bg( background() );
switch ( bg.style() )
{
case Qt::NoBrush:
style.addProperty( "draw:fill","none" );
break;
default:
//KoOasisStyles::saveOasisFillStyle( style, context.mainStyles(), bg );
break;
}
}
void KoShape::scale( double sx, double sy )
{
if(d->scaleX == sx && d->scaleY == sy)
......
/* This file is part of the KDE project
Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
Copyright (C) 2006-2007 Thorsten Zachmann <zachmann@kde.org>
Copyright (C) 2006 Casper Boemann Rasmussen <cbr@boemann.dk>
Copyright (C) 2006 Thomas Zander <zander@kde.org>
......@@ -45,7 +45,9 @@ class KoShapeUserData;
class KoViewConverter;
class KoShapeApplicationData;
class KoShapePrivate;
class KoShapeSavingContext;
class KoCanvasBase;
class KoGenStyle;
/**
*
......@@ -112,6 +114,31 @@ public:
*/
virtual void paintDecorations(QPainter &painter, const KoViewConverter &converter, const KoCanvasBase *canvas);
/**
* @brief Save the shape
*
* This is the method that will be called when saving a shape as a described in
* OpenDocument 9.2 Drawing Shapes. This method saves the common attributes of the
* drawing shapes.
* The special data for every shape is saved in @see saveOdfData().
*
* Please don't use yet as the design is not yet finished.
*
* @see saveOdfContent
*/
bool saveOdf( KoShapeSavingContext & context );
/**
* @brief Save the shape
*
* This is used to save a shape that is not used as a Drawing Shape, e.g.
* a text shape that is used as main part of the document as described in
* OpenDocument 2.3.1 Text Documents.
*
* Please don't use yet as the design is not yet finished.
*/
virtual bool saveOdfContext( KoShapeSavingContext & context ) { Q_UNUSED( context ); return true; }
/**
* @brief Scale the shape using the zero-point which is the top-left corner.
* @see position()
......@@ -519,6 +546,40 @@ public:
static void applyConversion(QPainter &painter, const KoViewConverter &converter);
protected:
/**
* @brief Get the tag name used for saving
*
* Get the name of the tag used for saving drawing shape
*
* This will be a pure virtual function once all shapes implemented it.
*
* @return the name of the tag
*
* @see saveOdf()
*/
virtual const char * odfTagName() const { return ""; }
/**
* @brief Save the data that is special by each shape
*
* This will be a pure virtual function once all shapes implemented it.
*
* @return true if successful, false otherwise
*
* @see saveOdf()
*/
virtual bool saveOdfData( KoShapeSavingContext &context ) const { Q_UNUSED( context ); return true; }
/**
* @brief Fill the style object
*
* @param style object
* @param context used for saving
*
* @see saveOdf()
*/
void fillStyle( KoGenStyle &style, KoShapeSavingContext &context );
/**
* Update the position of the shape in the tree of the KoShapeManager.
*/
......@@ -559,6 +620,16 @@ protected:
const QMatrix& matrix() const;
private:
/**
* @brief Get the style used for the shape
*
* This method calls fillStyle and add then the style to the context
*
* @param context used for saving
* @return the name of the style
*/
QString getStyle( KoShapeSavingContext &context );
friend class KoShapeManager;
void addShapeManager( KoShapeManager * manager );
void removeShapeManager( KoShapeManager * manager );
......
/* This file is part of the KDE project
* Copyright (C) 2006 Thomas Zander <zander@kde.org>
* Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -27,6 +28,8 @@
#include <flake_export.h>
class KoShape;
class KoGenStyle;
class KoShapeSavingContext;
class KoViewConverter;
/**
......@@ -42,6 +45,14 @@ public:
KoShapeBorderModel() {}
virtual ~KoShapeBorderModel() {}
/**
* @brief Fill the style object
*
* @param style object
* @param context used for saving
*/
virtual void fillStyle( KoGenStyle &style, KoShapeSavingContext &context ) = 0;
/**
* Return a new borderInsets object filled with the size around the shape that this
* border takes.
......
/* This file is part of the KDE project
Copyright (C) 2004-2006 David Faure <faure@kde.org>
Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or ( at your option ) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KoShapeSavingContext.h"
#include <KoGenStyles.h>
#include <KoSavingContext.h>
KoShapeSavingContext::KoShapeSavingContext( KoXmlWriter &xmlWriter, KoSavingContext &context )
: m_xmlWriter( xmlWriter )
, m_context( context )
, m_savingOptions( 0 )
, m_drawId( 0 )
{
}
KoShapeSavingContext::~KoShapeSavingContext()
{
}
KoXmlWriter & KoShapeSavingContext::xmlWriter()
{
return m_xmlWriter;
}
KoGenStyles & KoShapeSavingContext::mainStyles()
{
return m_context.mainStyles();
}
bool KoShapeSavingContext::isSet( KoShapeSavingOption option ) const
{
return m_savingOptions && option;
}
const QString & KoShapeSavingContext::drawId( KoShape * shape, bool insert )
{
QMap<KoShape *, QString>::const_iterator it( m_drawIds.find( shape ) );
if ( it == m_drawIds.constEnd() && insert == true )
{
it = m_drawIds.insert( shape, QString( "shape" ).arg( ++m_drawId ) );
return it.value();
}
return m_emptyString;
}
/* This file is part of the KDE project
Copyright (C) 2004-2006 David Faure <faure@kde.org>
Copyright (C) 2007 Thorsten Zachmann <zachmann@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or ( at your option ) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KOSHAPESAVEINGCONTEXT_H
#define KOSHAPESAVEINGCONTEXT_H
#include <flake_export.h>
#include <QFlags>
#include <QMap>
#include <QString>
class KoShape;
class KoXmlWriter;
class KoSavingContext;
class KoGenStyles;
class FLAKE_EXPORT KoShapeSavingContext
{
public:
/// The Style used for saving the shape
enum KoShapeSavingOption
{
/**
* If set the style of family peresentation is used, when not set the
* family graphic is used.
* See OpenDocument 9.2.15 Common Drawing Shape Attributes / Style
*/
PresentationShape = 1,
/**
* Save the draw:id used for referencing the shape.
* See OpenDocument 9.2.15 Common Drawing Shape Attributes / ID
*/
DrawId = 2,
/**
* If set the automatic style will be marked as being needed in styles.xml
*/
AutoStyleInStyleXml = 4
};
Q_DECLARE_FLAGS( KoShapeSavingOptions, KoShapeSavingOption )
/**
* @brief Constructor
* @param xmlWriter used for writing the xml
* @param context the saveing context used
*/
KoShapeSavingContext( KoXmlWriter &xmlWriter, KoSavingContext &context );
~KoShapeSavingContext();
/**
* @brief Get the xml writer
*
* @return xmlWriter
*/
KoXmlWriter & xmlWriter();
/**
* @brief Get the main styles
*
* @return main styles
*/
KoGenStyles & mainStyles();
/**
* @brief Check if an option is set
*
* @return ture if the option is set, false otherwise
*/
bool isSet( KoShapeSavingOption option ) const;
/**
* @brief Set the options to use
*
* @param options to use
*/
void set( KoShapeSavingOptions options );
/**
* @brief Get the draw id for a shape
*
* The draw:id is uniq for all shapes.
*
* @param shape for which the draw id should be returned
* @param if true a new draw id will be generated if there is non yet
*
* @retrun the draw id for the shape or and empty string if it was not found
*/
const QString & drawId( KoShape * shape, bool insert = true );
protected:
KoXmlWriter &m_xmlWriter;
KoSavingContext &m_context;
KoShapeSavingOptions m_savingOptions;
QMap<KoShape *, QString> m_drawIds;
int m_drawId;
QString m_emptyString;
// TODO handle realtive positions
};
Q_DECLARE_OPERATORS_FOR_FLAGS( KoShapeSavingContext::KoShapeSavingOptions )
#endif // KOSHAPESAVEINGCONTEXT_H
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