@@ -68,6 +68,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
MainMenu* main_menu = new MainMenu(this);
|
||||
setMenuBar(main_menu);
|
||||
|
||||
LoadCustomShortcuts();
|
||||
|
||||
// Create and set status bar
|
||||
MainStatusBar* status_bar = new MainStatusBar(this);
|
||||
status_bar->ConnectTaskManager(TaskManager::instance());
|
||||
@@ -406,6 +408,8 @@ void MainWindow::closeEvent(QCloseEvent *e)
|
||||
|
||||
PanelManager::instance()->DeleteAllPanels();
|
||||
|
||||
SaveCustomShortcuts();
|
||||
|
||||
QMainWindow::closeEvent(e);
|
||||
}
|
||||
|
||||
@@ -547,6 +551,107 @@ void MainWindow::TimelineFocused(ViewerOutput* viewer)
|
||||
curve_panel_->ConnectViewerNode(viewer);
|
||||
}
|
||||
|
||||
QString MainWindow::GetCustomShortcutsFile()
|
||||
{
|
||||
return QDir(FileFunctions::GetConfigurationLocation()).filePath(QStringLiteral("shortcuts"));
|
||||
}
|
||||
|
||||
void LoadCustomShortcutsInternal(QMenu* menu, const QMap<QString, QString>& shortcuts)
|
||||
{
|
||||
QList<QAction*> actions = menu->actions();
|
||||
|
||||
foreach (QAction* a, actions) {
|
||||
if (a->menu()) {
|
||||
LoadCustomShortcutsInternal(a->menu(), shortcuts);
|
||||
} else if (!a->isSeparator()) {
|
||||
QString action_id = a->property("id").toString();
|
||||
|
||||
if (shortcuts.contains(action_id)) {
|
||||
a->setShortcut(shortcuts.value(action_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::LoadCustomShortcuts()
|
||||
{
|
||||
QFile shortcut_file(GetCustomShortcutsFile());
|
||||
if (shortcut_file.exists() && shortcut_file.open(QFile::ReadOnly)) {
|
||||
QMap<QString, QString> shortcuts;
|
||||
|
||||
QString shortcut_str = QString::fromUtf8(shortcut_file.readAll());
|
||||
|
||||
QStringList shortcut_list = shortcut_str.split(QStringLiteral("\n"));
|
||||
|
||||
foreach (const QString& s, shortcut_list) {
|
||||
QStringList shortcut_line = s.split(QStringLiteral("\t"));
|
||||
if (shortcut_line.size() >= 2) {
|
||||
shortcuts.insert(shortcut_line.at(0), shortcut_line.at(1));
|
||||
}
|
||||
}
|
||||
|
||||
shortcut_file.close();
|
||||
|
||||
if (!shortcuts.isEmpty()) {
|
||||
QList<QAction*> menus = menuBar()->actions();
|
||||
|
||||
foreach (QAction* menu, menus) {
|
||||
LoadCustomShortcutsInternal(menu->menu(), shortcuts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SaveCustomShortcutsInternal(QMenu* menu, QMap<QString, QString>* shortcuts)
|
||||
{
|
||||
QList<QAction*> actions = menu->actions();
|
||||
|
||||
foreach (QAction* a, actions) {
|
||||
if (a->menu()) {
|
||||
SaveCustomShortcutsInternal(a->menu(), shortcuts);
|
||||
} else if (!a->isSeparator()) {
|
||||
QString default_shortcut = a->property("keydefault").toString();
|
||||
QString current_shortcut = a->shortcut().toString();
|
||||
if (current_shortcut != default_shortcut) {
|
||||
QString action_id = a->property("id").toString();
|
||||
shortcuts->insert(action_id, current_shortcut);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::SaveCustomShortcuts()
|
||||
{
|
||||
QMap<QString, QString> shortcuts;
|
||||
QList<QAction*> menus = menuBar()->actions();
|
||||
|
||||
foreach (QAction* menu, menus) {
|
||||
SaveCustomShortcutsInternal(menu->menu(), &shortcuts);
|
||||
}
|
||||
|
||||
QFile shortcut_file(GetCustomShortcutsFile());
|
||||
if (shortcuts.isEmpty()) {
|
||||
if (shortcut_file.exists()) {
|
||||
// No custom shortcuts, remove any existing file
|
||||
shortcut_file.remove();
|
||||
}
|
||||
} else if (shortcut_file.open(QFile::WriteOnly)) {
|
||||
for (auto it=shortcuts.cbegin(); it!=shortcuts.cend(); it++) {
|
||||
if (it != shortcuts.cbegin()) {
|
||||
shortcut_file.write(QStringLiteral("\n").toUtf8());
|
||||
}
|
||||
|
||||
shortcut_file.write(it.key().toUtf8());
|
||||
shortcut_file.write(QStringLiteral("\t").toUtf8());
|
||||
shortcut_file.write(it.value().toUtf8());
|
||||
}
|
||||
shortcut_file.close();
|
||||
} else {
|
||||
qCritical() << "Failed to save custom keyboard shortcuts";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::FocusedPanelChanged(PanelWidget *panel)
|
||||
{
|
||||
TimelinePanel* timeline = dynamic_cast<TimelinePanel*>(panel);
|
||||
|
||||
@@ -132,6 +132,12 @@ private:
|
||||
|
||||
void TimelineFocused(ViewerOutput *viewer);
|
||||
|
||||
static QString GetCustomShortcutsFile();
|
||||
|
||||
void LoadCustomShortcuts();
|
||||
|
||||
void SaveCustomShortcuts();
|
||||
|
||||
QByteArray premaximized_state_;
|
||||
|
||||
// Standard panels
|
||||
|
||||
Reference in New Issue
Block a user