Merge pull request #5614 from ligfx/qtinputmappingrandomcleanups
DolphinQt: small input mapping code cleanups and fixes
This commit is contained in:
commit
94ba78d717
|
@ -33,22 +33,21 @@ void MappingButton::Connect()
|
||||||
|
|
||||||
void MappingButton::OnButtonPressed()
|
void MappingButton::OnButtonPressed()
|
||||||
{
|
{
|
||||||
if (m_block || m_parent->GetDevice() == nullptr || !m_reference->IsInput())
|
if (m_parent->GetDevice() == nullptr || !m_reference->IsInput())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!m_block.TestAndSet())
|
||||||
|
return;
|
||||||
|
|
||||||
|
grabKeyboard();
|
||||||
|
grabMouse();
|
||||||
|
|
||||||
// Make sure that we don't block event handling
|
// Make sure that we don't block event handling
|
||||||
std::thread([this] {
|
std::thread([this] {
|
||||||
const auto dev = m_parent->GetDevice();
|
const auto dev = m_parent->GetDevice();
|
||||||
|
|
||||||
setText(QStringLiteral("..."));
|
setText(QStringLiteral("..."));
|
||||||
|
|
||||||
Common::SleepCurrentThread(100);
|
|
||||||
|
|
||||||
SetBlockInputs(true);
|
|
||||||
|
|
||||||
if (m_parent->GetFirstButtonPress())
|
|
||||||
m_reference->Detect(10, dev.get());
|
|
||||||
|
|
||||||
// Avoid that the button press itself is registered as an event
|
// Avoid that the button press itself is registered as an event
|
||||||
Common::SleepCurrentThread(100);
|
Common::SleepCurrentThread(100);
|
||||||
|
|
||||||
|
@ -56,7 +55,10 @@ void MappingButton::OnButtonPressed()
|
||||||
m_parent->GetParent()->GetDeviceQualifier(),
|
m_parent->GetParent()->GetDeviceQualifier(),
|
||||||
m_parent->GetController()->default_device);
|
m_parent->GetController()->default_device);
|
||||||
|
|
||||||
SetBlockInputs(false);
|
releaseMouse();
|
||||||
|
releaseKeyboard();
|
||||||
|
m_block.Clear();
|
||||||
|
|
||||||
if (!expr.isEmpty())
|
if (!expr.isEmpty())
|
||||||
{
|
{
|
||||||
m_reference->expression = expr.toStdString();
|
m_reference->expression = expr.toStdString();
|
||||||
|
@ -89,25 +91,20 @@ void MappingButton::Update()
|
||||||
m_parent->SaveSettings();
|
m_parent->SaveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MappingButton::SetBlockInputs(const bool block)
|
|
||||||
{
|
|
||||||
m_parent->SetBlockInputs(block);
|
|
||||||
m_block = block;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MappingWindow::OnDefaultFieldsPressed()
|
|
||||||
{
|
|
||||||
if (m_controller == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_controller->LoadDefaults(g_controller_interface);
|
|
||||||
m_controller->UpdateReferences(g_controller_interface);
|
|
||||||
emit Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MappingButton::event(QEvent* event)
|
bool MappingButton::event(QEvent* event)
|
||||||
{
|
{
|
||||||
return !m_block ? QPushButton::event(event) : true;
|
const QEvent::Type event_type = event->type();
|
||||||
|
// Returning 'true' means "yes, this event has been handled, don't propagate it to parent
|
||||||
|
// widgets".
|
||||||
|
if (m_block.IsSet() &&
|
||||||
|
(event_type == QEvent::KeyPress || event_type == QEvent::KeyRelease ||
|
||||||
|
event_type == QEvent::MouseButtonPress || event_type == QEvent::MouseButtonRelease ||
|
||||||
|
event_type == QEvent::MouseButtonDblClick))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QPushButton::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MappingButton::mouseReleaseEvent(QMouseEvent* event)
|
void MappingButton::mouseReleaseEvent(QMouseEvent* event)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Common/Flag.h"
|
||||||
#include "DolphinQt2/QtUtils/ElidedButton.h"
|
#include "DolphinQt2/QtUtils/ElidedButton.h"
|
||||||
|
|
||||||
class ControlReference;
|
class ControlReference;
|
||||||
|
@ -30,9 +31,8 @@ private:
|
||||||
void OnButtonPressed();
|
void OnButtonPressed();
|
||||||
void OnButtonTimeout();
|
void OnButtonTimeout();
|
||||||
void Connect();
|
void Connect();
|
||||||
void SetBlockInputs(const bool block);
|
|
||||||
|
|
||||||
MappingWidget* m_parent;
|
MappingWidget* m_parent;
|
||||||
ControlReference* m_reference;
|
ControlReference* m_reference;
|
||||||
bool m_block = false;
|
Common::Flag m_block;
|
||||||
};
|
};
|
||||||
|
|
|
@ -89,15 +89,16 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con
|
||||||
return group_box;
|
return group_box;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MappingWidget::SetBlockInputs(const bool block)
|
|
||||||
{
|
|
||||||
m_parent->SetBlockInputs(block);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MappingWidget::OnClearFields()
|
void MappingWidget::OnClearFields()
|
||||||
{
|
{
|
||||||
for (auto* button : m_buttons)
|
for (auto* button : m_buttons)
|
||||||
button->Clear();
|
button->Clear();
|
||||||
|
|
||||||
|
for (auto* spinbox : m_numerics)
|
||||||
|
spinbox->Clear();
|
||||||
|
|
||||||
|
for (auto* checkbox : m_bools)
|
||||||
|
checkbox->Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MappingWidget::Update()
|
void MappingWidget::Update()
|
||||||
|
@ -108,22 +109,12 @@ void MappingWidget::Update()
|
||||||
for (auto* spinbox : m_numerics)
|
for (auto* spinbox : m_numerics)
|
||||||
spinbox->Update();
|
spinbox->Update();
|
||||||
|
|
||||||
for (auto* checkbox : m_numerics)
|
for (auto* checkbox : m_bools)
|
||||||
checkbox->Update();
|
checkbox->Update();
|
||||||
|
|
||||||
LoadSettings();
|
LoadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MappingWidget::GetFirstButtonPress()
|
|
||||||
{
|
|
||||||
if (m_first)
|
|
||||||
{
|
|
||||||
m_first = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ControllerEmu::EmulatedController* MappingWidget::GetController() const
|
ControllerEmu::EmulatedController* MappingWidget::GetController() const
|
||||||
{
|
{
|
||||||
return m_parent->GetController();
|
return m_parent->GetController();
|
||||||
|
|
|
@ -43,7 +43,6 @@ public:
|
||||||
ControllerEmu::EmulatedController* GetController() const;
|
ControllerEmu::EmulatedController* GetController() const;
|
||||||
std::shared_ptr<ciface::Core::Device> GetDevice() const;
|
std::shared_ptr<ciface::Core::Device> GetDevice() const;
|
||||||
|
|
||||||
void SetBlockInputs(const bool block);
|
|
||||||
MappingWindow* GetParent() const;
|
MappingWindow* GetParent() const;
|
||||||
|
|
||||||
virtual void LoadSettings() = 0;
|
virtual void LoadSettings() = 0;
|
||||||
|
@ -51,7 +50,6 @@ public:
|
||||||
virtual InputConfig* GetConfig() = 0;
|
virtual InputConfig* GetConfig() = 0;
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
bool GetFirstButtonPress();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int GetPort() const;
|
int GetPort() const;
|
||||||
|
|
|
@ -369,15 +369,12 @@ std::shared_ptr<ciface::Core::Device> MappingWindow::GetDevice() const
|
||||||
return g_controller_interface.FindDevice(m_devq);
|
return g_controller_interface.FindDevice(m_devq);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MappingWindow::SetBlockInputs(const bool block)
|
void MappingWindow::OnDefaultFieldsPressed()
|
||||||
{
|
{
|
||||||
m_block = block;
|
if (m_controller == nullptr)
|
||||||
}
|
return;
|
||||||
|
|
||||||
bool MappingWindow::event(QEvent* event)
|
m_controller->LoadDefaults(g_controller_interface);
|
||||||
{
|
m_controller->UpdateReferences(g_controller_interface);
|
||||||
if (!m_block)
|
emit Update();
|
||||||
return QDialog::event(event);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,6 @@ public:
|
||||||
const ciface::Core::DeviceQualifier& GetDeviceQualifier() const;
|
const ciface::Core::DeviceQualifier& GetDeviceQualifier() const;
|
||||||
std::shared_ptr<ciface::Core::Device> GetDevice() const;
|
std::shared_ptr<ciface::Core::Device> GetDevice() const;
|
||||||
|
|
||||||
void SetBlockInputs(const bool block);
|
|
||||||
ControllerEmu::EmulatedController* GetController() const;
|
ControllerEmu::EmulatedController* GetController() const;
|
||||||
signals:
|
signals:
|
||||||
void Update();
|
void Update();
|
||||||
|
@ -80,8 +79,6 @@ private:
|
||||||
void OnProfileChanged(int index);
|
void OnProfileChanged(int index);
|
||||||
void OnDeviceChanged(int index);
|
void OnDeviceChanged(int index);
|
||||||
|
|
||||||
bool event(QEvent* event) override;
|
|
||||||
|
|
||||||
ControllerEmu::EmulatedController* m_controller = nullptr;
|
ControllerEmu::EmulatedController* m_controller = nullptr;
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
|
@ -114,7 +111,6 @@ private:
|
||||||
Type m_mapping_type;
|
Type m_mapping_type;
|
||||||
const int m_port;
|
const int m_port;
|
||||||
bool m_is_complex;
|
bool m_is_complex;
|
||||||
bool m_block = false;
|
|
||||||
InputConfig* m_config;
|
InputConfig* m_config;
|
||||||
ciface::Core::DeviceQualifier m_devq;
|
ciface::Core::DeviceQualifier m_devq;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue