pluginsViewDialog.cpp 2.56 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
	setupUi(this);
	setWindowTitle(m_view->getName() + QString(" : plugins"));
24

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
	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);
		}
	}
}

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

75 76 77 78 79 80 81 82 83 84 85
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);
			b_refreshingUI = false;
		}
86 87 88
	}
}

89
void PluginsViewDialog::addPluginToList(Plugin* p)
90
{
91 92
	if(p->getProvidesRendering())
		pluginList->addItem(p->getName());
93 94
}

95
void PluginsViewDialog::removePluginFromList(Plugin* p)
96
{
97
	if(p->getProvidesRendering())
98
	{
99 100 101
		QList<QListWidgetItem*> items = pluginList->findItems(p->getName(), Qt::MatchExactly);
		if(!items.empty())
			delete items[0];
102 103
	}
}
Pierre Kraemer's avatar
Pierre Kraemer committed
104 105 106 107

} // namespace SCHNApps

} // namespace CGoGN