diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2011-09-21 09:23:51 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-21 13:46:08 +0200 |
commit | bc60b6787c791be0168820c42febfdb57b5070e0 (patch) | |
tree | ab4f5214d855841e4fefb9d97d2d10cc2269952e /src/testlib/qtestkeyboard.h | |
parent | 294a3e7b4797f508ebe629000ee2b2b7c7bd7302 (diff) | |
download | qtbase-bc60b6787c791be0168820c42febfdb57b5070e0.tar.gz |
testlib: Separate the gui- and widgets-specific api
Group the widgets-specific ("legacy") api under as
few ifdefs as possible. (The diff can look confusing;
rest assured that this change "only" moves entire
functions around in the files.)
Change-Id: I27bdec7d1c96d0b040dc22a8fed17e4e47766276
Reviewed-on: http://codereview.qt-project.org/5290
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Matthew Cattell <matthew.cattell@nokia.com>
Diffstat (limited to 'src/testlib/qtestkeyboard.h')
-rw-r--r-- | src/testlib/qtestkeyboard.h | 174 |
1 files changed, 83 insertions, 91 deletions
diff --git a/src/testlib/qtestkeyboard.h b/src/testlib/qtestkeyboard.h index 86d56c8710..51e0908e6f 100644 --- a/src/testlib/qtestkeyboard.h +++ b/src/testlib/qtestkeyboard.h @@ -68,6 +68,88 @@ namespace QTest { enum KeyAction { Press, Release, Click }; + static void simulateEvent(QWindow *window, bool press, int code, + Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1) + { + QEvent::Type type; + type = press ? QEvent::KeyPress : QEvent::KeyRelease; + QWindowSystemInterface::handleKeyEvent(window, type, code, modifier, text, repeat, delay); + } + + static void sendKeyEvent(KeyAction action, QWindow *window, Qt::Key code, + QString text, Qt::KeyboardModifiers modifier, int delay=-1) + { + QTEST_ASSERT(qApp); + QTEST_ASSERT(window); + + if (action == Click) { + sendKeyEvent(Press, window, code, text, modifier, delay); + sendKeyEvent(Release, window, code, text, modifier, delay); + return; + } + + bool repeat = false; + + if (action == Press) { + if (modifier & Qt::ShiftModifier) + simulateEvent(window, true, Qt::Key_Shift, 0, QString(), false, delay); + + if (modifier & Qt::ControlModifier) + simulateEvent(window, true, Qt::Key_Control, modifier & Qt::ShiftModifier, QString(), false, delay); + + if (modifier & Qt::AltModifier) + simulateEvent(window, true, Qt::Key_Alt, + modifier & (Qt::ShiftModifier | Qt::ControlModifier), QString(), false, delay); + if (modifier & Qt::MetaModifier) + simulateEvent(window, true, Qt::Key_Meta, modifier & (Qt::ShiftModifier + | Qt::ControlModifier | Qt::AltModifier), QString(), false, delay); + simulateEvent(window, true, code, modifier, text, repeat, delay); + } else if (action == Release) { + simulateEvent(window, false, code, modifier, text, repeat, delay); + + if (modifier & Qt::MetaModifier) + simulateEvent(window, false, Qt::Key_Meta, modifier, QString(), false, delay); + if (modifier & Qt::AltModifier) + simulateEvent(window, false, Qt::Key_Alt, modifier & + (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier), QString(), false, delay); + + if (modifier & Qt::ControlModifier) + simulateEvent(window, false, Qt::Key_Control, + modifier & (Qt::ShiftModifier | Qt::ControlModifier), QString(), false, delay); + + if (modifier & Qt::ShiftModifier) + simulateEvent(window, false, Qt::Key_Shift, modifier & Qt::ShiftModifier, QString(), false, delay); + } + } + + // Convenience function + static void sendKeyEvent(KeyAction action, QWindow *window, Qt::Key code, + char ascii, Qt::KeyboardModifiers modifier, int delay=-1) + { + QString text; + if (ascii) + text = QString(QChar::fromLatin1(ascii)); + sendKeyEvent(action, window, code, text, modifier, delay); + } + + inline static void keyEvent(KeyAction action, QWindow *window, char ascii, + Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) + { sendKeyEvent(action, window, asciiToKey(ascii), ascii, modifier, delay); } + inline static void keyEvent(KeyAction action, QWindow *window, Qt::Key key, + Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) + { sendKeyEvent(action, window, key, keyToAscii(key), modifier, delay); } + + inline static void keyClick(QWindow *window, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) + { keyEvent(Click, window, key, modifier, delay); } + inline static void keyClick(QWindow *window, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) + { keyEvent(Click, window, key, modifier, delay); } + inline static void keyRelease(QWindow *window, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) + { keyEvent(Release, window, key, modifier, delay); } + inline static void keyPress(QWindow *window, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) + { keyEvent(Press, window, key, modifier, delay); } + inline static void keyPress(QWindow *window, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) + { keyEvent(Press, window, key, modifier, delay); } + #ifdef QT_WIDGETS_LIB static void simulateEvent(QWidget *widget, bool press, int code, Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1) @@ -85,17 +167,7 @@ namespace QTest if (!qApp->notify(widget, &a)) QTest::qWarn("Keyboard event not accepted by receiving widget"); } -#endif - //QWindow overload - static void simulateEvent(QWindow *window, bool press, int code, - Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1) - { - QEvent::Type type; - type = press ? QEvent::KeyPress : QEvent::KeyRelease; - QWindowSystemInterface::handleKeyEvent(window, type, code, modifier, text, repeat, delay); - } -#ifdef QT_WIDGETS_LIB static void sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, QString text, Qt::KeyboardModifiers modifier, int delay=-1) { @@ -159,55 +231,7 @@ namespace QTest simulateEvent(widget, false, Qt::Key_Shift, modifier & Qt::ShiftModifier, QString(), false, delay); } } -#endif - //QWindow overload - static void sendKeyEvent(KeyAction action, QWindow *window, Qt::Key code, - QString text, Qt::KeyboardModifiers modifier, int delay=-1) - { - QTEST_ASSERT(qApp); - QTEST_ASSERT(window); - - if (action == Click) { - sendKeyEvent(Press, window, code, text, modifier, delay); - sendKeyEvent(Release, window, code, text, modifier, delay); - return; - } - - bool repeat = false; - if (action == Press) { - if (modifier & Qt::ShiftModifier) - simulateEvent(window, true, Qt::Key_Shift, 0, QString(), false, delay); - - if (modifier & Qt::ControlModifier) - simulateEvent(window, true, Qt::Key_Control, modifier & Qt::ShiftModifier, QString(), false, delay); - - if (modifier & Qt::AltModifier) - simulateEvent(window, true, Qt::Key_Alt, - modifier & (Qt::ShiftModifier | Qt::ControlModifier), QString(), false, delay); - if (modifier & Qt::MetaModifier) - simulateEvent(window, true, Qt::Key_Meta, modifier & (Qt::ShiftModifier - | Qt::ControlModifier | Qt::AltModifier), QString(), false, delay); - simulateEvent(window, true, code, modifier, text, repeat, delay); - } else if (action == Release) { - simulateEvent(window, false, code, modifier, text, repeat, delay); - - if (modifier & Qt::MetaModifier) - simulateEvent(window, false, Qt::Key_Meta, modifier, QString(), false, delay); - if (modifier & Qt::AltModifier) - simulateEvent(window, false, Qt::Key_Alt, modifier & - (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier), QString(), false, delay); - - if (modifier & Qt::ControlModifier) - simulateEvent(window, false, Qt::Key_Control, - modifier & (Qt::ShiftModifier | Qt::ControlModifier), QString(), false, delay); - - if (modifier & Qt::ShiftModifier) - simulateEvent(window, false, Qt::Key_Shift, modifier & Qt::ShiftModifier, QString(), false, delay); - } - } - -#ifdef QT_WIDGETS_LIB // Convenience function static void sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, char ascii, Qt::KeyboardModifiers modifier, int delay=-1) @@ -217,35 +241,14 @@ namespace QTest text = QString(QChar::fromLatin1(ascii)); sendKeyEvent(action, widget, code, text, modifier, delay); } -#endif - // QWindow convenience function - static void sendKeyEvent(KeyAction action, QWindow *window, Qt::Key code, - char ascii, Qt::KeyboardModifiers modifier, int delay=-1) - { - QString text; - if (ascii) - text = QString(QChar::fromLatin1(ascii)); - sendKeyEvent(action, window, code, text, modifier, delay); - } -#ifdef QT_WIDGETS_LIB inline static void keyEvent(KeyAction action, QWidget *widget, char ascii, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) { sendKeyEvent(action, widget, asciiToKey(ascii), ascii, modifier, delay); } inline static void keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) { sendKeyEvent(action, widget, key, keyToAscii(key), modifier, delay); } -#endif - //Support QWindow - inline static void keyEvent(KeyAction action, QWindow *window, char ascii, - Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) - { sendKeyEvent(action, window, asciiToKey(ascii), ascii, modifier, delay); } - inline static void keyEvent(KeyAction action, QWindow *window, Qt::Key key, - Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) - { sendKeyEvent(action, window, key, keyToAscii(key), modifier, delay); } - /////////////// -#ifdef QT_WIDGETS_LIB inline static void keyClicks(QWidget *widget, const QString &sequence, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) { @@ -265,18 +268,7 @@ namespace QTest { keyEvent(Release, widget, key, modifier, delay); } inline static void keyClick(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) { keyEvent(Click, widget, key, modifier, delay); } -#endif - //Support QWindow - inline static void keyClick(QWindow *window, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) - { keyEvent(Click, window, key, modifier, delay); } - inline static void keyClick(QWindow *window, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) - { keyEvent(Click, window, key, modifier, delay); } - inline static void keyRelease(QWindow *window, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) - { keyEvent(Release, window, key, modifier, delay); } - inline static void keyPress(QWindow *window, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) - { keyEvent(Press, window, key, modifier, delay); } - inline static void keyPress(QWindow *window, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) - { keyEvent(Press, window, key, modifier, delay); } +#endif // QT_WIDGETS_LIB } |