kivio
kivio_pluginmanager.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kivio_pluginmanager.h"
00020
00021 #include <kdebug.h>
00022 #include <kparts/plugin.h>
00023
00024 #include "kivio_plugin.h"
00025
00026 namespace Kivio {
00027 PluginManager::PluginManager(KivioView* parent, const char* name) : QObject(parent, name)
00028 {
00029 m_activeTool = 0;
00030 m_defaultTool = 0;
00031 m_delegateEvents = true;
00032 }
00033
00034 PluginManager::~PluginManager()
00035 {
00036 }
00037
00038 bool PluginManager::delegateEvent(QEvent* e)
00039 {
00040 if(activeTool() && m_delegateEvents) {
00041 return activeTool()->processEvent(e);
00042 }
00043
00044 return false;
00045 }
00046
00047 Kivio::MouseTool* PluginManager::activeTool()
00048 {
00049 return m_activeTool;
00050 }
00051
00052 Kivio::MouseTool* PluginManager::defaultTool()
00053 {
00054 return m_defaultTool;
00055 }
00056
00057 void PluginManager::activateDefaultTool()
00058 {
00059 if(defaultTool()) {
00060 kdDebug(43000) << "Default tool activated! " << defaultTool()->name() << endl;
00061 defaultTool()->setActivated(true);
00062 }
00063 }
00064
00065 void PluginManager::activate(Kivio::MouseTool* tool)
00066 {
00067 if(tool != m_activeTool) {
00068 if(m_activeTool) {
00069 kdDebug(43000) << "Deactivate tool: " << m_activeTool->name() << endl;
00070 m_activeTool->setActivated(false);
00071 }
00072
00073 kdDebug(43000) << "Activate new tool: " << tool->name() << endl;
00074 m_activeTool = tool;
00075 }
00076 }
00077
00078 void PluginManager::setDefaultTool(Kivio::MouseTool* tool)
00079 {
00080 m_defaultTool = tool;
00081 kdDebug(43000) << "New default tool: " << tool->name() << endl;
00082 }
00083
00084 Kivio::Plugin* PluginManager::findPlugin(const QString& name)
00085 {
00086 QPtrList<KParts::Plugin> plugins = KParts::Plugin::pluginObjects(parent());
00087 KParts::Plugin* p = plugins.first();
00088 bool found = false;
00089
00090 while(p && !found) {
00091 if(p->name() == name) {
00092 found = true;
00093 } else {
00094 p = plugins.next();
00095 }
00096 }
00097
00098 return static_cast<Kivio::Plugin*>(p);
00099 }
00100 }
00101
00102 #include "kivio_pluginmanager.moc"
|