Merge pull request #5703 from ligfx/blockuserinputfilter
QtUtils: add BlockUserInputFilter
This commit is contained in:
commit
d6e051c942
|
@ -65,6 +65,7 @@ set(SRCS
|
|||
GameList/GameTracker.cpp
|
||||
GameList/ListProxyModel.cpp
|
||||
GameList/TableProxyModel.cpp
|
||||
QtUtils/BlockUserInputFilter.cpp
|
||||
QtUtils/DoubleClickEventFilter.cpp
|
||||
QtUtils/ElidedButton.cpp
|
||||
QtUtils/ListTabWidget.cpp
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "Core/Core.h"
|
||||
#include "DolphinQt2/Config/Mapping/MappingCommon.h"
|
||||
#include "DolphinQt2/Config/Mapping/MappingWindow.h"
|
||||
#include "DolphinQt2/QtUtils/BlockUserInputFilter.h"
|
||||
#include "InputCommon/ControlReference/ControlReference.h"
|
||||
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||
|
@ -171,11 +172,10 @@ void IOWindow::OnDialogButtonPressed(QAbstractButton* button)
|
|||
|
||||
void IOWindow::OnDetectButtonPressed()
|
||||
{
|
||||
if (m_block.IsSet())
|
||||
return;
|
||||
installEventFilter(BlockUserInputFilter::Instance());
|
||||
grabKeyboard();
|
||||
grabMouse();
|
||||
|
||||
m_block.Set(true);
|
||||
m_expression_text->setEnabled(false);
|
||||
std::thread([this] {
|
||||
auto* btn = m_type == IOWindow::Type::Input ? m_detect_button : m_test_button;
|
||||
const auto old_label = btn->text();
|
||||
|
@ -194,8 +194,10 @@ void IOWindow::OnDetectButtonPressed()
|
|||
if (list.size() > 0)
|
||||
m_option_list->setCurrentItem(list[0]);
|
||||
}
|
||||
m_expression_text->setEnabled(true);
|
||||
m_block.Set(false);
|
||||
|
||||
releaseMouse();
|
||||
releaseKeyboard();
|
||||
removeEventFilter(BlockUserInputFilter::Instance());
|
||||
}).detach();
|
||||
}
|
||||
|
||||
|
@ -208,9 +210,6 @@ void IOWindow::OnRangeChanged(int value)
|
|||
|
||||
void IOWindow::UpdateOptionList()
|
||||
{
|
||||
if (m_block.IsSet())
|
||||
return;
|
||||
|
||||
m_option_list->clear();
|
||||
|
||||
const auto device = g_controller_interface.FindDevice(m_devq);
|
||||
|
@ -233,7 +232,6 @@ void IOWindow::UpdateOptionList()
|
|||
|
||||
void IOWindow::UpdateDeviceList()
|
||||
{
|
||||
m_block.Set(true);
|
||||
m_devices_combo->clear();
|
||||
|
||||
Core::RunAsCPUThread([&] {
|
||||
|
@ -254,6 +252,4 @@ void IOWindow::UpdateDeviceList()
|
|||
|
||||
m_devices_combo->setCurrentIndex(0);
|
||||
});
|
||||
|
||||
m_block.Set(false);
|
||||
}
|
||||
|
|
|
@ -92,6 +92,5 @@ private:
|
|||
ControllerEmu::EmulatedController* m_controller;
|
||||
|
||||
ciface::Core::DeviceQualifier m_devq;
|
||||
Common::Flag m_block;
|
||||
Type m_type;
|
||||
};
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "DolphinQt2/Config/Mapping/MappingCommon.h"
|
||||
#include "DolphinQt2/Config/Mapping/MappingWidget.h"
|
||||
#include "DolphinQt2/Config/Mapping/MappingWindow.h"
|
||||
#include "DolphinQt2/QtUtils/BlockUserInputFilter.h"
|
||||
#include "InputCommon/ControlReference/ControlReference.h"
|
||||
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||
|
@ -42,9 +43,7 @@ void MappingButton::OnButtonPressed()
|
|||
if (m_parent->GetDevice() == nullptr || !m_reference->IsInput())
|
||||
return;
|
||||
|
||||
if (!m_block.TestAndSet())
|
||||
return;
|
||||
|
||||
installEventFilter(BlockUserInputFilter::Instance());
|
||||
grabKeyboard();
|
||||
grabMouse();
|
||||
|
||||
|
@ -63,7 +62,7 @@ void MappingButton::OnButtonPressed()
|
|||
|
||||
releaseMouse();
|
||||
releaseKeyboard();
|
||||
m_block.Clear();
|
||||
removeEventFilter(BlockUserInputFilter::Instance());
|
||||
|
||||
if (!expr.isEmpty())
|
||||
{
|
||||
|
@ -97,22 +96,6 @@ void MappingButton::Update()
|
|||
m_parent->SaveSettings();
|
||||
}
|
||||
|
||||
bool MappingButton::event(QEvent* event)
|
||||
{
|
||||
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)
|
||||
{
|
||||
switch (event->button())
|
||||
|
|
|
@ -25,7 +25,6 @@ signals:
|
|||
void AdvancedPressed();
|
||||
|
||||
private:
|
||||
bool event(QEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
|
||||
void OnButtonPressed();
|
||||
|
@ -34,5 +33,4 @@ private:
|
|||
|
||||
MappingWidget* m_parent;
|
||||
ControlReference* m_reference;
|
||||
Common::Flag m_block;
|
||||
};
|
||||
|
|
|
@ -189,6 +189,7 @@
|
|||
<ClCompile Include="Main.cpp" />
|
||||
<ClCompile Include="MainWindow.cpp" />
|
||||
<ClCompile Include="MenuBar.cpp" />
|
||||
<ClCompile Include="QtUtils\BlockUserInputFilter.cpp" />
|
||||
<ClCompile Include="QtUtils\DoubleClickEventFilter.cpp" />
|
||||
<ClCompile Include="QtUtils\ElidedButton.cpp" />
|
||||
<ClCompile Include="QtUtils\ListTabWidget.cpp" />
|
||||
|
@ -220,6 +221,7 @@
|
|||
<ClInclude Include="Config\Mapping\WiimoteEmuExtension.h" />
|
||||
<ClInclude Include="Config\Mapping\WiimoteEmuGeneral.h" />
|
||||
<ClInclude Include="Config\Mapping\WiimoteEmuMotionControl.h" />
|
||||
<ClInclude Include="QtUtils\BlockUserInputFilter.h" />
|
||||
<ClInclude Include="QtUtils\ElidedButton.h" />
|
||||
<ClInclude Include="QtUtils\ListTabWidget.h" />
|
||||
<ClInclude Include="Resources.h" />
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt2/QtUtils/BlockUserInputFilter.h"
|
||||
|
||||
#include <QEvent>
|
||||
|
||||
BlockUserInputFilter* BlockUserInputFilter::Instance()
|
||||
{
|
||||
static BlockUserInputFilter s_block_user_input_filter;
|
||||
return &s_block_user_input_filter;
|
||||
}
|
||||
|
||||
bool BlockUserInputFilter::eventFilter(QObject* object, QEvent* event)
|
||||
{
|
||||
const QEvent::Type event_type = event->type();
|
||||
return event_type == QEvent::KeyPress || event_type == QEvent::KeyRelease ||
|
||||
event_type == QEvent::MouseButtonPress || event_type == QEvent::MouseButtonRelease ||
|
||||
event_type == QEvent::MouseButtonDblClick;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QEvent;
|
||||
|
||||
class BlockUserInputFilter : public QObject
|
||||
{
|
||||
public:
|
||||
static BlockUserInputFilter* Instance();
|
||||
|
||||
private:
|
||||
BlockUserInputFilter() = default;
|
||||
bool eventFilter(QObject* object, QEvent* event) override;
|
||||
};
|
Loading…
Reference in New Issue