pluginsViewDialog.cpp 2.67 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
#include "dialogs/pluginsViewDialog.h"
2 3 4 5 6 7 8 9

#include "window.h"
#include "view.h"
#include "plugin.h"

#include <QMessageBox>
#include <QMouseEvent>

Pierre Kraemer's avatar
Pierre Kraemer committed
10 11 12 13 14 15
namespace CGoGN
{

namespace SCHNApps
{

16 17 18
PluginsViewDialog::PluginsViewDialog(Window* window, View* view) :
	QDialog(view),
	m_window(window),
19 20
	m_view(view),
	b_refreshingUI(false)
21 22 23 24
{
	this->setupUi(this);
	this->setWindowTitle(m_view->getName() + QString(" : plugins"));

25
	connect(pluginList, SIGNAL(itemSelectionChanged()), this, SLOT(selectedPluginsChanged()));
26

27 28
	connect(m_window, SIGNAL(pluginLoaded(Plugin*)), this, SLOT(addPluginToList(Plugin*)));
	connect(m_window, SIGNAL(pluginUnloaded(Plugin*)), this, SLOT(removePluginFromList(Plugin*)));
29

30 31 32
	connect(m_window, SIGNAL(viewAndPluginLinked(View*, Plugin*)), this, SLOT(selectPlugin(View*, Plugin*)));
	connect(m_window, SIGNAL(viewAndPluginUnlinked(View*, Plugin*)), this, SLOT(deselectPlugin(View*, Plugin*)));

33 34 35 36 37 38 39 40 41 42 43
	QList<Plugin*> plugins = m_window->getPluginsList();
	foreach(Plugin* p, plugins)
	{
		if(p->getProvidesRendering())
			pluginList->addItem(p->getName());
	}
}

PluginsViewDialog::~PluginsViewDialog()
{}

44
void PluginsViewDialog::selectedPluginsChanged()
45
{
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
	if(!b_refreshingUI)
	{
		for(int i = 0; i < pluginList->count(); ++i)
		{
			QString pluginName = pluginList->item(i)->text();
			Plugin* plugin = m_window->getPlugin(pluginName);
			if(pluginList->item(i)->isSelected() && !m_view->isLinkedToPlugin(plugin))
				m_window->linkViewAndPlugin(m_view, plugin);

			else if(!pluginList->item(i)->isSelected() && m_view->isLinkedToPlugin(plugin))
				m_window->unlinkViewAndPlugin(m_view, plugin);
		}
		m_view->updateGL();
	}
}

void PluginsViewDialog::selectPlugin(View* view, Plugin* plugin)
{
	if(view == m_view)
65
	{
66 67 68 69 70 71 72 73 74 75
		QList<QListWidgetItem*> items = pluginList->findItems(plugin->getName(), Qt::MatchExactly);
		if(!items.empty())
		{
			b_refreshingUI = true;
			items[0]->setSelected(true);
			m_view->updateGL();
			b_refreshingUI = false;
		}
	}
}
76

77 78 79 80 81 82 83 84 85 86 87 88
void PluginsViewDialog::deselectPlugin(View* view, Plugin* plugin)
{
	if(view == m_view)
	{
		QList<QListWidgetItem*> items = pluginList->findItems(plugin->getName(), Qt::MatchExactly);
		if(!items.empty())
		{
			b_refreshingUI = true;
			items[0]->setSelected(false);
			m_view->updateGL();
			b_refreshingUI = false;
		}
89 90 91
	}
}

92
void PluginsViewDialog::addPluginToList(Plugin* p)
93
{
94 95
	if(p->getProvidesRendering())
		pluginList->addItem(p->getName());
96 97
}

98
void PluginsViewDialog::removePluginFromList(Plugin* p)
99
{
100
	if(p->getProvidesRendering())
101
	{
102
		for(int i = 0; i < pluginList->count(); ++i)
103
		{
104 105 106 107 108
			if(pluginList->item(i)->text() == p->getName())
			{
				delete pluginList->item(i);
				return;
			}
109 110 111
		}
	}
}
Pierre Kraemer's avatar
Pierre Kraemer committed
112 113 114 115

} // namespace SCHNApps

} // namespace CGoGN