all repos — mgba @ c90d105e3490d0b94a4dc5de182c6cf18b5616ba

mGBA Game Boy Advance Emulator

Qt: Add clear button for shortcut editor
Jeffrey Pfau jeffrey@endrift.com
Mon, 05 Jan 2015 01:57:25 -0800
commit

c90d105e3490d0b94a4dc5de182c6cf18b5616ba

parent

3854c7e4010cd4b1795aab47dd2009980e4d2b00

M src/platform/qt/ShortcutController.cppsrc/platform/qt/ShortcutController.cpp

@@ -193,7 +193,9 @@ QKeySequence oldShortcut = item->shortcut();

if (!oldShortcut.isEmpty()) { m_heldKeys.take(oldShortcut); } - m_heldKeys[keySequence] = item; + if (!keySequence.isEmpty()) { + m_heldKeys[keySequence] = item; + } } item->setShortcut(keySequence); if (m_config) {

@@ -216,11 +218,21 @@ item->setButton(button);

if (oldButton >= 0) { m_buttons.take(oldButton); } - m_buttons[button] = item; + if (button >= 0) { + m_buttons[button] = item; + } if (m_config) { m_config->setQtOption(item->name(), button, BUTTON_SECTION); } emit dataChanged(createIndex(index.row(), 0, index.internalPointer()), createIndex(index.row(), 2, index.internalPointer())); +} + +void ShortcutController::clearKey(const QModelIndex& index) { + updateKey(index, QKeySequence()); +} + +void ShortcutController::clearButton(const QModelIndex& index) { + updateButton(index, -1); } bool ShortcutController::eventFilter(QObject*, QEvent* event) {
M src/platform/qt/ShortcutController.hsrc/platform/qt/ShortcutController.h

@@ -92,6 +92,9 @@

void updateKey(const QModelIndex& index, const QKeySequence& keySequence); void updateButton(const QModelIndex& index, int button); + void clearKey(const QModelIndex& index); + void clearButton(const QModelIndex& index); + protected: bool eventFilter(QObject*, QEvent*) override;
M src/platform/qt/ShortcutView.cppsrc/platform/qt/ShortcutView.cpp

@@ -21,6 +21,7 @@

connect(m_ui.keySequenceEdit, SIGNAL(editingFinished()), this, SLOT(updateKey())); connect(m_ui.keyEdit, SIGNAL(valueChanged(int)), this, SLOT(updateButton(int))); connect(m_ui.shortcutTable, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(load(const QModelIndex&))); + connect(m_ui.clearButton, SIGNAL(clicked()), this, SLOT(clear())); } void ShortcutView::setController(ShortcutController* controller) {

@@ -51,9 +52,29 @@ if (!action || m_controller->isMenuAt(index)) {

return; } if (m_ui.gamepadButton->isChecked()) { - loadButton(); + m_ui.keyEdit->setFocus(); + m_ui.keyEdit->setValueButton(-1); // There are no default bindings + } else { + m_ui.keySequenceEdit->setFocus(); + m_ui.keySequenceEdit->setKeySequence(action->shortcut()); + } +} + +void ShortcutView::clear() { + if (!m_controller) { + return; + } + QModelIndex index = m_ui.shortcutTable->selectionModel()->currentIndex(); + const QAction* action = m_controller->actionAt(index); + if (!action || m_controller->isMenuAt(index)) { + return; + } + if (m_ui.gamepadButton->isChecked()) { + m_controller->clearButton(index); + m_ui.keyEdit->setValueButton(-1); } else { - loadKey(action); + m_controller->clearKey(index); + m_ui.keySequenceEdit->setKeySequence(QKeySequence()); } }

@@ -69,15 +90,7 @@ void ShortcutView::updateButton(int button) {

if (!m_controller || m_controller->isMenuAt(m_ui.shortcutTable->selectionModel()->currentIndex())) { return; } + m_ui.keyEdit->clearFocus(); m_controller->updateButton(m_ui.shortcutTable->selectionModel()->currentIndex(), button); } -void ShortcutView::loadKey(const QAction* action) { - m_ui.keySequenceEdit->setFocus(); - m_ui.keySequenceEdit->setKeySequence(action->shortcut()); -} - -void ShortcutView::loadButton() { - m_ui.keyEdit->setFocus(); - m_ui.keyEdit->setValueButton(-1); // There are no default bindings -}
M src/platform/qt/ShortcutView.hsrc/platform/qt/ShortcutView.h

@@ -29,6 +29,7 @@ virtual bool event(QEvent* event) override;

private slots: void load(const QModelIndex&); + void clear(); void updateKey(); void updateButton(int button);
M src/platform/qt/ShortcutView.uisrc/platform/qt/ShortcutView.ui

@@ -41,6 +41,13 @@ </property>

</widget> </item> <item> + <widget class="QPushButton" name="clearButton"> + <property name="text"> + <string>Clear</string> + </property> + </widget> + </item> + <item> <spacer name="horizontalSpacer_2"> <property name="orientation"> <enum>Qt::Horizontal</enum>

@@ -60,18 +67,6 @@ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">

<horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>40</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>100</width> - <height>16777215</height> - </size> </property> </widget> </item>

@@ -83,26 +78,8 @@ <horstretch>0</horstretch>

<verstretch>0</verstretch> </sizepolicy> </property> - <property name="minimumSize"> - <size> - <width>40</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>100</width> - <height>16777215</height> - </size> - </property> <property name="visible"> <bool>false</bool> - </property> - <property name="alignment"> - <set>Qt::AlignCenter</set> - </property> - <property name="placeholderText"> - <string>Press button</string> </property> </widget> </item>