kivio

kivio_pluginmanager.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2003 Peter Simonsson
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#include "kivio_pluginmanager.h"
20
21#include <kdebug.h>
22#include <tdeparts/plugin.h>
23
24#include "kivio_plugin.h"
25
26namespace Kivio {
27 PluginManager::PluginManager(KivioView* parent, const char* name) : TQObject(parent, name)
28 {
29 m_activeTool = 0;
30 m_defaultTool = 0;
31 m_delegateEvents = true;
32 }
33
34 PluginManager::~PluginManager()
35 {
36 }
37
38 bool PluginManager::delegateEvent(TQEvent* e)
39 {
40 if(activeTool() && m_delegateEvents) {
41 return activeTool()->processEvent(e);
42 }
43
44 return false;
45 }
46
48 {
49 return m_activeTool;
50 }
51
53 {
54 return m_defaultTool;
55 }
56
58 {
59 if(defaultTool()) {
60 kdDebug(43000) << "Default tool activated! " << defaultTool()->name() << endl;
61 defaultTool()->setActivated(true);
62 }
63 }
64
66 {
67 if(tool != m_activeTool) {
68 if(m_activeTool) {
69 kdDebug(43000) << "Deactivate tool: " << m_activeTool->name() << endl;
70 m_activeTool->setActivated(false);
71 }
72
73 kdDebug(43000) << "Activate new tool: " << tool->name() << endl;
74 m_activeTool = tool;
75 }
76 }
77
79 {
80 m_defaultTool = tool;
81 kdDebug(43000) << "New default tool: " << tool->name() << endl;
82 }
83
84 Kivio::Plugin* PluginManager::findPlugin(const TQString& name)
85 {
86 TQPtrList<KParts::Plugin> plugins = KParts::Plugin::pluginObjects(parent());
87 KParts::Plugin* p = plugins.first();
88 bool found = false;
89
90 while(p && !found) {
91 if(p->name() == name) {
92 found = true;
93 } else {
94 p = plugins.next();
95 }
96 }
97
98 return static_cast<Kivio::Plugin*>(p);
99 }
100}
101
102#include "kivio_pluginmanager.moc"
Baseclass for mouse tools (like eg the select tool).
void activate(Kivio::MouseTool *tool)
Makes.
void setDefaultTool(Kivio::MouseTool *tool)
Make.
Kivio::MouseTool * activeTool()
Returns the tool that is in use.
Kivio::MouseTool * defaultTool()
Returns the default tool.
void activateDefaultTool()
Makes the default tool active.
This class provides the base for all plugins in Kivio.