| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #include "dynamic-shortcuts/dynamicshortcuts.h" |
| 4 | |
| 5 | #include "miscellaneous/application.h" |
| 6 | #include "miscellaneous/settings.h" |
| 7 | |
| 8 | #include <QAction> |
| 9 | |
| 10 | void DynamicShortcuts::save(const QList<QAction*>& actions) { |
| 11 | Settings* settings = qApp->settings(); |
| 12 | |
| 13 | for (const QAction* action : actions) { |
| 14 | settings->setValue(GROUP(Keyboard), |
| 15 | action->objectName(), |
| 16 | action->shortcut().toString(QKeySequence::SequenceFormat::PortableText)); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | void DynamicShortcuts::load(const QList<QAction*>& actions) { |
| 21 | Settings* settings = qApp->settings(); |
| 22 | |
| 23 | for (QAction* action : actions) { |
| 24 | QString shortcut_for_action = settings |
| 25 | ->value(GROUP(Keyboard), |
| 26 | action->objectName(), |
| 27 | action->shortcut().toString(QKeySequence::SequenceFormat::PortableText)) |
| 28 | .toString(); |
| 29 | |
| 30 | action->setShortcut(QKeySequence::fromString(shortcut_for_action, QKeySequence::SequenceFormat::PortableText)); |
| 31 | } |
| 32 | } |