MappingButton: grab and release mouse and keyboard instead of calling parent SetBlockInputs

This commit is contained in:
Michael Maltese 2017-06-13 17:11:52 -07:00
parent 2188ac785a
commit 5b6c8c3ad0
6 changed files with 19 additions and 33 deletions

View file

@ -42,7 +42,9 @@ void MappingButton::OnButtonPressed()
setText(QStringLiteral("..."));
SetBlockInputs(true);
m_block = true;
grabKeyboard();
grabMouse();
// Avoid that the button press itself is registered as an event
Common::SleepCurrentThread(100);
@ -51,7 +53,10 @@ void MappingButton::OnButtonPressed()
m_parent->GetParent()->GetDeviceQualifier(),
m_parent->GetController()->default_device);
SetBlockInputs(false);
releaseMouse();
releaseKeyboard();
m_block = false;
if (!expr.isEmpty())
{
m_reference->expression = expr.toStdString();
@ -84,15 +89,20 @@ void MappingButton::Update()
m_parent->SaveSettings();
}
void MappingButton::SetBlockInputs(const bool block)
{
m_parent->SetBlockInputs(block);
m_block = block;
}
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 &&
(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

@ -30,7 +30,6 @@ private:
void OnButtonPressed();
void OnButtonTimeout();
void Connect();
void SetBlockInputs(const bool block);
MappingWidget* m_parent;
ControlReference* m_reference;

View file

@ -89,11 +89,6 @@ 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)

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;

View file

@ -369,19 +369,6 @@ std::shared_ptr<ciface::Core::Device> MappingWindow::GetDevice() const
return g_controller_interface.FindDevice(m_devq);
}
void MappingWindow::SetBlockInputs(const bool block)
{
m_block = block;
}
bool MappingWindow::event(QEvent* event)
{
if (!m_block)
return QDialog::event(event);
return false;
}
void MappingWindow::OnDefaultFieldsPressed()
{
if (m_controller == nullptr)

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;
};