Qt: Fix a handful of UX issues with gamepad mapping

This commit is contained in:
Jeffrey Pfau 2015-01-05 01:17:53 -08:00
parent e263467f13
commit 3854c7e401
4 changed files with 20 additions and 7 deletions

View File

@ -20,7 +20,11 @@ KeyEditor::KeyEditor(QWidget* parent)
void KeyEditor::setValue(int key) {
if (m_button) {
setText(QString::number(key));
if (key < 0) {
clear();
} else {
setText(QString::number(key));
}
} else {
setText(QKeySequence(key).toString(QKeySequence::NativeText));
}

View File

@ -171,6 +171,14 @@ const QAction* ShortcutController::actionAt(const QModelIndex& index) const {
return item->action();
}
bool ShortcutController::isMenuAt(const QModelIndex& index) const {
const ShortcutItem* item = itemAt(index);
if (!item) {
return false;
}
return item->menu();
}
void ShortcutController::updateKey(const QModelIndex& index, const QKeySequence& keySequence) {
if (!index.isValid()) {
return;

View File

@ -86,9 +86,8 @@ public:
void addFunctions(QMenu* menu, std::function<void ()> press, std::function<void()> release, const QKeySequence& shortcut, const QString& visibleName, const QString& name);
void addMenu(QMenu* menu, QMenu* parent = nullptr);
ShortcutItem* itemAt(const QModelIndex& index);
const ShortcutItem* itemAt(const QModelIndex& index) const;
const QAction* actionAt(const QModelIndex& index) const;
bool isMenuAt(const QModelIndex& index) const;
void updateKey(const QModelIndex& index, const QKeySequence& keySequence);
void updateButton(const QModelIndex& index, int button);
@ -99,6 +98,8 @@ protected:
private:
static QKeySequence keyEventToSequence(const QKeyEvent*);
ShortcutItem* itemAt(const QModelIndex& index);
const ShortcutItem* itemAt(const QModelIndex& index) const;
void loadShortcuts(ShortcutItem*);
ShortcutItem m_rootMenu;

View File

@ -47,7 +47,7 @@ void ShortcutView::load(const QModelIndex& index) {
return;
}
const QAction* action = m_controller->actionAt(index);
if (!action) {
if (!action || m_controller->isMenuAt(index)) {
return;
}
if (m_ui.gamepadButton->isChecked()) {
@ -58,7 +58,7 @@ void ShortcutView::load(const QModelIndex& index) {
}
void ShortcutView::updateKey() {
if (!m_controller) {
if (!m_controller || m_controller->isMenuAt(m_ui.shortcutTable->selectionModel()->currentIndex())) {
return;
}
m_ui.keySequenceEdit->clearFocus();
@ -66,7 +66,7 @@ void ShortcutView::updateKey() {
}
void ShortcutView::updateButton(int button) {
if (!m_controller) {
if (!m_controller || m_controller->isMenuAt(m_ui.shortcutTable->selectionModel()->currentIndex())) {
return;
}
m_controller->updateButton(m_ui.shortcutTable->selectionModel()->currentIndex(), button);
@ -79,5 +79,5 @@ void ShortcutView::loadKey(const QAction* action) {
void ShortcutView::loadButton() {
m_ui.keyEdit->setFocus();
m_ui.keyEdit->setValueButton(-1); // TODO: Real value
m_ui.keyEdit->setValueButton(-1); // There are no default bindings
}