Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/tselectionhandle.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/selection.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// TSelectionHandle
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSelectionHandle::TSelectionHandle()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_selectionStack.push_back(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSelectionHandle::~TSelectionHandle()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSelection *TSelectionHandle::getSelection() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_selectionStack.back();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSelectionHandle::setSelection(TSelection *selection)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (getSelection() == selection)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	TSelection *oldSelection = getSelection();
Toshihiro Shimizu 890ddd
	if (oldSelection) {
Toshihiro Shimizu 890ddd
		oldSelection->selectNone();
Toshihiro Shimizu 890ddd
		// disable selection related commands
Toshihiro Shimizu 890ddd
		CommandManager *commandManager = CommandManager::instance();
Toshihiro Shimizu 890ddd
		int i;
Toshihiro Shimizu 890ddd
		for (i = 0; i < (int)m_enabledCommandIds.size(); i++)
Toshihiro Shimizu 890ddd
			commandManager->setHandler(m_enabledCommandIds[i].c_str(), 0);
Toshihiro Shimizu 890ddd
		m_enabledCommandIds.clear();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	m_selectionStack.back() = selection;
Toshihiro Shimizu 890ddd
	if (selection)
Toshihiro Shimizu 890ddd
		selection->enableCommands();
Toshihiro Shimizu 890ddd
	emit selectionSwitched(oldSelection, selection);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSelectionHandle::pushSelection()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//NOTE
Toshihiro Shimizu 890ddd
	//  We push 0, and NOT a copy of the last item. I think this is done on purpose,
Toshihiro Shimizu 890ddd
	//  as having it copied and then selecting a different one invokes selectNone()
Toshihiro Shimizu 890ddd
	//  on the former.
Toshihiro Shimizu 890ddd
	m_selectionStack.push_back(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSelectionHandle::popSelection()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_selectionStack.size() > 1)
Toshihiro Shimizu 890ddd
		m_selectionStack.pop_back();
Toshihiro Shimizu 890ddd
	TSelection *selection = getSelection();
Toshihiro Shimizu 890ddd
	if (selection)
Toshihiro Shimizu 890ddd
		selection->enableCommands();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSelectionHandle::enableCommand(std::string cmdId, CommandHandlerInterface *handler)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	CommandManager::instance()->setHandler(cmdId.c_str(), handler);
Toshihiro Shimizu 890ddd
	m_enabledCommandIds.push_back(cmdId);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TSelectionHandle::notifySelectionChanged()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	emit selectionChanged(m_selectionStack.back());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TSelectionHandle *TSelectionHandle::getCurrent()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	static TSelectionHandle _currentSelection;
Toshihiro Shimizu 890ddd
	return &_currentSelection;
Toshihiro Shimizu 890ddd
}