Commit 8e762844 authored by Thomas Zander's avatar Thomas Zander

- put a icon() method in the ToolFactory

- add api Docs in the ToolFactory
- keep non-trivial implementation out of header files, even when this means
the .cpp are not very large.
- remove unused classes
- make ShapeFactory use a KoID instead of the incorrectly named name/description pair
- alter ToolFactory to have the same return types as the ShapeFactory
- alter the trader to identify shapes as 'KOffice/Shape' instead of
'KOffice/FlakeShape'  since not all shapes come from flake.
- One (public) class per file please.

svn path=/trunk/koffice/; revision=550029
parent 5b870af5
......@@ -27,6 +27,8 @@ set(flake_SRCS
KoToolFactory.cpp
KoCreateShapesToolFactory.cpp
KoInteractionToolFactory.cpp
KoRectangleShapeFactory.cpp
KoPathShapeFactory.cpp
)
kde4_automoc(${flake_SRCS})
......
......@@ -27,6 +27,7 @@
#include <QColor>
#include <QRectF>
#include <QPixmap>
KoCreateShapesToolFactory::KoCreateShapesToolFactory() {
}
......@@ -60,15 +61,18 @@ quint32 KoCreateShapesToolFactory::priority() const {
return 1;
}
QString KoCreateShapesToolFactory::toolType() const {
const QString& KoCreateShapesToolFactory::toolType() const {
return QString("main");
}
QString KoCreateShapesToolFactory::tooltipText() const {
return i18n("Create tooltip");
const QString& KoCreateShapesToolFactory::tooltipText() const {
return i18n("Create object");
}
KoID* KoCreateShapesToolFactory::activationShapeId() const {
return 0;
KoID KoCreateShapesToolFactory::activationShapeId() const {
return KoID("createTool", i18n("Create object"));
}
const QPixmap& KoCreateShapesToolFactory::icon() const {
return QPixmap();
}
......@@ -33,8 +33,9 @@ public:
KoTool* createTool(KoCanvasBase *canvas);
KoID id();
quint32 priority() const;
QString toolType() const;
QString tooltipText() const;
KoID* activationShapeId() const;
const QString& toolType() const;
const QString& tooltipText() const;
KoID activationShapeId() const;
const QPixmap& icon() const;
};
#endif
......@@ -23,6 +23,8 @@
#include <klocale.h>
#include <QPixmap>
KoInteractionToolFactory::KoInteractionToolFactory() {
}
......@@ -41,15 +43,18 @@ quint32 KoInteractionToolFactory::priority() const {
return 0;
}
QString KoInteractionToolFactory::toolType() const {
const QString& KoInteractionToolFactory::toolType() const {
return QString("main");
}
QString KoInteractionToolFactory::tooltipText() const {
const QString& KoInteractionToolFactory::tooltipText() const {
return i18n("Default tool");
}
KoID* KoInteractionToolFactory::activationShapeId() const {
return 0;
KoID KoInteractionToolFactory::activationShapeId() const {
return KoID("defaultTool", i18n("Default Tool"));
}
const QPixmap& KoInteractionToolFactory::icon() const {
return QPixmap();
}
......@@ -33,8 +33,9 @@ public:
KoTool* createTool(KoCanvasBase *canvas);
KoID id();
quint32 priority() const;
QString toolType() const;
QString tooltipText() const;
KoID* activationShapeId() const;
const QString& toolType() const;
const QString& tooltipText() const;
KoID activationShapeId() const;
const QPixmap& icon() const;
};
#endif
......@@ -18,14 +18,13 @@
* Boston, MA 02110-1301, USA.
*/
#ifndef KOPATHGFXOBJ_H
#define KOPATHGFXOBJ_H
#ifndef KOPATHSHAPE_H
#define KOPATHSHAPE_H
class KoSelection;
#include <QPainterPath>
#include <QPoint>
#include "KoShape.h"
#include "KoShapeFactory.h"
#include <koffice_export.h>
......@@ -54,35 +53,5 @@ private:
};
class KoPathShapeFactory : public KoShapeFactory
{
public:
// XXX: Add a nice pixmap
KoPathShapeFactory()
{
setName("PathShape");
setDescription("A simple path shape");
setToolTip("A simple path shape");
}
KoShape * createDefaultShape()
{
return new KoPathShape();
}
KoShape * createShape(KoShapeParameters * params) const
{
Q_UNUSED(params);
return new KoPathShape();
}
KoShape * createShapeFromTemplate(KoShapeTemplate * shapeTemplate) const
{
Q_UNUSED(shapeTemplate);
return new KoPathShape();
}
};
#endif /* KOPATHGFXOBJ_H */
#endif
/* This file is part of the KDE project
* Copyright (C) 2006 Thomas Zander <zander@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 "KoPathShapeFactory.h"
#include "KoPathShape.h"
#include <klocale.h>
KoPathShapeFactory::KoPathShapeFactory() {
setId(KoID("PathShape", i18n("A simple path shape")));
setToolTip("A simple path shape");
}
KoShape * KoPathShapeFactory::createDefaultShape() {
return new KoPathShape();
}
KoShape * KoPathShapeFactory::createShape(KoProperties * params) const {
Q_UNUSED(params);
return new KoPathShape();
}
KoShape * KoPathShapeFactory::createShapeFromTemplate(KoShapeTemplate * shapeTemplate) const {
Q_UNUSED(shapeTemplate);
return new KoPathShape();
}
/* This file is part of the KDE project
Copyright (C) 2006 Rob Buis <buis@kde.org>
Copyright (C) 2006 Thomas Zander <zander@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 KOPATHSHAPEFACTORY_H
#define KOPATHSHAPEFACTORY_H
#include "KoShape.h"
#include "KoShapeFactory.h"
class KoPathShapeFactory : public KoShapeFactory
{
public:
KoPathShapeFactory();
KoShape * createDefaultShape();
KoShape * createShape(KoProperties * params) const;
KoShape * createShapeFromTemplate(KoShapeTemplate * shapeTemplate) const;
};
#endif /* KOPATHGFXOBJ_H */
......@@ -23,7 +23,6 @@
#define KORECTANGLESHAPE_H
#include "KoShape.h"
#include "KoShapeFactory.h"
#include <koffice_export.h>
......@@ -39,35 +38,5 @@ public:
void paint(QPainter &painter, KoViewConverter &converter);
};
class KoRectangleShapeFactory : public KoShapeFactory
{
public:
// XXX: Add a nice pixmap
KoRectangleShapeFactory()
{
setName("RectangleShape");
setDescription("A simple square shape");
setToolTip("A simple square shape");
}
KoShape * createDefaultShape()
{
return new KoRectangleShape();
}
KoShape * createShape(KoShapeParameters * params) const
{
Q_UNUSED(params);
return new KoRectangleShape();
}
KoShape * createShapeFromTemplate(KoShapeTemplate * shapeTemplate) const
{
Q_UNUSED(shapeTemplate);
return new KoRectangleShape();
}
};
#endif
/* This file is part of the KDE project
* Copyright (C) 2006 Thomas Zander <zander@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 "KoRectangleShapeFactory.h"
#include "KoRectangleShape.h"
#include <klocale.h>
KoRectangleShapeFactory::KoRectangleShapeFactory() {
setId(KoID("RectangleShape", i18n("A simple square shape")));
setToolTip(i18n("A simple square shape"));
// XXX: Add a nice icon using the KIconLoader
}
KoShape * KoRectangleShapeFactory::createDefaultShape() {
return new KoRectangleShape();
}
KoShape * KoRectangleShapeFactory::createShape(KoProperties * params) const {
return new KoRectangleShape();
}
KoShape * KoRectangleShapeFactory::createShapeFromTemplate(KoShapeTemplate * shapeTemplate) const {
return new KoRectangleShape();
}
/* This file is part of the KDE project
* Copyright (C) 2006 Thomas Zander <zander@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 KORECTANGLESHAPEFACTORY_H
#define KORECTANGLESHAPEFACTORY_H
#include "KoShape.h"
#include "KoShapeFactory.h"
class KoRectangleShapeFactory : public KoShapeFactory
{
public:
KoRectangleShapeFactory();
KoShape * createDefaultShape();
KoShape * createShape(KoProperties * params) const;
KoShape * createShapeFromTemplate(KoShapeTemplate * shapeTemplate) const;
};
#endif
......@@ -31,21 +31,7 @@
#include "KoShape.h"
/**
* For the design: see krita's filter configuration objects. Maybe a
* straight copy is good enough?
*
* XXX: Should we move this to KoShape itself?
*/
class KoShapeParameters : KoProperties {
public:
virtual ~KoShapeParameters(){}
};
/**
* Contains a KoShapeParameters object that describes the settings of a
* Contains a KoProperties object that describes the settings of a
* particular variant of a shape object, together with a name, a description
* and a pixmap for use in the user interface.
*/
......@@ -55,68 +41,45 @@ struct KoShapeTemplate {
QString description;
QString tooltip;
QPixmap pixmap;
KoShapeParameters * params;
};
/**
* An option widget that can create a KoShapeParameters for the creation
* of KoShapes.
*/
class KoShapeOptionsWidget : public QWidget {
public:
/// get the parameters as set in the widget's widget
virtual KoShapeParameters * shapeParameters() = 0;
/// set the widget's widgets according to the given parameters
virtual void setShapeParameters( KoShapeParameters * ) = 0;
KoProperties * params;
};
/**
* The shape factory can create a flake object without needing a tool or a direct
* new().
*
* XXX: Should we wrap the shapes the factory returns in a shared pointer?
* The shape factory can create a KoShape without needing a tool or a direct new().
*/
class KoShapeFactory {
public:
KoShapeFactory() { m_optionWidget = 0; }
virtual ~KoShapeFactory() {}
virtual KoID id() { return KoID(m_name, m_description); }
virtual KoID id() { return m_id; }
virtual KoShape * createDefaultShape() = 0;
virtual KoShape * createShape(KoShapeParameters * params) const = 0;
virtual KoShape * createShape(KoProperties * params) const = 0;
virtual KoShape * createShapeFromTemplate(KoShapeTemplate * shapeTemplate) const = 0;
virtual QWidget * createOptionWidget(QWidget * parent) { Q_UNUSED(parent); return 0; }
virtual QWidget * optionWidget() const { return m_optionWidget; }
const QList<KoShapeParameters*> getTemplates() const { return m_templates; }
const QString & name() const { return m_name; }
const QString & description() const { return m_description; }
const QList<KoProperties*> templates() const { return m_templates; }
const QString & tooltip() const { return m_tooltip; }
const QPixmap & pixmap() const { return m_pixmap; }
const QPixmap & icon() const { return m_icon; }
protected:
void addTemplate(KoShapeParameters * params) { m_templates.append(params); }
void setName(const QString & name) { m_name = name; }
void setDescription(const QString & description) { m_description = description; }
void addTemplate(KoProperties * params) { m_templates.append(params); }
void setId(KoID id) { m_id = id; }
void setToolTip(const QString & tooltip) { m_tooltip = tooltip; }
void setPixmap(const QPixmap & pixmap) { m_pixmap = pixmap; }
void setIcon(const QPixmap & icon) { m_icon = icon; }
void setOptionWidget(QWidget * widget) { m_optionWidget = widget; }
private:
QList<KoShapeParameters*> m_templates;
QString m_name;
QString m_description;
QList<KoProperties*> m_templates;
QString m_tooltip;
QPixmap m_pixmap;
QPixmap m_icon;
QWidget * m_optionWidget;
KoID m_id;
};
#endif // _KO_SHAPE_FACTORY_
......@@ -30,19 +30,16 @@
#include <KoGenericRegistry.h>
#include <KoShapeRegistry.h>
#include <KoRectangleShape.h>
#include <KoPathShape.h>
#include <KoRectangleShapeFactory.h>
#include <KoPathShapeFactory.h>
KoShapeRegistry *KoShapeRegistry::m_singleton = 0;
KoShapeRegistry::KoShapeRegistry()
{
Q_ASSERT(KoShapeRegistry::m_singleton == 0);
KoShapeRegistry::m_singleton = this;
KService::List offers = KServiceTypeTrader::self()->query(QString::fromLatin1("KOffice/FlakeShape"),
QString::fromLatin1("(Type == 'Service') and "
"([X-KOffice-Version] == 2)"));
KService::List offers = KServiceTypeTrader::self()->query(QString::fromLatin1("KOffice/Shape"),
QString::fromLatin1("(Type == 'Service') and "
"([X-KOffice-Version] == 1)"));
KService::List::ConstIterator iter;
......
......@@ -26,26 +26,39 @@
#include <klocale.h>
#include <QObject>
#include <QObject>
/**
* A factory for KoTool objects.
* This abstract class is a baseclass for real factories; each class inheriting from this one
* will be the creator of one specific tool class. So there is one toolFactory for each type
* of tool.
*/
class FLAKE_EXPORT KoToolFactory : public QObject {
Q_OBJECT
public:
/// constructor
KoToolFactory();
virtual ~KoToolFactory();
/// instanciate a new tool
virtual KoTool * createTool(KoCanvasBase *canvas) = 0;
/**
* return the ID for the tool this factory is associated with.
* @return the ID for the tool this factory is associated with.
*/
virtual KoID id() = 0;
/// The priority of this tool in its section in the toolbox
virtual quint32 priority() const = 0;
/// the type of tool, used to group tools in the toolbox
virtual QString toolType() const = 0;
virtual const QString& toolType() const = 0;
/// return a translated tooltip Text
virtual QString tooltipText() const = 0;
// getter for icon?
virtual const QString& tooltipText() const = 0;
/// return an icon for this tool
virtual const QPixmap& icon() const = 0;
/// The shape ID the tool is associated with, or 0 when the tool is a generic tool
virtual KoID* activationShapeId() const = 0;
virtual KoID activationShapeId() const = 0;
};
#endif
......
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