|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/menubarcommand.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "menubarcommandids.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/dvdialog.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/gutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/toonzfolders.h"
|
|
Toshihiro Shimizu |
890ddd |
#include <assert.h></assert.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <qobject></qobject>
|
|
Toshihiro Shimizu |
890ddd |
#include <qaction></qaction>
|
|
Toshihiro Shimizu |
890ddd |
#include <qsettings></qsettings>
|
|
Toshihiro Shimizu |
890ddd |
#include <qkeysequence></qkeysequence>
|
|
Toshihiro Shimizu |
890ddd |
#include <qapplication></qapplication>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <sys types.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace DVGui;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void updateToolTip(QAction *action)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString tooltip = action->text();
|
|
Toshihiro Shimizu |
890ddd |
QString shortcut = action->shortcut().toString();
|
|
Toshihiro Shimizu |
890ddd |
if (shortcut != "")
|
|
Toshihiro Shimizu |
890ddd |
tooltip += " (" + shortcut + ")";
|
|
Toshihiro Shimizu |
890ddd |
action->setToolTip(tooltip);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
AuxActionsCreator::AuxActionsCreator()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
AuxActionsCreatorManager::instance()->addAuxActionsCreator(this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
AuxActionsCreatorManager::AuxActionsCreatorManager()
|
|
Toshihiro Shimizu |
890ddd |
: m_auxActionsCreated(false)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
AuxActionsCreatorManager *AuxActionsCreatorManager::instance()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static AuxActionsCreatorManager _instance;
|
|
Toshihiro Shimizu |
890ddd |
return &_instance;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void AuxActionsCreatorManager::addAuxActionsCreator(AuxActionsCreator *auxActionsCreator)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_auxActionsCreators.push_back(auxActionsCreator);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void AuxActionsCreatorManager::createAuxActions(QObject *parent)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_auxActionsCreated)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
m_auxActionsCreated = true;
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < (int)m_auxActionsCreators.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
m_auxActionsCreators[i]->createActions(parent);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=========================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CommandManager::CommandManager()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CommandManager::~CommandManager()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<std::string, *="" node="">::iterator it;</std::string,>
|
|
Toshihiro Shimizu |
890ddd |
for (it = m_idTable.begin(); it != m_idTable.end(); ++it)
|
|
Toshihiro Shimizu |
890ddd |
delete it->second;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CommandManager *CommandManager::instance()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
static CommandManager _instance;
|
|
Toshihiro Shimizu |
890ddd |
return &_instance;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// command id => command
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
CommandManager::Node *CommandManager::getNode(CommandId id, bool createIfNeeded)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
AuxActionsCreatorManager::instance()->createAuxActions(qApp);
|
|
Toshihiro Shimizu |
890ddd |
std::map<std::string, *="" node="">::iterator it = m_idTable.find(id);</std::string,>
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_idTable.end())
|
|
Toshihiro Shimizu |
890ddd |
return it->second;
|
|
Toshihiro Shimizu |
890ddd |
if (createIfNeeded) {
|
|
Toshihiro Shimizu |
890ddd |
Node *node = new Node(id);
|
|
Toshihiro Shimizu |
890ddd |
m_idTable[id] = node;
|
|
Toshihiro Shimizu |
890ddd |
return node;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CommandManager::setShortcut(CommandId id, QAction *action, std::string shortcutString)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (shortcutString != "")
|
|
Toshihiro Shimizu |
890ddd |
action->setShortcut(QKeySequence(QString::fromStdString(shortcutString)));
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
action->setShortcut(QKeySequence());
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp = ToonzFolder::getMyModuleDir() + TFilePath("shortcuts.ini");
|
|
Toshihiro Shimizu |
890ddd |
QSettings settings(toQString(fp), QSettings::IniFormat);
|
|
Toshihiro Shimizu |
890ddd |
settings.beginGroup("shortcuts");
|
|
Toshihiro Shimizu |
890ddd |
settings.setValue(QString(id), QString::fromStdString(shortcutString));
|
|
Toshihiro Shimizu |
890ddd |
settings.endGroup();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CommandManager::define(
|
|
Toshihiro Shimizu |
890ddd |
CommandId id,
|
|
Toshihiro Shimizu |
890ddd |
CommandType type,
|
|
Toshihiro Shimizu |
890ddd |
std::string defaultShortcutString,
|
|
Toshihiro Shimizu |
890ddd |
QAction *qaction)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(type != UndefinedCommandType);
|
|
Toshihiro Shimizu |
890ddd |
assert(qaction != 0);
|
|
Toshihiro Shimizu |
890ddd |
assert(m_qactionTable.count(qaction) == 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Node *node = getNode(id);
|
|
Toshihiro Shimizu |
890ddd |
if (node->m_type != UndefinedCommandType) {
|
|
Toshihiro Shimizu |
890ddd |
assert(!"Duplicate command id");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
node->m_type = type;
|
|
Toshihiro Shimizu |
890ddd |
node->m_qaction = qaction;
|
|
Toshihiro Shimizu |
890ddd |
node->m_qaction->setEnabled(
|
|
Toshihiro Shimizu |
890ddd |
node->m_enabled && (!!node->m_handler || node->m_qaction->actionGroup() != 0) ||
|
|
Toshihiro Shimizu |
890ddd |
node->m_type == MiscCommandType || node->m_type == ToolModifierCommandType);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_qactionTable[qaction] = node;
|
|
Toshihiro Shimizu |
890ddd |
qaction->setShortcutContext(Qt::ApplicationShortcut);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp = ToonzFolder::getModuleFile("shortcuts.ini");
|
|
Toshihiro Shimizu |
890ddd |
QSettings settings(toQString(fp), QSettings::IniFormat);
|
|
Toshihiro Shimizu |
890ddd |
settings.beginGroup("shortcuts");
|
|
Toshihiro Shimizu |
890ddd |
QString defaultShortcutQString = QString::fromStdString(defaultShortcutString);
|
|
Toshihiro Shimizu |
890ddd |
QString shortcutString = settings.value(id).toString();
|
|
Toshihiro Shimizu |
890ddd |
settings.endGroup();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (shortcutString != "") {
|
|
Toshihiro Shimizu |
890ddd |
// shortcut definito dall'utente. potrebbe essere stato assegnato come shortcut di default
|
|
Toshihiro Shimizu |
890ddd |
// a qualche altro comando
|
|
Toshihiro Shimizu |
890ddd |
QAction *other = getActionFromShortcut(shortcutString.toStdString());
|
|
Toshihiro Shimizu |
890ddd |
if (other)
|
|
Toshihiro Shimizu |
890ddd |
other->setShortcut(QKeySequence());
|
|
Toshihiro Shimizu |
890ddd |
} else if (defaultShortcutQString != "") {
|
|
Toshihiro Shimizu |
890ddd |
// shortcut di default. se e' gia' stato assegnato non lo assegno
|
|
Toshihiro Shimizu |
890ddd |
QAction *other = getActionFromShortcut(defaultShortcutQString.toStdString());
|
|
Toshihiro Shimizu |
890ddd |
if (!other)
|
|
Toshihiro Shimizu |
890ddd |
shortcutString = defaultShortcutQString;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (shortcutString != "") {
|
|
Toshihiro Shimizu |
890ddd |
qaction->setShortcut(QKeySequence(shortcutString));
|
|
Toshihiro Shimizu |
890ddd |
m_shortcutTable[shortcutString.toStdString()] = node;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (type == ToolCommandType)
|
|
Toshihiro Shimizu |
890ddd |
updateToolTip(qaction);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// set handler (id, handler)
|
|
Toshihiro Shimizu |
890ddd |
// possibly changes enable/disable qaction state
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
void CommandManager::setHandler(CommandId id, CommandHandlerInterface *handler)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Node *node = getNode(id);
|
|
Toshihiro Shimizu |
890ddd |
if (node->m_handler != handler) {
|
|
Toshihiro Shimizu |
890ddd |
delete node->m_handler;
|
|
Toshihiro Shimizu |
890ddd |
node->m_handler = handler;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (node->m_qaction) {
|
|
Toshihiro Shimizu |
890ddd |
node->m_qaction->setEnabled(node->m_enabled && (!!node->m_handler || node->m_qaction->actionGroup() != 0));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// qaction -> command; execute
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CommandManager::execute(QAction *qaction)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(qaction);
|
|
Toshihiro Shimizu |
890ddd |
std::map<qaction *="" *,="" node="">::iterator it = m_qactionTable.find(qaction);</qaction>
|
|
Toshihiro Shimizu |
890ddd |
assert(it != m_qactionTable.end());
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_qactionTable.end() && it->second->m_handler) {
|
|
Toshihiro Shimizu |
890ddd |
it->second->m_handler->execute();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CommandManager::execute(QAction *action, QAction *menuAction)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<qaction *="" *,="" node="">::iterator it = m_qactionTable.find(action);</qaction>
|
|
Toshihiro Shimizu |
890ddd |
if (it != m_qactionTable.end())
|
|
Toshihiro Shimizu |
890ddd |
execute(action);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
execute(menuAction);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CommandManager::execute(CommandId id)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Node *node = getNode(id, false);
|
|
Toshihiro Shimizu |
890ddd |
if (node && node->m_handler) {
|
|
Toshihiro Shimizu |
890ddd |
QAction *action = node->m_qaction;
|
|
Toshihiro Shimizu |
890ddd |
if (action && action->isCheckable()) {
|
|
Toshihiro Shimizu |
890ddd |
// principalmente per i tool
|
|
Toshihiro Shimizu |
890ddd |
action->setChecked(true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
node->m_handler->execute();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CommandManager::getActions(CommandType type, std::vector<qaction *=""> &actions)</qaction>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
AuxActionsCreatorManager::instance()->createAuxActions(qApp);
|
|
Toshihiro Shimizu |
890ddd |
std::map<qaction *="" *,="" node="">::iterator it;</qaction>
|
|
Toshihiro Shimizu |
890ddd |
for (it = m_qactionTable.begin(); it != m_qactionTable.end(); ++it)
|
|
Toshihiro Shimizu |
890ddd |
if (it->second->m_type == type)
|
|
Toshihiro Shimizu |
890ddd |
actions.push_back(it->first);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QAction *CommandManager::getActionFromShortcut(std::string shortcutString)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<std::string, *="" node="">::iterator it = m_shortcutTable.find(shortcutString);</std::string,>
|
|
Toshihiro Shimizu |
890ddd |
return it != m_shortcutTable.end() ? it->second->m_qaction : 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::string CommandManager::getShortcutFromAction(QAction *action)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<std::string, *="" node="">::iterator it = m_shortcutTable.begin();</std::string,>
|
|
Toshihiro Shimizu |
890ddd |
for (; it != m_shortcutTable.end(); ++it) {
|
|
Toshihiro Shimizu |
890ddd |
if (it->second->m_qaction == action)
|
|
Toshihiro Shimizu |
890ddd |
return it->first;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return "";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::string CommandManager::getShortcutFromId(const char *id)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QAction *action = getAction(id);
|
|
Toshihiro Shimizu |
890ddd |
assert(action);
|
|
Toshihiro Shimizu |
890ddd |
if (!action)
|
|
Toshihiro Shimizu |
890ddd |
return "";
|
|
Toshihiro Shimizu |
890ddd |
return getShortcutFromAction(action);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int CommandManager::getKeyFromShortcut(const std::string &shortcut)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString qShortcut = QString::fromStdString(shortcut);
|
|
Toshihiro Shimizu |
890ddd |
if (qShortcut == "")
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QKeySequence ks(qShortcut);
|
|
Toshihiro Shimizu |
890ddd |
assert(ks.count() == 1);
|
|
Toshihiro Shimizu |
890ddd |
return ks[0];
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int CommandManager::getKeyFromId(const char *id)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return getKeyFromShortcut(getShortcutFromId(id));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CommandManager::setShortcut(QAction *action, std::string shortcutString)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString shortcut = QString::fromStdString(shortcutString);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::string oldShortcutString = action->shortcut().toString().toStdString();
|
|
Toshihiro Shimizu |
890ddd |
if (oldShortcutString == shortcutString)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Cerco il nodo corrispondente ad action. Deve esistere
|
|
Toshihiro Shimizu |
890ddd |
std::map<qaction *="" *,="" node="">::iterator it = m_qactionTable.find(action);</qaction>
|
|
Toshihiro Shimizu |
890ddd |
Node *node = it != m_qactionTable.end() ? it->second : 0;
|
|
Toshihiro Shimizu |
890ddd |
assert(node);
|
|
Toshihiro Shimizu |
890ddd |
assert(node->m_qaction == action);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QKeySequence ks(shortcut);
|
|
Toshihiro Shimizu |
890ddd |
assert(ks.count() == 1 || ks.count() == 0 && shortcut == "");
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (node->m_type == ZoomCommandType && ks.count() > 1) {
|
|
Toshihiro Shimizu |
890ddd |
MsgBox(WARNING, QObject::tr("It is not possible to assing a shortcut with modifiers to the visualization commands."));
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
// lo shortcut e' gia' assegnato?
|
|
Toshihiro Shimizu |
890ddd |
QString oldActionId;
|
|
Toshihiro Shimizu |
890ddd |
std::map<std::string, *="" node="">::iterator sit = m_shortcutTable.find(shortcutString);</std::string,>
|
|
Toshihiro Shimizu |
890ddd |
if (sit != m_shortcutTable.end()) {
|
|
Toshihiro Shimizu |
890ddd |
// la vecchia azione non ha piu' shortcut
|
|
Toshihiro Shimizu |
890ddd |
oldActionId = QString::fromStdString(sit->second->m_id);
|
|
Toshihiro Shimizu |
890ddd |
sit->second->m_qaction->setShortcut(QKeySequence());
|
|
Toshihiro Shimizu |
890ddd |
if (sit->second->m_type == ToolCommandType)
|
|
Toshihiro Shimizu |
890ddd |
updateToolTip(sit->second->m_qaction);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
// assegno lo shortcut all'azione
|
|
Toshihiro Shimizu |
890ddd |
action->setShortcut(QKeySequence::fromString(QString::fromStdString(shortcutString)));
|
|
Toshihiro Shimizu |
890ddd |
if (node->m_type == ToolCommandType)
|
|
Toshihiro Shimizu |
890ddd |
updateToolTip(action);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Aggiorno la tabella shortcut -> azioni
|
|
Toshihiro Shimizu |
890ddd |
// Cancello il riferimento all'eventuale vecchio shortcut di action
|
|
Toshihiro Shimizu |
890ddd |
if (oldShortcutString != "")
|
|
Toshihiro Shimizu |
890ddd |
m_shortcutTable.erase(oldShortcutString);
|
|
Toshihiro Shimizu |
890ddd |
// e aggiungo il nuovo legame
|
|
Toshihiro Shimizu |
890ddd |
m_shortcutTable[shortcutString] = node;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// registro il tutto
|
|
Toshihiro Shimizu |
890ddd |
TFilePath fp = ToonzFolder::getMyModuleDir() + TFilePath("shortcuts.ini");
|
|
Toshihiro Shimizu |
890ddd |
QSettings settings(toQString(fp), QSettings::IniFormat);
|
|
Toshihiro Shimizu |
890ddd |
settings.beginGroup("shortcuts");
|
|
Toshihiro Shimizu |
890ddd |
settings.setValue(
|
|
Toshihiro Shimizu |
890ddd |
QString::fromStdString(node->m_id),
|
|
Toshihiro Shimizu |
890ddd |
QString::fromStdString(shortcutString));
|
|
Toshihiro Shimizu |
890ddd |
if (oldActionId != "")
|
|
Toshihiro Shimizu |
890ddd |
settings.remove(oldActionId);
|
|
Toshihiro Shimizu |
890ddd |
settings.endGroup();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CommandManager::enable(CommandId id, bool enabled)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Node *node = getNode(id, false);
|
|
Toshihiro Shimizu |
890ddd |
if (!node)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
if (node->m_enabled == enabled)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
node->m_enabled = enabled;
|
|
Toshihiro Shimizu |
890ddd |
if (node->m_qaction)
|
|
Toshihiro Shimizu |
890ddd |
node->m_qaction->setEnabled(
|
|
Toshihiro Shimizu |
890ddd |
node->m_enabled && (!!node->m_handler || node->m_qaction->actionGroup() != 0));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CommandManager::setChecked(CommandId id, bool checked)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Node *node = getNode(id, false);
|
|
Toshihiro Shimizu |
890ddd |
if (!node)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
if (node->m_qaction) {
|
|
Toshihiro Shimizu |
890ddd |
node->m_qaction->setChecked(checked);
|
|
Toshihiro Shimizu |
890ddd |
if (node->m_handler)
|
|
Toshihiro Shimizu |
890ddd |
node->m_handler->execute();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QAction *CommandManager::getAction(CommandId id, bool createIfNeeded)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Node *node = getNode(id, createIfNeeded);
|
|
Toshihiro Shimizu |
890ddd |
if (node) {
|
|
Toshihiro Shimizu |
890ddd |
return node->m_qaction;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QAction *CommandManager::createAction(CommandId id, QObject *parent, bool state)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Node *node = getNode(id, false);
|
|
Toshihiro Shimizu |
890ddd |
if (!node)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
QAction *refAction = node->m_qaction;
|
|
Toshihiro Shimizu |
890ddd |
if (!refAction)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
QString text = refAction->text();
|
|
Toshihiro Shimizu |
890ddd |
if (node->m_onText != "" && node->m_offText != "")
|
|
Toshihiro Shimizu |
890ddd |
text = state ? node->m_onText : node->m_offText;
|
|
Toshihiro Shimizu |
890ddd |
QAction *action = new QAction(text, parent);
|
|
Toshihiro Shimizu |
890ddd |
action->setShortcut(refAction->shortcut());
|
|
Toshihiro Shimizu |
890ddd |
return action;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void CommandManager::setToggleTexts(CommandId id, const QString &onText, const QString &offText)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Node *node = getNode(id, false);
|
|
Toshihiro Shimizu |
890ddd |
if (node) {
|
|
Toshihiro Shimizu |
890ddd |
node->m_onText = onText;
|
|
Toshihiro Shimizu |
890ddd |
node->m_offText = offText;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun_iwasawa |
dde155 |
//---------------------------------------------------------
|
|
shun_iwasawa |
dde155 |
|
|
shun_iwasawa |
dde155 |
std::string CommandManager::getIdFromAction(QAction* action)
|
|
shun_iwasawa |
dde155 |
{
|
|
shun_iwasawa |
dde155 |
std::map<qaction *="" *,="" node="">::iterator it = m_qactionTable.find(action);</qaction>
|
|
shun_iwasawa |
dde155 |
if (it != m_qactionTable.end())
|
|
shun_iwasawa |
dde155 |
return it->second->m_id;
|
|
shun_iwasawa |
dde155 |
else
|
|
shun_iwasawa |
dde155 |
return "";
|
|
shun_iwasawa |
dde155 |
}
|
|
shun_iwasawa |
dde155 |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QString CommandManager::getFullText(CommandId id, bool state)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::map<std::string, node*="">::iterator it;</std::string,>
|
|
Toshihiro Shimizu |
890ddd |
it = m_idTable.find(id);
|
|
Toshihiro Shimizu |
890ddd |
if(it == m_idTable.end()) return "";
|
|
Toshihiro Shimizu |
890ddd |
Node *node = it->second;
|
|
Toshihiro Shimizu |
890ddd |
QAction *action = it->second->m_qaction;
|
|
Toshihiro Shimizu |
890ddd |
QString text = action->text();
|
|
Toshihiro Shimizu |
890ddd |
if(node->m_onText != "" && node->m_offText != "")
|
|
Toshihiro Shimizu |
890ddd |
text = state ? node->m_onText : node->m_offText;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QString shortcut = QString::fromStdString(getShortcutFromAction(action));
|
|
Toshihiro Shimizu |
890ddd |
if(shortcut != "") text += " " + shortcut;
|
|
Toshihiro Shimizu |
890ddd |
return text;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
MenuItemHandler::MenuItemHandler(const char *cmdId)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
CommandManager::instance()->setHandler(cmdId,
|
|
Toshihiro Shimizu |
890ddd |
new CommandHandlerHelper<menuitemhandler>(this, &MenuItemHandler::execute));</menuitemhandler>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// DVAction
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DVAction::DVAction(const QString &text, QObject *parent)
|
|
Toshihiro Shimizu |
890ddd |
: QAction(text, parent)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
connect(this, SIGNAL(triggered()), this, SLOT(onTriggered()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DVAction::DVAction(const QIcon &icon, const QString &text, QObject *parent)
|
|
Toshihiro Shimizu |
890ddd |
: QAction(icon, text, parent)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
connect(this, SIGNAL(triggered()), this, SLOT(onTriggered()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void DVAction::onTriggered()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
CommandManager::instance()->execute(this);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// DVMenuAction
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! It is a menu' with action defined in \b actions.
|
|
Toshihiro Shimizu |
890ddd |
Actions can contain CommandId or simple action name.
|
|
Toshihiro Shimizu |
890ddd |
In first case action triggered is connected with action command execute directly.
|
|
Toshihiro Shimizu |
890ddd |
In second case action triggered is connected with menu action command execute;
|
|
Toshihiro Shimizu |
890ddd |
is helpful to use \b m_triggeredActionIndex to distingue action.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
DVMenuAction::DVMenuAction(const QString &text, QWidget *parent, QList<qstring> actions)</qstring>
|
|
Toshihiro Shimizu |
890ddd |
: QMenu(text, parent), m_triggeredActionIndex(-1)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < actions.size(); i++)
|
|
Toshihiro Shimizu |
890ddd |
addAction(actions.at(i));
|
|
Toshihiro Shimizu |
890ddd |
connect(this, SIGNAL(triggered(QAction *)), this, SLOT(onTriggered(QAction *)));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! Set a new list of action to menu'.
|
|
Toshihiro Shimizu |
890ddd |
NB. If action list is composed by action menaged and action to create pay
|
|
Toshihiro Shimizu |
890ddd |
attention to inserted order.*/
|
|
Toshihiro Shimizu |
890ddd |
void DVMenuAction::setActions(QList<qstring> actions)</qstring>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_triggeredActionIndex != -1) //Sta facendo l'onTriggered
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
clear();
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i < actions.size(); i++) {
|
|
Toshihiro Shimizu |
890ddd |
QString actionId = actions.at(i);
|
|
Toshihiro Shimizu |
890ddd |
//Se l'azione e' definita da un CommandId la aggiungo.
|
|
Toshihiro Shimizu |
890ddd |
QAction *action = CommandManager::instance()->getAction(actionId.toStdString().c_str());
|
|
Toshihiro Shimizu |
890ddd |
if (action) {
|
|
Toshihiro Shimizu |
890ddd |
addAction(action);
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//Altrimenti creo una nuova azione e la aggiungo.
|
|
Toshihiro Shimizu |
890ddd |
action = addAction(actionId);
|
|
Toshihiro Shimizu |
890ddd |
action->setData(QVariant(i));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString changeStringNumber(QString str, int index)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QString newStr = str;
|
|
Toshihiro Shimizu |
890ddd |
int n = 3;
|
|
Toshihiro Shimizu |
890ddd |
if (index >= 10)
|
|
Toshihiro Shimizu |
890ddd |
n = 4;
|
|
Toshihiro Shimizu |
890ddd |
QString number;
|
|
Toshihiro Shimizu |
890ddd |
newStr.replace(0, n, number.number(index + 1) + QString(". "));
|
|
Toshihiro Shimizu |
890ddd |
return newStr;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void DVMenuAction::onTriggered(QAction *action)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
QVariant data = action->data();
|
|
Toshihiro Shimizu |
890ddd |
if (data.isValid())
|
|
Toshihiro Shimizu |
890ddd |
m_triggeredActionIndex = data.toInt();
|
|
Toshihiro Shimizu |
890ddd |
CommandManager::instance()->execute(action, menuAction());
|
|
Toshihiro Shimizu |
890ddd |
int oldIndex = m_triggeredActionIndex;
|
|
Toshihiro Shimizu |
890ddd |
if (m_triggeredActionIndex != -1)
|
|
Toshihiro Shimizu |
890ddd |
m_triggeredActionIndex = -1;
|
|
Toshihiro Shimizu |
890ddd |
QString str = data.toString();
|
|
Toshihiro Shimizu |
890ddd |
QAction *tableAction = CommandManager::instance()->getAction(str.toStdString().c_str());
|
|
Toshihiro Shimizu |
890ddd |
if (tableAction || oldIndex == 0)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
QList<qaction *=""> acts = actions();</qaction>
|
|
Toshihiro Shimizu |
890ddd |
removeAction(action);
|
|
Toshihiro Shimizu |
890ddd |
insertAction(acts[0], action);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
acts = actions();
|
|
Toshihiro Shimizu |
890ddd |
int i;
|
|
Toshihiro Shimizu |
890ddd |
for (i = 0; i <= oldIndex; i++) {
|
|
Toshihiro Shimizu |
890ddd |
QAction *a = acts.at(i);
|
|
Toshihiro Shimizu |
890ddd |
QString newTxt = changeStringNumber(a->text(), i);
|
|
Toshihiro Shimizu |
890ddd |
a->setText(newTxt);
|
|
Toshihiro Shimizu |
890ddd |
a->setData(QVariant(i));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
m_triggeredActionIndex = -1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|