Qt: Controller profiles now store shortcut settings

This commit is contained in:
Jeffrey Pfau 2015-07-14 22:51:27 -07:00
parent 73518ceda5
commit 8ef50827fd
6 changed files with 59 additions and 11 deletions

View File

@ -25,6 +25,7 @@ Features:
- 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

View File

@ -108,6 +108,7 @@ void InputController::loadConfiguration(uint32_t type) {
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() {

View File

@ -77,6 +77,9 @@ public:
GBARumble* rumble();
GBARotationSource* rotationSource();
signals:
void profileLoaded(const QString& profile);
public slots:
void testGamepad(int type);

View File

@ -239,6 +239,9 @@ void ShortcutController::updateButton(const QModelIndex& index, int button) {
}
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 @@ void ShortcutController::updateAxis(const QModelIndex& index, int axis, GamepadA
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 @@ bool ShortcutController::eventFilter(QObject*, QEvent* event) {
}
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 @@ void ShortcutController::loadShortcuts(ShortcutItem* item) {
}
item->setShortcut(keySequence);
}
QVariant button = m_config->getQtOption(item->name(), BUTTON_SECTION);
if (!button.isNull()) {
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();
item->setButton(button.toInt());
if (oldButton >= 0) {
m_buttons.take(oldButton);
item->setButton(-1);
}
if (!button.isNull()) {
item->setButton(button.toInt());
m_buttons[button.toInt()] = item;
}
QVariant axis = m_config->getQtOption(item->name(), AXIS_SECTION);
if (!axis.isNull()) {
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()) {
QString axisDesc = axis.toString();
if (axisDesc.size() >= 2) {
GamepadAxisEvent::Direction direction = GamepadAxisEvent::NEUTRAL;
@ -403,9 +425,6 @@ void ShortcutController::loadShortcuts(ShortcutItem* item) {
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;
}
}
@ -432,6 +451,20 @@ QKeySequence ShortcutController::keyEventToSequence(const QKeyEvent* event) {
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_action(action)
, m_shortcut(action->shortcut())

View File

@ -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 @@ public:
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 @@ private:
QMap<QPair<int, GamepadAxisEvent::Direction>, ShortcutItem*> m_axes;
QMap<QKeySequence, ShortcutItem*> m_heldKeys;
ConfigController* m_config;
QString m_profile;
};
}

View File

@ -136,6 +136,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
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);