Qt/MappingButton: light up when mapped key is pressed
This commit is contained in:
parent
87d7c994e7
commit
220e4bcd99
|
@ -7,6 +7,9 @@
|
|||
#include <QMouseEvent>
|
||||
#include <QRegExp>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "DolphinQt2/Config/Mapping/MappingButton.h"
|
||||
|
||||
|
@ -16,6 +19,7 @@
|
|||
#include "DolphinQt2/Config/Mapping/MappingWidget.h"
|
||||
#include "DolphinQt2/Config/Mapping/MappingWindow.h"
|
||||
#include "DolphinQt2/QtUtils/BlockUserInputFilter.h"
|
||||
#include "DolphinQt2/Settings.h"
|
||||
#include "InputCommon/ControlReference/ControlReference.h"
|
||||
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||
|
@ -26,11 +30,39 @@ static QString EscapeAmpersand(QString&& string)
|
|||
return string.replace(QStringLiteral("&"), QStringLiteral("&&"));
|
||||
}
|
||||
|
||||
MappingButton::MappingButton(MappingWidget* widget, ControlReference* ref)
|
||||
MappingButton::MappingButton(MappingWidget* widget, ControlReference* ref, bool indicator)
|
||||
: ElidedButton(EscapeAmpersand(QString::fromStdString(ref->GetExpression()))), m_parent(widget),
|
||||
m_reference(ref)
|
||||
{
|
||||
Connect();
|
||||
if (!m_reference->IsInput() || !indicator)
|
||||
return;
|
||||
|
||||
m_timer = new QTimer(this);
|
||||
connect(m_timer, &QTimer::timeout, this, [this] {
|
||||
if (!isActiveWindow())
|
||||
return;
|
||||
|
||||
Settings::Instance().SetControllerStateNeeded(true);
|
||||
|
||||
auto state = m_reference->State();
|
||||
|
||||
QFont f = m_parent->font();
|
||||
QPalette p = m_parent->palette();
|
||||
|
||||
if (state != 0)
|
||||
{
|
||||
f.setBold(true);
|
||||
p.setColor(QPalette::ButtonText, Qt::red);
|
||||
}
|
||||
|
||||
setFont(f);
|
||||
setPalette(p);
|
||||
|
||||
Settings::Instance().SetControllerStateNeeded(false);
|
||||
});
|
||||
|
||||
m_timer->start(1000 / 30);
|
||||
}
|
||||
|
||||
void MappingButton::Connect()
|
||||
|
|
|
@ -11,12 +11,13 @@ class ControlReference;
|
|||
class MappingWidget;
|
||||
class QEvent;
|
||||
class QMouseEvent;
|
||||
class QTimer;
|
||||
|
||||
class MappingButton : public ElidedButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MappingButton(MappingWidget* widget, ControlReference* ref);
|
||||
MappingButton(MappingWidget* widget, ControlReference* ref, bool indicator);
|
||||
|
||||
void Clear();
|
||||
void Update();
|
||||
|
@ -33,4 +34,5 @@ private:
|
|||
|
||||
MappingWidget* m_parent;
|
||||
ControlReference* m_reference;
|
||||
QTimer* m_timer;
|
||||
};
|
||||
|
|
|
@ -47,9 +47,13 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con
|
|||
|
||||
group_box->setLayout(form_layout);
|
||||
|
||||
bool need_indicator = group->type == ControllerEmu::GroupType::Cursor ||
|
||||
group->type == ControllerEmu::GroupType::Stick ||
|
||||
group->type == ControllerEmu::GroupType::Tilt;
|
||||
|
||||
for (auto& control : group->controls)
|
||||
{
|
||||
auto* button = new MappingButton(this, control->control_ref.get());
|
||||
auto* button = new MappingButton(this, control->control_ref.get(), !need_indicator);
|
||||
|
||||
button->setMinimumWidth(100);
|
||||
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
|
@ -87,6 +91,9 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con
|
|||
m_bools.push_back(checkbox);
|
||||
}
|
||||
|
||||
if (need_indicator)
|
||||
form_layout->addRow(new MappingIndicator(group));
|
||||
|
||||
return group_box;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue