Qt: Buttons for clearing analog and buttons

This commit is contained in:
Jeffrey Pfau 2015-07-25 21:55:28 -07:00
parent 3c55784c54
commit 24a910c9d3
4 changed files with 50 additions and 1 deletions

View File

@ -6,6 +6,7 @@
#include "GBAKeyEditor.h"
#include <QComboBox>
#include <QHBoxLayout>
#include <QPaintEvent>
#include <QPainter>
#include <QPushButton>
@ -24,6 +25,7 @@ const qreal GBAKeyEditor::DPAD_HEIGHT = 0.1;
GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, const QString& profile, QWidget* parent)
: QWidget(parent)
, m_profileSelect(nullptr)
, m_clear(nullptr)
, m_type(type)
, m_profile(profile)
, m_controller(controller)
@ -65,6 +67,33 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, const QString&
m_controller->loadProfile(m_type, m_profile);
refresh();
});
m_clear = new QWidget(this);
QHBoxLayout* layout = new QHBoxLayout;
m_clear->setLayout(layout);
layout->setSpacing(6);
QPushButton* clearButton = new QPushButton(tr("Clear Button"));
layout->addWidget(clearButton);
connect(clearButton, &QAbstractButton::pressed, [this]() {
if (!findFocus()) {
return;
}
bool signalsBlocked = (*m_currentKey)->blockSignals(true);
(*m_currentKey)->clearButton();
(*m_currentKey)->blockSignals(signalsBlocked);
});
QPushButton* clearAxis = new QPushButton(tr("Clear Analog"));
layout->addWidget(clearAxis);
connect(clearAxis, &QAbstractButton::pressed, [this]() {
if (!findFocus()) {
return;
}
bool signalsBlocked = (*m_currentKey)->blockSignals(true);
(*m_currentKey)->clearAxis();
(*m_currentKey)->blockSignals(signalsBlocked);
});
}
#endif
@ -125,7 +154,11 @@ void GBAKeyEditor::resizeEvent(QResizeEvent* event) {
setLocation(m_keyR, 0.9, 0.1);
if (m_profileSelect) {
setLocation(m_profileSelect, 0.5, 0.7);
setLocation(m_profileSelect, 0.5, 0.67);
}
if (m_clear) {
setLocation(m_clear, 0.5, 0.77);
}
}

View File

@ -66,6 +66,7 @@ private:
KeyEditor* keyById(GBAKey);
QComboBox* m_profileSelect;
QWidget* m_clear;
QWidget* m_buttons;
KeyEditor* m_keyDU;
KeyEditor* m_keyDD;

View File

@ -50,6 +50,19 @@ void KeyEditor::setValueAxis(int axis, int32_t value) {
emit axisChanged(axis, m_direction);
}
void KeyEditor::clearButton() {
m_button = true;
setValue(-1);
}
void KeyEditor::clearAxis() {
m_button = true;
m_axis = -1;
m_direction = GamepadAxisEvent::NEUTRAL;
updateButtonText();
emit axisChanged(m_axis, m_direction);
}
QSize KeyEditor::sizeHint() const {
QSize hint = QLineEdit::sizeHint();
hint.setWidth(40);

View File

@ -29,6 +29,8 @@ public slots:
void setValueKey(int key);
void setValueButton(int button);
void setValueAxis(int axis, int32_t value);
void clearButton();
void clearAxis();
signals:
void valueChanged(int key);