controlDock_pluginTab.cpp 5.5 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include "controlDock_pluginTab.h"

#include <QFileDialog>

#include "schnapps.h"
#include "plugin.h"
#include "plugin_interaction.h"
#include "plugin_processing.h"
#include "view.h"

namespace CGoGN
{

namespace SCHNApps
{

ControlDock_PluginTab::ControlDock_PluginTab(SCHNApps* s) :
	m_schnapps(s),
	b_updatingUI(false)
{
	setupUi(this);

	button_enablePlugins->setIcon(QIcon(":icons/icons/arrow_down.png"));
	button_disablePlugins->setIcon(QIcon(":icons/icons/arrow_up.png"));

	connect(button_addPluginDirectory, SIGNAL(clicked()), this, SLOT(addPluginDirectoryClicked()));
	connect(button_enablePlugins, SIGNAL(clicked()), this, SLOT(enableSelectedPluginsClicked()));
	connect(button_disablePlugins, SIGNAL(clicked()), this, SLOT(disableSelectedPluginsClicked()));
Sylvain Thery's avatar
Sylvain Thery committed
29
//	connect(list_pluginsEnabled, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(pluginCheckStateChanged(QListWidgetItem*)));
Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32 33

	connect(m_schnapps, SIGNAL(pluginAvailableAdded(QString)), this, SLOT(pluginAvailableAdded(QString)));
	connect(m_schnapps, SIGNAL(pluginEnabled(Plugin*)), this, SLOT(pluginEnabled(Plugin*)));
	connect(m_schnapps, SIGNAL(pluginDisabled(Plugin*)), this, SLOT(pluginDisabled(Plugin*)));
Sylvain Thery's avatar
Sylvain Thery committed
34
//	connect(m_schnapps, SIGNAL(selectedViewChanged(View*,View*)), this, SLOT(selectedViewChanged(View*,View*)));
Pierre Kraemer's avatar
Pierre Kraemer committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
}





void ControlDock_PluginTab::addPluginDirectoryClicked()
{
	if(!b_updatingUI)
	{
		QString dir = QFileDialog::getExistingDirectory(
			this,
			tr("Select a directory"),
			m_schnapps->getAppPath(),
			QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
		);

		if (!dir.isEmpty())
			m_schnapps->registerPluginsDirectory(dir);
	}
}

void ControlDock_PluginTab::enableSelectedPluginsClicked()
{
	if(!b_updatingUI)
	{
		QList<QListWidgetItem*> items = list_pluginsAvailable->selectedItems();
		foreach(QListWidgetItem* item, items)
			m_schnapps->enablePlugin(item->text());
	}
}

void ControlDock_PluginTab::disableSelectedPluginsClicked()
{
	if(!b_updatingUI)
	{
		QList<QListWidgetItem*> items = list_pluginsEnabled->selectedItems();
		foreach(QListWidgetItem* item, items)
			m_schnapps->disablePlugin(item->text());
	}
}

Sylvain Thery's avatar
Sylvain Thery committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
//void ControlDock_PluginTab::pluginCheckStateChanged(QListWidgetItem *item)
//{
//	if(!b_updatingUI)
//	{
//		View* selectedView = m_schnapps->getSelectedView();
//		PluginInteraction* p = dynamic_cast<PluginInteraction*>(m_schnapps->getPlugin(item->text()));
//		if(p)
//		{
//			if(item->checkState() == Qt::Checked)
//				selectedView->linkPlugin(p);
//			else
//				selectedView->unlinkPlugin(p);
//		}
//	}
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111





void ControlDock_PluginTab::pluginAvailableAdded(QString name)
{
	b_updatingUI = true;
	list_pluginsAvailable->addItem(name);
	b_updatingUI = false;
}

void ControlDock_PluginTab::pluginEnabled(Plugin *plugin)
{
	b_updatingUI = true;
	const QString& pluginName = plugin->getName();
	QList<QListWidgetItem*> av = list_pluginsAvailable->findItems(pluginName, Qt::MatchExactly);
	if(!av.empty())
		delete av[0];

Thery Sylvain's avatar
Thery Sylvain committed
112 113
//	QListWidgetItem* item = new QListWidgetItem(pluginName, list_pluginsEnabled);
	new QListWidgetItem(pluginName, list_pluginsEnabled);
Pierre Kraemer's avatar
Pierre Kraemer committed
114 115

	// only interaction plugins are checkable (i.e. can be associated to a view)
Sylvain Thery's avatar
Sylvain Thery committed
116 117 118
//	PluginInteraction* p = dynamic_cast<PluginInteraction*>(plugin);
//	if(p)
//		item->setCheckState(Qt::Unchecked);
Pierre Kraemer's avatar
Pierre Kraemer committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132
	b_updatingUI = false;
}

void ControlDock_PluginTab::pluginDisabled(Plugin *plugin)
{
	b_updatingUI = true;
	const QString& pluginName = plugin->getName();
	QList<QListWidgetItem*> av = list_pluginsEnabled->findItems(pluginName, Qt::MatchExactly);
	if(!av.empty())
		delete av[0];
	list_pluginsAvailable->addItem(pluginName);
	b_updatingUI = false;
}

Sylvain Thery's avatar
Sylvain Thery committed
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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
//void ControlDock_PluginTab::selectedViewChanged(View* prev, View* cur)
//{
//	if(prev)
//	{
//		foreach(PluginInteraction* pi, prev->getLinkedPlugins())
//		{
//			QList<QListWidgetItem*> prevItems = list_pluginsEnabled->findItems(pi->getName(), Qt::MatchExactly);
//			if(!prevItems.empty())
//			{
//				b_updatingUI = true;
//				prevItems[0]->setCheckState(Qt::Unchecked);
//				b_updatingUI = false;
//			}
//		}

//		disconnect(prev, SIGNAL(pluginLinked(PluginInteraction*)), this, SLOT(selectedViewPluginLinked(PluginInteraction*)));
//		disconnect(prev, SIGNAL(pluginUnlinked(PluginInteraction*)), this, SLOT(selectedViewPluginUnlinked(PluginInteraction*)));
//	}
//	if(cur)
//	{
//		foreach(PluginInteraction* pi, cur->getLinkedPlugins())
//		{
//			QList<QListWidgetItem*> curItems = list_pluginsEnabled->findItems(pi->getName(), Qt::MatchExactly);
//			if(!curItems.empty())
//			{
//				b_updatingUI = true;
//				curItems[0]->setCheckState(Qt::Checked);
//				b_updatingUI = false;
//			}
//		}

//		connect(cur, SIGNAL(pluginLinked(PluginInteraction*)), this, SLOT(selectedViewPluginLinked(PluginInteraction*)));
//		connect(cur, SIGNAL(pluginUnlinked(PluginInteraction*)), this, SLOT(selectedViewPluginUnlinked(PluginInteraction*)));
//	}
//}





//void ControlDock_PluginTab::selectedViewPluginLinked(PluginInteraction* plugin)
//{
//	QList<QListWidgetItem*> curItems = list_pluginsEnabled->findItems(plugin->getName(), Qt::MatchExactly);
//	if(!curItems.empty())
//	{
//		b_updatingUI = true;
//		curItems[0]->setCheckState(Qt::Checked);
//		b_updatingUI = false;
//	}
//}

//void ControlDock_PluginTab::selectedViewPluginUnlinked(PluginInteraction* plugin)
//{
//	QList<QListWidgetItem*> prevItems = list_pluginsEnabled->findItems(plugin->getName(), Qt::MatchExactly);
//	if(!prevItems.empty())
//	{
//		b_updatingUI = true;
//		prevItems[0]->setCheckState(Qt::Unchecked);
//		b_updatingUI = false;
//	}
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
194 195 196 197

} // namespace SCHNApps

} // namespace CGoGN