all repos — mgba @ d15c4f4bfb2ee7fcb920a391812b72e746353208

mGBA Game Boy Advance Emulator

src/platform/qt/ShortcutView.cpp (view raw)

 1/* Copyright (c) 2013-2015 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "ShortcutView.h"
 7
 8#include "ShortcutController.h"
 9
10using namespace QGBA;
11
12ShortcutView::ShortcutView(QWidget* parent)
13	: QWidget(parent)
14{
15	m_ui.setupUi(this);
16
17	connect(m_ui.keySequenceEdit, SIGNAL(editingFinished()), this, SLOT(updateKey()));
18	connect(m_ui.shortcutTable, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(loadKey(const QModelIndex&)));
19}
20
21void ShortcutView::setController(ShortcutController* controller) {
22	m_controller = controller;
23	m_ui.shortcutTable->setModel(controller);
24}
25
26void ShortcutView::loadKey(const QModelIndex& index) {
27	if (!m_controller) {
28		return;
29	}
30	const QAction* action = m_controller->actionAt(index);
31	if (!action) {
32		return;
33	}
34	m_ui.keySequenceEdit->setFocus();
35	m_ui.keySequenceEdit->setKeySequence(action->shortcut());
36}
37
38void ShortcutView::updateKey() {
39	if (!m_controller) {
40		return;
41	}
42	m_ui.keySequenceEdit->clearFocus();
43	m_controller->updateKey(m_ui.shortcutTable->selectionModel()->currentIndex(), m_ui.keySequenceEdit->keySequence());
44}