plugin.h 4.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#ifndef _PLUGIN_H_
#define _PLUGIN_H_

#include <QtPlugin>

#include <iostream>
#include <list>

#include "window.h"
#include "system.h"
#include "view.h"
#include "camera.h"
#include "mapHandler.h"
#include "vboHandler.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
16
class Plugin : public QObject
17
{
18
	Q_OBJECT
19

20
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
21
	Plugin();
Pierre Kraemer's avatar
Pierre Kraemer committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35
	virtual ~Plugin();

	virtual bool enable() = 0;
	virtual void disable() = 0;

	const QString& getName() { return m_name; }
	void setName(const QString& name) { m_name = name; }

	const QString& getFilePath() { return m_filePath; }
	void setFilePath(const QString& f) { m_filePath = f; }

	Window* getWindow() { return m_window; }
	void setWindow(Window* w) { m_window = w; }

36
	bool getProvidesRendering() { return b_providesRendering; }
37 38 39 40 41 42
	void setProvidesRendering(bool b)
	{
		b_providesRendering = b;
		if(b_providesRendering)
			glewInit();
	}
43

44
	virtual void redraw(View* view) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
45

46 47 48 49 50 51 52 53 54 55
	virtual void keyPress(View* view, int key) = 0;
	virtual void keyRelease(View* view, int key) = 0;
	virtual void mousePress(View* view, int button, int x, int y) = 0;
	virtual void mouseRelease(View* view, int button, int x, int y) = 0;
//	virtual void mouseClick(View* view, int button, int x, int y) = 0;
	virtual void mouseMove(View* view, int buttons, int x, int y) = 0;
	virtual void wheelEvent(View* view, int delta, int x, int y) = 0;

	virtual void viewAdded(View* view) = 0;
	virtual void viewRemoved(View* view) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
56 57

	/*********************************************************
Pierre Kraemer's avatar
Pierre Kraemer committed
58
	 * MANAGE LINKED VIEWS
Pierre Kraemer's avatar
Pierre Kraemer committed
59 60
	 *********************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
61 62 63 64
	bool linkView(View* view);
	void unlinkView(View* view);
	bool isLinkedToView(View* view) { return l_views.contains(view); }
	QList<View*> getLinkedViews() { return l_views; }
Pierre Kraemer's avatar
Pierre Kraemer committed
65 66 67 68

	/*********************************************************
	 * MANAGE DOCK TABS
	 *********************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
69

Pierre Kraemer's avatar
Pierre Kraemer committed
70 71 72 73 74 75
	bool addTabInDock(QWidget* tabWidget, const QString& tabText);
	void removeTabInDock(QWidget* tabWidget);

	/*********************************************************
	 * MANAGE MENU ACTIONS
	 *********************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
76

Pierre Kraemer's avatar
Pierre Kraemer committed
77 78 79 80 81 82
	bool addMenuAction(const QString& menuPath, QAction* action);
	void removeMenuAction(QAction* action);

	/*********************************************************
	 * MANAGE TOOLBAR ACTIONS
	 *********************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
83

Pierre Kraemer's avatar
Pierre Kraemer committed
84 85
	bool addToolbarAction(QAction* action);
	void removeToolbarAction(QAction* action);
86

Pierre Kraemer's avatar
Pierre Kraemer committed
87 88 89 90
protected:
	QString m_name;
	QString m_filePath;
	Window* m_window;
91

92 93
	bool b_providesRendering;

Pierre Kraemer's avatar
Pierre Kraemer committed
94
	QList<View*> l_views;
Pierre Kraemer's avatar
Pierre Kraemer committed
95 96 97
	QList<QWidget*> l_tabWidgets;
	QList<QAction*> l_menuActions;
	QList<QAction*> l_toolbarActions;
98

99 100 101
public slots:
	void cb_viewRemoved(View* view);

Pierre Kraemer's avatar
Pierre Kraemer committed
102 103
//	QList<Plugin*> l_dependencies;
//	QList<Plugin*> l_dependantPlugins;
104

Pierre Kraemer's avatar
Pierre Kraemer committed
105
/*
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
	void addDependantPlugin(Plugin* p) { l_dependantPlugins.push_back(p); }
	void removeDependantPlugin(Plugin* p) { l_dependantPlugins.removeAll(p); }
	void removeAllDependantPlugins() { l_dependantPlugins.clear(); }
	bool hasDependantPlugins() { return !l_dependantPlugins.isEmpty(); }
	QStringList getDependantPluginNames()
	{
		QStringList l;
		for(QList<Plugin*>::iterator it = l_dependantPlugins.begin(); it != l_dependantPlugins.end(); ++it)
			l.push_back((*it)->getName());
		return l;
	}

	Plugin* addDependency(QString dependency)
	{
		Plugin* plugin;
		if((plugin = m_window->checkPluginDependency(dependency, this)))
		{
			l_dependencies.push_back(plugin);
			return plugin;
		}
		else
			return NULL;
	}

	template<typename T>
	T* getDependency(QString dependency)
	{
		return (T*)(this->addDependency(dependency));
	}

	virtual void removeDependencyLink(Plugin* p)
	{
		p->removeDependantPlugin(this);
		l_dependencies.removeAll(p);
	}
	virtual void removeAllDependencyLinks()
	{
		foreach(Plugin* p, l_dependencies)
			p->removeDependantPlugin(this);
		l_dependencies.clear();
	}
	void removeDependantLink(Plugin* p)
	{
		int i = l_dependantPlugins.indexOf(p);
		if(i >= 0)
			p->removeDependencyLink(this);
	}
	void removeAllDependantLinks()
	{
		foreach(Plugin* p, l_dependantPlugins)
			p->removeDependencyLink(this);
	}

	virtual void unloadDependantPlugins()
	{
		while(!l_dependantPlugins.empty())
		{
			if(l_dependantPlugins.back())
				m_window->unloadPlugin(l_dependantPlugins.back()->getName());
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
167
*/
168 169 170 171 172
};

Q_DECLARE_INTERFACE(Plugin, "Window.Plugin")

#endif