Qt: Controller profiles now store shortcut settings
Jeffrey Pfau jeffrey@endrift.com
Tue, 14 Jul 2015 22:51:27 -0700
6 files changed,
59 insertions(+),
11 deletions(-)
M
CHANGES
→
CHANGES
@@ -25,6 +25,7 @@ - Preliminary support for yanking out the game pak while a game is running
- Thumb-drive mode by putting a file called portable.ini in the same folder - Configurable display driver, between software and OpenGL - Undo-able savestate loading and saving + - Controller profiles now store shortcut settings Bugfixes: - ARM7: Fix SWI and IRQ timings - GBA Audio: Force audio FIFOs to 32-bit
M
src/platform/qt/InputController.cpp
→
src/platform/qt/InputController.cpp
@@ -108,6 +108,7 @@
void InputController::loadProfile(uint32_t type, const QString& profile) { GBAInputProfileLoad(&m_inputMap, type, m_config->input(), profile.toUtf8().constData()); recalibrateAxes(); + emit profileLoaded(profile); } void InputController::saveConfiguration() {
M
src/platform/qt/InputController.h
→
src/platform/qt/InputController.h
@@ -77,6 +77,9 @@
GBARumble* rumble(); GBARotationSource* rotationSource(); +signals: + void profileLoaded(const QString& profile); + public slots: void testGamepad(int type);
M
src/platform/qt/ShortcutController.cpp
→
src/platform/qt/ShortcutController.cpp
@@ -239,6 +239,9 @@ m_buttons[button] = item;
} if (m_config) { m_config->setQtOption(item->name(), button, BUTTON_SECTION); + if (!m_profile.isNull()) { + m_config->setQtOption(item->name(), button, BUTTON_PROFILE_SECTION + m_profile); + } } emit dataChanged(createIndex(index.row(), 0, index.internalPointer()), createIndex(index.row(), 2, index.internalPointer()));@@ -272,6 +275,9 @@ if (direction == GamepadAxisEvent::NEGATIVE) {
d = '-'; } m_config->setQtOption(item->name(), QString("%1%2").arg(d).arg(axis), AXIS_SECTION); + if (!m_profile.isNull()) { + m_config->setQtOption(item->name(), QString("%1%2").arg(d).arg(axis), AXIS_PROFILE_SECTION + m_profile); + } } emit dataChanged(createIndex(index.row(), 0, index.internalPointer()), createIndex(index.row(), 2, index.internalPointer()));@@ -365,6 +371,9 @@ return false;
} void ShortcutController::loadShortcuts(ShortcutItem* item) { + if (item->name().isNull()) { + return; + } QVariant shortcut = m_config->getQtOption(item->name(), KEY_SECTION); if (!shortcut.isNull()) { QKeySequence keySequence(shortcut.toString());@@ -377,19 +386,32 @@ m_heldKeys[keySequence] = item;
} item->setShortcut(keySequence); } - QVariant button = m_config->getQtOption(item->name(), BUTTON_SECTION); + loadGamepadShortcuts(item); +} + +void ShortcutController::loadGamepadShortcuts(ShortcutItem* item) { + if (item->name().isNull()) { + return; + } + QVariant button = m_config->getQtOption(item->name(), !m_profile.isNull() ? BUTTON_PROFILE_SECTION + m_profile : BUTTON_SECTION); + int oldButton = item->button(); + if (oldButton >= 0) { + m_buttons.take(oldButton); + item->setButton(-1); + } if (!button.isNull()) { - int oldButton = item->button(); item->setButton(button.toInt()); - if (oldButton >= 0) { - m_buttons.take(oldButton); - } m_buttons[button.toInt()] = item; } - QVariant axis = m_config->getQtOption(item->name(), AXIS_SECTION); + + QVariant axis = m_config->getQtOption(item->name(), !m_profile.isNull() ? AXIS_PROFILE_SECTION + m_profile : AXIS_SECTION); + int oldAxis = item->axis(); + GamepadAxisEvent::Direction oldDirection = item->direction(); + if (oldAxis >= 0) { + m_axes.take(qMakePair(oldAxis, oldDirection)); + item->setAxis(-1, GamepadAxisEvent::NEUTRAL); + } if (!axis.isNull()) { - int oldAxis = item->axis(); - GamepadAxisEvent::Direction oldDirection = item->direction(); QString axisDesc = axis.toString(); if (axisDesc.size() >= 2) { GamepadAxisEvent::Direction direction = GamepadAxisEvent::NEUTRAL;@@ -403,9 +425,6 @@ bool ok;
int axis = axisDesc.mid(1).toInt(&ok); if (ok) { item->setAxis(axis, direction); - if (oldAxis >= 0) { - m_axes.take(qMakePair(oldAxis, oldDirection)); - } m_axes[qMakePair(axis, direction)] = item; } }@@ -430,6 +449,20 @@ }
QString key = QKeySequence(event->key()).toString(); return QKeySequence(modifier + key); +} + +void ShortcutController::loadProfile(const QString& profile) { + m_profile = profile; + onSubitems(&m_rootMenu, [this](ShortcutItem* item) { + loadGamepadShortcuts(item); + }); +} + +void ShortcutController::onSubitems(ShortcutItem* item, std::function<void(ShortcutItem*)> func) { + for (ShortcutItem& subitem : item->items()) { + func(&subitem); + onSubitems(&subitem, func); + } } ShortcutController::ShortcutItem::ShortcutItem(QAction* action, const QString& name, ShortcutItem* parent)
M
src/platform/qt/ShortcutController.h
→
src/platform/qt/ShortcutController.h
@@ -29,6 +29,8 @@ private:
constexpr static const char* const KEY_SECTION = "shortcutKey"; constexpr static const char* const BUTTON_SECTION = "shortcutButton"; constexpr static const char* const AXIS_SECTION = "shortcutAxis"; + constexpr static const char* const BUTTON_PROFILE_SECTION = "shortcutProfileButton."; + constexpr static const char* const AXIS_PROFILE_SECTION = "shortcutProfileAxis."; class ShortcutItem { public:@@ -84,6 +86,7 @@ public:
ShortcutController(QObject* parent = nullptr); void setConfigController(ConfigController* controller); + void setProfile(const QString& profile); virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;@@ -111,6 +114,9 @@ void clearButton(const QModelIndex& index);
static QKeySequence keyEventToSequence(const QKeyEvent*); +public slots: + void loadProfile(const QString& profile); + protected: bool eventFilter(QObject*, QEvent*) override;@@ -118,6 +124,8 @@ private:
ShortcutItem* itemAt(const QModelIndex& index); const ShortcutItem* itemAt(const QModelIndex& index) const; void loadShortcuts(ShortcutItem*); + void loadGamepadShortcuts(ShortcutItem*); + void onSubitems(ShortcutItem*, std::function<void(ShortcutItem*)> func); ShortcutItem m_rootMenu; QMap<QMenu*, ShortcutItem*> m_menuMap;@@ -125,6 +133,7 @@ QMap<int, ShortcutItem*> m_buttons;
QMap<QPair<int, GamepadAxisEvent::Direction>, ShortcutItem*> m_axes; QMap<QKeySequence, ShortcutItem*> m_heldKeys; ConfigController* m_config; + QString m_profile; }; }
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -136,6 +136,7 @@ });
connect(m_display, &Display::showCursor, [this]() { unsetCursor(); }); + connect(&m_inputController, SIGNAL(profileLoaded(const QString&)), m_shortcutController, SLOT(loadProfile(const QString&))); m_log.setLevels(GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL | GBA_LOG_STATUS); m_fpsTimer.setInterval(FPS_TIMER_INTERVAL);