Fix for events that should have been consumed by manipulators (#3108)
* fix for events that should have been consumed by manipulators making their way to the main viewport handler Signed-off-by: hultonha <hultonha@amazon.co.uk> * add missing include for SANDBOX_API macro Signed-off-by: hultonha <hultonha@amazon.co.uk> * add dependency on Qt::Test for AzToolsFrameworkTestCommon Signed-off-by: hultonha <hultonha@amazon.co.uk> * fix order of buttons passed to QMouseEvent Signed-off-by: hultonha <hultonha@amazon.co.uk> * potential fix for vtable error on linux Signed-off-by: hultonha <hultonha@amazon.co.uk> * potential fix for vtable error on linux again Signed-off-by: hultonha <hultonha@amazon.co.uk>
This commit is contained in:
+29
@@ -27,6 +27,35 @@ using namespace AzToolsFramework;
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
void MousePressAndMove(
|
||||
QWidget* widget, const QPoint& initialPositionWidget, const QPoint& mouseDelta, const Qt::MouseButton mouseButton)
|
||||
{
|
||||
QPoint position = widget->mapToGlobal(initialPositionWidget);
|
||||
QTest::mousePress(widget, mouseButton, Qt::NoModifier, position);
|
||||
|
||||
MouseMove(widget, initialPositionWidget, mouseDelta, mouseButton);
|
||||
}
|
||||
|
||||
// Note: There are a series of bugs in Qt that appear to be preventing mouseMove events
|
||||
// firing when sent through the QTest framework. This is a work around for our version
|
||||
// of Qt. In future this can hopefully be simplified. See ^1 for workaround.
|
||||
// More info: Issues with mouse move in Qt
|
||||
// - https://bugreports.qt.io/browse/QTBUG-5232
|
||||
// - https://bugreports.qt.io/browse/QTBUG-69414
|
||||
// - https://lists.qt-project.org/pipermail/development/2019-July/036873.html
|
||||
void MouseMove(QWidget* widget, const QPoint& initialPositionWidget, const QPoint& mouseDelta, const Qt::MouseButton mouseButton)
|
||||
{
|
||||
QPoint nextPosition = widget->mapToGlobal(initialPositionWidget + mouseDelta);
|
||||
|
||||
// ^1 To ensure a mouse move event is fired we must call the test mouse move function
|
||||
// and also send a mouse move event that matches. Each on their own do not appear to
|
||||
// work - please see the links above for more context.
|
||||
QTest::mouseMove(widget, nextPosition);
|
||||
QMouseEvent mouseMoveEvent(
|
||||
QEvent::MouseMove, QPointF(nextPosition), QPointF(nextPosition), Qt::NoButton, mouseButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(widget, &mouseMoveEvent);
|
||||
}
|
||||
|
||||
bool TestWidget::eventFilter(QObject* watched, QEvent* event)
|
||||
{
|
||||
AZ_UNUSED(watched);
|
||||
|
||||
+15
@@ -59,6 +59,21 @@ namespace UnitTest
|
||||
{
|
||||
constexpr AZStd::string_view prefabSystemSetting = "/Amazon/Preferences/EnablePrefabSystem";
|
||||
|
||||
/// Performs a mouse press and move event on the provided widget.
|
||||
/// @param widget The widget to perform the mouse press and move on.
|
||||
/// @param initialPositionWidget The position of the mouse relative to the widget (will be remapped to a global position internally).
|
||||
/// @param mouseDelta How far to move the mouse.
|
||||
/// @param mouseButton The button to be used during the press and move.
|
||||
void MousePressAndMove(
|
||||
QWidget* widget, const QPoint& initialPositionWidget, const QPoint& mouseDelta, Qt::MouseButton mouseButton = Qt::LeftButton);
|
||||
|
||||
/// Performs a mouse move event on the provided widget.
|
||||
/// @param widget The widget to perform the mouse move on.
|
||||
/// @param initialPositionWidget The position of the mouse relative to the widget (will be remapped to a global position internally).
|
||||
/// @param mouseDelta How far to move the mouse (note: mouseDelta may be zero and the mouse will only be moved to initialPosition).
|
||||
/// @param mouseButton The button to be held during the move.
|
||||
void MouseMove(QWidget* widget, const QPoint& initialPosition, const QPoint& mouseDelta, Qt::MouseButton mouseButton = Qt::NoButton);
|
||||
|
||||
/// Test widget to store QActions generated by EditorTransformComponentSelection.
|
||||
class TestWidget : public QWidget
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user