add support for QWindow in mouseEvent
Change-Id: I0cbc2f2e6f4753da44a7709b31cf0e228def628c Reviewed-on: http://codereview.qt.nokia.com/4271 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
This commit is contained in:
parent
079ec157f8
commit
d130382776
@ -51,12 +51,12 @@
|
||||
#include <QtTest/qtestassert.h>
|
||||
#include <QtTest/qtestsystem.h>
|
||||
#include <QtTest/qtestspontaneevent.h>
|
||||
|
||||
#include <QtCore/qpoint.h>
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtWidgets/qapplication.h>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QtWidgets/qwidget.h>
|
||||
#include <QtGui/qwindowsysteminterface_qpa.h>
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
|
||||
@ -125,6 +125,60 @@ namespace QTest
|
||||
}
|
||||
|
||||
}
|
||||
static void mouseEvent(MouseAction action, QWindow *window, Qt::MouseButton button,
|
||||
Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
|
||||
{
|
||||
QTEST_ASSERT(window);
|
||||
extern int Q_TESTLIB_EXPORT defaultMouseDelay();
|
||||
|
||||
if (delay == -1 || delay < defaultMouseDelay())
|
||||
delay = defaultMouseDelay();
|
||||
if (delay > 0)
|
||||
QTest::qWait(delay);
|
||||
|
||||
if (pos.isNull())
|
||||
pos = window->geometry().center();
|
||||
|
||||
if (action == MouseClick) {
|
||||
mouseEvent(MousePress, window, button, stateKey, pos);
|
||||
mouseEvent(MouseRelease, window, button, stateKey, pos);
|
||||
return;
|
||||
}
|
||||
QTEST_ASSERT(button == Qt::NoButton || button & Qt::MouseButtonMask);
|
||||
QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask);
|
||||
|
||||
stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
|
||||
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case MousePress:
|
||||
QWindowSystemInterface::handleMouseEvent(window,pos,window->mapToGlobal(pos),Qt::LeftButton);
|
||||
break;
|
||||
case MouseRelease:
|
||||
QWindowSystemInterface::handleMouseEvent(window,pos,window->mapToGlobal(pos),Qt::NoButton);
|
||||
break;
|
||||
case MouseDClick:
|
||||
QWindowSystemInterface::handleMouseEvent(window,pos,window->mapToGlobal(pos),Qt::LeftButton);
|
||||
qWait(10);
|
||||
QWindowSystemInterface::handleMouseEvent(window,pos,window->mapToGlobal(pos),Qt::NoButton);
|
||||
qWait(20);
|
||||
QWindowSystemInterface::handleMouseEvent(window,pos,window->mapToGlobal(pos),Qt::LeftButton);
|
||||
qWait(10);
|
||||
QWindowSystemInterface::handleMouseEvent(window,pos,window->mapToGlobal(pos),Qt::NoButton);
|
||||
break;
|
||||
case MouseMove:
|
||||
QCursor::setPos(window->mapToGlobal(pos));
|
||||
#ifdef QT_MAC_USE_COCOA
|
||||
QTest::qWait(20);
|
||||
#else
|
||||
qApp->processEvents();
|
||||
#endif
|
||||
return;
|
||||
default:
|
||||
QTEST_ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
inline void mousePress(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
|
||||
QPoint pos = QPoint(), int delay=-1)
|
||||
@ -141,6 +195,21 @@ namespace QTest
|
||||
inline void mouseMove(QWidget *widget, QPoint pos = QPoint(), int delay=-1)
|
||||
{ mouseEvent(MouseMove, widget, Qt::NoButton, 0, pos, delay); }
|
||||
|
||||
//Support QWindow
|
||||
inline void mousePress(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
|
||||
QPoint pos = QPoint(), int delay=-1)
|
||||
{ mouseEvent(MousePress, window, button, stateKey, pos, delay); }
|
||||
inline void mouseRelease(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
|
||||
QPoint pos = QPoint(), int delay=-1)
|
||||
{ mouseEvent(MouseRelease, window, button, stateKey, pos, delay); }
|
||||
inline void mouseClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
|
||||
QPoint pos = QPoint(), int delay=-1)
|
||||
{ mouseEvent(MouseClick, window, button, stateKey, pos, delay); }
|
||||
inline void mouseDClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
|
||||
QPoint pos = QPoint(), int delay=-1)
|
||||
{ mouseEvent(MouseDClick, window, button, stateKey, pos, delay); }
|
||||
inline void mouseMove(QWindow *window, QPoint pos = QPoint(), int delay=-1)
|
||||
{ mouseEvent(MouseMove, window, Qt::NoButton, 0, pos, delay); }
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user