diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-20 18:48:39 -0400 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-20 18:48:39 -0400 |
commit | 42c97432cf777f02dc8ef8f456a4d9da54ad5dbd (patch) | |
tree | 07f23962ace2d24d130d9ec0a480b90a9afea4b4 /sigencore | |
parent | 0b64daead405876967b1be5cb8ad7a0f7455ad61 (diff) | |
download | sigen-42c97432cf777f02dc8ef8f456a4d9da54ad5dbd.tar.gz sigen-42c97432cf777f02dc8ef8f456a4d9da54ad5dbd.tar.xz sigen-42c97432cf777f02dc8ef8f456a4d9da54ad5dbd.zip |
Add CanvasPlugin interface
Diffstat (limited to 'sigencore')
-rw-r--r-- | sigencore/plugins/CMakeLists.txt | 2 | ||||
-rw-r--r-- | sigencore/plugins/CanvasPlugin.cpp | 73 | ||||
-rw-r--r-- | sigencore/plugins/CanvasPlugin.h | 72 | ||||
-rw-r--r-- | sigencore/plugins/CanvasPlugin_p.h | 49 |
4 files changed, 196 insertions, 0 deletions
diff --git a/sigencore/plugins/CMakeLists.txt b/sigencore/plugins/CMakeLists.txt index 891aec5d..7188d416 100644 --- a/sigencore/plugins/CMakeLists.txt +++ b/sigencore/plugins/CMakeLists.txt @@ -2,10 +2,12 @@ project(plugins) set(sigencoreplugins_HEADERS ArenaPlugin.h + CanvasPlugin.h Global.h ) set(sigencoreplugins_SRCS ArenaPlugin.cpp + CanvasPlugin.cpp ) set(sigencoreplugins_SERVICETYPES sigen_arena.desktop diff --git a/sigencore/plugins/CanvasPlugin.cpp b/sigencore/plugins/CanvasPlugin.cpp new file mode 100644 index 00000000..e1f52a61 --- /dev/null +++ b/sigencore/plugins/CanvasPlugin.cpp @@ -0,0 +1,73 @@ +/* + * Copyright 2009 Ben Boeckel <MathStuf@gmail.com> + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "CanvasPlugin.h" +#include "CanvasPlugin_p.h" + +// Sigencore includes +#include <sigencore/Canvas.h> + +// Qt includes +#include <QtCore/QSignalMapper> + +using namespace Sigscript; +using namespace Sigencore; +using namespace Sigencore::Interfaces; + +CanvasPlugin::CanvasPlugin(QObject* parent, const QVariantList& args) : + QObject(parent), + d(new Private(this, args)) +{ +} + +CanvasPlugin::~CanvasPlugin() +{ + delete d; +} + +Canvas* CanvasPlugin::getCanvas(const QString& name, Config* parent) +{ + Canvas* arena = createCanvas(name, parent); + d->addCanvas(arena); + return arena; +} + +CanvasPlugin::Private::Private(CanvasPlugin* plugin, const QVariantList& args) : + q(plugin), + m_mapper(new QSignalMapper(this)) +{ + Q_UNUSED(args) + connect(m_mapper, SIGNAL(mapped(QObject*)), this, SLOT(cleanupCanvas(QObject*))); +} + +CanvasPlugin::Private::~Private() +{ +} + +void CanvasPlugin::Private::addCanvas(Canvas* arena) +{ + connect(arena, SIGNAL(cleanupCanvas()), m_mapper, SLOT(map())); + m_mapper->setMapping(arena, arena); +} + +void CanvasPlugin::Private::cleanupCanvas(QObject* object) +{ + Canvas* arena = qobject_cast<Canvas*>(object); + if (arena) + q->cleanupCanvas(arena); +} diff --git a/sigencore/plugins/CanvasPlugin.h b/sigencore/plugins/CanvasPlugin.h new file mode 100644 index 00000000..47d49c7f --- /dev/null +++ b/sigencore/plugins/CanvasPlugin.h @@ -0,0 +1,72 @@ +/* + * Copyright 2009 Ben Boeckel <MathStuf@gmail.com> + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGENCOREINTERFACES_CANVASPLUGIN +#define SIGENCOREINTERFACES_CANVASPLUGIN + +// Plugin includes +#include "Global.h" + +// KDE includes +#include <KPluginFactory> + +// Qt includes +#include <QtCore/QStringList> +#include <QtCore/QVariantList> +#include <QtGui/QIcon> + +// Forward declarations +namespace Sigscript +{ +class Config; +} + +namespace Sigencore +{ +class Canvas; + +namespace Interfaces +{ +class SIGENCOREPLUGINS_EXPORT CanvasPlugin : public QObject +{ + Q_OBJECT + + public: + CanvasPlugin(QObject* parent, const QVariantList& args); + virtual ~CanvasPlugin(); + + Canvas* getCanvas(const QString& name, Sigscript::Config* parent); + + virtual QStringList canvases() const = 0; + virtual QString description(const QString& name) const = 0; + virtual QIcon icon(const QString& name) = 0; + protected: + virtual Canvas* createCanvas(const QString& name, Sigscript::Config* parent) = 0; + protected slots: + virtual void cleanupCanvas(Sigencore::Canvas* arena) = 0; + private: + class Private; + Private* const d; +}; +} +} + +#define SIGEN_CANVAS_PLUGIN(type, name) \ + K_PLUGIN_FACTORY(CanvasFactory, registerPlugin<type>();) \ + K_EXPORT_PLUGIN(CanvasFactory(name)) + +#endif diff --git a/sigencore/plugins/CanvasPlugin_p.h b/sigencore/plugins/CanvasPlugin_p.h new file mode 100644 index 00000000..81e15103 --- /dev/null +++ b/sigencore/plugins/CanvasPlugin_p.h @@ -0,0 +1,49 @@ +/* + * Copyright 2009 Ben Boeckel <MathStuf@gmail.com> + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SIGENCOREINTERFACES_CANVASPLUGIN_P +#define SIGENCOREINTERFACES_CANVASPLUGIN_P + +// Header include +#include "CanvasPlugin.h" + +// Forward declarations +class QSignalMapper; + +namespace Sigencore +{ +namespace Interfaces +{ +class SIGENCOREPLUGINS_NO_EXPORT CanvasPlugin::Private : public QObject +{ + Q_OBJECT + + public: + Private(CanvasPlugin* plugin, const QVariantList& args); + ~Private(); + + void addCanvas(Canvas* arena); + private: + CanvasPlugin* const q; + QSignalMapper* m_mapper; + private slots: + void cleanupCanvas(QObject* object); +}; +} +} + +#endif |