Merge pull request #5614 from ligfx/qtinputmappingrandomcleanups

DolphinQt: small input mapping code cleanups and fixes
This commit is contained in:
shuffle2 2017-06-27 01:57:26 -07:00 committed by GitHub
commit 94ba78d717
6 changed files with 38 additions and 59 deletions

View File

@ -33,22 +33,21 @@ void MappingButton::Connect()
void MappingButton::OnButtonPressed()
{
if (m_block || m_parent->GetDevice() == nullptr || !m_reference->IsInput())
if (m_parent->GetDevice() == nullptr || !m_reference->IsInput())
return;
if (!m_block.TestAndSet())
return;
grabKeyboard();
grabMouse();
// Make sure that we don't block event handling
std::thread([this] {
const auto dev = m_parent->GetDevice();
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
Common::SleepCurrentThread(100);
@ -56,7 +55,10 @@ void MappingButton::OnButtonPressed()
m_parent->GetParent()->GetDeviceQualifier(),
m_parent->GetController()->default_device);
SetBlockInputs(false);
releaseMouse();
releaseKeyboard();
m_block.Clear();
if (!expr.isEmpty())
{
m_reference->expression = expr.toStdString();
@ -89,25 +91,20 @@ void MappingButton::Update()
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)
{
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)

View File

@ -4,6 +4,7 @@
#pragma once
#include "Common/Flag.h"
#include "DolphinQt2/QtUtils/ElidedButton.h"
class ControlReference;
@ -30,9 +31,8 @@ private:
void OnButtonPressed();
void OnButtonTimeout();
void Connect();
void SetBlockInputs(const bool block);
MappingWidget* m_parent;
ControlReference* m_reference;
bool m_block = false;
Common::Flag m_block;
};

View File

@ -89,15 +89,16 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con
return group_box;
}
void MappingWidget::SetBlockInputs(const bool block)
{
m_parent->SetBlockInputs(block);
}
void MappingWidget::OnClearFields()
{
for (auto* button : m_buttons)
button->Clear();
for (auto* spinbox : m_numerics)
spinbox->Clear();
for (auto* checkbox : m_bools)
checkbox->Clear();
}
void MappingWidget::Update()
@ -108,22 +109,12 @@ void MappingWidget::Update()
for (auto* spinbox : m_numerics)
spinbox->Update();
for (auto* checkbox : m_numerics)
for (auto* checkbox : m_bools)
checkbox->Update();
LoadSettings();
}
bool MappingWidget::GetFirstButtonPress()
{
if (m_first)
{
m_first = false;
return true;
}
return false;
}
ControllerEmu::EmulatedController* MappingWidget::GetController() const
{
return m_parent->GetController();

View File

@ -43,7 +43,6 @@ public:
ControllerEmu::EmulatedController* GetController() const;
std::shared_ptr<ciface::Core::Device> GetDevice() const;
void SetBlockInputs(const bool block);
MappingWindow* GetParent() const;
virtual void LoadSettings() = 0;
@ -51,7 +50,6 @@ public:
virtual InputConfig* GetConfig() = 0;
void Update();
bool GetFirstButtonPress();
protected:
int GetPort() const;

View File

@ -369,15 +369,12 @@ std::shared_ptr<ciface::Core::Device> MappingWindow::GetDevice() const
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)
{
if (!m_block)
return QDialog::event(event);
return false;
m_controller->LoadDefaults(g_controller_interface);
m_controller->UpdateReferences(g_controller_interface);
emit Update();
}

View File

@ -53,7 +53,6 @@ public:
const ciface::Core::DeviceQualifier& GetDeviceQualifier() const;
std::shared_ptr<ciface::Core::Device> GetDevice() const;
void SetBlockInputs(const bool block);
ControllerEmu::EmulatedController* GetController() const;
signals:
void Update();
@ -80,8 +79,6 @@ private:
void OnProfileChanged(int index);
void OnDeviceChanged(int index);
bool event(QEvent* event) override;
ControllerEmu::EmulatedController* m_controller = nullptr;
// Main
@ -114,7 +111,6 @@ private:
Type m_mapping_type;
const int m_port;
bool m_is_complex;
bool m_block = false;
InputConfig* m_config;
ciface::Core::DeviceQualifier m_devq;
};