all repos — mgba @ cb0f95b07053e63e817bd05df0a36bf917667d09

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_keys(-1)
 16	, m_menu(nullptr)
 17	, m_name(name)
 18	, m_button(-1)
 19	, m_axis(-1)
 20	, m_direction(GamepadAxisEvent::NEUTRAL)
 21	, m_platform(PLATFORM_NONE)
 22	, m_parent(parent)
 23{
 24	m_visibleName = action->text()
 25		.remove(QRegExp("&(?!&)"))
 26		.remove("...");
 27}
 28
 29InputItem::InputItem(InputItem::Functions functions, int shortcut, const QString& visibleName, const QString& name, InputItem* parent)
 30	: m_action(nullptr)
 31	, m_shortcut(shortcut)
 32	, m_functions(functions)
 33	, m_keys(-1)
 34	, m_menu(nullptr)
 35	, m_name(name)
 36	, m_visibleName(visibleName)
 37	, m_button(-1)
 38	, m_axis(-1)
 39	, m_direction(GamepadAxisEvent::NEUTRAL)
 40	, m_platform(PLATFORM_NONE)
 41	, m_parent(parent)
 42{
 43}
 44
 45InputItem::InputItem(mPlatform platform, int key, int shortcut, const QString& visibleName, const QString& name, InputItem* parent)
 46	: m_action(nullptr)
 47	, m_shortcut(shortcut)
 48	, m_keys(key)
 49	, m_menu(nullptr)
 50	, m_name(name)
 51	, m_visibleName(visibleName)
 52	, m_button(-1)
 53	, m_axis(-1)
 54	, m_direction(GamepadAxisEvent::NEUTRAL)
 55	, m_platform(platform)
 56	, m_parent(parent)
 57{
 58}
 59
 60InputItem::InputItem(QMenu* menu, InputItem* parent)
 61	: m_action(nullptr)
 62	, m_shortcut(0)
 63	, m_menu(menu)
 64	, m_button(-1)
 65	, m_axis(-1)
 66	, m_direction(GamepadAxisEvent::NEUTRAL)
 67	, m_parent(parent)
 68{
 69	if (menu) {
 70		m_visibleName = menu->title()
 71			.remove(QRegExp("&(?!&)"))
 72			.remove("...");
 73	}
 74}
 75
 76void InputItem::addAction(QAction* action, const QString& name) {
 77	m_items.append(InputItem(action, name, this));
 78}
 79
 80void InputItem::addFunctions(InputItem::Functions functions,
 81                             int shortcut, const QString& visibleName,
 82                             const QString& name) {
 83	m_items.append(InputItem(functions, shortcut, visibleName, name, this));
 84}
 85
 86void InputItem::addKey(mPlatform platform, int key, int shortcut, const QString& visibleName, const QString& name) {
 87	m_items.append(InputItem(platform, key, shortcut, visibleName, name, this));
 88}
 89
 90void InputItem::addSubmenu(QMenu* menu) {
 91	m_items.append(InputItem(menu, this));
 92}
 93
 94void InputItem::setShortcut(int shortcut) {
 95	m_shortcut = shortcut;
 96	if (m_action) {
 97		m_action->setShortcut(QKeySequence(shortcut));
 98	}
 99}
100
101void InputItem::setAxis(int axis, GamepadAxisEvent::Direction direction) {
102	m_axis = axis;
103	m_direction = direction;
104}