Commit 92ca9637 authored by Thomas Zander's avatar Thomas Zander

First iteration of KoToolManager and needed classes to load them as KTrader items.

svn path=/trunk/koffice/; revision=548913
parent 8860d0d9
......@@ -24,6 +24,8 @@ set(flake_SRCS
KoCreateShapeStrategy.cpp
KoCreateShapesTool.cpp
KoShapeRegistry.cpp
KoToolFactory.cpp
KoCreateShapesToolFactory.cpp
)
kde4_automoc(${flake_SRCS})
......@@ -36,5 +38,5 @@ set_target_properties(flake PROPERTIES VERSION ${GENERIC_KOFFICE_LIB_VERSION} SO
install_targets(${LIB_INSTALL_DIR} flake )
install_files( ${SERVICES_INSTALL_DIR} FILES flaketoolcreateshapes.desktop )
/* 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 "KoCreateShapesToolFactory.h"
#include "KoCreateShapesTool.h"
#include <klocale.h>
KoCreateShapesToolFactory::KoCreateShapesToolFactory() {
}
KoCreateShapesToolFactory::~KoCreateShapesToolFactory() {
}
KoTool* KoCreateShapesToolFactory::createTool(KoCanvasBase *canvas) {
return new KoCreateShapesTool(canvas, 0);
}
KoID KoCreateShapesToolFactory::id() {
return KoID("Create Shapes", i18n("Create Shapes"));
}
quint32 KoCreateShapesToolFactory::priority() const {
return 1;
}
QString KoCreateShapesToolFactory::toolType() const {
return QString("main");
}
QString KoCreateShapesToolFactory::tooltipText() const {
return i18n("Create tooltip");
}
KoID* KoCreateShapesToolFactory::activationShapeId() const {
return 0;
}
/* 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 KOCREATESHAPESTOOLFACTORY_H
#define KOCREATESHAPESTOOLFACTORY_H
#include "KoToolFactory.h"
class KoCreateShapesToolFactory : public KoToolFactory {
KoCreateShapesToolFactory();
~KoCreateShapesToolFactory();
KoTool* createTool(KoCanvasBase *canvas);
KoID id();
quint32 priority() const;
QString toolType() const;
QString tooltipText() const;
KoID* activationShapeId() const;
};
#endif
......@@ -47,16 +47,10 @@ QPointF KoInteractionTool::m_handleDiff[] = {
QPointF( -HANDLE_DISTANCE, -HANDLE_DISTANCE )
};
KoInteractionTool::KoInteractionTool( const QString & name, const QString & id, const QString & type, KoCanvasBase *canvas )
: KoTool( name, id, type, canvas )
, m_currentStrategy( 0 )
, m_mouseWasInsideHandles( false )
{
}
KoInteractionTool::KoInteractionTool( KoCanvasBase *canvas )
: KoTool( "", "", "", canvas )
: KoTool( canvas )
, m_currentStrategy( 0 )
, m_mouseWasInsideHandles( false )
{
}
......
......@@ -47,12 +47,8 @@ public:
/**
* Constructor for basic interaction tool where user actions are translated
* and handled by interaction strategies of type KoInteractionStrategy.
* @param name ??
* @param id ??
* @param type ??
* @param canvas the canvas this tool will be working for.
*/
KoInteractionTool(const QString & name, const QString & id, const QString & type, KoCanvasBase *canvas );
KoInteractionTool( KoCanvasBase *canvas );
virtual ~KoInteractionTool();
......@@ -73,11 +69,6 @@ public: // Identification
Q_UNUSED(ac);
}
virtual KRadioAction * action()
{
return m_action;
}
public:
virtual bool wantsAutoScroll();
......
......@@ -25,27 +25,12 @@
#include "KoGfxEvent.h"
#include "KoTool.moc"
KoTool::KoTool(const QString & name, const QString & id, const QString & type, KoCanvasBase *canvas )
KoTool::KoTool(KoCanvasBase *canvas )
: m_optionWidget( 0 )
, m_action( 0 )
, m_canvas(canvas)
, m_name( name )
, m_id( id )
, m_type( type )
{
}
quint32 KoTool::priority() {
return 0;
}
QString KoTool::quickHelp() {
return QString( "" );
}
void KoTool::setup(KActionCollection *ac) {
Q_UNUSED(ac);
}
QWidget * KoTool::optionWidget(QWidget * parent) {
if ( !m_optionWidget )
m_optionWidget = new QWidget( parent );
......
......@@ -61,44 +61,11 @@ public:
* @param type a string identifying the type of this tool
* @param canvas the canvas interface this tool will work for.
*/
KoTool(const QString & name, const QString & id, const QString & type, KoCanvasBase *canvas );
KoTool(KoCanvasBase *canvas );
virtual ~KoTool() {}
public: // Identification
QString & name() { return m_name; }
QString & id() { return m_id; }
QString & type() { return m_type; }
/**
* The priority of this tool in its section in the toolbox
*/
virtual quint32 priority();
/**
* A short helptext that can be displayed in the option widget or
* as tool help
*/
virtual QString quickHelp();
/**
* The setup() method creates a an action and adds it to the
* actioncollection. This is necessary to show the tool in a
* toolbar or menu.
*
* XXX: Make this abstract when we first link to kdelibs
* XXX: Actually create an action.
*/
virtual void setup(KActionCollection *ac);
/**
* Return the action associated with this tool.
*/
virtual KRadioAction * action() {
return m_action;
}
/**
* Return the option widget for this tool. Create it if it
* does not exist yet.
......@@ -224,21 +191,14 @@ signals:
*/
void sigDone();
protected:
QWidget * m_optionWidget;
KRadioAction * m_action;
KoCanvasBase *m_canvas; ///< the canvas interface this tool will work for.
private:
KoTool();
KoTool(const KoTool&);
KoTool& operator=(const KoTool&);
private:
QString m_name;
QString m_id;
QString m_type;
};
#endif /* KOTOOL_H */
/*
* Copyright (c) 2006 Thomas Zander <zander@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "KoToolFactory.h"
KoToolFactory::KoToolFactory()
{
}
KoToolFactory::~KoToolFactory()
{
}
#include "KoToolFactory.moc"
/*
* Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2006 Thomas Zander <zander@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KO_TOOL_FACTORY_H
#define KO_TOOL_FACTORY_H
#include "KoTool.h"
#include <KoID.h>
#include <koffice_export.h>
#include <klocale.h>
#include <QObject>
class FLAKE_EXPORT KoToolFactory : public QObject {
Q_OBJECT
public:
KoToolFactory();
virtual ~KoToolFactory();
/// instanciate a new tool
virtual KoTool * createTool(KoCanvasBase *canvas) = 0;
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;
/// return a translated tooltip Text
virtual QString tooltipText() const = 0;
// getter for icon?
/// The shape ID the tool is associated with, or 0 when the tool is a generic tool
virtual KoID* activationShapeId() const = 0;
};
#endif
[Desktop Entry]
Encoding=UTF-8
Name=Create Shapes
ServiceTypes=KOffice/Tool
Type=Service
X-KDE-Library=flake
X-Flake-Version=2
......@@ -39,8 +39,8 @@ protected:
public:
KoGenericRegistry() { }
virtual ~KoGenericRegistry() { }
public:
public:
/**
* add an object to the registry
* @param item the item to add (NOTE: T must have an KoID id() function)
......@@ -141,9 +141,9 @@ public:
/** This function return a list of all the keys
*/
KoIDList listKeys() const
QList<KoID> listKeys() const
{
KoIDList list;
QList<KoID> list;
typename storageMap::const_iterator it = m_storage.begin();
typename storageMap::const_iterator endit = m_storage.end();
while( it != endit )
......
......@@ -30,7 +30,6 @@
*/
class KoID {
public:
KoID() : m_id(), m_name() {}
KoID(const QString & id, const QString & name = QString())
......@@ -74,7 +73,4 @@ inline bool operator>(const KoID &v1, const KoID &v2)
return v1.m_id < v2.m_id;
}
typedef QList<KoID> KoIDList;
#endif
......@@ -40,6 +40,8 @@ set(kofficeui_LIB_SRCS
KoPageLayoutHeader.cpp
KoPen.cpp
KoZoomMode.cpp
KoToolManager.cpp
KoToolRegistry.cpp
KoGeneralPropertyUi.cpp )
kde4_automoc(${kofficeui_LIB_SRCS})
......@@ -49,7 +51,7 @@ kde4_add_ui_files( kofficeui_LIB_SRCS KoGeneralPropertyUi.ui KoPageLayoutHeaderB
kde4_add_library(kofficeui SHARED ${kofficeui_LIB_SRCS})
target_link_libraries(kofficeui ${KDE4_KDECORE_LIBS} kofficecore )
target_link_libraries(kofficeui ${KDE4_KDECORE_LIBS} kofficecore flake )
set_target_properties(kofficeui PROPERTIES VERSION ${GENERIC_KOFFICE_LIB_VERSION} SOVERSION ${GENERIC_KOFFICE_LIB_SOVERSION} )
install_targets(${LIB_INSTALL_DIR} kofficeui )
......
/*
* Copyright (c) 2005-2006 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2006 Thomas Zander <zander@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "KoToolManager.h"
//#include "KoToolBox.h"
#include "KoToolRegistry.h"
#include <KoToolFactory.h>
#include "kactioncollection.h"
#include "kdebug.h"
#include <QToolButton>
#include <QButtonGroup>
#include <QVBoxLayout>
KoToolManager::KoToolManager()
: QObject()
, m_toolBox(0)
{
}
KoToolManager::~KoToolManager()
{
}
void KoToolManager::setup() {
if(m_tools.size() > 0)
return;
KoToolRegistry *registry = KoToolRegistry::instance();
foreach(KoID id, registry->listKeys()) {
ToolHelper *t = new ToolHelper(registry->get(id));
kDebug(30004) << " th" << t->id().name() << endl;
connect(t, SIGNAL(toolActivated(ToolHelper*)), this, SLOT(toolActivated(ToolHelper*)));
m_tools.append(t);
}
// do some magic for the sorting here :) TODO
}
QWidget *KoToolManager::createToolBox() {
setup();
QWidget *widget = new QWidget();
widget->setMinimumSize(20, 100);
QButtonGroup *group = new QButtonGroup(widget);
QVBoxLayout *lay = new QVBoxLayout(widget);
foreach(ToolHelper *tool, m_tools) {
QAbstractButton *but = tool->createButton(widget);
group->addButton(but);
lay->addWidget(but);
}
return widget;
}
void KoToolManager::registerTools(KActionCollection *ac) {
// TODO
}
void KoToolManager::addCanvasView(const KoCanvasView *view) {
// TODO
}
void KoToolManager::toolActivated(ToolHelper *tool) {
kDebug(30004) << "ToolActivated " << tool->id().name();
}
// ************ ToolHelper **********
QAbstractButton* ToolHelper::createButton(QWidget *parent) {
QToolButton *but = new QToolButton(parent);
but->setText(m_toolFactory->id().name());
connect(but, SIGNAL(clicked()), this, SLOT(buttonPressed()));
return but;
}
void ToolHelper::buttonPressed() {
emit toolActivated(this);
}
//static
KoToolManager* KoToolManager::s_instance = 0;
KoToolManager* KoToolManager::instance() {
if(s_instance == 0)
s_instance = new KoToolManager();
return s_instance;
}
KoID ToolHelper::id() const {
return m_toolFactory->id();
}
#include "KoToolManager.moc"
/*
* Copyright (c) 2005-2006 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2006 Thomas Zander <zander@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KO_TOOL_MANAGER
#define KO_TOOL_MANAGER
#include "KoToolBox.h"
#include <KoID.h>
#include <KoCanvasView.h>
#include <koffice_export.h>
#include <QMap>
#include <QObject>
class ToolHelper;
class KActionCollection;
class QAbstractButton;
class KoToolFactory;
/**
* This class manages the activation and deactivation of tools for
* each input device.
*
* We assume ONE toolbox per application instance (process), not one
* per view. This one toolbox is owned and managed by this
* toolmanager. We will create that without using actions, just signal slots.
*
* There is one tool instance per pointer
* There is one set of tools per pointer per process
* All views share this set of tools
* The tool manager knows all canvasView intances
* The tool manager set the active tool in all canvasses
* (Tools can set another tool as active)
*/
class KOFFICEUI_EXPORT KoToolManager : public QObject {
Q_OBJECT
public:
static KoToolManager* instance();
~KoToolManager();
QWidget *createToolBox(); // TODO alter from QWidget to KoToolBox
void registerTools(KActionCollection *ac);
void addCanvasView(const KoCanvasView *view);
private:
KoToolManager();
KoToolManager(const KoToolManager&);
KoToolManager operator=(const KoToolManager&);
void setup();
private slots:
void toolActivated(ToolHelper *tool);
private:
static KoToolManager* s_instance;
KoToolBox *m_toolBox;
QList<ToolHelper*> m_tools;
};
class ToolHelper : public QObject {
Q_OBJECT
public:
ToolHelper(KoToolFactory *tool) { m_toolFactory = tool; }
QAbstractButton *createButton(QWidget *parent);
KoID id() const;
signals:
void toolActivated(ToolHelper *tool);
private slots:
void buttonPressed();
private:
KoToolFactory *m_toolFactory;
};
#endif
/*
* Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2006 Thomas Zander <zander@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "KoToolRegistry.h"
#include "kdebug.h"
#include <kparts/plugin.h>
#include <kservice.h>
#include <kservicetypetrader.h>
#include <kparts/componentfactory.h>
KoToolRegistry::KoToolRegistry() {
KService::List offers = KServiceTypeTrader::self()->query(QString::fromLatin1("KOffice/Tool"),
QString::fromLatin1("(Type == 'Service') and ([X-Flake-Version] == 1)"));
foreach(KService::Ptr service, offers) {
int errCode = 0;
KoToolFactory* plugin =
KParts::ComponentFactory::createInstanceFromService<KoToolFactory>(
service, this, QStringList(), &errCode );
if ( plugin ) {
kDebug(30008) << "found plugin " << service->property("Name").toString() << endl;
add(plugin);
}
else {
kDebug(30008) << " plugin " << service->property("Name").toString() << ", " <<
errCode << endl;
if( errCode == KParts::ComponentFactory::ErrNoLibrary)
kWarning(30008) << " Error loading plugin was : ErrNoLibrary " <<
KLibLoader::self()->lastErrorMessage() << endl;
}
}
}
KoToolRegistry::~KoToolRegistry()
{
}
// static
KoToolRegistry *KoToolRegistry::s_instance = 0;
KoToolRegistry* KoToolRegistry::instance()
{
if(KoToolRegistry::s_instance == 0)
KoToolRegistry::s_instance = new KoToolRegistry();
return KoToolRegistry::s_instance;
}
#include "KoToolRegistry.moc"
/*
* Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2006 Thomas Zander <zander@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KO_TOOL_REGISTRY_H_
#define KO_TOOL_REGISTRY_H_
#include <QObject>
#include "KoGenericRegistry.h"
#include <KoToolFactory.h>
#include <koffice_export.h>
class KOFFICEUI_EXPORT KoToolRegistry : public QObject, public KoGenericRegistry<KoToolFactory*> {
Q_OBJECT
public:
virtual ~KoToolRegistry();
static KoToolRegistry* instance();
private:
KoToolRegistry();
KoToolRegistry(const KoToolRegistry&);
KoToolRegistry operator=(const KoToolRegistry&);
static KoToolRegistry *s_instance;
};
#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