shortcut template
This commit is contained in:
parent
136f68fcd4
commit
cf18d82356
4 changed files with 59 additions and 39 deletions
|
@ -173,6 +173,9 @@ public:
|
||||||
const QString &offText);
|
const QString &offText);
|
||||||
|
|
||||||
std::string getIdFromAction(QAction *action);
|
std::string getIdFromAction(QAction *action);
|
||||||
|
|
||||||
|
// load user defined shortcuts
|
||||||
|
void loadShortcuts();
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
@ -522,8 +522,8 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
loadShaderInterfaces(ToonzFolder::getLibraryFolder() + TFilePath("shaders"));
|
loadShaderInterfaces(ToonzFolder::getLibraryFolder() + TFilePath("shaders"));
|
||||||
|
|
||||||
splash.showMessage(offsetStr + "Initializing OpenToonz ...",
|
splash.showMessage(offsetStr + "Initializing OpenToonz ...", Qt::AlignCenter,
|
||||||
Qt::AlignCenter, Qt::white);
|
Qt::white);
|
||||||
a.processEvents();
|
a.processEvents();
|
||||||
|
|
||||||
TTool::setApplication(TApp::instance());
|
TTool::setApplication(TApp::instance());
|
||||||
|
|
|
@ -380,6 +380,8 @@ MainWindow::MainWindow(const QString &argumentLayoutFileName, QWidget *parent,
|
||||||
m_toolsActionGroup->setExclusive(true);
|
m_toolsActionGroup->setExclusive(true);
|
||||||
m_currentRoomsChoice = Preferences::instance()->getCurrentRoomChoice();
|
m_currentRoomsChoice = Preferences::instance()->getCurrentRoomChoice();
|
||||||
defineActions();
|
defineActions();
|
||||||
|
// user defined shortcuts will be loaded here
|
||||||
|
CommandManager::instance()->loadShortcuts();
|
||||||
TApp::instance()->getCurrentScene()->setDirtyFlag(false);
|
TApp::instance()->getCurrentScene()->setDirtyFlag(false);
|
||||||
|
|
||||||
// La menuBar altro non è che una toolbar
|
// La menuBar altro non è che una toolbar
|
||||||
|
@ -2357,9 +2359,9 @@ RecentFiles::~RecentFiles() {}
|
||||||
|
|
||||||
void RecentFiles::addFilePath(QString path, FileType fileType) {
|
void RecentFiles::addFilePath(QString path, FileType fileType) {
|
||||||
QList<QString> files =
|
QList<QString> files =
|
||||||
(fileType == Scene) ? m_recentScenes : (fileType == Level)
|
(fileType == Scene)
|
||||||
? m_recentLevels
|
? m_recentScenes
|
||||||
: m_recentFlipbookImages;
|
: (fileType == Level) ? m_recentLevels : m_recentFlipbookImages;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < files.size(); i++)
|
for (i = 0; i < files.size(); i++)
|
||||||
if (files.at(i) == path) files.removeAt(i);
|
if (files.at(i) == path) files.removeAt(i);
|
||||||
|
@ -2484,9 +2486,9 @@ void RecentFiles::saveRecentFiles() {
|
||||||
|
|
||||||
QList<QString> RecentFiles::getFilesNameList(FileType fileType) {
|
QList<QString> RecentFiles::getFilesNameList(FileType fileType) {
|
||||||
QList<QString> files =
|
QList<QString> files =
|
||||||
(fileType == Scene) ? m_recentScenes : (fileType == Level)
|
(fileType == Scene)
|
||||||
? m_recentLevels
|
? m_recentScenes
|
||||||
: m_recentFlipbookImages;
|
: (fileType == Level) ? m_recentLevels : m_recentFlipbookImages;
|
||||||
QList<QString> names;
|
QList<QString> names;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < files.size(); i++) {
|
for (i = 0; i < files.size(); i++) {
|
||||||
|
@ -2513,9 +2515,9 @@ void RecentFiles::refreshRecentFilesMenu(FileType fileType) {
|
||||||
menu->setEnabled(false);
|
menu->setEnabled(false);
|
||||||
else {
|
else {
|
||||||
CommandId clearActionId =
|
CommandId clearActionId =
|
||||||
(fileType == Scene) ? MI_ClearRecentScene : (fileType == Level)
|
(fileType == Scene)
|
||||||
? MI_ClearRecentLevel
|
? MI_ClearRecentScene
|
||||||
: MI_ClearRecentImage;
|
: (fileType == Level) ? MI_ClearRecentLevel : MI_ClearRecentImage;
|
||||||
menu->setActions(names);
|
menu->setActions(names);
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
QAction *clearAction = CommandManager::instance()->getAction(clearActionId);
|
QAction *clearAction = CommandManager::instance()->getAction(clearActionId);
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "toonzqt/dvdialog.h"
|
#include "toonzqt/dvdialog.h"
|
||||||
#include "toonzqt/gutil.h"
|
#include "toonzqt/gutil.h"
|
||||||
#include "toonz/toonzfolders.h"
|
#include "toonz/toonzfolders.h"
|
||||||
|
#include "tsystem.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
@ -130,36 +131,12 @@ void CommandManager::define(CommandId id, CommandType type,
|
||||||
|
|
||||||
m_qactionTable[qaction] = node;
|
m_qactionTable[qaction] = node;
|
||||||
qaction->setShortcutContext(Qt::ApplicationShortcut);
|
qaction->setShortcutContext(Qt::ApplicationShortcut);
|
||||||
|
// user defined shortcuts will be loaded afterwards in loadShortcuts()
|
||||||
TFilePath fp = ToonzFolder::getModuleFile("shortcuts.ini");
|
|
||||||
QSettings settings(toQString(fp), QSettings::IniFormat);
|
|
||||||
settings.beginGroup("shortcuts");
|
|
||||||
QString defaultShortcutQString =
|
QString defaultShortcutQString =
|
||||||
QString::fromStdString(defaultShortcutString);
|
QString::fromStdString(defaultShortcutString);
|
||||||
/*-
|
if (!defaultShortcutQString.isEmpty()) {
|
||||||
Some shortcuts may just removed from the default settings.
|
qaction->setShortcut(QKeySequence(defaultShortcutQString));
|
||||||
So you need to distinguish between "shortcut is not defined by user"
|
m_shortcutTable[defaultShortcutString] = node;
|
||||||
and "shortcut is removed (i.e. defined as "") by user".
|
|
||||||
-*/
|
|
||||||
QString shortcutString = settings.value(id, "undefined").toString();
|
|
||||||
settings.endGroup();
|
|
||||||
|
|
||||||
if (shortcutString != "" && shortcutString != "undefined") {
|
|
||||||
// User-defined shortcuts. It may have been assigned as a shortcut by
|
|
||||||
// default to some other command
|
|
||||||
QAction *other = getActionFromShortcut(shortcutString.toStdString());
|
|
||||||
if (other) other->setShortcut(QKeySequence());
|
|
||||||
} else if (defaultShortcutQString != "" && shortcutString == "undefined") {
|
|
||||||
// Shortcut key set by default. Check if the key already been assigned to
|
|
||||||
// another action
|
|
||||||
QAction *other =
|
|
||||||
getActionFromShortcut(defaultShortcutQString.toStdString());
|
|
||||||
if (!other) shortcutString = defaultShortcutQString;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shortcutString != "" && shortcutString != "undefined") {
|
|
||||||
qaction->setShortcut(QKeySequence(shortcutString));
|
|
||||||
m_shortcutTable[shortcutString.toStdString()] = node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == ToolCommandType) updateToolTip(qaction);
|
if (type == ToolCommandType) updateToolTip(qaction);
|
||||||
|
@ -407,6 +384,44 @@ std::string CommandManager::getIdFromAction(QAction *action) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------
|
||||||
|
// load user defined shortcuts
|
||||||
|
|
||||||
|
void CommandManager::loadShortcuts() {
|
||||||
|
TFilePath fp = ToonzFolder::getMyModuleDir() + TFilePath("shortcuts.ini");
|
||||||
|
if (!TFileStatus(fp).doesExist()) {
|
||||||
|
// if user shortcut file does not exist, then try to load from template
|
||||||
|
TFilePath tmplFp =
|
||||||
|
ToonzFolder::getTemplateModuleDir() + TFilePath("shortcuts.ini");
|
||||||
|
if (TFileStatus(tmplFp).doesExist()) TSystem::copyFile(fp, tmplFp);
|
||||||
|
// if neither settings exist, do nothing and return
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSettings settings(toQString(fp), QSettings::IniFormat);
|
||||||
|
settings.beginGroup("shortcuts");
|
||||||
|
QStringList ids = settings.allKeys();
|
||||||
|
for (int i = 0; i < ids.size(); i++) {
|
||||||
|
std::string id = ids.at(i).toStdString();
|
||||||
|
QString shortcut = settings.value(ids.at(i), "").toString();
|
||||||
|
QAction *action = getAction(&id[0], false);
|
||||||
|
if (action) {
|
||||||
|
QString oldShortcut = action->shortcut().toString();
|
||||||
|
if (oldShortcut == shortcut) continue;
|
||||||
|
if (!oldShortcut.isEmpty())
|
||||||
|
m_shortcutTable.erase(oldShortcut.toStdString());
|
||||||
|
if (!shortcut.isEmpty()) {
|
||||||
|
QAction *other = getActionFromShortcut(shortcut.toStdString());
|
||||||
|
if (other) other->setShortcut(QKeySequence());
|
||||||
|
m_shortcutTable[shortcut.toStdString()] = getNode(&id[0]);
|
||||||
|
}
|
||||||
|
action->setShortcut(QKeySequence(shortcut));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//---------------------------------------------------------
|
//---------------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue