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/GameTracker.cpp
|
||||||
GameList/ListProxyModel.cpp
|
GameList/ListProxyModel.cpp
|
||||||
GameList/TableProxyModel.cpp
|
GameList/TableProxyModel.cpp
|
||||||
|
QtUtils/BlockUserInputFilter.cpp
|
||||||
QtUtils/DoubleClickEventFilter.cpp
|
QtUtils/DoubleClickEventFilter.cpp
|
||||||
QtUtils/ElidedButton.cpp
|
QtUtils/ElidedButton.cpp
|
||||||
QtUtils/ListTabWidget.cpp
|
QtUtils/ListTabWidget.cpp
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
#include "DolphinQt2/Config/Mapping/MappingCommon.h"
|
#include "DolphinQt2/Config/Mapping/MappingCommon.h"
|
||||||
#include "DolphinQt2/Config/Mapping/MappingWindow.h"
|
#include "DolphinQt2/Config/Mapping/MappingWindow.h"
|
||||||
|
#include "DolphinQt2/QtUtils/BlockUserInputFilter.h"
|
||||||
#include "InputCommon/ControlReference/ControlReference.h"
|
#include "InputCommon/ControlReference/ControlReference.h"
|
||||||
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||||
|
@ -171,11 +172,10 @@ void IOWindow::OnDialogButtonPressed(QAbstractButton* button)
|
||||||
|
|
||||||
void IOWindow::OnDetectButtonPressed()
|
void IOWindow::OnDetectButtonPressed()
|
||||||
{
|
{
|
||||||
if (m_block.IsSet())
|
installEventFilter(BlockUserInputFilter::Instance());
|
||||||
return;
|
grabKeyboard();
|
||||||
|
grabMouse();
|
||||||
|
|
||||||
m_block.Set(true);
|
|
||||||
m_expression_text->setEnabled(false);
|
|
||||||
std::thread([this] {
|
std::thread([this] {
|
||||||
auto* btn = m_type == IOWindow::Type::Input ? m_detect_button : m_test_button;
|
auto* btn = m_type == IOWindow::Type::Input ? m_detect_button : m_test_button;
|
||||||
const auto old_label = btn->text();
|
const auto old_label = btn->text();
|
||||||
|
@ -194,8 +194,10 @@ void IOWindow::OnDetectButtonPressed()
|
||||||
if (list.size() > 0)
|
if (list.size() > 0)
|
||||||
m_option_list->setCurrentItem(list[0]);
|
m_option_list->setCurrentItem(list[0]);
|
||||||
}
|
}
|
||||||
m_expression_text->setEnabled(true);
|
|
||||||
m_block.Set(false);
|
releaseMouse();
|
||||||
|
releaseKeyboard();
|
||||||
|
removeEventFilter(BlockUserInputFilter::Instance());
|
||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,9 +210,6 @@ void IOWindow::OnRangeChanged(int value)
|
||||||
|
|
||||||
void IOWindow::UpdateOptionList()
|
void IOWindow::UpdateOptionList()
|
||||||
{
|
{
|
||||||
if (m_block.IsSet())
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_option_list->clear();
|
m_option_list->clear();
|
||||||
|
|
||||||
const auto device = g_controller_interface.FindDevice(m_devq);
|
const auto device = g_controller_interface.FindDevice(m_devq);
|
||||||
|
@ -233,7 +232,6 @@ void IOWindow::UpdateOptionList()
|
||||||
|
|
||||||
void IOWindow::UpdateDeviceList()
|
void IOWindow::UpdateDeviceList()
|
||||||
{
|
{
|
||||||
m_block.Set(true);
|
|
||||||
m_devices_combo->clear();
|
m_devices_combo->clear();
|
||||||
|
|
||||||
Core::RunAsCPUThread([&] {
|
Core::RunAsCPUThread([&] {
|
||||||
|
@ -254,6 +252,4 @@ void IOWindow::UpdateDeviceList()
|
||||||
|
|
||||||
m_devices_combo->setCurrentIndex(0);
|
m_devices_combo->setCurrentIndex(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
m_block.Set(false);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,5 @@ private:
|
||||||
ControllerEmu::EmulatedController* m_controller;
|
ControllerEmu::EmulatedController* m_controller;
|
||||||
|
|
||||||
ciface::Core::DeviceQualifier m_devq;
|
ciface::Core::DeviceQualifier m_devq;
|
||||||
Common::Flag m_block;
|
|
||||||
Type m_type;
|
Type m_type;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "DolphinQt2/Config/Mapping/MappingCommon.h"
|
#include "DolphinQt2/Config/Mapping/MappingCommon.h"
|
||||||
#include "DolphinQt2/Config/Mapping/MappingWidget.h"
|
#include "DolphinQt2/Config/Mapping/MappingWidget.h"
|
||||||
#include "DolphinQt2/Config/Mapping/MappingWindow.h"
|
#include "DolphinQt2/Config/Mapping/MappingWindow.h"
|
||||||
|
#include "DolphinQt2/QtUtils/BlockUserInputFilter.h"
|
||||||
#include "InputCommon/ControlReference/ControlReference.h"
|
#include "InputCommon/ControlReference/ControlReference.h"
|
||||||
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||||
|
@ -42,9 +43,7 @@ void MappingButton::OnButtonPressed()
|
||||||
if (m_parent->GetDevice() == nullptr || !m_reference->IsInput())
|
if (m_parent->GetDevice() == nullptr || !m_reference->IsInput())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!m_block.TestAndSet())
|
installEventFilter(BlockUserInputFilter::Instance());
|
||||||
return;
|
|
||||||
|
|
||||||
grabKeyboard();
|
grabKeyboard();
|
||||||
grabMouse();
|
grabMouse();
|
||||||
|
|
||||||
|
@ -63,7 +62,7 @@ void MappingButton::OnButtonPressed()
|
||||||
|
|
||||||
releaseMouse();
|
releaseMouse();
|
||||||
releaseKeyboard();
|
releaseKeyboard();
|
||||||
m_block.Clear();
|
removeEventFilter(BlockUserInputFilter::Instance());
|
||||||
|
|
||||||
if (!expr.isEmpty())
|
if (!expr.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -97,22 +96,6 @@ void MappingButton::Update()
|
||||||
m_parent->SaveSettings();
|
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)
|
void MappingButton::mouseReleaseEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
switch (event->button())
|
switch (event->button())
|
||||||
|
|
|
@ -25,7 +25,6 @@ signals:
|
||||||
void AdvancedPressed();
|
void AdvancedPressed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool event(QEvent* event) override;
|
|
||||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||||
|
|
||||||
void OnButtonPressed();
|
void OnButtonPressed();
|
||||||
|
@ -34,5 +33,4 @@ private:
|
||||||
|
|
||||||
MappingWidget* m_parent;
|
MappingWidget* m_parent;
|
||||||
ControlReference* m_reference;
|
ControlReference* m_reference;
|
||||||
Common::Flag m_block;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -189,6 +189,7 @@
|
||||||
<ClCompile Include="Main.cpp" />
|
<ClCompile Include="Main.cpp" />
|
||||||
<ClCompile Include="MainWindow.cpp" />
|
<ClCompile Include="MainWindow.cpp" />
|
||||||
<ClCompile Include="MenuBar.cpp" />
|
<ClCompile Include="MenuBar.cpp" />
|
||||||
|
<ClCompile Include="QtUtils\BlockUserInputFilter.cpp" />
|
||||||
<ClCompile Include="QtUtils\DoubleClickEventFilter.cpp" />
|
<ClCompile Include="QtUtils\DoubleClickEventFilter.cpp" />
|
||||||
<ClCompile Include="QtUtils\ElidedButton.cpp" />
|
<ClCompile Include="QtUtils\ElidedButton.cpp" />
|
||||||
<ClCompile Include="QtUtils\ListTabWidget.cpp" />
|
<ClCompile Include="QtUtils\ListTabWidget.cpp" />
|
||||||
|
@ -220,6 +221,7 @@
|
||||||
<ClInclude Include="Config\Mapping\WiimoteEmuExtension.h" />
|
<ClInclude Include="Config\Mapping\WiimoteEmuExtension.h" />
|
||||||
<ClInclude Include="Config\Mapping\WiimoteEmuGeneral.h" />
|
<ClInclude Include="Config\Mapping\WiimoteEmuGeneral.h" />
|
||||||
<ClInclude Include="Config\Mapping\WiimoteEmuMotionControl.h" />
|
<ClInclude Include="Config\Mapping\WiimoteEmuMotionControl.h" />
|
||||||
|
<ClInclude Include="QtUtils\BlockUserInputFilter.h" />
|
||||||
<ClInclude Include="QtUtils\ElidedButton.h" />
|
<ClInclude Include="QtUtils\ElidedButton.h" />
|
||||||
<ClInclude Include="QtUtils\ListTabWidget.h" />
|
<ClInclude Include="QtUtils\ListTabWidget.h" />
|
||||||
<ClInclude Include="Resources.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