Qt: Add support for clearing input bindings with right click

This commit is contained in:
Connor McLaughlin 2020-03-22 00:49:55 +10:00
parent 29a09a3685
commit 45050709f2
2 changed files with 22 additions and 0 deletions

View file

@ -4,6 +4,7 @@
#include "qthostinterface.h"
#include "qtutils.h"
#include <QtCore/QTimer>
#include <QtGui/QMouseEvent>
#include <QtGui/QKeyEvent>
#include <cmath>
@ -34,6 +35,17 @@ bool InputBindingWidget::eventFilter(QObject* watched, QEvent* event)
return false;
}
void InputBindingWidget::mouseReleaseEvent(QMouseEvent* e)
{
if (e->button() == Qt::RightButton)
{
clearBinding();
return;
}
QPushButton::mouseReleaseEvent(e);
}
void InputBindingWidget::setNewBinding()
{
if (m_new_binding_value.isEmpty())
@ -46,6 +58,14 @@ void InputBindingWidget::setNewBinding()
m_new_binding_value.clear();
}
void InputBindingWidget::clearBinding()
{
m_current_binding_value.clear();
m_host_interface->removeSettingValue(m_setting_name);
m_host_interface->updateInputMap();
setText(m_current_binding_value);
}
void InputBindingWidget::onPressed()
{
if (isListeningForInput())

View file

@ -16,6 +16,7 @@ public:
protected:
virtual bool eventFilter(QObject* watched, QEvent* event) override;
virtual void mouseReleaseEvent(QMouseEvent* e) override;
protected Q_SLOTS:
void onPressed();
@ -27,6 +28,7 @@ protected:
bool isListeningForInput() const { return m_input_listen_timer != nullptr; }
void setNewBinding();
void clearBinding();
QtHostInterface* m_host_interface;
QString m_setting_name;