Commit 2146ecda authored by Thomas Zander's avatar Thomas Zander

After an invigorating litle design talk on IRC; use

    #define TOOLNAME_ID "fooBar"
if you really must use the tool/shape from another place.

svn path=/trunk/koffice/; revision=550974
parent 586aa715
......@@ -31,6 +31,7 @@
class KoCanvasBase;
class KoShapeControllerBase;
#define KoCreateShapesTool_ID "CreateShapesTool"
/**
* A tool to create shapes with.
......@@ -38,8 +39,6 @@ class KoShapeControllerBase;
class FLAKE_EXPORT KoCreateShapesTool : public KoInteractionTool
{
public:
enum createShapesToolenum { TOOLID = 58297 };
/**
* Create a new tool; typically not called by applications, only by the KoToolManager
* @param canvas the canvas this tool works for.
......@@ -74,16 +73,16 @@ public:
* create the new shape.
* @param id the SHAPEID of the to be generated shape
*/
void setShapeId(int id) { m_shapeId = id; }
void setShapeId(const QString id) { m_shapeId = id; }
/**
* return the shape Id that is to be created.
* @return the shape Id that is to be created.
*/
int shapeId() const { return m_shapeId; }
const QString shapeId() const { return m_shapeId; }
private:
KoShapeControllerBase *m_shapeController;
int m_shapeId;
QString m_shapeId;
};
#endif
......@@ -29,7 +29,7 @@
#include <QPixmap>
KoCreateShapesToolFactory::KoCreateShapesToolFactory()
: KoToolFactory(KoCreateShapesTool::TOOLID, i18n("Create Shapes"))
: KoToolFactory(KoCreateShapesTool_ID, i18n("Create Shapes"))
{
setToolTip(i18n("Create object"));
setToolType("main");
......
......@@ -33,6 +33,8 @@
class KoInteractionStrategy;
#define KoInteractionTool_ID "InteractionTool"
/**
* The default tool (associated with the arrow icon) implements the default
* interactions you have with flake objects.<br>
......@@ -44,8 +46,6 @@ class KoInteractionStrategy;
class FLAKE_EXPORT KoInteractionTool : public KoTool
{
public:
enum InteractionToolenum { TOOLID = 20766 };
/**
* Constructor for basic interaction tool where user actions are translated
* and handled by interaction strategies of type KoInteractionStrategy.
......
......@@ -26,7 +26,7 @@
#include <QPixmap>
KoInteractionToolFactory::KoInteractionToolFactory()
: KoToolFactory(KoInteractionTool::TOOLID, i18n("Default Tool"))
: KoToolFactory(KoInteractionTool_ID, i18n("Default Tool"))
{
setToolTip(i18n("Default tool"));
setToolType("main");
......
......@@ -34,7 +34,6 @@
class FLAKE_EXPORT KoPathShape : public KoShape
{
public:
enum PathShape { SHAPEID = 54291 };
KoPathShape();
virtual void paint( QPainter &painter, KoViewConverter &converter );
......
......@@ -23,7 +23,7 @@
#include <klocale.h>
KoPathShapeFactory::KoPathShapeFactory()
: KoShapeFactory(KoPathShape::SHAPEID, i18n("A simple path shape"))
: KoShapeFactory("KoPathShape", i18n("A simple path shape"))
{
setToolTip("A simple path shape");
}
......
......@@ -37,5 +37,4 @@ public:
QWidget * optionWidget() const { return 0; }
};
#endif
......@@ -27,6 +27,7 @@
#include <koffice_export.h>
class QPainter;
#define KoRectangleShape_SHAPEID "43751"
/**
* Simple Rectangle shape.
......@@ -34,8 +35,6 @@ class QPainter;
class FLAKE_EXPORT KoRectangleShape : public KoShape
{
public:
enum RectangleShape { SHAPEID = 43751 };
KoRectangleShape();
void paint(QPainter &painter, KoViewConverter &converter);
};
......
......@@ -22,7 +22,7 @@
#include <klocale.h>
KoRectangleShapeFactory::KoRectangleShapeFactory()
: KoShapeFactory(KoRectangleShape::SHAPEID, i18n("A simple square shape"))
: KoShapeFactory(KoRectangleShape_SHAPEID, i18n("A simple square shape"))
{
setToolTip(i18n("A simple square shape"));
// XXX: Add a nice icon using the KIconLoader
......
......@@ -19,14 +19,14 @@
#include "KoShapeFactory.h"
KoShapeFactory::KoShapeFactory(int id, const QString name)
KoShapeFactory::KoShapeFactory(const QString id, const QString name)
: m_id(id)
, m_name(name)
{
}
const KoID KoShapeFactory::id() const {
return KoID(QString::number(m_id), m_name);
return KoID(m_id, m_name);
}
const QString & KoShapeFactory::toolTip() const {
......@@ -53,7 +53,7 @@ void KoShapeFactory::setIcon(const QPixmap & icon) {
m_icon = icon;
}
int KoShapeFactory::shapeId() const {
const QString &KoShapeFactory::shapeId() const {
return m_id;
}
......
......@@ -54,7 +54,7 @@ class FLAKE_EXPORT KoShapeFactory : public QObject {
public:
/// Factory for shapes
KoShapeFactory(int id, const QString name);
KoShapeFactory(const QString id, const QString name);
virtual ~KoShapeFactory() {}
virtual KoShape * createDefaultShape() = 0;
......@@ -63,11 +63,11 @@ public:
virtual QWidget * optionWidget() const = 0;
const KoID id() const;
int shapeId() const;
const QString & shapeId() const;
const QList<KoProperties*> templates() const { return m_templates; }
const QString & toolTip() const;
const QPixmap & icon() const;
const QString& name() const;
const QString & name() const;
protected:
......@@ -81,8 +81,7 @@ private:
QList<KoProperties*> m_templates;
QString m_tooltip;
QPixmap m_icon;
const QString m_name;
const int m_id;
const QString m_id, m_name;
};
#endif // _KO_SHAPE_FACTORY_
......@@ -165,7 +165,7 @@ signals:
*
* @param id the identification of the desired tool
*/
void sigActivateTool(int id );
void sigActivateTool(const QString &id );
/**
* Emitted when this tool wants itself to temporarily be replaced by another tool.
......@@ -174,7 +174,7 @@ signals:
* replaced by a colourpicker.
* @param id the identification of the desired tool
*/
void sigActivateTemporary(int id);
void sigActivateTemporary(const QString & id);
/**
* Emitted when the tool has been temporarily activated and wants
......
......@@ -18,7 +18,7 @@
#include "KoToolFactory.h"
KoToolFactory::KoToolFactory(int id, const QString name)
KoToolFactory::KoToolFactory(const QString id, const QString name)
: m_name(name)
, m_id(id)
{
......@@ -30,7 +30,7 @@ KoToolFactory::~KoToolFactory()
{
}
int KoToolFactory::toolId() const {
const QString &KoToolFactory::toolId() const {
return m_id;
}
......@@ -71,7 +71,7 @@ void KoToolFactory::setPriority(int newPriority) {
}
const KoID KoToolFactory::id() const {
return KoID(QString::number(m_id), m_name);
return KoID(m_id, m_name);
}
const QString& KoToolFactory::name() const {
......
......@@ -38,7 +38,7 @@ class FLAKE_EXPORT KoToolFactory : public QObject {
Q_OBJECT
public:
KoToolFactory(int id, const QString name);
KoToolFactory(const QString id, const QString name);
virtual ~KoToolFactory();
/// instanciate a new tool
......@@ -47,7 +47,7 @@ public:
* return the id for the tool this factory is associated with.
* @return the id for the tool this factory is associated with.
*/
int toolId() const;
const QString& toolId() const;
const QString& name() const;
const KoID id() const;
/// The priority of this tool in its section in the toolbox
......@@ -75,8 +75,7 @@ private:
QString m_toolType;
QString m_tooltip;
QPixmap m_icon;
const QString m_name;
const int m_id;
const QString m_name, m_id;
int m_priority, m_activationId;
};
......
......@@ -96,15 +96,6 @@ public:
return p;
}
/**
* Get a single entry based on a integer based id.
* @param id the integer ID as used by Tools and Shapes.
*/
T get(int id) const
{
return get(KoID(QString::number(id), ""));
}
/**
* Get a single entry based on the identifying part of KoID, not the
* the descriptive part.
......
......@@ -134,7 +134,7 @@ void KoToolManager::removeCanvasController(KoCanvasController *controller) {
m_mutex.lock();
m_canvases.removeAll(controller);
m_shapeControllers.remove(controller);
QMap<int, KoTool*> toolsMap = m_allTools.value(controller);
QMap<QString, KoTool*> toolsMap = m_allTools.value(controller);
foreach(KoTool *tool, toolsMap.values())
delete tool;
m_allTools.remove(controller);
......@@ -147,14 +147,14 @@ void KoToolManager::removeCanvasController(KoCanvasController *controller) {
void KoToolManager::toolActivated(ToolHelper *tool) {
kDebug(30004) << "ToolActivated: '" << tool->name() << "'\n";
QMap<int, KoTool*> toolsMap = m_allTools.value(m_activeCanvas);
QMap<QString, KoTool*> toolsMap = m_allTools.value(m_activeCanvas);
KoTool *t = toolsMap.value(tool->id());
switchTool(t, false);
}
void KoToolManager::switchTool(int id, bool temporary) {
void KoToolManager::switchTool(const QString &id, bool temporary) {
Q_ASSERT(m_activeCanvas);
QMap<int, KoTool*> toolsMap = m_allTools.value(m_activeCanvas);
QMap<QString, KoTool*> toolsMap = m_allTools.value(m_activeCanvas);
KoTool *tool = toolsMap.value(id);
if(! tool) {
kWarning(30004) << "Tool requested " << (temporary?"temporary":"") << "switch to unknown tool: '" << id << "'\n";
......@@ -174,10 +174,10 @@ void KoToolManager::switchTool(KoTool *tool, bool temporary) {
m_activeTool->deactivate();
disconnect(m_activeTool, SIGNAL(sigCursorChanged(QCursor)),
this, SLOT(updateCursor(QCursor)));
disconnect(m_activeTool, SIGNAL(sigActivateTool(int)),
this, SLOT(switchToolRequested(int)));
disconnect(m_activeTool, SIGNAL(sigActivateTemporary(int)),
this, SLOT(switchToolTemporaryRequested(int)));
disconnect(m_activeTool, SIGNAL(sigActivateTool(const QString &)),
this, SLOT(switchToolRequested(const QString &)));
disconnect(m_activeTool, SIGNAL(sigActivateTemporary(const QString &)),
this, SLOT(switchToolTemporaryRequested(const QString &)));
disconnect(m_activeTool, SIGNAL(sigDone()), this, SLOT(switchBackRequested()));
}
if(m_activeTool && temporary)
......@@ -185,10 +185,10 @@ void KoToolManager::switchTool(KoTool *tool, bool temporary) {
m_activeTool = tool;
connect(m_activeTool, SIGNAL(sigCursorChanged(QCursor)),
this, SLOT(updateCursor(QCursor)));
connect(m_activeTool, SIGNAL(sigActivateTool(int)),
this, SLOT(switchToolRequested(int)));
connect(m_activeTool, SIGNAL(sigActivateTemporary(int)),
this, SLOT(switchToolTemporaryRequested(int)));
connect(m_activeTool, SIGNAL(sigActivateTool(const QString &)),
this, SLOT(switchToolRequested(const QString &)));
connect(m_activeTool, SIGNAL(sigActivateTemporary(const QString &)),
this, SLOT(switchToolTemporaryRequested(const QString &)));
connect(m_activeTool, SIGNAL(sigDone()), this, SLOT(switchBackRequested()));
// and set it.
......@@ -207,10 +207,10 @@ void KoToolManager::attachCanvas(KoCanvasController *controller) {
kDebug(30004) << "KoToolManager::attachCanvas\n";
// TODO listen to focus changes
// TODO listen to selection changes
QMap<int, KoTool*> toolsMap;
QMap<QString, KoTool*> toolsMap;
foreach(ToolHelper *tool, m_tools)
toolsMap.insert(tool->id(), tool->createTool(controller->canvas()));
KoCreateShapesTool *createTool = dynamic_cast<KoCreateShapesTool*>(toolsMap.value(KoCreateShapesTool::TOOLID));
KoCreateShapesTool *createTool = dynamic_cast<KoCreateShapesTool*>(toolsMap.value(KoCreateShapesTool_ID));
Q_ASSERT(createTool);
createTool->setShapeController(m_shapeControllers[controller]);
......@@ -231,7 +231,7 @@ void KoToolManager::detachCanvas(KoCanvasController *controller) {
// TODO detach
if(m_activeCanvas == controller)
m_activeCanvas = 0;
QMap<int, KoTool*> toolsMap = m_allTools.value(controller);
QMap<QString, KoTool*> toolsMap = m_allTools.value(controller);
foreach(KoTool *tool, toolsMap.values())
delete tool;
toolsMap.clear();
......@@ -244,20 +244,20 @@ void KoToolManager::updateCursor(QCursor cursor) {
m_activeCanvas->canvas()->canvasWidget()->setCursor(cursor);
}
void KoToolManager::switchToolRequested(int id) {
void KoToolManager::switchToolRequested(const QString & id) {
while (!m_stack.isEmpty()) // switching means to flush the stack
m_stack.pop();
switchTool(id, false);
}
void KoToolManager::switchToolTemporaryRequested(int id) {
void KoToolManager::switchToolTemporaryRequested(const QString &id) {
switchTool(id, true);
}
void KoToolManager::switchBackRequested() {
if(m_stack.isEmpty()) {
// default to changing to the interactionTool
switchTool(KoInteractionTool::TOOLID, false);
switchTool(KoInteractionTool_ID, false);
return;
}
switchTool(m_stack.pop(), false);
......@@ -266,9 +266,9 @@ void KoToolManager::switchBackRequested() {
KoCreateShapesTool *KoToolManager::shapeCreatorTool(KoCanvasBase *canvas) const {
foreach(KoCanvasController *controller, m_canvases) {
if(controller->canvas() == canvas) {
QMap<int, KoTool*> tools = m_allTools.value(controller);
QMap<QString, KoTool*> tools = m_allTools.value(controller);
KoCreateShapesTool *tool =
dynamic_cast<KoCreateShapesTool*>(tools.value(KoCreateShapesTool::TOOLID));
dynamic_cast<KoCreateShapesTool*>(tools.value(KoCreateShapesTool_ID));
Q_ASSERT(tool /* ID changed? */);
return tool;
}
......@@ -289,7 +289,7 @@ void ToolHelper::buttonPressed() {
emit toolActivated(this);
}
int ToolHelper::id() const {
const QString &ToolHelper::id() const {
return m_toolFactory->toolId();
}
......
......@@ -75,15 +75,15 @@ private:
KoToolManager operator=(const KoToolManager&);
void setup();
void switchTool(KoTool *tool, bool temporary);
void switchTool(int id, bool temporary);
void switchTool(const QString &id, bool temporary);
private slots:
void toolActivated(ToolHelper *tool);
void detachCanvas(KoCanvasController* controller);
void attachCanvas(KoCanvasController* controller);
void updateCursor(QCursor cursor);
void switchToolRequested(int id);
void switchToolTemporaryRequested(int id);
void switchToolRequested(const QString &id);
void switchToolTemporaryRequested(const QString &id);
void switchBackRequested();
private:
......@@ -102,7 +102,7 @@ private:
* and m_toolBox members. */
QMutex m_mutex;
QMap<KoCanvasController*, QMap<int, KoTool*> > m_allTools;
QMap<KoCanvasController*, QMap<QString, KoTool*> > m_allTools;
QStack<KoTool*> m_stack;
};
......@@ -111,8 +111,8 @@ class ToolHelper : public QObject {
public:
ToolHelper(KoToolFactory *tool) { m_toolFactory = tool; }
QAbstractButton *createButton(QWidget *parent);
int id() const;
const QString& name() const;
const QString &id() const;
const QString &name() const;
KoTool *createTool(KoCanvasBase *canvas) const;
signals:
......
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