2015-01-04 23:06:57 +05:30
|
|
|
// Copyright 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-06-21 19:28:59 +05:30
|
|
|
#include <map>
|
2014-04-01 07:56:50 +05:30
|
|
|
#include <QKeySequence>
|
2015-06-21 19:28:59 +05:30
|
|
|
#include <QShortcut>
|
2016-09-18 06:08:01 +05:30
|
|
|
#include <QtGlobal>
|
2016-09-21 12:22:38 +05:30
|
|
|
#include "citra_qt/hotkeys.h"
|
2016-01-25 01:53:55 +05:30
|
|
|
#include "citra_qt/ui_settings.h"
|
2014-04-01 07:56:50 +05:30
|
|
|
|
2018-08-07 10:13:07 +05:30
|
|
|
HotkeyRegistry::HotkeyRegistry() = default;
|
|
|
|
HotkeyRegistry::~HotkeyRegistry() = default;
|
2014-04-01 07:56:50 +05:30
|
|
|
|
2018-08-07 10:13:07 +05:30
|
|
|
void HotkeyRegistry::LoadHotkeys() {
|
2016-09-18 06:08:01 +05:30
|
|
|
// Make sure NOT to use a reference here because it would become invalid once we call
|
|
|
|
// beginGroup()
|
|
|
|
for (auto shortcut : UISettings::values.shortcuts) {
|
2018-08-07 10:13:07 +05:30
|
|
|
const QStringList cat = shortcut.first.split('/');
|
2016-01-25 01:53:55 +05:30
|
|
|
Q_ASSERT(cat.size() >= 2);
|
2014-04-01 07:56:50 +05:30
|
|
|
|
2016-01-25 01:53:55 +05:30
|
|
|
// RegisterHotkey assigns default keybindings, so use old values as default parameters
|
|
|
|
Hotkey& hk = hotkey_groups[cat[0]][cat[1]];
|
2016-09-18 06:08:01 +05:30
|
|
|
if (!shortcut.second.first.isEmpty()) {
|
2016-01-25 01:53:55 +05:30
|
|
|
hk.keyseq = QKeySequence::fromString(shortcut.second.first);
|
2018-08-07 10:13:07 +05:30
|
|
|
hk.context = static_cast<Qt::ShortcutContext>(shortcut.second.second);
|
2014-04-01 07:56:50 +05:30
|
|
|
}
|
2016-01-25 01:53:55 +05:30
|
|
|
if (hk.shortcut)
|
|
|
|
hk.shortcut->setKey(hk.keyseq);
|
2014-04-01 07:56:50 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 10:13:07 +05:30
|
|
|
void HotkeyRegistry::SaveHotkeys() {
|
|
|
|
UISettings::values.shortcuts.clear();
|
|
|
|
for (const auto& group : hotkey_groups) {
|
|
|
|
for (const auto& hotkey : group.second) {
|
|
|
|
UISettings::values.shortcuts.emplace_back(
|
|
|
|
UISettings::Shortcut(group.first + '/' + hotkey.first,
|
|
|
|
UISettings::ContextualShortcut(hotkey.second.keyseq.toString(),
|
|
|
|
hotkey.second.context)));
|
|
|
|
}
|
2014-04-01 07:56:50 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 10:13:07 +05:30
|
|
|
void HotkeyRegistry::RegisterHotkey(const QString& group, const QString& action,
|
|
|
|
const QKeySequence& default_keyseq,
|
|
|
|
Qt::ShortcutContext default_context) {
|
|
|
|
auto& hotkey_group = hotkey_groups[group];
|
|
|
|
if (hotkey_group.find(action) != hotkey_group.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& hotkey_action = hotkey_groups[group][action];
|
|
|
|
hotkey_action.keyseq = default_keyseq;
|
|
|
|
hotkey_action.context = default_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
QShortcut* HotkeyRegistry::GetHotkey(const QString& group, const QString& action, QWidget* widget) {
|
2014-04-01 07:56:50 +05:30
|
|
|
Hotkey& hk = hotkey_groups[group][action];
|
|
|
|
|
|
|
|
if (!hk.shortcut)
|
2014-12-04 00:27:57 +05:30
|
|
|
hk.shortcut = new QShortcut(hk.keyseq, widget, nullptr, nullptr, hk.context);
|
2014-04-01 07:56:50 +05:30
|
|
|
|
|
|
|
return hk.shortcut;
|
|
|
|
}
|
|
|
|
|
2016-09-18 06:08:01 +05:30
|
|
|
GHotkeysDialog::GHotkeysDialog(QWidget* parent) : QWidget(parent) {
|
2014-04-01 07:56:50 +05:30
|
|
|
ui.setupUi(this);
|
2018-08-07 10:13:07 +05:30
|
|
|
}
|
2014-04-01 07:56:50 +05:30
|
|
|
|
2018-08-07 10:13:07 +05:30
|
|
|
void GHotkeysDialog::Populate(const HotkeyRegistry& registry) {
|
|
|
|
for (const auto& group : registry.hotkey_groups) {
|
2014-08-12 06:14:59 +05:30
|
|
|
QTreeWidgetItem* toplevel_item = new QTreeWidgetItem(QStringList(group.first));
|
2018-08-07 10:13:07 +05:30
|
|
|
for (const auto& hotkey : group.second) {
|
2014-04-01 07:56:50 +05:30
|
|
|
QStringList columns;
|
2014-08-12 06:14:59 +05:30
|
|
|
columns << hotkey.first << hotkey.second.keyseq.toString();
|
2014-04-01 07:56:50 +05:30
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem(columns);
|
|
|
|
toplevel_item->addChild(item);
|
|
|
|
}
|
|
|
|
ui.treeWidget->addTopLevelItem(toplevel_item);
|
|
|
|
}
|
|
|
|
// TODO: Make context configurable as well (hiding the column for now)
|
|
|
|
ui.treeWidget->setColumnCount(2);
|
|
|
|
|
|
|
|
ui.treeWidget->resizeColumnToContents(0);
|
|
|
|
ui.treeWidget->resizeColumnToContents(1);
|
|
|
|
}
|
2018-07-24 09:53:38 +05:30
|
|
|
|
|
|
|
void GHotkeysDialog::retranslateUi() {
|
|
|
|
ui.retranslateUi(this);
|
|
|
|
}
|