all repos — mgba @ 5fef1b72e4963b3ad04da790aa6c1f225706c63f

mGBA Game Boy Advance Emulator

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

 1/* Copyright (c) 2013-2017 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 "InputItem.h"
 7
 8#include <QMenu>
 9
10using namespace QGBA;
11
12InputItem::InputItem(QAction* action, const QString& name, InputItem* parent)
13	: m_action(action)
14	, m_shortcut(action->shortcut().isEmpty() ? 0 : action->shortcut()[0])
15	, m_menu(nullptr)
16	, m_name(name)
17	, m_button(-1)
18	, m_axis(-1)
19	, m_direction(GamepadAxisEvent::NEUTRAL)
20	, m_parent(parent)
21{
22	m_visibleName = action->text()
23		.remove(QRegExp("&(?!&)"))
24		.remove("...");
25}
26
27InputItem::InputItem(InputItem::Functions functions, int shortcut, const QString& visibleName, const QString& name, InputItem* parent)
28	: m_action(nullptr)
29	, m_shortcut(shortcut)
30	, m_functions(functions)
31	, m_menu(nullptr)
32	, m_name(name)
33	, m_visibleName(visibleName)
34	, m_button(-1)
35	, m_axis(-1)
36	, m_direction(GamepadAxisEvent::NEUTRAL)
37	, m_parent(parent)
38{
39}
40
41InputItem::InputItem(QMenu* menu, InputItem* parent)
42	: m_action(nullptr)
43	, m_shortcut(0)
44	, m_menu(menu)
45	, m_button(-1)
46	, m_axis(-1)
47	, m_direction(GamepadAxisEvent::NEUTRAL)
48	, m_parent(parent)
49{
50	if (menu) {
51		m_visibleName = menu->title()
52			.remove(QRegExp("&(?!&)"))
53			.remove("...");
54	}
55}
56
57void InputItem::addAction(QAction* action, const QString& name) {
58	m_items.append(InputItem(action, name, this));
59}
60
61void InputItem::addFunctions(InputItem::Functions functions,
62                             int shortcut, const QString& visibleName,
63                             const QString& name) {
64	m_items.append(InputItem(functions, shortcut, visibleName, name, this));
65}
66
67void InputItem::addSubmenu(QMenu* menu) {
68	m_items.append(InputItem(menu, this));
69}
70
71void InputItem::setShortcut(int shortcut) {
72	m_shortcut = shortcut;
73	if (m_action) {
74		m_action->setShortcut(QKeySequence(shortcut));
75	}
76}
77
78void InputItem::setAxis(int axis, GamepadAxisEvent::Direction direction) {
79	m_axis = axis;
80	m_direction = direction;
81}