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