#include "MyPlugin.h"
namespace Tinkercell
{
MyTool:: MyTool() : Tool(tr("My Great Tool"))
{
//initialize your variables
}
MyTool::~MyTool() { }
bool MyTool::setMainWindow(MainWindow * main)
{
Tool::setMainWindow(main);
if (mainWindow)
{
connect(mainWindow,SIGNAL(itemsSelected(GraphicsScene*, QList< QGraphicsItem* >&, QPointF, Qt::KeyboardModifiers)),
this,SLOT(itemsSelected(GraphicsScene*, QList < QGraphicsItem* >&, QPointF, Qt::KeyboardModifiers)));
connect(mainWindow,SIGNAL(itemsRemoved(GraphicsScene *, QList < QGraphicsItem* >&, QList < ItemHandle* >&)),
this,SLOT(itemsRemoved(GraphicsScene *, QList< QGraphicsItem* >&, QList< ItemHandle* >&)));
QDockWidget* dock = mainWindow->addDockingWindow(name,this,Qt::RightDockWidgetArea);
connectCollisionDetector();
connect(mainWindow,SIGNAL(pluginLoaded(const QString&)),this,SLOT(pluginLoaded(const QString&)));
return true;
}
return false;
}
void MyTool::pluginLoaded(const QString&)
{
connectCollisionDetector();
}
void MyTool::connectCollisionDetector()
{
static bool alreadyConnected = false;
if (alreadyConnected || !mainWindow) return;
if (mainWindow->tools.contains(tr("Collision Detection")))
{
QWidget * widget = mainWindow->tools[tr("Collision Detection")];
CollisionDetection * collisionDetection = static_cast < CollisionDetection* >(widget);
if (collisionDetection)
{
alreadyConnected = true;
connect(collisionDetection,SIGNAL(partCollided(QList < QGraphicsItem* >& , PartGraphicsItem * , QPointF , Qt::KeyboardModifiers )),
this, SLOT( partCollided(QList < QGraphicsItem* >& , PartGraphicsItem * , QPointF , Qt::KeyboardModifiers )));
}
}
}
void MyTool::itemsSelected(GraphicsScene * scene, QList < QGraphicsItem* >& items, QPointF , Qt::KeyboardModifiers )
{
if (!scene || items.isEmpty()) return;
//do something when items are selected
}
void MyTool::partCollided(QList < QGraphicsItem* >& movingItems, PartGraphicsItem * partHit, QPointF , Qt::KeyboardModifiers )
{
if (!mainWindow || !partHit) return;
GraphicsScene * scene = currentScene();
if (!scene) return;
ItemHandle * handle = getHandle(partHit);
//do something when two parts collide
}
void MyTool::itemsRemoved(GraphicsScene * scene, QList < QGraphicsItem* >&, QList< ItemHandle* >& handles)
{
if (!mainWindow || !scene) return;
//do something when items are removed
}
QSize MyTool::sizeHint() const
{
//set size of docking window
return QSize(100, 300);
}
}
extern "C" MY_EXPORT void loadTCTool(Tinkercell::MainWindow * main)
{
if (!main) return;
if (!main->tools.contains("My Great Tool"))
{
Tinkercell::MyTool * mytool = new Tinkercell:: MyTool ;
mytool->setMainWindow(main);
}
} //end namespace