summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel
diff options
context:
space:
mode:
authorJo Asplin <jo.asplin@nokia.com>2011-08-31 17:11:06 +0200
committerJo Asplin <jo.asplin@nokia.com>2011-09-01 10:59:49 +0200
commita90f50942e5304e6bf1c8a3e32f1f65c7a38f60b (patch)
tree6ed9a3d0a0a3dd09a78593d89c000f29d3494b89 /tests/auto/gui/kernel
parenta863eb1c7bbd5d40a741151f811bd7c62cf51e2d (diff)
Moved gui autotests into new directory structure
Task-number: QTBUG-21133 Change-Id: I83b8f652935cf92151265ca2530a3cf81c31fdef Reviewed-on: http://codereview.qt.nokia.com/3996 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Jo Asplin <jo.asplin@nokia.com>
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r--tests/auto/gui/kernel/kernel.pro17
-rw-r--r--tests/auto/gui/kernel/qclipboard/.gitignore5
-rw-r--r--tests/auto/gui/kernel/qclipboard/copier/copier.pro10
-rw-r--r--tests/auto/gui/kernel/qclipboard/copier/main.cpp54
-rw-r--r--tests/auto/gui/kernel/qclipboard/paster/main.cpp54
-rw-r--r--tests/auto/gui/kernel/qclipboard/paster/paster.pro11
-rw-r--r--tests/auto/gui/kernel/qclipboard/qclipboard.pro4
-rw-r--r--tests/auto/gui/kernel/qclipboard/test/test.pro32
-rw-r--r--tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp422
-rw-r--r--tests/auto/gui/kernel/qdrag/.gitignore1
-rw-r--r--tests/auto/gui/kernel/qdrag/qdrag.pro9
-rw-r--r--tests/auto/gui/kernel/qdrag/tst_qdrag.cpp94
-rw-r--r--tests/auto/gui/kernel/qevent/.gitignore1
-rw-r--r--tests/auto/gui/kernel/qevent/qevent.pro4
-rw-r--r--tests/auto/gui/kernel/qevent/tst_qevent.cpp92
-rw-r--r--tests/auto/gui/kernel/qfileopenevent/qfileopenevent.pro3
-rw-r--r--tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp72
-rw-r--r--tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro10
-rw-r--r--tests/auto/gui/kernel/qfileopenevent/test/test.pro7
-rw-r--r--tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp362
-rw-r--r--tests/auto/gui/kernel/qguivariant/.gitignore1
-rw-r--r--tests/auto/gui/kernel/qguivariant/qguivariant.pro5
-rw-r--r--tests/auto/gui/kernel/qguivariant/tst_qguivariant.cpp72
-rw-r--r--tests/auto/gui/kernel/qkeysequence/.gitignore1
-rw-r--r--tests/auto/gui/kernel/qkeysequence/keys_de.qmbin0 -> 721 bytes
-rw-r--r--tests/auto/gui/kernel/qkeysequence/keys_de.ts61
-rw-r--r--tests/auto/gui/kernel/qkeysequence/qkeysequence.pro8
-rw-r--r--tests/auto/gui/kernel/qkeysequence/qkeysequence.qrc6
-rw-r--r--tests/auto/gui/kernel/qkeysequence/qt_de.qmbin0 -> 186240 bytes
-rw-r--r--tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp636
-rw-r--r--tests/auto/gui/kernel/qmouseevent/.gitignore1
-rw-r--r--tests/auto/gui/kernel/qmouseevent/qmouseevent.pro3
-rw-r--r--tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp231
-rw-r--r--tests/auto/gui/kernel/qmouseevent_modal/.gitignore1
-rw-r--r--tests/auto/gui/kernel/qmouseevent_modal/qmouseevent_modal.pro6
-rw-r--r--tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp231
-rw-r--r--tests/auto/gui/kernel/qpalette/.gitignore1
-rw-r--r--tests/auto/gui/kernel/qpalette/qpalette.pro6
-rw-r--r--tests/auto/gui/kernel/qpalette/tst_qpalette.cpp132
-rw-r--r--tests/auto/gui/kernel/qshortcut/.gitignore1
-rw-r--r--tests/auto/gui/kernel/qshortcut/qshortcut.pro11
-rw-r--r--tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp1272
-rw-r--r--tests/auto/gui/kernel/qtouchevent/qtouchevent.pro3
-rw-r--r--tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp1398
44 files changed, 5351 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro
new file mode 100644
index 0000000000..880c3c8613
--- /dev/null
+++ b/tests/auto/gui/kernel/kernel.pro
@@ -0,0 +1,17 @@
+TEMPLATE=subdirs
+SUBDIRS=\
+ qclipboard \
+ qdrag \
+ qevent \
+ qfileopenevent \
+ qguivariant \
+ qkeysequence \
+ qmouseevent \
+ qmouseevent_modal \
+ qpalette \
+ qshortcut \
+ qtouchevent \
+
+symbian {
+ SUBDIRS += qsoftkeymanager
+}
diff --git a/tests/auto/gui/kernel/qclipboard/.gitignore b/tests/auto/gui/kernel/qclipboard/.gitignore
new file mode 100644
index 0000000000..4fcf7d55fc
--- /dev/null
+++ b/tests/auto/gui/kernel/qclipboard/.gitignore
@@ -0,0 +1,5 @@
+tst_qclipboard
+copier/copier
+copier/copier.exe
+paster/paster
+paster/paster.exe
diff --git a/tests/auto/gui/kernel/qclipboard/copier/copier.pro b/tests/auto/gui/kernel/qclipboard/copier/copier.pro
new file mode 100644
index 0000000000..d345d33eb5
--- /dev/null
+++ b/tests/auto/gui/kernel/qclipboard/copier/copier.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+CONFIG -= app_bundle
+QT += widgets
+win32: DESTDIR = ../copier
+# Input
+SOURCES += main.cpp
+
diff --git a/tests/auto/gui/kernel/qclipboard/copier/main.cpp b/tests/auto/gui/kernel/qclipboard/copier/main.cpp
new file mode 100644
index 0000000000..e4417352ff
--- /dev/null
+++ b/tests/auto/gui/kernel/qclipboard/copier/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QApplication>
+#include <QClipboard>
+#include <QStringList>
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ QClipboard *board = QApplication::clipboard();
+#ifdef Q_OS_WINCE
+ board->setText(QLatin1String("testString.!"));
+#else
+ board->setText(app.arguments().at(1));
+#endif
+ return 0;
+}
diff --git a/tests/auto/gui/kernel/qclipboard/paster/main.cpp b/tests/auto/gui/kernel/qclipboard/paster/main.cpp
new file mode 100644
index 0000000000..4df4d7fb45
--- /dev/null
+++ b/tests/auto/gui/kernel/qclipboard/paster/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QApplication>
+#include <QClipboard>
+#include <QStringList>
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ QClipboard *board = QApplication::clipboard();
+#ifdef Q_OS_WINCE
+ return (board->text() == QLatin1String("testString.!")) ? 0 : 1;
+#else
+ return (board->text() == app.arguments().at(1)) ? 0 : 1;
+#endif
+}
diff --git a/tests/auto/gui/kernel/qclipboard/paster/paster.pro b/tests/auto/gui/kernel/qclipboard/paster/paster.pro
new file mode 100644
index 0000000000..d214c9e90a
--- /dev/null
+++ b/tests/auto/gui/kernel/qclipboard/paster/paster.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+win32: DESTDIR = ../paster
+CONFIG -= app_bundle
+QT += widgets
+# Input
+SOURCES += main.cpp
+
+
diff --git a/tests/auto/gui/kernel/qclipboard/qclipboard.pro b/tests/auto/gui/kernel/qclipboard/qclipboard.pro
new file mode 100644
index 0000000000..692ca5dd3f
--- /dev/null
+++ b/tests/auto/gui/kernel/qclipboard/qclipboard.pro
@@ -0,0 +1,4 @@
+TEMPLATE = subdirs
+SUBDIRS = test copier paster
+
+
diff --git a/tests/auto/gui/kernel/qclipboard/test/test.pro b/tests/auto/gui/kernel/qclipboard/test/test.pro
new file mode 100644
index 0000000000..12c6b6ce4f
--- /dev/null
+++ b/tests/auto/gui/kernel/qclipboard/test/test.pro
@@ -0,0 +1,32 @@
+load(qttest_p4)
+SOURCES += ../tst_qclipboard.cpp
+TARGET = ../tst_qclipboard
+
+win32 {
+ CONFIG(debug, debug|release) {
+ TARGET = ../../debug/tst_qclipboard
+} else {
+ TARGET = ../../release/tst_qclipboard
+ }
+}
+
+wince*|symbian: {
+ copier.files = ../copier/copier.exe
+ copier.path = copier
+ paster.files = ../paster/paster.exe
+ paster.path = paster
+
+ symbian: {
+ LIBS += -lbafl -lestor -letext
+
+ load(data_caging_paths)
+ rsc.files = $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/copier.rsc
+ rsc.files += $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/paster.rsc
+ rsc.path = $$APP_RESOURCE_DIR
+ reg_resource.files = $${EPOCROOT}$$HW_ZDIR$$REG_RESOURCE_IMPORT_DIR/copier_reg.rsc
+ reg_resource.files += $${EPOCROOT}$$HW_ZDIR$$REG_RESOURCE_IMPORT_DIR/paster_reg.rsc
+ reg_resource.path = $$REG_RESOURCE_IMPORT_DIR
+ }
+
+ DEPLOYMENT += copier paster rsc reg_resource
+} \ No newline at end of file
diff --git a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
new file mode 100644
index 0000000000..4d3bb29e13
--- /dev/null
+++ b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
@@ -0,0 +1,422 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+#include <QtCore/QDebug>
+#include <QtWidgets/QApplication>
+#include <QtGui/QClipboard>
+#ifdef Q_WS_MAC
+#include <Carbon/Carbon.h>
+#endif
+#ifdef Q_OS_SYMBIAN
+#include "private/qcore_symbian_p.h"
+#include "txtetext.h"
+#include <baclipb.h>
+#endif
+#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
+#include "txtclipboard.h"
+#endif
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+class tst_QClipboard : public QObject
+{
+ Q_OBJECT
+private slots:
+
+ void copy_exit_paste();
+ void capabiliyFunctions();
+ void modes();
+ void testSignals();
+ void setMimeData();
+ void clearBeforeSetText();
+#ifdef Q_OS_SYMBIAN
+ void pasteCopySymbian();
+ void copyPasteSymbian();
+#endif
+
+private:
+ bool nativeClipboardWorking();
+};
+
+
+bool tst_QClipboard::nativeClipboardWorking()
+{
+#ifdef Q_WS_MAC
+ PasteboardRef pasteboard;
+ OSStatus status = PasteboardCreate(0, &pasteboard);
+ if (status == noErr)
+ CFRelease(pasteboard);
+ return status == noErr;
+#endif
+ return true;
+}
+
+Q_DECLARE_METATYPE(QClipboard::Mode)
+
+/*
+ Tests that the capability functions are implemented on all
+ platforms.
+*/
+void tst_QClipboard::capabiliyFunctions()
+{
+ QClipboard * const clipboard = QApplication::clipboard();
+
+ clipboard->supportsSelection();
+ clipboard->supportsFindBuffer();
+ clipboard->ownsSelection();
+ clipboard->ownsClipboard();
+ clipboard->ownsFindBuffer();
+}
+
+/*
+ Test that text inserted into the clipboard in different modes is
+ kept separate.
+*/
+void tst_QClipboard::modes()
+{
+ QClipboard * const clipboard = QApplication::clipboard();
+
+ if (!nativeClipboardWorking())
+ QSKIP("Native clipboard not working in this setup", SkipAll);
+
+ const QString defaultMode = "default mode text;";
+ clipboard->setText(defaultMode);
+ QCOMPARE(clipboard->text(), defaultMode);
+
+ if (clipboard->supportsSelection()) {
+ const QString selectionMode = "selection mode text";
+ clipboard->setText(selectionMode, QClipboard::Selection);
+ QCOMPARE(clipboard->text(QClipboard::Selection), selectionMode);
+ QCOMPARE(clipboard->text(), defaultMode);
+ }
+
+ if (clipboard->supportsFindBuffer()) {
+ const QString searchMode = "find mode text";
+ clipboard->setText(searchMode, QClipboard::FindBuffer);
+ QCOMPARE(clipboard->text(QClipboard::FindBuffer), searchMode);
+ QCOMPARE(clipboard->text(), defaultMode);
+ }
+}
+
+/*
+ Test that the appropriate signals are emitted when the cliboard
+ contents is changed by calling the qt functions.
+*/
+void tst_QClipboard::testSignals()
+{
+ qRegisterMetaType<QClipboard::Mode>("QClipboard::Mode");
+
+ if (!nativeClipboardWorking())
+ QSKIP("Native clipboard not working in this setup", SkipAll);
+
+ QClipboard * const clipboard = QApplication::clipboard();
+
+ QSignalSpy changedSpy(clipboard, SIGNAL(changed(QClipboard::Mode)));
+ QSignalSpy dataChangedSpy(clipboard, SIGNAL(dataChanged()));
+ QSignalSpy searchChangedSpy(clipboard, SIGNAL(findBufferChanged()));
+ QSignalSpy selectionChangedSpy(clipboard, SIGNAL(selectionChanged()));
+
+ const QString text = "clipboard text;";
+
+ // Test the default mode signal.
+ clipboard->setText(text);
+ QCOMPARE(dataChangedSpy.count(), 1);
+ QCOMPARE(searchChangedSpy.count(), 0);
+ QCOMPARE(selectionChangedSpy.count(), 0);
+ QCOMPARE(changedSpy.count(), 1);
+ QCOMPARE(changedSpy.at(0).count(), 1);
+ QCOMPARE(qVariantValue<QClipboard::Mode>(changedSpy.at(0).at(0)), QClipboard::Clipboard);
+
+ changedSpy.clear();
+
+ // Test the selection mode signal.
+ if (clipboard->supportsSelection()) {
+ clipboard->setText(text, QClipboard::Selection);
+ QCOMPARE(selectionChangedSpy.count(), 1);
+ QCOMPARE(changedSpy.count(), 1);
+ QCOMPARE(changedSpy.at(0).count(), 1);
+ QCOMPARE(qVariantValue<QClipboard::Mode>(changedSpy.at(0).at(0)), QClipboard::Selection);
+ } else {
+ QCOMPARE(selectionChangedSpy.count(), 0);
+ }
+ QCOMPARE(dataChangedSpy.count(), 1);
+ QCOMPARE(searchChangedSpy.count(), 0);
+
+ changedSpy.clear();
+
+ // Test the search mode signal.
+ if (clipboard->supportsFindBuffer()) {
+ clipboard->setText(text, QClipboard::FindBuffer);
+ QCOMPARE(searchChangedSpy.count(), 1);
+ QCOMPARE(changedSpy.count(), 1);
+ QCOMPARE(changedSpy.at(0).count(), 1);
+ QCOMPARE(qVariantValue<QClipboard::Mode>(changedSpy.at(0).at(0)), QClipboard::FindBuffer);
+ } else {
+ QCOMPARE(searchChangedSpy.count(), 0);
+ }
+ QCOMPARE(dataChangedSpy.count(), 1);
+}
+
+/*
+ Test that pasted text remain on the clipboard
+ after a Qt application exits.
+*/
+void tst_QClipboard::copy_exit_paste()
+{
+#ifndef QT_NO_PROCESS
+#if defined Q_WS_X11 || defined Q_WS_QWS || defined (Q_WS_QPA)
+ QSKIP("This test does not make sense on X11 and embedded, copied data disappears from the clipboard when the application exits ", SkipAll);
+ // ### It's still possible to test copy/paste - just keep the apps running
+#elif defined (Q_OS_SYMBIAN) && defined (Q_CC_NOKIAX86)
+ QSKIP("emulator cannot launch multiple processes",SkipAll);
+#endif
+ if (!nativeClipboardWorking())
+ QSKIP("Native clipboard not working in this setup", SkipAll);
+ const QStringList stringArgument = QStringList() << "Test string.";
+ QCOMPARE(QProcess::execute("copier/copier", stringArgument), 0);
+#ifdef Q_WS_MAC
+ // The Pasteboard needs a moment to breathe (at least on older Macs).
+ QTest::qWait(100);
+#endif
+ QCOMPARE(QProcess::execute("paster/paster", stringArgument), 0);
+#endif
+}
+
+void tst_QClipboard::setMimeData()
+{
+ if (!nativeClipboardWorking())
+ QSKIP("Native clipboard not working in this setup", SkipAll);
+ QMimeData *mimeData = new QMimeData;
+ const QString TestName(QLatin1String("tst_QClipboard::setMimeData() mimeData"));
+ mimeData->setObjectName(TestName);
+#if defined(Q_OS_WINCE)
+ // need to set text on CE
+ mimeData->setText(QLatin1String("Qt/CE foo"));
+#endif
+
+ QApplication::clipboard()->setMimeData(mimeData);
+ QCOMPARE(QApplication::clipboard()->mimeData(), (const QMimeData *)mimeData);
+ QCOMPARE(QApplication::clipboard()->mimeData()->objectName(), TestName);
+
+ // set it to the same data again, it shouldn't delete mimeData (and crash as a result)
+ QApplication::clipboard()->setMimeData(mimeData);
+ QCOMPARE(QApplication::clipboard()->mimeData(), (const QMimeData *)mimeData);
+ QCOMPARE(QApplication::clipboard()->mimeData()->objectName(), TestName);
+ QApplication::clipboard()->clear();
+ const QMimeData *appMimeData = QApplication::clipboard()->mimeData();
+ QVERIFY(appMimeData != mimeData || appMimeData->objectName() != TestName);
+
+ // check for crash when using the same mimedata object on several clipboards
+ QMimeData *data = new QMimeData;
+ data->setText("foo");
+
+ QApplication::clipboard()->setMimeData(data, QClipboard::Clipboard);
+ QApplication::clipboard()->setMimeData(data, QClipboard::Selection);
+ QApplication::clipboard()->setMimeData(data, QClipboard::FindBuffer);
+
+ QSignalSpy spySelection(QApplication::clipboard(), SIGNAL(selectionChanged()));
+ QSignalSpy spyData(QApplication::clipboard(), SIGNAL(dataChanged()));
+ QSignalSpy spyFindBuffer(QApplication::clipboard(), SIGNAL(findBufferChanged()));
+
+ QApplication::clipboard()->clear(QClipboard::Clipboard);
+ QApplication::clipboard()->clear(QClipboard::Selection); // used to crash on X11
+ QApplication::clipboard()->clear(QClipboard::FindBuffer);
+
+#if defined(Q_WS_X11)
+ QCOMPARE(spySelection.count(), 1);
+ QCOMPARE(spyData.count(), 1);
+ QCOMPARE(spyFindBuffer.count(), 0);
+#elif defined(Q_WS_MAC)
+ QCOMPARE(spySelection.count(), 0);
+ QCOMPARE(spyData.count(), 1);
+ QCOMPARE(spyFindBuffer.count(), 1);
+#elif defined(Q_WS_WIN)
+ QCOMPARE(spySelection.count(), 0);
+ QCOMPARE(spyData.count(), 1);
+ QCOMPARE(spyFindBuffer.count(), 0);
+#endif
+
+ // an other crash test
+ data = new QMimeData;
+ data->setText("foo");
+
+ QApplication::clipboard()->setMimeData(data, QClipboard::Clipboard);
+ QApplication::clipboard()->setMimeData(data, QClipboard::Selection);
+ QApplication::clipboard()->setMimeData(data, QClipboard::FindBuffer);
+
+ QMimeData *newData = new QMimeData;
+ newData->setText("bar");
+
+ spySelection.clear();
+ spyData.clear();
+ spyFindBuffer.clear();
+
+ QApplication::clipboard()->setMimeData(newData, QClipboard::Clipboard);
+ QApplication::clipboard()->setMimeData(newData, QClipboard::Selection); // used to crash on X11
+ QApplication::clipboard()->setMimeData(newData, QClipboard::FindBuffer);
+
+#if defined(Q_WS_X11)
+ QCOMPARE(spySelection.count(), 1);
+ QCOMPARE(spyData.count(), 1);
+ QCOMPARE(spyFindBuffer.count(), 0);
+#elif defined(Q_WS_MAC)
+ QCOMPARE(spySelection.count(), 0);
+ QCOMPARE(spyData.count(), 1);
+ QCOMPARE(spyFindBuffer.count(), 1);
+#elif defined(Q_WS_WIN)
+ QCOMPARE(spySelection.count(), 0);
+ QCOMPARE(spyData.count(), 1);
+ QCOMPARE(spyFindBuffer.count(), 0);
+#endif
+}
+
+void tst_QClipboard::clearBeforeSetText()
+{
+ QApplication::processEvents();
+
+ if (!nativeClipboardWorking())
+ QSKIP("Native clipboard not working in this setup", SkipAll);
+
+ const QString text = "tst_QClipboard::clearBeforeSetText()";
+
+ // setText() should work after processEvents()
+ QApplication::clipboard()->setText(text);
+ QCOMPARE(QApplication::clipboard()->text(), text);
+ QApplication::processEvents();
+ QCOMPARE(QApplication::clipboard()->text(), text);
+
+ // same with clear()
+ QApplication::clipboard()->clear();
+ QVERIFY(QApplication::clipboard()->text().isEmpty());
+ QApplication::processEvents();
+ QVERIFY(QApplication::clipboard()->text().isEmpty());
+
+ // setText() again
+ QApplication::clipboard()->setText(text);
+ QCOMPARE(QApplication::clipboard()->text(), text);
+ QApplication::processEvents();
+ QCOMPARE(QApplication::clipboard()->text(), text);
+
+ // clear() immediately followed by setText() should still return the text
+ QApplication::clipboard()->clear();
+ QVERIFY(QApplication::clipboard()->text().isEmpty());
+ QApplication::clipboard()->setText(text);
+ QCOMPARE(QApplication::clipboard()->text(), text);
+ QApplication::processEvents();
+ QCOMPARE(QApplication::clipboard()->text(), text);
+}
+
+/*
+ Test that text copied from qt application
+ can be pasted with symbian clipboard
+*/
+#ifdef Q_OS_SYMBIAN
+// ### This test case only makes sense in symbian
+void tst_QClipboard::pasteCopySymbian()
+{
+ if (!nativeClipboardWorking())
+ QSKIP("Native clipboard not working in this setup", SkipAll);
+ const QString string("Test string symbian.");
+ QApplication::clipboard()->setText(string);
+
+ const TInt KPlainTextBegin = 0;
+ RFs fs = qt_s60GetRFs();
+ CClipboard* cb = CClipboard::NewForReadingLC(fs);
+
+ CPlainText* text = CPlainText::NewL();
+ CleanupStack::PushL(text);
+ TInt dataLength = text->PasteFromStoreL(cb->Store(), cb->StreamDictionary(),
+ KPlainTextBegin);
+ if (dataLength == 0) {
+ User::Leave(KErrNotFound);
+ }
+ HBufC* hBuf = HBufC::NewL(dataLength);
+ TPtr buf = hBuf->Des();
+ text->Extract(buf, KPlainTextBegin, dataLength);
+
+ QString storeString = qt_TDesC2QString(buf);
+ CleanupStack::PopAndDestroy(text);
+ CleanupStack::PopAndDestroy(cb);
+
+ QCOMPARE(string, storeString);
+}
+#endif
+
+/*
+ Test that text copied to symbian clipboard
+ can be pasted to qt clipboard
+*/
+#ifdef Q_OS_SYMBIAN
+// ### This test case only makes sense in symbian
+void tst_QClipboard::copyPasteSymbian()
+{
+ if (!nativeClipboardWorking())
+ QSKIP("Native clipboard not working in this setup", SkipAll);
+ const QString string("Test string symbian.");
+ const TInt KPlainTextBegin = 0;
+
+ RFs fs = qt_s60GetRFs();
+ CClipboard* cb = CClipboard::NewForWritingLC(fs);
+ CStreamStore& store = cb->Store();
+ CStreamDictionary& dict = cb->StreamDictionary();
+ RStoreWriteStream symbianStream;
+ TStreamId symbianStId = symbianStream.CreateLC(cb->Store());
+
+ CPlainText* text = CPlainText::NewL();
+ CleanupStack::PushL(text);
+ TPtrC textPtr(qt_QString2TPtrC(string));
+ text->InsertL(KPlainTextBegin, textPtr);
+ text->CopyToStoreL(store, dict, KPlainTextBegin, textPtr.Length());
+ CleanupStack::PopAndDestroy(text);
+ (cb->StreamDictionary()).AssignL(KClipboardUidTypePlainText, symbianStId);
+ cb->CommitL();
+ CleanupStack::PopAndDestroy(2, cb);
+
+ QCOMPARE(QApplication::clipboard()->text(), string);
+}
+#endif
+
+QTEST_MAIN(tst_QClipboard)
+
+#include "tst_qclipboard.moc"
diff --git a/tests/auto/gui/kernel/qdrag/.gitignore b/tests/auto/gui/kernel/qdrag/.gitignore
new file mode 100644
index 0000000000..d210808afe
--- /dev/null
+++ b/tests/auto/gui/kernel/qdrag/.gitignore
@@ -0,0 +1 @@
+tst_qdrag
diff --git a/tests/auto/gui/kernel/qdrag/qdrag.pro b/tests/auto/gui/kernel/qdrag/qdrag.pro
new file mode 100644
index 0000000000..d9d645559b
--- /dev/null
+++ b/tests/auto/gui/kernel/qdrag/qdrag.pro
@@ -0,0 +1,9 @@
+############################################################
+# Project file for autotest for file qdrag.h
+############################################################
+
+load(qttest_p4)
+QT += widgets
+SOURCES += tst_qdrag.cpp
+
+
diff --git a/tests/auto/gui/kernel/qdrag/tst_qdrag.cpp b/tests/auto/gui/kernel/qdrag/tst_qdrag.cpp
new file mode 100644
index 0000000000..4d18cefb2c
--- /dev/null
+++ b/tests/auto/gui/kernel/qdrag/tst_qdrag.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+
+#include <qcoreapplication.h>
+#include <qdebug.h>
+#include <qdrag.h>
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+class tst_QDrag : public QObject
+{
+Q_OBJECT
+
+public:
+ tst_QDrag();
+ virtual ~tst_QDrag();
+
+private slots:
+ void getSetCheck();
+};
+
+tst_QDrag::tst_QDrag()
+{
+}
+
+tst_QDrag::~tst_QDrag()
+{
+}
+
+// Testing get/set functions
+void tst_QDrag::getSetCheck()
+{
+ QDrag obj1(0);
+ // QMimeData * QDrag::mimeData()
+ // void QDrag::setMimeData(QMimeData *)
+ QMimeData *var1 = new QMimeData;
+ obj1.setMimeData(var1);
+ QCOMPARE(var1, obj1.mimeData());
+ obj1.setMimeData(var1);
+ QCOMPARE(var1, obj1.mimeData());
+ obj1.setMimeData((QMimeData *)0);
+ QCOMPARE((QMimeData *)0, obj1.mimeData());
+ // delete var1; // No delete, since QDrag takes ownership
+
+ Qt::DropAction result = obj1.start();
+ QCOMPARE(result, Qt::IgnoreAction);
+ result = obj1.start(Qt::MoveAction | Qt::LinkAction);
+ QCOMPARE(result, Qt::IgnoreAction);
+}
+
+QTEST_MAIN(tst_QDrag)
+#include "tst_qdrag.moc"
diff --git a/tests/auto/gui/kernel/qevent/.gitignore b/tests/auto/gui/kernel/qevent/.gitignore
new file mode 100644
index 0000000000..2a3ef2a115
--- /dev/null
+++ b/tests/auto/gui/kernel/qevent/.gitignore
@@ -0,0 +1 @@
+tst_qevent
diff --git a/tests/auto/gui/kernel/qevent/qevent.pro b/tests/auto/gui/kernel/qevent/qevent.pro
new file mode 100644
index 0000000000..6042b6cdc9
--- /dev/null
+++ b/tests/auto/gui/kernel/qevent/qevent.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+SOURCES += tst_qevent.cpp
+QT = core
+CONFIG += parallel_test
diff --git a/tests/auto/gui/kernel/qevent/tst_qevent.cpp b/tests/auto/gui/kernel/qevent/tst_qevent.cpp
new file mode 100644
index 0000000000..ae39380883
--- /dev/null
+++ b/tests/auto/gui/kernel/qevent/tst_qevent.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qcoreevent.h>
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+class tst_QEvent : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QEvent();
+ ~tst_QEvent();
+
+private slots:
+ void registerEventType_data();
+ void registerEventType();
+};
+
+tst_QEvent::tst_QEvent()
+{ }
+
+tst_QEvent::~tst_QEvent()
+{ }
+
+void tst_QEvent::registerEventType_data()
+{
+ QTest::addColumn<int>("hint");
+ QTest::addColumn<int>("expected");
+
+ // default argument
+ QTest::newRow("default") << -1 << int(QEvent::MaxUser);
+ // hint not valid
+ QTest::newRow("User-1") << int(QEvent::User - 1) << int(QEvent::MaxUser - 1);
+ // hint valid, but already taken
+ QTest::newRow("MaxUser-1") << int(QEvent::MaxUser - 1) << int(QEvent::MaxUser - 2);
+ // hint valid, but not taken
+ QTest::newRow("User + 1000") << int(QEvent::User + 1000) << int(QEvent::User + 1000);
+}
+
+void tst_QEvent::registerEventType()
+{
+ QFETCH(int, hint);
+ QFETCH(int, expected);
+ QCOMPARE(QEvent::registerEventType(hint), expected);
+}
+
+QTEST_MAIN(tst_QEvent)
+#include "tst_qevent.moc"
diff --git a/tests/auto/gui/kernel/qfileopenevent/qfileopenevent.pro b/tests/auto/gui/kernel/qfileopenevent/qfileopenevent.pro
new file mode 100644
index 0000000000..73724828db
--- /dev/null
+++ b/tests/auto/gui/kernel/qfileopenevent/qfileopenevent.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+QT += widgets
+SUBDIRS = test qfileopeneventexternal
diff --git a/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp
new file mode 100644
index 0000000000..5d1a6a390f
--- /dev/null
+++ b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QApplication>
+#include <QEvent>
+
+struct MyApplication : public QApplication
+{
+ MyApplication(int& argc, char** argv)
+ : QApplication(argc, argv)
+ {}
+
+ bool event(QEvent * event)
+ {
+ if (event->type() == QEvent::FileOpen) {
+ QFileOpenEvent* ev = static_cast<QFileOpenEvent *>(event);
+ QFile file;
+ bool ok = ev->openFile(file, QFile::Append | QFile::Unbuffered);
+ if (ok)
+ file.write(QByteArray("+external"));
+ return true;
+ } else {
+ return QApplication::event(event);
+ }
+ }
+};
+
+int main(int argc, char *argv[])
+{
+ MyApplication a(argc, argv);
+ a.sendPostedEvents(&a, QEvent::FileOpen);
+ return 0;
+}
diff --git a/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro
new file mode 100644
index 0000000000..cb61b82e38
--- /dev/null
+++ b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+TARGET = qfileopeneventexternal
+QT += core gui widgets
+SOURCES += qfileopeneventexternal.cpp
+symbian: {
+ RSS_RULES += "embeddability=KAppEmbeddable;"
+ RSS_RULES.datatype_list += "priority = EDataTypePriorityHigh; type = \"application/x-tst_qfileopenevent\";"
+ LIBS += -lapparc \
+ -leikcore -lefsrv -lcone
+}
diff --git a/tests/auto/gui/kernel/qfileopenevent/test/test.pro b/tests/auto/gui/kernel/qfileopenevent/test/test.pro
new file mode 100644
index 0000000000..3f16dcf6ee
--- /dev/null
+++ b/tests/auto/gui/kernel/qfileopenevent/test/test.pro
@@ -0,0 +1,7 @@
+load(qttest_p4)
+TARGET = tst_qfileopenevent
+HEADERS +=
+SOURCES += tst_qfileopenevent.cpp
+symbian {
+ LIBS+=-lefsrv -lapgrfx -lapmime
+}
diff --git a/tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp b/tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp
new file mode 100644
index 0000000000..69cc4ccc01
--- /dev/null
+++ b/tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp
@@ -0,0 +1,362 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QEvent>
+
+#ifdef Q_OS_SYMBIAN
+#include <apgcli.h>
+#include "private/qcore_symbian_p.h"
+#endif
+
+class tst_qfileopenevent : public QObject
+{
+ Q_OBJECT
+public:
+ tst_qfileopenevent(){}
+ ~tst_qfileopenevent();
+
+public slots:
+ void initTestCase();
+
+private slots:
+ void constructor();
+ void fileOpen();
+ void handleLifetime();
+ void multiOpen();
+ void sendAndReceive();
+ void external_data();
+ void external();
+
+private:
+#ifdef Q_OS_SYMBIAN
+ RFile createRFile(const TDesC& filename, const TDesC8& content);
+#else
+ void createFile(const QString &filename, const QByteArray &content);
+#endif
+ QFileOpenEvent * createFileAndEvent(const QString &filename, const QByteArray &content);
+ void checkReadAndWrite(QFileOpenEvent& event, const QByteArray& readContent, const QByteArray& writeContent, bool writeOk);
+ QByteArray readFileContent(QFileOpenEvent& event);
+ bool appendFileContent(QFileOpenEvent& event, const QByteArray& writeContent);
+
+ bool event(QEvent *);
+
+private:
+#ifdef Q_OS_SYMBIAN
+ struct AutoRFs : public RFs
+ {
+ AutoRFs()
+ {
+ qt_symbian_throwIfError(Connect());
+ qt_symbian_throwIfError(ShareProtected());
+ }
+
+ ~AutoRFs()
+ {
+ Close();
+ }
+ };
+ AutoRFs fsSession;
+#endif
+};
+
+tst_qfileopenevent::~tst_qfileopenevent()
+{
+};
+
+void tst_qfileopenevent::initTestCase()
+{
+}
+
+#ifdef Q_OS_SYMBIAN
+RFile tst_qfileopenevent::createRFile(const TDesC& filename, const TDesC8& content)
+{
+ RFile file;
+ qt_symbian_throwIfError(file.Replace(fsSession, filename, EFileWrite));
+ qt_symbian_throwIfError(file.Write(content));
+ return file;
+}
+#else
+void tst_qfileopenevent::createFile(const QString &filename, const QByteArray &content)
+{
+ QFile file(filename);
+ file.open(QFile::WriteOnly);
+ file.write(content);
+ file.close();
+}
+#endif
+
+QFileOpenEvent * tst_qfileopenevent::createFileAndEvent(const QString &filename, const QByteArray &content)
+{
+#ifdef Q_OS_SYMBIAN
+ RFile rFile = createRFile(qt_QString2TPtrC(filename), TPtrC8((TText8*)content.constData(), content.size()));
+ QScopedPointer<RFile, QScopedPointerRCloser<RFile> > closeRFile(&rFile);
+ return new QFileOpenEvent(rFile);
+#else
+ createFile(filename, content);
+ return new QFileOpenEvent(filename);
+#endif
+}
+
+void tst_qfileopenevent::constructor()
+{
+ // check that filename get/set works
+ QFileOpenEvent nameTest(QLatin1String("fileNameTest"));
+ QCOMPARE(nameTest.file(), QLatin1String("fileNameTest"));
+
+ // check that url get/set works
+ QFileOpenEvent urlTest(QUrl(QLatin1String("file:///urlNameTest")));
+ QCOMPARE(urlTest.url().toString(), QLatin1String("file:///urlNameTest"));
+
+#ifdef Q_OS_SYMBIAN
+ // check that RFile construction works
+ RFile rFile = createRFile(_L("testRFile"), _L8("test content"));
+ QFileOpenEvent rFileTest(rFile);
+ QString targetName(QLatin1String("testRFile"));
+ QCOMPARE(rFileTest.file().right(targetName.size()), targetName);
+ QCOMPARE(rFileTest.url().toString().right(targetName.size()), targetName);
+ rFile.Close();
+#endif
+}
+
+QByteArray tst_qfileopenevent::readFileContent(QFileOpenEvent& event)
+{
+ QFile file;
+ event.openFile(file, QFile::ReadOnly);
+ file.seek(0);
+ QByteArray data = file.readAll();
+ return data;
+}
+
+bool tst_qfileopenevent::appendFileContent(QFileOpenEvent& event, const QByteArray& writeContent)
+{
+ QFile file;
+ bool ok = event.openFile(file, QFile::Append | QFile::Unbuffered);
+ if (ok)
+ ok = file.write(writeContent) == writeContent.size();
+ return ok;
+}
+
+void tst_qfileopenevent::checkReadAndWrite(QFileOpenEvent& event, const QByteArray& readContent, const QByteArray& writeContent, bool writeOk)
+{
+ QCOMPARE(readFileContent(event), readContent);
+ QCOMPARE(appendFileContent(event, writeContent), writeOk);
+ QCOMPARE(readFileContent(event), writeOk ? readContent+writeContent : readContent);
+}
+
+void tst_qfileopenevent::fileOpen()
+{
+#ifdef Q_OS_SYMBIAN
+ // create writeable file
+ {
+ RFile rFile = createRFile(_L("testFileOpen"), _L8("test content"));
+ QFileOpenEvent rFileTest(rFile);
+ checkReadAndWrite(rFileTest, QByteArray("test content"), QByteArray("+RFileWrite"), true);
+ rFile.Close();
+ }
+
+ // open read-only RFile
+ {
+ RFile rFile;
+ int err = rFile.Open(fsSession, _L("testFileOpen"), EFileRead);
+ QFileOpenEvent rFileTest(rFile);
+ checkReadAndWrite(rFileTest, QByteArray("test content+RFileWrite"), QByteArray("+RFileRead"), false);
+ rFile.Close();
+ }
+#else
+ createFile(QLatin1String("testFileOpen"), QByteArray("test content+RFileWrite"));
+#endif
+
+ // filename event
+ QUrl fileUrl; // need to get the URL during the file test, for use in the URL test
+ {
+ QFileOpenEvent nameTest(QLatin1String("testFileOpen"));
+ fileUrl = nameTest.url();
+ checkReadAndWrite(nameTest, QByteArray("test content+RFileWrite"), QByteArray("+nameWrite"), true);
+ }
+
+ // url event
+ {
+ QFileOpenEvent urlTest(fileUrl);
+ checkReadAndWrite(urlTest, QByteArray("test content+RFileWrite+nameWrite"), QByteArray("+urlWrite"), true);
+ }
+
+ QFile::remove(QLatin1String("testFileOpen"));
+}
+
+void tst_qfileopenevent::handleLifetime()
+{
+ QScopedPointer<QFileOpenEvent> event(createFileAndEvent(QLatin1String("testHandleLifetime"), QByteArray("test content")));
+
+ // open a QFile after the original RFile is closed
+ QFile qFile;
+ QCOMPARE(event->openFile(qFile, QFile::Append | QFile::Unbuffered), true);
+ event.reset(0);
+
+ // write to the QFile after the event is closed
+ QString writeContent(QLatin1String("+closed original handles"));
+ QCOMPARE(int(qFile.write(writeContent.toUtf8())), writeContent.size());
+ qFile.close();
+
+ // check the content
+ QFile check("testHandleLifetime");
+ check.open(QFile::ReadOnly);
+ QString content(check.readAll());
+ QCOMPARE(content, QLatin1String("test content+closed original handles"));
+ check.close();
+
+ QFile::remove(QLatin1String("testHandleLifetime"));
+}
+
+void tst_qfileopenevent::multiOpen()
+{
+ QScopedPointer<QFileOpenEvent> event(createFileAndEvent(QLatin1String("testMultiOpen"), QByteArray("itlum")));
+
+ QFile files[5];
+ for (int i=0; i<5; i++) {
+ QCOMPARE(event->openFile(files[i], QFile::ReadOnly), true);
+ }
+ for (int i=0; i<5; i++)
+ files[i].seek(i);
+ QString str;
+ for (int i=4; i>=0; i--) {
+ char c;
+ files[i].getChar(&c);
+ str.append(c);
+ files[i].close();
+ }
+ QCOMPARE(str, QLatin1String("multi"));
+
+ QFile::remove(QLatin1String("testMultiOpen"));
+}
+
+bool tst_qfileopenevent::event(QEvent *event)
+{
+ if (event->type() != QEvent::FileOpen)
+ return QObject::event(event);
+ QFileOpenEvent* fileOpenEvent = static_cast<QFileOpenEvent *>(event);
+ appendFileContent(*fileOpenEvent, "+received");
+ return true;
+}
+
+void tst_qfileopenevent::sendAndReceive()
+{
+ QScopedPointer<QFileOpenEvent> event(createFileAndEvent(QLatin1String("testSendAndReceive"), QByteArray("sending")));
+
+ QCoreApplication::instance()->postEvent(this, event.take());
+ QCoreApplication::instance()->processEvents();
+
+ // QTBUG-17468: On Mac, processEvents doesn't always process posted events
+ QCoreApplication::instance()->sendPostedEvents();
+
+ // check the content
+ QFile check("testSendAndReceive");
+ QCOMPARE(check.open(QFile::ReadOnly), true);
+ QString content(check.readAll());
+ QCOMPARE(content, QLatin1String("sending+received"));
+ check.close();
+
+ QFile::remove(QLatin1String("testSendAndReceive"));
+}
+
+void tst_qfileopenevent::external_data()
+{
+ QTest::addColumn<QString>("filename");
+ QTest::addColumn<QByteArray>("targetContent");
+ QTest::addColumn<bool>("sendHandle");
+
+ QString privateName(QLatin1String("tst_qfileopenevent_external"));
+ QString publicName(QLatin1String("C:\\Data\\tst_qfileopenevent_external"));
+ QByteArray writeSuccess("original+external");
+ QByteArray writeFail("original");
+ QTest::newRow("public name") << publicName << writeSuccess << false;
+ QTest::newRow("data caged name") << privateName << writeFail << false;
+ QTest::newRow("public handle") << publicName << writeSuccess << true;
+ QTest::newRow("data caged handle") << privateName << writeSuccess << true;
+}
+
+void tst_qfileopenevent::external()
+{
+#ifndef Q_OS_SYMBIAN
+ QSKIP("external app file open test only valid in Symbian", SkipAll);
+#else
+
+ QFETCH(QString, filename);
+ QFETCH(QByteArray, targetContent);
+ QFETCH(bool, sendHandle);
+
+ RFile rFile = createRFile(qt_QString2TPtrC(filename), _L8("original"));
+
+ // launch app with the file
+ RApaLsSession apa;
+ QCOMPARE(apa.Connect(), KErrNone);
+ TThreadId threadId;
+ TDataType type(_L8("application/x-tst_qfileopenevent"));
+ if (sendHandle) {
+ QCOMPARE(apa.StartDocument(rFile, type, threadId), KErrNone);
+ rFile.Close();
+ } else {
+ TFileName fullName;
+ rFile.FullName(fullName);
+ rFile.Close();
+ QCOMPARE(apa.StartDocument(fullName, type, threadId), KErrNone);
+ }
+
+ // wait for app exit
+ RThread appThread;
+ if (appThread.Open(threadId) == KErrNone) {
+ TRequestStatus status;
+ appThread.Logon(status);
+ User::WaitForRequest(status);
+ }
+
+ // check the contents
+ QFile check(filename);
+ QCOMPARE(check.open(QFile::ReadOnly), true);
+ QCOMPARE(check.readAll(), targetContent);
+ bool ok = check.remove();
+
+ QFile::remove(filename);
+#endif
+}
+
+QTEST_MAIN(tst_qfileopenevent)
+#include "tst_qfileopenevent.moc"
diff --git a/tests/auto/gui/kernel/qguivariant/.gitignore b/tests/auto/gui/kernel/qguivariant/.gitignore
new file mode 100644
index 0000000000..ea64ae90a0
--- /dev/null
+++ b/tests/auto/gui/kernel/qguivariant/.gitignore
@@ -0,0 +1 @@
+tst_qguivariant
diff --git a/tests/auto/gui/kernel/qguivariant/qguivariant.pro b/tests/auto/gui/kernel/qguivariant/qguivariant.pro
new file mode 100644
index 0000000000..68082f0037
--- /dev/null
+++ b/tests/auto/gui/kernel/qguivariant/qguivariant.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+SOURCES += tst_qguivariant.cpp
+
+
+
diff --git a/tests/auto/gui/kernel/qguivariant/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/tst_qguivariant.cpp
new file mode 100644
index 0000000000..988580b874
--- /dev/null
+++ b/tests/auto/gui/kernel/qguivariant/tst_qguivariant.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+
+#include <qvariant.h>
+
+
+
+class tst_QGuiVariant : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QGuiVariant();
+
+private slots:
+ void variantWithoutApplication();
+};
+
+tst_QGuiVariant::tst_QGuiVariant()
+{}
+
+void tst_QGuiVariant::variantWithoutApplication()
+{
+ QVariant v = QString("red");
+
+ QVERIFY(qvariant_cast<QColor>(v) == QColor(Qt::red));
+}
+
+
+QTEST_APPLESS_MAIN(tst_QGuiVariant)
+#include "tst_qguivariant.moc"
diff --git a/tests/auto/gui/kernel/qkeysequence/.gitignore b/tests/auto/gui/kernel/qkeysequence/.gitignore
new file mode 100644
index 0000000000..e06a7b0f43
--- /dev/null
+++ b/tests/auto/gui/kernel/qkeysequence/.gitignore
@@ -0,0 +1 @@
+tst_qkeysequence
diff --git a/tests/auto/gui/kernel/qkeysequence/keys_de.qm b/tests/auto/gui/kernel/qkeysequence/keys_de.qm
new file mode 100644
index 0000000000..5d7aedd765
--- /dev/null
+++ b/tests/auto/gui/kernel/qkeysequence/keys_de.qm
Binary files differ
diff --git a/tests/auto/gui/kernel/qkeysequence/keys_de.ts b/tests/auto/gui/kernel/qkeysequence/keys_de.ts
new file mode 100644
index 0000000000..1db18f1fdd
--- /dev/null
+++ b/tests/auto/gui/kernel/qkeysequence/keys_de.ts
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS><TS version="1.1" language="de">
+<context>
+ <name>tst_QKeySequence</name>
+ <message>
+ <location filename="tst_qkeysequence.cpp" line="369"/>
+ <source>Shift+K</source>
+ <translation type="obsolete">Umschalt+K</translation>
+ </message>
+ <message>
+ <location filename="tst_qkeysequence.cpp" line="370"/>
+ <source>Ctrl+K</source>
+ <translation type="obsolete">Strg+K</translation>
+ </message>
+ <message>
+ <location filename="tst_qkeysequence.cpp" line="371"/>
+ <source>Alt+K</source>
+ <translation type="obsolete">Alt+K</translation>
+ </message>
+ <message>
+ <location filename="tst_qkeysequence.cpp" line="391"/>
+ <source>Shift++</source>
+ <translation>Umschalt++</translation>
+ </message>
+ <message>
+ <location filename="tst_qkeysequence.cpp" line="392"/>
+ <source>Ctrl++</source>
+ <translation>Strg++</translation>
+ </message>
+ <message>
+ <location filename="tst_qkeysequence.cpp" line="393"/>
+ <source>Alt++</source>
+ <translation>Alt++</translation>
+ </message>
+ <message>
+ <location filename="tst_qkeysequence.cpp" line="394"/>
+ <source>Meta++</source>
+ <translation>Meta++</translation>
+ </message>
+ <message>
+ <location filename="tst_qkeysequence.cpp" line="401"/>
+ <source>Shift+,, Shift++</source>
+ <translation>Umschalt+,, Umschalt++</translation>
+ </message>
+ <message>
+ <location filename="tst_qkeysequence.cpp" line="402"/>
+ <source>Shift+,, Ctrl++</source>
+ <translation>Umschalt+,, Strg++</translation>
+ </message>
+ <message>
+ <location filename="tst_qkeysequence.cpp" line="403"/>
+ <source>Shift+,, Alt++</source>
+ <translation>Umschalt+,, Alt++</translation>
+ </message>
+ <message>
+ <location filename="tst_qkeysequence.cpp" line="404"/>
+ <source>Shift+,, Meta++</source>
+ <translation>Umschalt+,, Meta++</translation>
+ </message>
+</context>
+</TS>
diff --git a/tests/auto/gui/kernel/qkeysequence/qkeysequence.pro b/tests/auto/gui/kernel/qkeysequence/qkeysequence.pro
new file mode 100644
index 0000000000..6cfbe459ea
--- /dev/null
+++ b/tests/auto/gui/kernel/qkeysequence/qkeysequence.pro
@@ -0,0 +1,8 @@
+load(qttest_p4)
+
+QT += widgets widgets-private
+QT += core-private gui-private
+
+SOURCES += tst_qkeysequence.cpp
+
+RESOURCES += qkeysequence.qrc
diff --git a/tests/auto/gui/kernel/qkeysequence/qkeysequence.qrc b/tests/auto/gui/kernel/qkeysequence/qkeysequence.qrc
new file mode 100644
index 0000000000..e224faaddd
--- /dev/null
+++ b/tests/auto/gui/kernel/qkeysequence/qkeysequence.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource>
+ <file>keys_de.qm</file>
+ <file>qt_de.qm</file>
+ </qresource>
+</RCC>
diff --git a/tests/auto/gui/kernel/qkeysequence/qt_de.qm b/tests/auto/gui/kernel/qkeysequence/qt_de.qm
new file mode 100644
index 0000000000..595e4d7e8f
--- /dev/null
+++ b/tests/auto/gui/kernel/qkeysequence/qt_de.qm
Binary files differ
diff --git a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp
new file mode 100644
index 0000000000..5753fb8df4
--- /dev/null
+++ b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp
@@ -0,0 +1,636 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+#include <private/qapplication_p.h>
+#include <qkeysequence.h>
+#include <private/qkeysequence_p.h>
+#include <QTranslator>
+#include <QLibraryInfo>
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+#ifdef Q_WS_MAC
+#include <Carbon/Carbon.h>
+struct MacSpecialKey {
+ int key;
+ ushort macSymbol;
+};
+
+static const int NumEntries = 21;
+static const MacSpecialKey entries[NumEntries] = {
+ { Qt::Key_Escape, 0x238B },
+ { Qt::Key_Tab, 0x21E5 },
+ { Qt::Key_Backtab, 0x21E4 },
+ { Qt::Key_Backspace, 0x232B },
+ { Qt::Key_Return, 0x21B5 },
+ { Qt::Key_Enter, 0x21B5 },
+ { Qt::Key_Delete, 0x2326 },
+ { Qt::Key_Home, 0x2196 },
+ { Qt::Key_End, 0x2198 },
+ { Qt::Key_Left, 0x2190 },
+ { Qt::Key_Up, 0x2191 },
+ { Qt::Key_Right, 0x2192 },
+ { Qt::Key_Down, 0x2193 },
+ { Qt::Key_PageUp, 0x21DE },
+ { Qt::Key_PageDown, 0x21DF },
+ { Qt::Key_Shift, kShiftUnicode },
+ { Qt::Key_Control, kCommandUnicode },
+ { Qt::Key_Meta, kControlUnicode },
+ { Qt::Key_Alt, kOptionUnicode },
+ { Qt::Key_CapsLock, 0x21EA },
+};
+
+static bool operator<(const MacSpecialKey &entry, int key)
+{
+ return entry.key < key;
+}
+
+static bool operator<(int key, const MacSpecialKey &entry)
+{
+ return key < entry.key;
+}
+
+static const MacSpecialKey * const MacSpecialKeyEntriesEnd = entries + NumEntries;
+
+static QChar macSymbolForQtKey(int key)
+{
+ const MacSpecialKey *i = qBinaryFind(entries, MacSpecialKeyEntriesEnd, key);
+ if (i == MacSpecialKeyEntriesEnd)
+ return QChar();
+ return QChar(i->macSymbol);
+}
+
+#endif
+
+class tst_QKeySequence : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QKeySequence();
+ virtual ~tst_QKeySequence();
+
+private slots:
+ void swap();
+ void operatorQString_data();
+ void operatorQString();
+ void compareConstructors_data();
+ void compareConstructors();
+ void symetricConstructors_data();
+ void symetricConstructors();
+ void checkMultipleNames();
+ void checkMultipleCodes();
+ void mnemonic_data();
+ void mnemonic();
+ void toString_data();
+ void toString();
+ void streamOperators_data();
+ void streamOperators();
+ void fromString_data();
+ void fromString();
+ void ensureSorted();
+ void standardKeys_data();
+ void standardKeys();
+ void keyBindings();
+ void translated_data();
+ void translated();
+ void i18nKeys_data();
+ void i18nKeys();
+
+
+ void initTestCase();
+private:
+ QTranslator *ourTranslator;
+ QTranslator *qtTranslator;
+#ifdef Q_WS_MAC
+ static const QString MacCtrl;
+ static const QString MacMeta;
+ static const QString MacAlt;
+ static const QString MacShift;
+#endif
+
+
+};
+
+#ifdef Q_WS_MAC
+const QString tst_QKeySequence::MacCtrl = QString(QChar(0x2318));
+const QString tst_QKeySequence::MacMeta = QString(QChar(0x2303));
+const QString tst_QKeySequence::MacAlt = QString(QChar(0x2325));
+const QString tst_QKeySequence::MacShift = QString(QChar(0x21E7));
+#endif
+
+tst_QKeySequence::tst_QKeySequence()
+{
+}
+
+tst_QKeySequence::~tst_QKeySequence()
+{
+
+}
+
+void tst_QKeySequence::initTestCase()
+{
+ ourTranslator = new QTranslator(this);
+ ourTranslator->load(":/keys_de");
+ qtTranslator = new QTranslator(this);
+ qtTranslator->load(":/qt_de");
+}
+
+void tst_QKeySequence::swap()
+{
+ QKeySequence ks1(Qt::CTRL+Qt::Key_O);
+ QKeySequence ks2(Qt::CTRL+Qt::Key_L);
+ ks1.swap(ks2);
+ QCOMPARE(ks1[0], int(Qt::CTRL+Qt::Key_L));
+ QCOMPARE(ks2[0], int(Qt::CTRL+Qt::Key_O));
+}
+
+void tst_QKeySequence::operatorQString_data()
+{
+ QTest::addColumn<int>("modifiers");
+ QTest::addColumn<int>("keycode");
+ QTest::addColumn<QString>("keystring");
+
+ QTest::newRow( "No modifier" ) << 0 << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "\x0c5" );
+
+#ifndef Q_WS_MAC
+ QTest::newRow( "Ctrl+Left" ) << int(Qt::CTRL) << int(Qt::Key_Left) << QString( "Ctrl+Left" );
+ QTest::newRow( "Ctrl+," ) << int(Qt::CTRL) << int(Qt::Key_Comma) << QString( "Ctrl+," );
+ QTest::newRow( "Alt+Left" ) << int(Qt::ALT) << int(Qt::Key_Left) << QString( "Alt+Left" );
+ QTest::newRow( "Alt+Shift+Left" ) << int(Qt::ALT | Qt::SHIFT) << int(Qt::Key_Left) << QString( "Alt+Shift+Left" );
+ QTest::newRow( "Ctrl" ) << int(Qt::CTRL) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "Ctrl+\x0c5" );
+ QTest::newRow( "Alt" ) << int(Qt::ALT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "Alt+\x0c5" );
+ QTest::newRow( "Shift" ) << int(Qt::SHIFT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "Shift+\x0c5" );
+ QTest::newRow( "Meta" ) << int(Qt::META) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << QString( "Meta+\x0c5" );
+#else
+ QTest::newRow( "Ctrl+Left" ) << int(Qt::CTRL) << int(Qt::Key_Left) << MacCtrl + macSymbolForQtKey(Qt::Key_Left);
+ QTest::newRow( "Ctrl+," ) << int(Qt::CTRL) << int(Qt::Key_Comma) << MacCtrl + ",";
+ QTest::newRow( "Alt+Left" ) << int(Qt::ALT) << int(Qt::Key_Left) << MacAlt + macSymbolForQtKey(Qt::Key_Left);
+ QTest::newRow( "Alt+Shift+Left" ) << int(Qt::ALT | Qt::SHIFT) << int(Qt::Key_Left) << MacAlt + MacShift + macSymbolForQtKey(Qt::Key_Left);
+ QTest::newRow( "Ctrl" ) << int(Qt::CTRL) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << MacCtrl + "\x0c5";
+ QTest::newRow( "Alt" ) << int(Qt::ALT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << MacAlt + "\x0c5";
+ QTest::newRow( "Shift" ) << int(Qt::SHIFT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << MacShift + "\x0c5";
+ QTest::newRow( "Meta" ) << int(Qt::META) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL) << MacMeta + "\x0c5";
+#endif
+}
+
+void tst_QKeySequence::symetricConstructors_data()
+{
+ QTest::addColumn<int>("modifiers");
+ QTest::addColumn<int>("keycode");
+
+ QTest::newRow( "No modifier" ) << 0 << int(Qt::Key_Aring | Qt::UNICODE_ACCEL);
+ QTest::newRow( "Ctrl" ) << int(Qt::CTRL) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL);
+ QTest::newRow( "Alt" ) << int(Qt::ALT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL);
+ QTest::newRow( "Shift" ) << int(Qt::SHIFT) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL);
+ QTest::newRow( "Meta" ) << int(Qt::META) << int(Qt::Key_Aring | Qt::UNICODE_ACCEL);
+}
+
+void tst_QKeySequence::compareConstructors_data()
+{
+ operatorQString_data();
+}
+
+// operator QString()
+void tst_QKeySequence::operatorQString()
+{
+ QKeySequence seq;
+ QFETCH( int, modifiers );
+ QFETCH( int, keycode );
+ QFETCH( QString, keystring );
+
+ seq = QKeySequence( modifiers | keycode );
+
+ QCOMPARE( (QString)seq, keystring );
+}
+
+// this verifies that the constructors can handle the same strings in and out
+void tst_QKeySequence::symetricConstructors()
+{
+ QFETCH( int, modifiers );
+ QFETCH( int, keycode );
+
+ QKeySequence seq1( modifiers | keycode );
+ QKeySequence seq2( (QString)seq1 );
+
+ QVERIFY( seq1 == seq2 );
+}
+
+/* Compares QKeySequence constructurs with int or QString arguments
+ We don't do this for 3.0 since it doesn't support unicode accelerators */
+void tst_QKeySequence::compareConstructors()
+{
+ QFETCH( int, modifiers );
+ QFETCH( int, keycode );
+ QFETCH( QString, keystring );
+
+ QKeySequence qstringSeq( keystring );
+ QKeySequence intSeq( modifiers | keycode );
+
+ QVERIFY( qstringSeq == intSeq );
+}
+
+void tst_QKeySequence::checkMultipleNames()
+{
+ QKeySequence oldK( "Ctrl+Page Up" );
+ QKeySequence newK( "Ctrl+PgUp" );
+ QVERIFY( oldK == newK );
+}
+
+//TODO: could test third constructor, or test fromString on all constructor-data
+void tst_QKeySequence::checkMultipleCodes()
+{
+ QKeySequence seq1("Alt+d, l");
+ QKeySequence seq2 = QKeySequence::fromString("Alt+d, l");
+ QVERIFY( seq1 == seq2 );
+
+ QKeySequence seq3("Alt+d,l");
+ QKeySequence seq4 = QKeySequence::fromString("Alt+d,l");
+ QVERIFY( seq3 == seq4 );
+}
+
+/*
+* We must ensure that the keyBindings data is always sorted
+* so that we can safely perform binary searches.
+*/
+void tst_QKeySequence::ensureSorted()
+{
+//### accessing static members from private classes does not work on msvc at the moment
+#if defined(QT_BUILD_INTERNAL) && !defined(Q_WS_WIN)
+ uint N = QKeySequencePrivate::numberOfKeyBindings;
+ uint val = QKeySequencePrivate::keyBindings[0].shortcut;
+ for ( uint i = 1 ; i < N ; ++i) {
+ uint nextval = QKeySequencePrivate::keyBindings[i].shortcut;
+ if (nextval < val)
+ qDebug() << "Data not sorted at index " << i;
+ QVERIFY(nextval >= val);
+ val = nextval;
+ }
+#endif
+}
+
+void tst_QKeySequence::standardKeys_data()
+{
+ QTest::addColumn<int>("standardKey");
+ QTest::addColumn<QString>("expected");
+ QTest::newRow("unknownkey") << (int)QKeySequence::UnknownKey<< QString("");
+ QTest::newRow("copy") << (int)QKeySequence::Copy << QString("CTRL+C");
+ QTest::newRow("cut") << (int)QKeySequence::Cut << QString("CTRL+X");
+ QTest::newRow("paste") << (int)QKeySequence::Paste << QString("CTRL+V");
+ QTest::newRow("delete") << (int)QKeySequence::Delete<< QString("DEL");
+ QTest::newRow("open") << (int)QKeySequence::Open << QString("CTRL+O");
+ QTest::newRow("find") << (int)QKeySequence::Find<< QString("CTRL+F");
+#ifdef Q_WS_WIN
+ QTest::newRow("addTab") << (int)QKeySequence::AddTab<< QString("CTRL+T");
+ QTest::newRow("findNext") << (int)QKeySequence::FindNext<< QString("F3");
+ QTest::newRow("findPrevious") << (int)QKeySequence::FindPrevious << QString("SHIFT+F3");
+ QTest::newRow("close") << (int)QKeySequence::Close<< QString("CTRL+F4");
+ QTest::newRow("replace") << (int)QKeySequence::Replace<< QString("CTRL+H");
+#endif
+ QTest::newRow("bold") << (int)QKeySequence::Bold << QString("CTRL+B");
+ QTest::newRow("italic") << (int)QKeySequence::Italic << QString("CTRL+I");
+ QTest::newRow("underline") << (int)QKeySequence::Underline << QString("CTRL+U");
+ QTest::newRow("selectall") << (int)QKeySequence::SelectAll << QString("CTRL+A");
+ QTest::newRow("print") << (int)QKeySequence::Print << QString("CTRL+P");
+ QTest::newRow("movenextchar") << (int)QKeySequence::MoveToNextChar<< QString("RIGHT");
+ QTest::newRow("zoomIn") << (int)QKeySequence::ZoomIn<< QString("CTRL++");
+ QTest::newRow("zoomOut") << (int)QKeySequence::ZoomOut<< QString("CTRL+-");
+ QTest::newRow("whatsthis") << (int)QKeySequence::WhatsThis<< QString("SHIFT+F1");
+
+#if defined(Q_WS_MAC)
+ QTest::newRow("help") << (int)QKeySequence::HelpContents<< QString("Ctrl+?");
+ QTest::newRow("nextChild") << (int)QKeySequence::NextChild << QString("CTRL+}");
+ QTest::newRow("previousChild") << (int)QKeySequence::PreviousChild << QString("CTRL+{");
+ QTest::newRow("MoveToEndOfBlock") << (int)QKeySequence::MoveToEndOfBlock << QString("ALT+DOWN");
+ QTest::newRow("forward") << (int)QKeySequence::Forward << QString("CTRL+]");
+ QTest::newRow("backward") << (int)QKeySequence::Back << QString("CTRL+[");
+ QTest::newRow("SelectEndOfDocument") << (int)QKeySequence::SelectEndOfDocument<< QString("CTRL+SHIFT+DOWN"); //mac only
+#elif defined(Q_WS_S60)
+ QTest::newRow("help") << (int)QKeySequence::HelpContents<< QString("F2");
+ QTest::newRow("SelectEndOfDocument") << (int)QKeySequence::SelectEndOfDocument<< QString("CTRL+SHIFT+END"); //mac only
+#else
+ QTest::newRow("help") << (int)QKeySequence::HelpContents<< QString("F1");
+ QTest::newRow("nextChild") << (int)QKeySequence::NextChild<< QString("CTRL+Tab");
+ QTest::newRow("previousChild") << (int)QKeySequence::PreviousChild<< QString("CTRL+SHIFT+BACKTAB");
+ QTest::newRow("forward") << (int)QKeySequence::Forward << QString("ALT+RIGHT");
+ QTest::newRow("backward") << (int)QKeySequence::Back << QString("ALT+LEFT");
+ QTest::newRow("MoveToEndOfBlock") << (int)QKeySequence::MoveToEndOfBlock<< QString(""); //mac only
+ QTest::newRow("SelectEndOfDocument") << (int)QKeySequence::SelectEndOfDocument<< QString("CTRL+SHIFT+END"); //mac only
+#endif
+}
+
+void tst_QKeySequence::standardKeys()
+{
+ QFETCH(int, standardKey);
+ QFETCH(QString, expected);
+ QKeySequence ks((QKeySequence::StandardKey)standardKey);
+ QKeySequence ks2(expected);
+ QVERIFY(ks == ks2);
+}
+
+void tst_QKeySequence::keyBindings()
+{
+ QList<QKeySequence> bindings = QKeySequence::keyBindings(QKeySequence::Copy);
+ QList<QKeySequence> expected;
+#if defined(Q_WS_MAC) || defined (Q_WS_S60)
+ expected << QKeySequence("CTRL+C");
+#elif defined Q_WS_X11
+ expected << QKeySequence("CTRL+C") << QKeySequence("F16") << QKeySequence("CTRL+INSERT");
+#else
+ expected << QKeySequence("CTRL+C") << QKeySequence("CTRL+INSERT");
+#endif
+ QVERIFY(bindings == expected);
+}
+
+
+
+void tst_QKeySequence::mnemonic_data()
+{
+ QTest::addColumn<QString>("string");
+ QTest::addColumn<QString>("key");
+ QTest::addColumn<bool>("warning");
+
+ QTest::newRow("1") << QString::fromLatin1("&bonjour") << QString::fromLatin1("ALT+B") << false;
+ QTest::newRow("2") << QString::fromLatin1("&&bonjour") << QString() << false;
+ QTest::newRow("3") << QString::fromLatin1("&&bon&jour") << QString::fromLatin1("ALT+J") << false;
+ QTest::newRow("4") << QString::fromLatin1("&&bon&jo&ur") << QString::fromLatin1("ALT+J") << true;
+ QTest::newRow("5") << QString::fromLatin1("b&on&&jour") << QString::fromLatin1("ALT+O") << false;
+ QTest::newRow("6") << QString::fromLatin1("bonjour") << QString() << false;
+ QTest::newRow("7") << QString::fromLatin1("&&&bonjour") << QString::fromLatin1("ALT+B") << false;
+ QTest::newRow("8") << QString::fromLatin1("bonjour&&&") << QString() << false;
+ QTest::newRow("9") << QString::fromLatin1("bo&&nj&o&&u&r") << QString::fromLatin1("ALT+O") << true;
+ QTest::newRow("10") << QString::fromLatin1("BON&JOUR") << QString::fromLatin1("ALT+J") << false;
+ QTest::newRow("11") << QString::fromUtf8("bonjour") << QString() << false;
+}
+
+void tst_QKeySequence::mnemonic()
+{
+#ifdef Q_WS_MAC
+ QSKIP("mnemonics are not used on Mac OS X", SkipAll);
+#endif
+ QFETCH(QString, string);
+ QFETCH(QString, key);
+ QFETCH(bool, warning);
+
+#ifndef QT_NO_DEBUG
+ if (warning) {
+ QString str = QString::fromLatin1("QKeySequence::mnemonic: \"%1\" contains multiple occurrences of '&'").arg(string);
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(str));
+ // qWarning(qPrintable(str));
+ }
+#endif
+ QKeySequence seq = QKeySequence::mnemonic(string);
+ QKeySequence res = QKeySequence(key);
+
+ QCOMPARE(seq, res);
+}
+
+
+
+void tst_QKeySequence::toString_data()
+{
+ QTest::addColumn<QString>("strSequence");
+ QTest::addColumn<QString>("neutralString");
+ QTest::addColumn<QString>("platformString");
+
+
+#ifndef Q_WS_MAC
+ QTest::newRow("Ctrl+Left") << QString("Ctrl+Left") << QString("Ctrl+Left") << QString("Ctrl+Left");
+ QTest::newRow("Alt+Left") << QString("Alt+Left") << QString("Alt+Left") << QString("Alt+Left");
+ QTest::newRow("Alt+Shift+Left") << QString("Alt+Shift+Left") << QString("Alt+Shift+Left") << QString("Alt+Shift+Left");
+ QTest::newRow("Ctrl") << QString("Ctrl+\x0c5") << QString("Ctrl+\x0c5") << QString("Ctrl+\x0c5");
+ QTest::newRow("Alt") << QString("Alt+\x0c5") << QString("Alt+\x0c5") << QString("Alt+\x0c5");
+ QTest::newRow("Shift") << QString("Shift+\x0c5") << QString("Shift+\x0c5") << QString("Shift+\x0c5");
+ QTest::newRow("Meta") << QString("Meta+\x0c5") << QString("Meta+\x0c5") << QString("Meta+\x0c5");
+ QTest::newRow("Ctrl+Plus") << QString("Ctrl++") << QString("Ctrl++") << QString("Ctrl++");
+ QTest::newRow("Ctrl+,") << QString("Ctrl+,") << QString("Ctrl+,") << QString("Ctrl+,");
+ QTest::newRow("Ctrl+,,Ctrl+,") << QString("Ctrl+,,Ctrl+,") << QString("Ctrl+,, Ctrl+,") << QString("Ctrl+,, Ctrl+,");
+ QTest::newRow("MultiKey") << QString("Alt+X, Ctrl+Y, Z") << QString("Alt+X, Ctrl+Y, Z")
+ << QString("Alt+X, Ctrl+Y, Z");
+
+ QTest::newRow("Invalid") << QString("Ctrly") << QString("") << QString("");
+#else
+ /*
+ QTest::newRow("Ctrl+Left") << MacCtrl + "Left" << QString("Ctrl+Left") << MacCtrl + macSymbolForQtKey(Qt::Key_Left);
+ QTest::newRow("Alt+Left") << MacAlt + "Left" << QString("Alt+Left") << MacAlt + macSymbolForQtKey(Qt::Key_Left);
+ QTest::newRow("Alt+Shift+Left") << MacAlt + MacShift + "Left" << QString("Alt+Shift+Left")
+ << MacAlt + MacShift + macSymbolForQtKey(Qt::Key_Left);
+ */
+ QTest::newRow("Ctrl+Right,Left") << MacCtrl + "Right, Left" << QString("Ctrl+Right, Left") << MacCtrl + macSymbolForQtKey(Qt::Key_Right) + QString(", ") + macSymbolForQtKey(Qt::Key_Left);
+ QTest::newRow("Ctrl") << MacCtrl + "\x0c5" << QString("Ctrl+\x0c5") << MacCtrl + "\x0c5";
+ QTest::newRow("Alt") << MacAlt + "\x0c5" << QString("Alt+\x0c5") << MacAlt + "\x0c5";
+ QTest::newRow("Shift") << MacShift + "\x0c5" << QString("Shift+\x0c5") << MacShift + "\x0c5";
+ QTest::newRow("Meta") << MacMeta + "\x0c5" << QString("Meta+\x0c5") << MacMeta + "\x0c5";
+ QTest::newRow("Ctrl+Plus") << MacCtrl + "+" << QString("Ctrl++") << MacCtrl + "+";
+ QTest::newRow("Ctrl+,") << MacCtrl + "," << QString("Ctrl+,") << MacCtrl + ",";
+ QTest::newRow("Ctrl+,,Ctrl+,") << MacCtrl + ",, " + MacCtrl + "," << QString("Ctrl+,, Ctrl+,") << MacCtrl + ",, " + MacCtrl + ",";
+ QTest::newRow("MultiKey") << MacAlt + "X, " + MacCtrl + "Y, Z" << QString("Alt+X, Ctrl+Y, Z")
+ << MacAlt + "X, " + MacCtrl + "Y, Z";
+ QTest::newRow("Invalid") << QString("Ctrly") << QString("") << QString("");
+#endif
+}
+
+void tst_QKeySequence::toString()
+{
+ QFETCH(QString, strSequence);
+ QFETCH(QString, neutralString);
+ QFETCH(QString, platformString);
+
+ QKeySequence ks1(strSequence);
+
+ QCOMPARE(ks1.toString(QKeySequence::NativeText), platformString);
+ QCOMPARE(ks1.toString(QKeySequence::PortableText), neutralString);
+
+}
+
+void tst_QKeySequence::streamOperators_data()
+{
+ operatorQString_data();
+}
+
+void tst_QKeySequence::streamOperators()
+{
+ QFETCH( int, modifiers );
+ QFETCH( int, keycode );
+
+ QByteArray data;
+ QKeySequence refK( modifiers | keycode );
+ QKeySequence orgK( "Ctrl+A" );
+ QKeySequence copyOrgK = orgK;
+ QVERIFY( copyOrgK == orgK );
+
+ QDataStream in(&data, QIODevice::WriteOnly);
+ in << refK;
+ QDataStream out(&data, QIODevice::ReadOnly);
+ out >> orgK;
+
+ QVERIFY( orgK == refK );
+
+ // check if detached
+ QVERIFY( orgK != copyOrgK );
+}
+
+void tst_QKeySequence::fromString_data()
+{
+ toString_data();
+}
+
+void tst_QKeySequence::fromString()
+{
+ QFETCH(QString, strSequence);
+ QFETCH(QString, neutralString);
+ QFETCH(QString, platformString);
+
+ QKeySequence ks1(strSequence);
+ QKeySequence ks2 = QKeySequence::fromString(ks1.toString());
+ QKeySequence ks3 = QKeySequence::fromString(neutralString, QKeySequence::PortableText);
+ QKeySequence ks4 = QKeySequence::fromString(platformString, QKeySequence::NativeText);
+
+
+ // assume the transitive property exists here.
+ QCOMPARE(ks2, ks1);
+ QCOMPARE(ks3, ks1);
+ QCOMPARE(ks4, ks1);
+}
+
+void tst_QKeySequence::translated_data()
+{
+ qApp->installTranslator(ourTranslator);
+ qApp->installTranslator(qtTranslator);
+
+ QTest::addColumn<QString>("transKey");
+ QTest::addColumn<QString>("compKey");
+
+ QTest::newRow("Shift++") << tr("Shift++") << QString("Umschalt++");
+ QTest::newRow("Ctrl++") << tr("Ctrl++") << QString("Strg++");
+ QTest::newRow("Alt++") << tr("Alt++") << QString("Alt++");
+ QTest::newRow("Meta++") << tr("Meta++") << QString("Meta++");
+
+ QTest::newRow("Shift+,, Shift++") << tr("Shift+,, Shift++") << QString("Umschalt+,, Umschalt++");
+ QTest::newRow("Shift+,, Ctrl++") << tr("Shift+,, Ctrl++") << QString("Umschalt+,, Strg++");
+ QTest::newRow("Shift+,, Alt++") << tr("Shift+,, Alt++") << QString("Umschalt+,, Alt++");
+ QTest::newRow("Shift+,, Meta++") << tr("Shift+,, Meta++") << QString("Umschalt+,, Meta++");
+
+ QTest::newRow("Ctrl+,, Shift++") << tr("Ctrl+,, Shift++") << QString("Strg+,, Umschalt++");
+ QTest::newRow("Ctrl+,, Ctrl++") << tr("Ctrl+,, Ctrl++") << QString("Strg+,, Strg++");
+ QTest::newRow("Ctrl+,, Alt++") << tr("Ctrl+,, Alt++") << QString("Strg+,, Alt++");
+ QTest::newRow("Ctrl+,, Meta++") << tr("Ctrl+,, Meta++") << QString("Strg+,, Meta++");
+
+ qApp->removeTranslator(ourTranslator);
+ qApp->removeTranslator(qtTranslator);
+}
+
+void tst_QKeySequence::translated()
+{
+ QFETCH(QString, transKey);
+ QFETCH(QString, compKey);
+#ifdef Q_WS_MAC
+ QSKIP("No need to translate modifiers on Mac OS X", SkipAll);
+#elif defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
+ QSKIP("No need to translate modifiers on WinCE or Symbian", SkipAll);
+#endif
+
+ qApp->installTranslator(ourTranslator);
+ qApp->installTranslator(qtTranslator);
+
+ QKeySequence ks1(transKey);
+ QCOMPARE(ks1.toString(QKeySequence::NativeText), compKey);
+
+ qApp->removeTranslator(ourTranslator);
+ qApp->removeTranslator(qtTranslator);
+}
+
+
+void tst_QKeySequence::i18nKeys_data()
+{
+ QTest::addColumn<int>("keycode");
+ QTest::addColumn<QString>("keystring");
+
+ // Japanese keyboard support
+ QTest::newRow("Kanji") << (int)Qt::Key_Kanji << QString("Kanji");
+ QTest::newRow("Muhenkan") << (int)Qt::Key_Muhenkan << QString("Muhenkan");
+ QTest::newRow("Henkan") << (int)Qt::Key_Henkan << QString("Henkan");
+ QTest::newRow("Romaji") << (int)Qt::Key_Romaji << QString("Romaji");
+ QTest::newRow("Hiragana") << (int)Qt::Key_Hiragana << QString("Hiragana");
+ QTest::newRow("Katakana") << (int)Qt::Key_Katakana << QString("Katakana");
+ QTest::newRow("Hiragana Katakana") << (int)Qt::Key_Hiragana_Katakana << QString("Hiragana Katakana");
+ QTest::newRow("Zenkaku") << (int)Qt::Key_Zenkaku << QString("Zenkaku");
+ QTest::newRow("Hankaku") << (int)Qt::Key_Hankaku << QString("Hankaku");
+ QTest::newRow("Zenkaku Hankaku") << (int)Qt::Key_Zenkaku_Hankaku << QString("Zenkaku Hankaku");
+ QTest::newRow("Touroku") << (int)Qt::Key_Touroku << QString("Touroku");
+ QTest::newRow("Massyo") << (int)Qt::Key_Massyo << QString("Massyo");
+ QTest::newRow("Kana Lock") << (int)Qt::Key_Kana_Lock << QString("Kana Lock");
+ QTest::newRow("Kana Shift") << (int)Qt::Key_Kana_Shift << QString("Kana Shift");
+ QTest::newRow("Eisu Shift") << (int)Qt::Key_Eisu_Shift << QString("Eisu Shift");
+ QTest::newRow("Eisu_toggle") << (int)Qt::Key_Eisu_toggle << QString("Eisu toggle");
+ QTest::newRow("Code input") << (int)Qt::Key_Codeinput << QString("Code input");
+ QTest::newRow("Multiple Candidate") << (int)Qt::Key_MultipleCandidate << QString("Multiple Candidate");
+ QTest::newRow("Previous Candidate") << (int)Qt::Key_PreviousCandidate << QString("Previous Candidate");
+
+ // Korean keyboard support
+ QTest::newRow("Hangul") << (int)Qt::Key_Hangul << QString("Hangul");
+ QTest::newRow("Hangul Start") << (int)Qt::Key_Hangul_Start << QString("Hangul Start");
+ QTest::newRow("Hangul End") << (int)Qt::Key_Hangul_End << QString("Hangul End");
+ QTest::newRow("Hangul Hanja") << (int)Qt::Key_Hangul_Hanja << QString("Hangul Hanja");
+ QTest::newRow("Hangul Jamo") << (int)Qt::Key_Hangul_Jamo << QString("Hangul Jamo");
+ QTest::newRow("Hangul Romaja") << (int)Qt::Key_Hangul_Romaja << QString("Hangul Romaja");
+ QTest::newRow("Hangul Jeonja") << (int)Qt::Key_Hangul_Jeonja << QString("Hangul Jeonja");
+ QTest::newRow("Hangul Banja") << (int)Qt::Key_Hangul_Banja << QString("Hangul Banja");
+ QTest::newRow("Hangul PreHanja") << (int)Qt::Key_Hangul_PreHanja << QString("Hangul PreHanja");
+ QTest::newRow("Hangul PostHanja") << (int)Qt::Key_Hangul_PostHanja << QString("Hangul PostHanja");
+ QTest::newRow("Hangul Special") << (int)Qt::Key_Hangul_Special << QString("Hangul Special");
+}
+
+void tst_QKeySequence::i18nKeys()
+{
+ QFETCH(int, keycode);
+ QFETCH(QString, keystring);
+ QKeySequence seq(keycode);
+
+ QCOMPARE(seq, QKeySequence(keystring));
+ QCOMPARE(seq.toString(), keystring);
+}
+
+QTEST_MAIN(tst_QKeySequence)
+#include "tst_qkeysequence.moc"
diff --git a/tests/auto/gui/kernel/qmouseevent/.gitignore b/tests/auto/gui/kernel/qmouseevent/.gitignore
new file mode 100644
index 0000000000..17cd6be116
--- /dev/null
+++ b/tests/auto/gui/kernel/qmouseevent/.gitignore
@@ -0,0 +1 @@
+tst_qmouseevent
diff --git a/tests/auto/gui/kernel/qmouseevent/qmouseevent.pro b/tests/auto/gui/kernel/qmouseevent/qmouseevent.pro
new file mode 100644
index 0000000000..58cebd3d06
--- /dev/null
+++ b/tests/auto/gui/kernel/qmouseevent/qmouseevent.pro
@@ -0,0 +1,3 @@
+load(qttest_p4)
+QT += widgets
+SOURCES += tst_qmouseevent.cpp
diff --git a/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp b/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp
new file mode 100644
index 0000000000..5998aa0c08
--- /dev/null
+++ b/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp
@@ -0,0 +1,231 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+#include <qapplication.h>
+#include <qlineedit.h>
+#include <qlabel.h>
+#include <qdialog.h>
+
+
+#include <qevent.h>
+#include <qwidget.h>
+
+//TESTED_CLASS=
+//TESTED_FILES=gui/widgets/qmenubar.h gui/widgets/qmenubar.cpp
+
+class MouseEventWidget : public QWidget
+{
+public:
+ MouseEventWidget(QWidget *parent = 0) : QWidget(parent)
+ {
+ setFocusPolicy(Qt::StrongFocus);
+ }
+ bool mousePressEventRecieved;
+ bool mouseReleaseEventRecieved;
+ int mousePressButton;
+ int mousePressButtons;
+ int mousePressModifiers;
+ int mouseReleaseButton;
+ int mouseReleaseButtons;
+ int mouseReleaseModifiers;
+protected:
+ void mousePressEvent(QMouseEvent *e)
+ {
+ QWidget::mousePressEvent(e);
+ mousePressButton = e->button();
+ mousePressButtons = e->buttons();
+ mousePressModifiers = e->modifiers();
+ mousePressEventRecieved = TRUE;
+ e->accept();
+ }
+ void mouseReleaseEvent(QMouseEvent *e)
+ {
+ QWidget::mouseReleaseEvent(e);
+ mouseReleaseButton = e->button();
+ mouseReleaseButtons = e->buttons();
+ mouseReleaseModifiers = e->modifiers();
+ mouseReleaseEventRecieved = TRUE;
+ e->accept();
+ }
+};
+
+class tst_QMouseEvent : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QMouseEvent();
+ virtual ~tst_QMouseEvent();
+
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void init();
+ void cleanup();
+private slots:
+ void checkMousePressEvent_data();
+ void checkMousePressEvent();
+ void checkMouseReleaseEvent_data();
+ void checkMouseReleaseEvent();
+
+private:
+ MouseEventWidget* testMouseWidget;
+};
+
+
+
+tst_QMouseEvent::tst_QMouseEvent()
+{
+}
+
+tst_QMouseEvent::~tst_QMouseEvent()
+{
+
+}
+
+void tst_QMouseEvent::initTestCase()
+{
+ testMouseWidget = new MouseEventWidget(0);
+ testMouseWidget->show();
+}
+
+void tst_QMouseEvent::cleanupTestCase()
+{
+ delete testMouseWidget;
+}
+
+void tst_QMouseEvent::init()
+{
+ testMouseWidget->mousePressEventRecieved = FALSE;
+ testMouseWidget->mouseReleaseEventRecieved = FALSE;
+ testMouseWidget->mousePressButton = 0;
+ testMouseWidget->mousePressButtons = 0;
+ testMouseWidget->mousePressModifiers = 0;
+ testMouseWidget->mouseReleaseButton = 0;
+ testMouseWidget->mouseReleaseButtons = 0;
+ testMouseWidget->mouseReleaseModifiers = 0;
+}
+
+void tst_QMouseEvent::cleanup()
+{
+}
+
+void tst_QMouseEvent::checkMousePressEvent_data()
+{
+ QTest::addColumn<int>("buttonPressed");
+ QTest::addColumn<int>("keyPressed");
+
+ QTest::newRow("leftButton-nokey") << int(Qt::LeftButton) << int(Qt::NoButton);
+ QTest::newRow("leftButton-shiftkey") << int(Qt::LeftButton) << int(Qt::ShiftModifier);
+ QTest::newRow("leftButton-controlkey") << int(Qt::LeftButton) << int(Qt::ControlModifier);
+ QTest::newRow("leftButton-altkey") << int(Qt::LeftButton) << int(Qt::AltModifier);
+ QTest::newRow("leftButton-metakey") << int(Qt::LeftButton) << int(Qt::MetaModifier);
+ QTest::newRow("rightButton-nokey") << int(Qt::RightButton) << int(Qt::NoButton);
+ QTest::newRow("rightButton-shiftkey") << int(Qt::RightButton) << int(Qt::ShiftModifier);
+ QTest::newRow("rightButton-controlkey") << int(Qt::RightButton) << int(Qt::ControlModifier);
+ QTest::newRow("rightButton-altkey") << int(Qt::RightButton) << int(Qt::AltModifier);
+ QTest::newRow("rightButton-metakey") << int(Qt::RightButton) << int(Qt::MetaModifier);
+ QTest::newRow("midButton-nokey") << int(Qt::MidButton) << int(Qt::NoButton);
+ QTest::newRow("midButton-shiftkey") << int(Qt::MidButton) << int(Qt::ShiftModifier);
+ QTest::newRow("midButton-controlkey") << int(Qt::MidButton) << int(Qt::ControlModifier);
+ QTest::newRow("midButton-altkey") << int(Qt::MidButton) << int(Qt::AltModifier);
+ QTest::newRow("midButton-metakey") << int(Qt::MidButton) << int(Qt::MetaModifier);
+}
+
+void tst_QMouseEvent::checkMousePressEvent()
+{
+ QFETCH(int,buttonPressed);
+ QFETCH(int,keyPressed);
+ int button = buttonPressed;
+ int buttons = button;
+ int modifiers = keyPressed;
+
+ QTest::mousePress(testMouseWidget, Qt::MouseButton(buttonPressed), Qt::KeyboardModifiers(keyPressed));
+ QVERIFY(testMouseWidget->mousePressEventRecieved);
+ QCOMPARE(testMouseWidget->mousePressButton, button);
+ QCOMPARE(testMouseWidget->mousePressButtons, buttons);
+ QCOMPARE(testMouseWidget->mousePressModifiers, modifiers);
+
+ QTest::mouseRelease(testMouseWidget, Qt::MouseButton(buttonPressed), Qt::KeyboardModifiers(keyPressed));
+}
+
+void tst_QMouseEvent::checkMouseReleaseEvent_data()
+{
+ QTest::addColumn<int>("buttonReleased");
+ QTest::addColumn<int>("keyPressed");
+
+ QTest::newRow("leftButton-nokey") << int(Qt::LeftButton) << int(Qt::NoButton);
+ QTest::newRow("leftButton-shiftkey") << int(Qt::LeftButton) << int(Qt::ShiftModifier);
+ QTest::newRow("leftButton-controlkey") << int(Qt::LeftButton) << int(Qt::ControlModifier);
+ QTest::newRow("leftButton-altkey") << int(Qt::LeftButton) << int(Qt::AltModifier);
+ QTest::newRow("leftButton-metakey") << int(Qt::LeftButton) << int(Qt::MetaModifier);
+ QTest::newRow("rightButton-nokey") << int(Qt::RightButton) << int(Qt::NoButton);
+ QTest::newRow("rightButton-shiftkey") << int(Qt::RightButton) << int(Qt::ShiftModifier);
+ QTest::newRow("rightButton-controlkey") << int(Qt::RightButton) << int(Qt::ControlModifier);
+ QTest::newRow("rightButton-altkey") << int(Qt::RightButton) << int(Qt::AltModifier);
+ QTest::newRow("rightButton-metakey") << int(Qt::RightButton) << int(Qt::MetaModifier);
+ QTest::newRow("midButton-nokey") << int(Qt::MidButton) << int(Qt::NoButton);
+ QTest::newRow("midButton-shiftkey") << int(Qt::MidButton) << int(Qt::ShiftModifier);
+ QTest::newRow("midButton-controlkey") << int(Qt::MidButton) << int(Qt::ControlModifier);
+ QTest::newRow("midButton-altkey") << int(Qt::MidButton) << int(Qt::AltModifier);
+ QTest::newRow("midButton-metakey") << int(Qt::MidButton) << int(Qt::MetaModifier);
+}
+
+void tst_QMouseEvent::checkMouseReleaseEvent()
+{
+ QFETCH(int,buttonReleased);
+ QFETCH(int,keyPressed);
+ int button = buttonReleased;
+ int buttons = 0;
+ int modifiers = keyPressed;
+
+ QTest::mouseClick(testMouseWidget, Qt::MouseButton(buttonReleased), Qt::KeyboardModifiers(keyPressed));
+ QVERIFY(testMouseWidget->mouseReleaseEventRecieved);
+ QCOMPARE(testMouseWidget->mouseReleaseButton, button);
+ QCOMPARE(testMouseWidget->mouseReleaseButtons, buttons);
+ QCOMPARE(testMouseWidget->mouseReleaseModifiers, modifiers);
+}
+
+QTEST_MAIN(tst_QMouseEvent)
+#include "tst_qmouseevent.moc"
diff --git a/tests/auto/gui/kernel/qmouseevent_modal/.gitignore b/tests/auto/gui/kernel/qmouseevent_modal/.gitignore
new file mode 100644
index 0000000000..e15c9eb18c
--- /dev/null
+++ b/tests/auto/gui/kernel/qmouseevent_modal/.gitignore
@@ -0,0 +1 @@
+tst_qmouseevent_modal
diff --git a/tests/auto/gui/kernel/qmouseevent_modal/qmouseevent_modal.pro b/tests/auto/gui/kernel/qmouseevent_modal/qmouseevent_modal.pro
new file mode 100644
index 0000000000..2f28de2675
--- /dev/null
+++ b/tests/auto/gui/kernel/qmouseevent_modal/qmouseevent_modal.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+QT += widgets
+SOURCES += tst_qmouseevent_modal.cpp
+
+
+
diff --git a/tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp b/tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp
new file mode 100644
index 0000000000..7006feeeb8
--- /dev/null
+++ b/tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp
@@ -0,0 +1,231 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+#include <qapplication.h>
+#include <qfontinfo.h>
+
+
+#include <qpushbutton.h>
+#include <qscrollbar.h>
+#include <qtimer.h>
+
+#include <qdialog.h>
+
+
+//TESTED_CLASS=
+//TESTED_FILES=gui/widgets/qmenubar.h gui/widgets/qmenubar.cpp
+
+class TstWidget;
+class TstDialog;
+QT_FORWARD_DECLARE_CLASS(QPushButton)
+
+class tst_qmouseevent_modal : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_qmouseevent_modal();
+ virtual ~tst_qmouseevent_modal();
+
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void init();
+ void cleanup();
+private slots:
+ void mousePressRelease();
+
+private:
+ TstWidget *w;
+};
+
+class TstWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ TstWidget();
+public slots:
+ void buttonPressed();
+public:
+ QPushButton *pb;
+ TstDialog *d;
+};
+
+
+class TstDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ TstDialog( QWidget *mouseWidget, QWidget *parent, const char *name );
+ int count() { return c; }
+protected:
+ void showEvent ( QShowEvent * );
+public slots:
+ void releaseMouse();
+ void closeDialog();
+private:
+ QWidget *m;
+ int c;
+};
+
+tst_qmouseevent_modal::tst_qmouseevent_modal()
+{
+}
+
+tst_qmouseevent_modal::~tst_qmouseevent_modal()
+{
+}
+
+void tst_qmouseevent_modal::initTestCase()
+{
+ w = new TstWidget;
+ w->show();
+}
+
+void tst_qmouseevent_modal::cleanupTestCase()
+{
+ delete w;
+ w = 0;
+}
+
+void tst_qmouseevent_modal::init()
+{
+}
+
+void tst_qmouseevent_modal::cleanup()
+{
+}
+
+/*
+ Test for task 22500
+*/
+void tst_qmouseevent_modal::mousePressRelease()
+{
+
+ QVERIFY( !w->d->isVisible() );
+ QVERIFY( w->d->count() == 0 );
+
+ QTest::mousePress( w->pb, Qt::LeftButton );
+ QTest::qWait(200);
+
+ QVERIFY( !w->d->isVisible() );
+ QVERIFY( w->d->count() == 1 );
+ QVERIFY( !w->pb->isDown() );
+
+ QTest::mousePress( w->pb, Qt::LeftButton );
+ QTest::qWait(200);
+
+ QVERIFY( !w->d->isVisible() );
+ QVERIFY( w->d->count() == 2 );
+ QVERIFY( !w->pb->isDown() );
+
+ // With the current QWS mouse handling, the 3rd press would fail...
+
+ QTest::mousePress( w->pb, Qt::LeftButton );
+ QTest::qWait(200);
+
+ QVERIFY( !w->d->isVisible() );
+ QVERIFY( w->d->count() == 3 );
+ QVERIFY( !w->pb->isDown() );
+
+ QTest::mousePress( w->pb, Qt::LeftButton );
+ QTest::qWait(200);
+
+ QVERIFY( !w->d->isVisible() );
+ QVERIFY( w->d->count() == 4 );
+ QVERIFY( !w->pb->isDown() );
+}
+
+
+TstWidget::TstWidget()
+{
+ pb = new QPushButton( "Press me", this );
+ pb->setObjectName("testbutton");
+ QSize s = pb->sizeHint();
+ pb->setGeometry( 5, 5, s.width(), s.height() );
+
+ connect( pb, SIGNAL(pressed()), this, SLOT(buttonPressed()) );
+
+// QScrollBar *sb = new QScrollBar( Qt::Horizontal, this );
+
+// sb->setGeometry( 5, pb->geometry().bottom() + 5, 100, sb->sizeHint().height() );
+
+ d = new TstDialog( pb, this , 0 );
+}
+
+void TstWidget::buttonPressed()
+{
+ d->exec();
+}
+
+TstDialog::TstDialog( QWidget *mouseWidget, QWidget *parent, const char *name )
+ :QDialog( parent )
+{
+ setObjectName(name);
+ setModal(true);
+ m = mouseWidget;
+ c = 0;
+}
+
+void TstDialog::showEvent ( QShowEvent * )
+{
+ QTimer::singleShot(1, this, SLOT(releaseMouse()));
+ QTimer::singleShot(100, this, SLOT(closeDialog()));
+}
+
+void TstDialog::releaseMouse()
+{
+ QTest::mouseRelease(m, Qt::LeftButton);
+}
+
+void TstDialog::closeDialog()
+{
+ if ( isVisible() ) {
+ c++;
+ accept();
+ }
+}
+
+QTEST_MAIN(tst_qmouseevent_modal)
+#include "tst_qmouseevent_modal.moc"
diff --git a/tests/auto/gui/kernel/qpalette/.gitignore b/tests/auto/gui/kernel/qpalette/.gitignore
new file mode 100644
index 0000000000..3c1aebac19
--- /dev/null
+++ b/tests/auto/gui/kernel/qpalette/.gitignore
@@ -0,0 +1 @@
+tst_qpalette
diff --git a/tests/auto/gui/kernel/qpalette/qpalette.pro b/tests/auto/gui/kernel/qpalette/qpalette.pro
new file mode 100644
index 0000000000..4b240e5f9c
--- /dev/null
+++ b/tests/auto/gui/kernel/qpalette/qpalette.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+QT += widgets
+SOURCES += tst_qpalette.cpp
+
+
+
diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp
new file mode 100644
index 0000000000..b63b8bf7b0
--- /dev/null
+++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+
+#include "qpalette.h"
+#include <qapplication.h>
+
+//TESTED_CLASS=QPalette
+//TESTED_FILES=qpalette.h qpalette.cpp
+
+class tst_QPalette : public QObject
+{
+Q_OBJECT
+
+public:
+ tst_QPalette();
+ virtual ~tst_QPalette();
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void init();
+ void cleanup();
+
+private slots:
+ void roleValues_data();
+ void roleValues();
+};
+
+tst_QPalette::tst_QPalette()
+{
+}
+
+tst_QPalette::~tst_QPalette()
+{
+}
+
+void tst_QPalette::initTestCase()
+{
+}
+
+void tst_QPalette::cleanupTestCase()
+{
+}
+
+void tst_QPalette::init()
+{
+}
+
+void tst_QPalette::cleanup()
+{
+}
+
+void tst_QPalette::roleValues_data()
+{
+ QTest::addColumn<int>("role");
+ QTest::addColumn<int>("value");
+
+ QTest::newRow("QPalette::WindowText") << int(QPalette::WindowText) << 0;
+ QTest::newRow("QPalette::Button") << int(QPalette::Button) << 1;
+ QTest::newRow("QPalette::Light") << int(QPalette::Light) << 2;
+ QTest::newRow("QPalette::Midlight") << int(QPalette::Midlight) << 3;
+ QTest::newRow("QPalette::Dark") << int(QPalette::Dark) << 4;
+ QTest::newRow("QPalette::Mid") << int(QPalette::Mid) << 5;
+ QTest::newRow("QPalette::Text") << int(QPalette::Text) << 6;
+ QTest::newRow("QPalette::BrightText") << int(QPalette::BrightText) << 7;
+ QTest::newRow("QPalette::ButtonText") << int(QPalette::ButtonText) << 8;
+ QTest::newRow("QPalette::Base") << int(QPalette::Base) << 9;
+ QTest::newRow("QPalette::Window") << int(QPalette::Window) << 10;
+ QTest::newRow("QPalette::Shadow") << int(QPalette::Shadow) << 11;
+ QTest::newRow("QPalette::Highlight") << int(QPalette::Highlight) << 12;
+ QTest::newRow("QPalette::HighlightedText") << int(QPalette::HighlightedText) << 13;
+ QTest::newRow("QPalette::Link") << int(QPalette::Link) << 14;
+ QTest::newRow("QPalette::LinkVisited") << int(QPalette::LinkVisited) << 15;
+ QTest::newRow("QPalette::AlternateBase") << int(QPalette::AlternateBase) << 16;
+ QTest::newRow("QPalette::NoRole") << int(QPalette::NoRole) << 17;
+ QTest::newRow("QPalette::ToolTipBase") << int(QPalette::ToolTipBase) << 18;
+ QTest::newRow("QPalette::ToolTipText") << int(QPalette::ToolTipText) << 19;
+
+ // Change this value as you add more roles.
+ QTest::newRow("QPalette::NColorRoles") << int(QPalette::NColorRoles) << 20;
+}
+
+void tst_QPalette::roleValues()
+{
+ QFETCH(int, role);
+ QFETCH(int, value);
+ QCOMPARE(role, value);
+}
+
+QTEST_MAIN(tst_QPalette)
+#include "tst_qpalette.moc"
diff --git a/tests/auto/gui/kernel/qshortcut/.gitignore b/tests/auto/gui/kernel/qshortcut/.gitignore
new file mode 100644
index 0000000000..3a17eb18e3
--- /dev/null
+++ b/tests/auto/gui/kernel/qshortcut/.gitignore
@@ -0,0 +1 @@
+tst_qshortcut
diff --git a/tests/auto/gui/kernel/qshortcut/qshortcut.pro b/tests/auto/gui/kernel/qshortcut/qshortcut.pro
new file mode 100644
index 0000000000..3f68d2377e
--- /dev/null
+++ b/tests/auto/gui/kernel/qshortcut/qshortcut.pro
@@ -0,0 +1,11 @@
+load(qttest_p4)
+
+# Project Configuration ----------------------------------------------
+INCLUDEPATH += ../
+
+# Normal Test Files --------------------------------------------------
+QT += widgets
+HEADERS +=
+SOURCES += tst_qshortcut.cpp
+
+
diff --git a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp
new file mode 100644
index 0000000000..a78e8cfd27
--- /dev/null
+++ b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp
@@ -0,0 +1,1272 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+#include <qapplication.h>
+#include <qtextedit.h>
+#include <qpushbutton.h>
+#include <qmainwindow.h>
+#include <qstatusbar.h>
+#include <qboxlayout.h>
+#include <qdebug.h>
+#include <qstring.h>
+#include <qshortcut.h>
+
+class AccelForm;
+QT_BEGIN_NAMESPACE
+class QMainWindow;
+class QTextEdit;
+QT_END_NAMESPACE
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+class tst_QShortcut : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QShortcut();
+ virtual ~tst_QShortcut();
+
+
+ enum Action {
+ SetupAccel,
+ TestAccel,
+ ClearAll
+ } currentAction;
+
+ enum Widget {
+ NoWidget,
+ TriggerSlot1,
+ TriggerSlot2,
+ TriggerSlot3,
+ TriggerSlot4,
+ TriggerSlot5,
+ TriggerSlot6,
+ TriggerSlot7
+ };
+
+ enum Result {
+ NoResult,
+ Slot1Triggered,
+ Slot2Triggered,
+ Slot3Triggered,
+ Slot4Triggered,
+ Slot5Triggered,
+ Slot6Triggered,
+ Slot7Triggered,
+ Ambiguous
+ } currentResult;
+
+public slots:
+ void slotTrig1() { currentResult = Slot1Triggered; }
+ void slotTrig2() { currentResult = Slot2Triggered; }
+ void slotTrig3() { currentResult = Slot3Triggered; }
+ void slotTrig4() { currentResult = Slot4Triggered; }
+ void slotTrig5() { currentResult = Slot5Triggered; }
+ void slotTrig6() { currentResult = Slot6Triggered; }
+ void slotTrig7() { currentResult = Slot7Triggered; }
+ void ambigSlot1() { currentResult = Ambiguous; ambigResult = Slot1Triggered; }
+ void ambigSlot2() { currentResult = Ambiguous; ambigResult = Slot2Triggered; }
+ void ambigSlot3() { currentResult = Ambiguous; ambigResult = Slot3Triggered; }
+ void ambigSlot4() { currentResult = Ambiguous; ambigResult = Slot4Triggered; }
+ void ambigSlot5() { currentResult = Ambiguous; ambigResult = Slot5Triggered; }
+ void ambigSlot6() { currentResult = Ambiguous; ambigResult = Slot6Triggered; }
+ void ambigSlot7() { currentResult = Ambiguous; ambigResult = Slot7Triggered; }
+ void statusMessage( const QString& message ) { sbText = message; }
+ void shortcutDestroyed(QObject* obj);
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+private slots:
+ void number_data();
+ void number();
+ void text_data();
+ void text();
+ void disabledItems();
+ void ambiguousItems();
+ void ambiguousRotation();
+ void keypressConsumption();
+ void unicodeCompare();
+ void context();
+
+protected:
+ static Qt::KeyboardModifiers toButtons( int key );
+ void defElements();
+
+ void clearAllShortcuts();
+ QShortcut *setupShortcut(int testWidget, const QKeySequence &ks);
+ QShortcut *setupShortcut(int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0);
+
+ QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0);
+ QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QKeySequence &ks, Qt::ShortcutContext context = Qt::WindowShortcut);
+
+ void sendKeyEvents(QWidget *w, int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0);
+ void sendKeyEvents(int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0);
+
+ void testElement();
+
+ QMainWindow *mainW;
+ QList<QShortcut*> shortcuts;
+ QTextEdit *edit;
+ QString sbText;
+ Result ambigResult;
+};
+
+QT_BEGIN_NAMESPACE
+template<> struct QMetaTypeId<tst_QShortcut::Widget>
+{ enum { Defined = 1 }; static inline int qt_metatype_id() { return QMetaType::Int; } };
+template<> struct QMetaTypeId<tst_QShortcut::Result>
+{ enum { Defined = 1 }; static inline int qt_metatype_id() { return QMetaType::Int; } };
+template<> struct QMetaTypeId<tst_QShortcut::Action>
+{ enum { Defined = 1 }; static inline int qt_metatype_id() { return QMetaType::Int; } };
+QT_END_NAMESPACE
+
+class TestEdit : public QTextEdit
+{
+ Q_OBJECT
+public:
+ TestEdit(QWidget *parent, const char *name)
+ : QTextEdit(parent)
+ {
+ setObjectName(name);
+ }
+
+protected:
+ bool event(QEvent *e) {
+ // Make testedit allow any Ctrl+Key as shortcut
+ if (e->type() == QEvent::ShortcutOverride) {
+ QKeyEvent *ke = static_cast<QKeyEvent*>(e);
+ if (ke->modifiers() == Qt::ControlModifier
+ && ke->key() > Qt::Key_Any
+ && ke->key() < Qt::Key_ydiaeresis) {
+ ke->ignore();
+ return true;
+ }
+ }
+
+ // If keypress not processed as normal, check for
+ // Ctrl+Key event, and input custom string for
+ // result comparison.
+ if (e->type() == QEvent::KeyPress) {
+ QKeyEvent *ke = static_cast<QKeyEvent*>(e);
+ if (ke->modifiers() && ke->key() > Qt::Key_Any
+ && ke->key() < Qt::Key_ydiaeresis) {
+ if (ke->modifiers() == Qt::ControlModifier)
+ insertPlainText(QString("<Ctrl+%1>").arg(char(ke->key())));
+ else if (ke->modifiers() == Qt::AltModifier)
+ insertPlainText(QString("<Alt+%1>").arg(char(ke->key())));
+ else if (ke->modifiers() == Qt::ShiftModifier)
+ insertPlainText(QString("<Shift+%1>").arg(char(ke->key())));
+ return true;
+ }
+ }
+ return QTextEdit::event(e);
+ }
+};
+
+tst_QShortcut::tst_QShortcut(): mainW( 0 )
+{
+}
+
+tst_QShortcut::~tst_QShortcut()
+{
+ clearAllShortcuts();
+}
+
+void tst_QShortcut::initTestCase()
+{
+ currentResult = NoResult;
+ mainW = new QMainWindow(0);
+ mainW->setWindowFlags(Qt::X11BypassWindowManagerHint);
+ edit = new TestEdit(mainW, "test_edit");
+ mainW->setFixedSize( 100, 100 );
+ mainW->setCentralWidget( edit );
+ mainW->show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(mainW);
+#endif
+ mainW->activateWindow();
+ QTest::qWait(100);
+ connect( mainW->statusBar(), SIGNAL(messageChanged(const QString&)),
+ this, SLOT(statusMessage(const QString&)) );
+}
+
+void tst_QShortcut::cleanupTestCase()
+{
+ delete mainW;
+}
+
+Qt::KeyboardModifiers tst_QShortcut::toButtons( int key )
+{
+ Qt::KeyboardModifiers result = Qt::NoModifier;
+ if ( key & Qt::SHIFT )
+ result |= Qt::ShiftModifier;
+ if ( key & Qt::CTRL )
+ result |= Qt::ControlModifier;
+ if ( key & Qt::META )
+ result |= Qt::MetaModifier;
+ if ( key & Qt::ALT )
+ result |= Qt::AltModifier;
+ return result;
+}
+
+void tst_QShortcut::defElements()
+{
+ QTest::addColumn<int>("action");
+ QTest::addColumn<int>("testWidget");
+ QTest::addColumn<QString>("txt");
+ QTest::addColumn<int>("k1");
+ QTest::addColumn<int>("c1");
+ QTest::addColumn<int>("k2");
+ QTest::addColumn<int>("c2");
+ QTest::addColumn<int>("k3");
+ QTest::addColumn<int>("c3");
+ QTest::addColumn<int>("k4");
+ QTest::addColumn<int>("c4");
+ QTest::addColumn<int>("result");
+}
+
+void tst_QShortcut::number()
+{
+ // We expect a failure on these tests, until QtTestKeyboard is
+ // fixed to do real platform dependent keyboard simulations
+ if (QTest::currentDataTag() == QString("N006a:Shift+Tab - [BackTab]")
+ || QTest::currentDataTag() == QString("N006b:Shift+Tab - [Shift+BackTab]"))
+ QEXPECT_FAIL("", "FLAW IN QTESTKEYBOARD: Keyboard events not passed through "
+ "platform dependent key handling code", Continue);
+ testElement();
+}
+void tst_QShortcut::text()
+{
+ testElement();
+}
+// ------------------------------------------------------------------
+// Number Elements --------------------------------------------------
+// ------------------------------------------------------------------
+void tst_QShortcut::number_data()
+{
+ defElements();
+
+ // Clear all
+ QTest::newRow("N00 - clear") << ClearAll <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
+
+ //===========================================
+ // [Shift + key] on non-shift shortcuts testing
+ //===========================================
+
+ /* Testing Single Sequences
+ Shift + Qt::Key_M on Qt::Key_M
+ Qt::Key_M on Qt::Key_M
+ Shift + Qt::Key_Plus on Qt::Key_Pluss
+ Qt::Key_Plus on Qt::Key_Pluss
+ */
+ QTest::newRow("N001 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ //commented out because the behaviour changed, those tests should be updated
+ //QTest::newRow("N001:Shift + M - [M]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N001:M - [M]") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N001 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ //commented out because the behaviour changed, those tests should be updated
+ //QTest::newRow("N001:Shift++ [+]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("N001:+ [+]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("N001 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Sequences
+ Shift + Qt::Key_M on Shift + Qt::Key_M
+ Qt::Key_M on Shift + Qt::Key_M
+ Shift + Qt::Key_Plus on Shift + Qt::Key_Pluss
+ Qt::Key_Plus on Shift + Qt::Key_Pluss
+ */
+ QTest::newRow("N002 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N002:Shift+M - [Shift+M]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N002:M - [Shift+M]") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N002 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N002:Shift++ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("N002:+ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N002 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Sequences
+ Shift + Qt::Key_F1 on Qt::Key_F1
+ Qt::Key_F1 on Qt::Key_F1
+ */
+ QTest::newRow("N003 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ //commented out because the behaviour changed, those tests should be updated
+ //QTest::newRow("N003:Shift+F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N003:F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N003 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+ /* Testing Single Sequences
+ Shift + Qt::Key_F1 on Shift + Qt::Key_F1
+ Qt::Key_F1 on Shift + Qt::Key_F1
+ */
+
+ QTest::newRow("N004 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N004:Shift+F1 - [Shift+F1]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N004:F1 - [Shift+F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N004 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Sequences
+ Qt::Key_Tab on Qt::Key_Tab
+ Shift + Qt::Key_Tab on Qt::Key_Tab
+ Qt::Key_Backtab on Qt::Key_Tab
+ Shift + Qt::Key_Backtab on Qt::Key_Tab
+ */
+ QTest::newRow("N005a - slot1") << SetupAccel << TriggerSlot1 << QString("")<< int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N005a:Tab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ //commented out because the behaviour changed, those tests should be updated
+ //QTest::newRow("N005a:Shift+Tab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ // (Shift+)BackTab != Tab, but Shift+BackTab == Shift+Tab
+ QTest::newRow("N005a:Backtab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N005a:Shift+Backtab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N005a - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Sequences
+ Qt::Key_Tab on Shift + Qt::Key_Tab
+ Shift + Qt::Key_Tab on Shift + Qt::Key_Tab
+ Qt::Key_Backtab on Shift + Qt::Key_Tab
+ Shift + Qt::Key_Backtab on Shift + Qt::Key_Tab
+ */
+ QTest::newRow("N005b - slot1") << SetupAccel << TriggerSlot1 << QString("")<< int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N005b:Tab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N005b:Shift+Tab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N005b:BackTab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N005b:Shift+BackTab - [Shift+Tab]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N005b - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Sequences
+ Qt::Key_Tab on Qt::Key_Backtab
+ Shift + Qt::Key_Tab on Qt::Key_Backtab
+ Qt::Key_Backtab on Qt::Key_Backtab
+ Shift + Qt::Key_Backtab on Qt::Key_Backtab
+ */
+ QTest::newRow("N006a - slot1") << SetupAccel << TriggerSlot1 << QString("")<< int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N006a:Tab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ // This should work, since platform dependent code will transform the
+ // Shift+Tab into a Shift+BackTab, which should trigger the shortcut
+ QTest::newRow("N006a:Shift+Tab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL
+ QTest::newRow("N006a:BackTab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ //commented out because the behaviour changed, those tests should be updated
+ //QTest::newRow("N006a:Shift+BackTab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N006a - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Sequences
+ Qt::Key_Tab on Shift + Qt::Key_Backtab
+ Shift + Qt::Key_Tab on Shift + Qt::Key_Backtab
+ Qt::Key_Backtab on Shift + Qt::Key_Backtab
+ Shift + Qt::Key_Backtab on Shift + Qt::Key_Backtab
+ */
+ QTest::newRow("N006b - slot1") << SetupAccel << TriggerSlot1 << QString("")<< int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N006b:Tab - [Shift+BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N006b:Shift+Tab - [Shift+BackTab]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N006b:BackTab - [Shift+BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N006b:Shift+BackTab - [Shift+BackTab]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL
+ QTest::newRow("N006b - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ //===========================================
+ // [Shift + key] and [key] on shortcuts with
+ // and without modifiers
+ //===========================================
+
+ /* Testing Single Sequences
+ Qt::Key_F1
+ Shift + Qt::Key_F1
+ */
+ QTest::newRow("N007 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N007 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N007:F1") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N007:Shift + F1") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("N007 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Sequences
+ Qt::Key_M
+ Shift + Qt::Key_M
+ Ctrl + Qt::Key_M
+ Alt + Qt::Key_M
+ */
+ QTest::newRow("N01 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N02 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N03 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N04 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N:Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N:Shift+Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("N:Ctrl+Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N:Alt+Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+
+ /* Testing Single Sequence Ambiguity
+ Qt::Key_M on shortcut2
+ */
+ QTest::newRow("N05 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N:Qt::Key_M on slot") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous;
+ QTest::newRow("N05 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Specialkeys
+ Qt::Key_aring
+ Qt::Key_Aring
+ Qt::UNICODE_ACCEL + Qt::Key_K
+ */
+ QTest::newRow("N06 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N07 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N08 - slot2") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::UNICODE_ACCEL + Qt::Key_K) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+
+ QTest::newRow("N:Qt::Key_aring") << TestAccel << NoWidget << QString("") << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N:Qt::Key_Aring") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("N:Qt::Key_aring - Text Form") << TestAccel << NoWidget << QString("") << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N:Qt::Key_Aring - Text Form") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("N:Qt::UNICODE_ACCEL + Qt::Key_K") << TestAccel << NoWidget << QString("") << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N09 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Multiple Sequences
+ Qt::Key_M
+ Qt::Key_I, Qt::Key_M
+ Shift+Qt::Key_I, Qt::Key_M
+ */
+ QTest::newRow("N10 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N11 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("N12 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << NoResult;
+
+ QTest::newRow("N:Qt::Key_M (2)") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N:Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("N:Shift+Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("N13 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+}
+
+// ------------------------------------------------------------------
+// Text Elements ----------------------------------------------------
+// ------------------------------------------------------------------
+void tst_QShortcut::text_data()
+{
+ defElements();
+ // Clear all
+ QTest::newRow("T00 - clear") << ClearAll <<0<<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<0;
+
+ //===========================================
+ // [Shift + key] on non-shift shortcuts testing
+ //===========================================
+
+ /* Testing Single Sequences
+ Shift + Qt::Key_M on Qt::Key_M
+ Qt::Key_M on Qt::Key_M
+ Shift + Qt::Key_Plus on Qt::Key_Pluss
+ Qt::Key_Plus on Qt::Key_Pluss
+ */
+ QTest::newRow("T001 - slot1") << SetupAccel << TriggerSlot1 << QString("M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ //commented out because the behaviour changed, those tests should be updated
+ //QTest::newRow("T001:Shift+M - [M]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T001:M - [M]") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T001 - slot2") << SetupAccel << TriggerSlot2 << QString("+") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ //commented out because the behaviour changed, those tests should be updated
+ //QTest::newRow("T001:Shift++ [+]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("T001:+ [+]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("T001 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Sequences
+ Shift + Qt::Key_M on Shift + Qt::Key_M
+ Qt::Key_M on Shift + Qt::Key_M
+ Shift + Qt::Key_Plus on Shift + Qt::Key_Pluss
+ Qt::Key_Plus on Shift + Qt::Key_Pluss
+ Shift + Ctrl + Qt::Key_Plus on Ctrl + Qt::Key_Pluss
+ Ctrl + Qt::Key_Plus on Ctrl + Qt::Key_Pluss
+ */
+ QTest::newRow("T002 - slot1") << SetupAccel << TriggerSlot1 << QString("Shift+M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T002:Shift+M - [Shift+M]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T002:M - [Shift+M]") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T002 - slot2") << SetupAccel << TriggerSlot2 << QString("Shift++") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T002:Shift++ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("T002:+ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T002 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Sequences
+ Shift + Ctrl + Qt::Key_Plus on Ctrl + Qt::Key_Plus
+ Ctrl + Qt::Key_Plus on Ctrl + Qt::Key_Plus
+ Qt::Key_Plus on Ctrl + Qt::Key_Plus
+ */
+ QTest::newRow("T002b - slot1") << SetupAccel << TriggerSlot1 << QString("Ctrl++") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ //commented out because the behaviour changed, those tests should be updated
+ //QTest::newRow("T002b:Shift+Ctrl++ [Ctrl++]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T002b:Ctrl++ [Ctrl++]") << TestAccel << NoWidget << QString("") << int(Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T002b:+ [Ctrl++]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T002b - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Sequences
+ Shift + Qt::Key_F1 on Qt::Key_F1
+ Qt::Key_F1 on Qt::Key_F1
+ */
+ QTest::newRow("T003 - slot1") << SetupAccel << TriggerSlot1 << QString("F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ //commented out because the behaviour changed, those tests should be updated
+ //QTest::newRow("T003:Shift+F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T003:F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T003 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Sequences
+ Shift + Qt::Key_F1 on Shift + Qt::Key_F1
+ Qt::Key_F1 on Shift + Qt::Key_F1
+ */
+ QTest::newRow("T004 - slot1") << SetupAccel << TriggerSlot1 << QString("Shift+F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T004:Shift+F1 - [Shift+F1]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T004:F1 - [Shift+F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T004 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ //===========================================
+ // [Shift + key] and [key] on shortcuts with
+ // and without modifiers
+ //===========================================
+
+ /* Testing Single Sequences
+ Qt::Key_F1
+ Shift + Qt::Key_F1
+ */
+ QTest::newRow("T007 - slot1") << SetupAccel << TriggerSlot1 << QString("F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T007 - slot2") << SetupAccel << TriggerSlot2 << QString("Shift+F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T007:F1") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T007:Shift + F1") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("T007 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Sequences
+ Qt::Key_M
+ Shift + Qt::Key_M
+ Ctrl + Qt::Key_M
+ Alt + Qt::Key_M
+ */
+ QTest::newRow("T01 - slot1") << SetupAccel << TriggerSlot1 << QString("M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T02 - slot2") << SetupAccel << TriggerSlot2 << QString("Shift+M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T03 - slot1") << SetupAccel << TriggerSlot1 << QString("Ctrl+M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T04 - slot2") << SetupAccel << TriggerSlot2 << QString("Alt+M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+
+ QTest::newRow("T:Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T:Shift + Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("T:Ctrl + Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T:Alt + Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+
+ /* Testing Single Sequence Ambiguity
+ Qt::Key_M on shortcut2
+ */
+ QTest::newRow("T05 - slot2") << SetupAccel << TriggerSlot2 << QString("M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T:Qt::Key_M on TriggerSlot2") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous;
+ QTest::newRow("T06 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Single Specialkeys
+ Qt::Key_aring
+ Qt::Key_Aring
+ Qt::UNICODE_ACCEL + Qt::Key_K
+ */
+ /* see comments above on the #ifdef'ery */
+ QTest::newRow("T06 - slot1") << SetupAccel << TriggerSlot1 << QString("\x0C5")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T07 - slot2") << SetupAccel << TriggerSlot2 << QString("Shift+\x0C5")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T08 - slot2") << SetupAccel << TriggerSlot1 << QString("K") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T:Qt::Key_aring") << TestAccel << NoWidget << QString("") << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T:Qt::Key_Aring") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("T:Qt::Key_aring - Text Form") << TestAccel << NoWidget << QString("") << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T:Qt::Key_Aring - Text Form") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("T:Qt::UNICODE_ACCEL + Qt::Key_K") << TestAccel << NoWidget << QString("") << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T09 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+
+ /* Testing Multiple Sequences
+ Qt::Key_M
+ Qt::Key_I, Qt::Key_M
+ Shift+Qt::Key_I, Qt::Key_M
+ */
+ QTest::newRow("T10 - slot1") << SetupAccel << TriggerSlot1 << QString("M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T11 - slot2") << SetupAccel << TriggerSlot2 << QString("I, M")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T12 - slot1") << SetupAccel << TriggerSlot1 << QString("Shift+I, M")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult;
+ QTest::newRow("T:Qt::Key_M (2)") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T:Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered;
+ QTest::newRow("T:Shift+Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered;
+ QTest::newRow("T13 - clear") << ClearAll << 0 << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; // Clear all
+}
+
+// ------------------------------------------------------------------
+// Disabled Elements ------------------------------------------------
+// ------------------------------------------------------------------
+void tst_QShortcut::disabledItems()
+{
+ clearAllShortcuts();
+ mainW->activateWindow();
+ qApp->syncX();
+ QTest::qWait(100);
+
+ /* Testing Disabled Shortcuts
+ Qt::Key_M on slot1
+ Shift + Qt::Key_M on slot1
+ Qt::Key_M on slot2 (disabled)
+ Shift + Qt::Key_M on slot2 (disabled)
+ */
+
+ // Setup two identical shortcuts on different pushbuttons
+ QPushButton pb1(mainW);
+ QPushButton pb2(mainW);
+ pb1.setObjectName("pushbutton-1");
+ pb2.setObjectName("pushbutton-2");
+ pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger
+ pb2.show();
+
+ QShortcut *cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M");
+ QShortcut *cut2 = setupShortcut(&pb1, "shortcut2-pb1", TriggerSlot1, "Shift+M");
+ QShortcut *cut3 = setupShortcut(&pb2, "shortcut3-pb2", TriggerSlot2, "M");
+ QShortcut *cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+M");
+
+ cut3->setEnabled(false);
+ cut4->setEnabled(false);
+
+ currentResult = NoResult;
+ sendKeyEvents(Qt::Key_M, 'm');
+ QCOMPARE(currentResult, Slot1Triggered);
+
+ currentResult = NoResult;
+ sendKeyEvents(Qt::SHIFT+Qt::Key_M, 'M');
+ QCOMPARE(currentResult, Slot1Triggered);
+
+ cut2->setEnabled(false);
+ cut4->setEnabled(true);
+
+ /* Testing Disabled Shortcuts
+ Qt::Key_M on slot1
+ Shift + Qt::Key_M on slot1 (disabled)
+ Qt::Key_M on slot2 (disabled)
+ Shift + Qt::Key_M on slot2
+ */
+ currentResult = NoResult;
+ sendKeyEvents( Qt::Key_M, 'm' );
+ QCOMPARE( currentResult, Slot1Triggered );
+
+ currentResult = NoResult;
+ sendKeyEvents( Qt::SHIFT+Qt::Key_M, 'M' );
+ QCOMPARE( currentResult, Slot2Triggered );
+
+
+ /* Testing Disabled Accel
+ Qt::Key_F5 on slot1
+ Shift + Qt::Key_F5 on slot2 (disabled)
+ */
+ clearAllShortcuts();
+ cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "F5");
+ cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+F5");
+
+ cut1->setKey(QKeySequence("F5"));
+ cut4->setKey(QKeySequence("Shift+F5"));
+
+ cut1->setEnabled(true);
+ cut4->setEnabled(false);
+
+ currentResult = NoResult;
+ sendKeyEvents( Qt::Key_F5, 0 );
+ QCOMPARE( currentResult, Slot1Triggered );
+
+ currentResult = NoResult;
+ sendKeyEvents( Qt::SHIFT+Qt::Key_F5, 0 );
+ QCOMPARE( currentResult, NoResult );
+
+#if 0
+ qFatal("Not testing statusbar text feedback yet, since not implemented");
+ /* Testing Disabled Accel, and the corresponding statusbar feedback
+ Ctrl + Qt::Key_K, Ctrl + Qt::Key_L on slot1
+ Ctrl + Qt::Key_K, Ctrl + Qt::Key_M on slot2 (disabled)
+ */
+ cut1->setKey(QKeySequence("Ctrl+K, Ctrl+L"));
+ cut4->setKey(QKeySequence("Ctrl+K, Ctrl+M"));
+
+ cut1->setEnabled(true);
+ cut4->setEnabled(false);
+
+ currentResult = NoResult;
+ sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 );
+ sendKeyEvents( Qt::CTRL+Qt::Key_Q, 0 );
+ QCOMPARE( currentResult, NoResult );
+ if (over_330)
+ QCOMPARE( sbText, QString("Ctrl+K, Ctrl+Q not defined") );
+
+ currentResult = NoResult;
+ sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 );
+ sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 );
+ QCOMPARE( currentResult, NoResult );
+ if (over_330)
+ QCOMPARE( sbText, QString::null );
+
+ currentResult = NoResult;
+ sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 );
+ sendKeyEvents( Qt::CTRL+Qt::Key_L, 0 );
+ QCOMPARE( currentResult, Slot1Triggered );
+ if (over_330)
+ QCOMPARE( sbText, QString::null );
+#endif
+ clearAllShortcuts();
+ cut1 = 0;
+ cut4 = 0;
+}
+// ------------------------------------------------------------------
+// Ambiguous Elements -----------------------------------------------
+// ------------------------------------------------------------------
+void tst_QShortcut::ambiguousRotation()
+{
+ clearAllShortcuts();
+ /* Testing Shortcut rotation scheme
+ Ctrl + Qt::Key_A on slot1 (disabled)
+ Ctrl + Qt::Key_A on slot2 (disabled)
+ Ctrl + Qt::Key_A on slot3
+ Ctrl + Qt::Key_A on slot4
+ Ctrl + Qt::Key_A on slot5 (disabled)
+ Ctrl + Qt::Key_A on slot6
+ Ctrl + Qt::Key_A on slot7 (disabled)
+ */
+ QShortcut *cut1 = setupShortcut(TriggerSlot1, "Ctrl+A");
+ QShortcut *cut2 = setupShortcut(TriggerSlot2, "Ctrl+A");
+ QShortcut *cut3 = setupShortcut(TriggerSlot3, "Ctrl+A");
+ QShortcut *cut4 = setupShortcut(TriggerSlot4, "Ctrl+A");
+ QShortcut *cut5 = setupShortcut(TriggerSlot5, "Ctrl+A");
+ QShortcut *cut6 = setupShortcut(TriggerSlot6, "Ctrl+A");
+ QShortcut *cut7 = setupShortcut(TriggerSlot7, "Ctrl+A");
+
+ cut1->setEnabled(false);
+ cut2->setEnabled(false);
+ cut5->setEnabled(false);
+ cut7->setEnabled(false);
+
+ // Test proper rotation
+ // Start on first
+ // Go to last
+ // Go back to first
+ // Continue...
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot3Triggered);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot4Triggered);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot6Triggered);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot3Triggered);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot4Triggered);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot6Triggered);
+
+ /* Testing Shortcut rotation scheme
+ Ctrl + Qt::Key_A on slot1
+ Ctrl + Qt::Key_A on slot2
+ Ctrl + Qt::Key_A on slot3 (disabled)
+ Ctrl + Qt::Key_A on slot4 (disabled)
+ Ctrl + Qt::Key_A on slot5
+ Ctrl + Qt::Key_A on slot6 (disabled)
+ Ctrl + Qt::Key_A on slot7
+ */
+
+ cut1->setEnabled(true);
+ cut2->setEnabled(true);
+ cut5->setEnabled(true);
+ cut7->setEnabled(true);
+
+ cut3->setEnabled(false);
+ cut4->setEnabled(false);
+ cut6->setEnabled(false);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot1Triggered);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot2Triggered);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot5Triggered);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot7Triggered);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot1Triggered);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot2Triggered);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot5Triggered);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(Qt::CTRL+Qt::Key_A);
+ QCOMPARE(currentResult, Ambiguous);
+ QCOMPARE(ambigResult, Slot7Triggered);
+
+ clearAllShortcuts();
+ cut1 = 0; cut2 = 0;
+ cut3 = 0; cut4 = 0;
+ cut5 = 0; cut6 = 0;
+ cut7 = 0;
+}
+
+void tst_QShortcut::ambiguousItems()
+{
+ clearAllShortcuts();
+ /* Testing Ambiguous Shortcuts
+ Qt::Key_M on Pushbutton 1
+ Qt::Key_M on Pushbutton 2
+ */
+
+ // Setup two identical shortcuts on different pushbuttons
+ QPushButton pb1(mainW);
+ QPushButton pb2(mainW);
+ pb1.setObjectName("pushbutton-1");
+ pb2.setObjectName("pushbutton-2");
+ pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger
+ pb2.show();
+
+ QShortcut *cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M");
+ QShortcut *cut2 = setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, "M");
+
+ currentResult = NoResult;
+ sendKeyEvents( Qt::Key_M, 'm' );
+ QCOMPARE( currentResult, Ambiguous );
+ QCOMPARE( ambigResult, Slot1Triggered );
+
+ currentResult = NoResult;
+ sendKeyEvents( Qt::Key_M, 'm' );
+ QCOMPARE( currentResult, Ambiguous );
+ QCOMPARE( ambigResult, Slot2Triggered );
+
+ currentResult = NoResult;
+ sendKeyEvents( Qt::Key_M, 'm' );
+ QCOMPARE( currentResult, Ambiguous );
+ QCOMPARE( ambigResult, Slot1Triggered );
+
+ clearAllShortcuts();
+ cut1 = 0; cut2 = 0;
+}
+
+
+// ------------------------------------------------------------------
+// Unicode and non-unicode Elements ---------------------------------
+// ------------------------------------------------------------------
+void tst_QShortcut::unicodeCompare()
+{
+ clearAllShortcuts();
+ /* Testing Unicode/non-Unicode Shortcuts
+ Qt::Key_M on Pushbutton 1
+ Qt::Key_M on Pushbutton 2
+ */
+ QPushButton pb1(mainW);
+ QPushButton pb2(mainW);
+ pb1.setObjectName("pushbutton-1");
+ pb2.setObjectName("pushbutton-2");
+ pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger
+ pb2.show();
+
+ QKeySequence ks1("Ctrl+M"); // Unicode
+ QKeySequence ks2(Qt::CTRL+Qt::Key_M); // non-Unicode
+ QShortcut *cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, ks1);
+ QShortcut *cut2 = setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, ks2);
+
+ currentResult = NoResult;
+ sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 );
+ QCOMPARE( currentResult, Ambiguous );
+ // They _are_ ambiguous, so the QKeySequence operator==
+ // should indicate the same
+ QVERIFY( ks1 == ks2 );
+ QVERIFY( !(ks1 != ks2) );
+
+ clearAllShortcuts();
+ cut1 = 0; cut2 = 0;
+}
+
+// ------------------------------------------------------------------
+// Keypress consumption verification --------------------------------
+// ------------------------------------------------------------------
+void tst_QShortcut::keypressConsumption()
+{
+ clearAllShortcuts();
+ edit->clear();
+ QCOMPARE(edit->toPlainText().size(), 0);
+
+ QShortcut *cut1 = setupShortcut(edit, "shortcut1-line", TriggerSlot1, "Ctrl+I, A");
+ QShortcut *cut2 = setupShortcut(edit, "shortcut1-line", TriggerSlot2, "Ctrl+I, B");
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0); // Send key to edit
+ QCOMPARE( currentResult, NoResult );
+ QCOMPARE( ambigResult, NoResult );
+ QCOMPARE(edit->toPlainText(), QString(""));
+
+ // Make sure next keypress is eaten (failing multiple keysequence)
+ sendKeyEvents(edit, Qt::Key_C, 'c'); // Send key to edit
+ QCOMPARE( currentResult, NoResult );
+ QCOMPARE( ambigResult, NoResult );
+ QCOMPARE(edit->toPlainText(), QString(""));
+
+ // Next keypress should be normal
+ sendKeyEvents(edit, Qt::Key_C, 'c'); // Send key to edit
+ QCOMPARE( currentResult, NoResult );
+ QCOMPARE( ambigResult, NoResult );
+ QCOMPARE(edit->toPlainText(), QString("c"));
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ edit->clear();
+ QCOMPARE(edit->toPlainText().size(), 0);
+
+ cut1->setEnabled(false);
+ cut2->setEnabled(false);
+
+ // Make sure keypresses is passed on, since all multiple keysequences
+ // with Ctrl+I are disabled
+ sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0); // Send key to edit
+ QCOMPARE( currentResult, NoResult );
+ QCOMPARE( ambigResult, NoResult );
+ QVERIFY(edit->toPlainText().endsWith("<Ctrl+I>"));
+
+ sendKeyEvents(edit, Qt::Key_A, 'a'); // Send key to edit
+ QCOMPARE( currentResult, NoResult );
+ QCOMPARE( ambigResult, NoResult );
+ QVERIFY(edit->toPlainText().endsWith("<Ctrl+I>a"));
+
+ clearAllShortcuts();
+}
+
+// ------------------------------------------------------------------
+// Context Validation -----------------------------------------------
+// ------------------------------------------------------------------
+void tst_QShortcut::context()
+{
+ clearAllShortcuts();
+
+ QWidget myBox;
+ TestEdit *other1 = new TestEdit(&myBox, "test_edit_other1");
+ TestEdit *other2 = new TestEdit(&myBox, "test_edit_other2");
+ QHBoxLayout *layout = new QHBoxLayout(&myBox);
+ layout->addWidget(other1);
+ layout->addWidget(other2);
+ myBox.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&myBox);
+#endif
+
+ setupShortcut(other1, "ActiveWindow", TriggerSlot1, QKeySequence("Alt+1"), Qt::WindowShortcut);
+ setupShortcut(other2, "Focus", TriggerSlot2, QKeySequence("Alt+2"), Qt::WidgetShortcut);
+ setupShortcut(edit, "Application", TriggerSlot3, QKeySequence("Alt+3"), Qt::ApplicationShortcut);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ edit->clear();
+ other1->clear();
+ other2->clear();
+
+ // edit doesn't have focus, so ActiveWindow context should work
+ // ..but Focus context shouldn't..
+ // Changing focus to edit should make focus context work
+ // Application context should always work
+
+
+ // Focus on 'other1' edit, so Active Window context should trigger
+ other1->activateWindow(); // <---
+ QApplication::setActiveWindow(other1);
+ QCOMPARE(qApp->activeWindow(), other1->window());
+ QCOMPARE(qApp->focusWidget(), (QWidget *)other1);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ edit->clear();
+ other1->clear();
+ other2->clear();
+
+ QCOMPARE(qApp->focusWidget(), (QWidget *)other1);
+ sendKeyEvents(other1, Qt::ALT+Qt::Key_1);
+ QCOMPARE(currentResult, Slot1Triggered);
+ QCOMPARE(ambigResult, NoResult);
+ QCOMPARE(edit->toPlainText(), QString(""));
+ QCOMPARE(other1->toPlainText(), QString(""));
+ QCOMPARE(other2->toPlainText(), QString(""));
+
+ // ..but not Focus context on 'other2'..
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ edit->clear();
+ other1->clear();
+ other2->clear();
+
+ sendKeyEvents(other1, Qt::ALT+Qt::Key_2);
+ QCOMPARE(currentResult, NoResult);
+ QCOMPARE(ambigResult, NoResult);
+ QCOMPARE(edit->toPlainText(), QString(""));
+ QCOMPARE(other1->toPlainText(), QString("<Alt+2>"));
+ QCOMPARE(other2->toPlainText(), QString(""));
+
+ // ..however, application global context on 'edit' should..
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ edit->clear();
+ other1->clear();
+ other2->clear();
+
+ sendKeyEvents(other1, Qt::ALT+Qt::Key_3);
+ QCOMPARE(currentResult, Slot3Triggered);
+ QCOMPARE(ambigResult, NoResult);
+ QCOMPARE(edit->toPlainText(), QString(""));
+ QCOMPARE(other1->toPlainText(), QString(""));
+ QCOMPARE(other2->toPlainText(), QString(""));
+
+ // Changing focus to 'other2' should make the Focus context there work
+ other2->activateWindow();
+ other2->setFocus(); // ###
+ qApp->syncX();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(other2);
+#endif
+ QTest::qWait(100);
+ QCOMPARE(qApp->activeWindow(), other2->window());
+ QCOMPARE(qApp->focusWidget(), (QWidget *)other2);
+
+ currentResult = NoResult;
+ ambigResult = NoResult;
+ edit->clear();
+ other1->clear();
+ other2->clear();
+
+ sendKeyEvents(other2, Qt::ALT+Qt::Key_2);
+ QCOMPARE(currentResult, Slot2Triggered);
+ QCOMPARE(ambigResult, NoResult);
+ QCOMPARE(edit->toPlainText(), QString(""));
+ QCOMPARE(other1->toPlainText(), QString(""));
+ QCOMPARE(other2->toPlainText(), QString(""));
+
+ clearAllShortcuts();
+ delete other1;
+ delete other2;
+ edit->activateWindow();
+ qApp->syncX();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(edit);
+#endif
+ QTest::qWait(100);
+}
+
+// ------------------------------------------------------------------
+// Element Testing helper functions ---------------------------------
+// ------------------------------------------------------------------
+void tst_QShortcut::clearAllShortcuts()
+{
+ qDeleteAll(shortcuts);
+ shortcuts.clear();
+}
+
+QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QKeySequence &ks)
+{
+ return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget, ks);
+}
+
+QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QString &txt, int k1, int k2, int k3, int k4)
+{
+ return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget,
+ (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt)));
+}
+
+QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1, int k2, int k3, int k4)
+{
+ return setupShortcut(parent, name, testWidget,
+ (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt)));
+}
+
+QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget,
+ const QKeySequence &ks, Qt::ShortcutContext context)
+{
+ // Set up shortcut for next test
+ QShortcut *cut = new QShortcut(QKeySequence(), parent, 0, 0, context);
+ cut->setObjectName(name);
+ cut->setKey(ks);
+
+ const char *normal = 0;
+ const char *ambig = 0;
+ switch(testWidget)
+ {
+ case TriggerSlot1:
+ normal = SLOT(slotTrig1());
+ ambig = SLOT(ambigSlot1());
+ break;
+ case TriggerSlot2:
+ normal = SLOT(slotTrig2());
+ ambig = SLOT(ambigSlot2());
+ break;
+ case TriggerSlot3:
+ normal = SLOT(slotTrig3());
+ ambig = SLOT(ambigSlot3());
+ break;
+ case TriggerSlot4:
+ normal = SLOT(slotTrig4());
+ ambig = SLOT(ambigSlot4());
+ break;
+ case TriggerSlot5:
+ normal = SLOT(slotTrig5());
+ ambig = SLOT(ambigSlot5());
+ break;
+ case TriggerSlot6:
+ normal = SLOT(slotTrig6());
+ ambig = SLOT(ambigSlot6());
+ break;
+ case TriggerSlot7:
+ normal = SLOT(slotTrig7());
+ ambig = SLOT(ambigSlot7());
+ break;
+ }
+ connect(cut, SIGNAL(activated()), this, normal);
+ connect(cut, SIGNAL(activatedAmbiguously()), this, ambig);
+ connect(cut, SIGNAL(destroyed(QObject*)), this, SLOT(shortcutDestroyed(QObject*)));
+ shortcuts.append(cut);
+ return cut;
+}
+
+void tst_QShortcut::shortcutDestroyed(QObject* obj)
+{
+ shortcuts.removeAll(static_cast<QShortcut *>(obj));
+}
+
+void tst_QShortcut::sendKeyEvents(int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4)
+{
+ sendKeyEvents(mainW, k1, c1, k2, c2, k3, c3, k4, c4);
+}
+
+void tst_QShortcut::sendKeyEvents(QWidget *w, int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4)
+{
+ Qt::KeyboardModifiers b1 = toButtons( k1 );
+ Qt::KeyboardModifiers b2 = toButtons( k2 );
+ Qt::KeyboardModifiers b3 = toButtons( k3 );
+ Qt::KeyboardModifiers b4 = toButtons( k4 );
+ k1 &= ~Qt::MODIFIER_MASK;
+ k2 &= ~Qt::MODIFIER_MASK;
+ k3 &= ~Qt::MODIFIER_MASK;
+ k4 &= ~Qt::MODIFIER_MASK;
+
+
+ if (k1 || c1.toAscii()) {
+ QString c(c1.unicode() == QChar::Null ? QString() : QString(c1));
+ QTest::sendKeyEvent(QTest::Press, w, static_cast<Qt::Key>(k1), c, b1);
+ QTest::sendKeyEvent(QTest::Release, w, static_cast<Qt::Key>(k1), c, b1);
+ }
+
+ if (k2 || c2.toAscii()) {
+ QString c(c2.unicode() == QChar::Null ? QString() : QString(c2));
+ QTest::sendKeyEvent(QTest::Press, w, static_cast<Qt::Key>(k2), c, b2);
+ QTest::sendKeyEvent(QTest::Release, w, static_cast<Qt::Key>(k2), c, b2);
+ }
+
+ if (k3 || c3.toAscii()) {
+ QString c(c3.unicode() == QChar::Null ? QString() : QString(c3));
+ QTest::sendKeyEvent(QTest::Press, w, static_cast<Qt::Key>(k3), c, b3);
+ QTest::sendKeyEvent(QTest::Release, w, static_cast<Qt::Key>(k3), c, b3);
+ }
+
+ if (k4 || c4.toAscii()) {
+ QString c(c4.unicode() == QChar::Null ? QString() : QString(c4));
+ QTest::sendKeyEvent(QTest::Press, w, static_cast<Qt::Key>(k4), c, b4);
+ QTest::sendKeyEvent(QTest::Release, w, static_cast<Qt::Key>(k4), c, b4);
+ }
+}
+
+void tst_QShortcut::testElement()
+{
+ currentResult = NoResult;
+ QFETCH(int, action);
+ QFETCH(int, testWidget);
+ QFETCH(QString, txt);
+ QFETCH(int, k1);
+ QFETCH(int, c1);
+ QFETCH(int, k2);
+ QFETCH(int, c2);
+ QFETCH(int, k3);
+ QFETCH(int, c3);
+ QFETCH(int, k4);
+ QFETCH(int, c4);
+ QFETCH(int, result);
+
+ if (action == ClearAll) {
+ clearAllShortcuts();
+ QCOMPARE(TRUE, TRUE);
+ } else if (action == SetupAccel) {
+ setupShortcut(testWidget, txt, k1, k2, k3, k4);
+ QCOMPARE(TRUE, TRUE);
+ } else {
+ sendKeyEvents(k1, c1, k2, c2, k3, c3, k4, c4);
+ QCOMPARE(int(currentResult), result);
+ }
+}
+
+QTEST_MAIN(tst_QShortcut)
+#include "tst_qshortcut.moc"
diff --git a/tests/auto/gui/kernel/qtouchevent/qtouchevent.pro b/tests/auto/gui/kernel/qtouchevent/qtouchevent.pro
new file mode 100644
index 0000000000..55f99b6cdd
--- /dev/null
+++ b/tests/auto/gui/kernel/qtouchevent/qtouchevent.pro
@@ -0,0 +1,3 @@
+SOURCES=tst_qtouchevent.cpp
+TARGET=tst_qtouchevent
+QT += testlib widgets
diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
new file mode 100644
index 0000000000..f0347e39ff
--- /dev/null
+++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
@@ -0,0 +1,1398 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the $MODULE$ of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtTest>
+
+class tst_QTouchEventWidget : public QWidget
+{
+public:
+ QList<QTouchEvent::TouchPoint> touchBeginPoints, touchUpdatePoints, touchEndPoints;
+ bool seenTouchBegin, seenTouchUpdate, seenTouchEnd;
+ bool acceptTouchBegin, acceptTouchUpdate, acceptTouchEnd;
+ bool deleteInTouchBegin, deleteInTouchUpdate, deleteInTouchEnd;
+
+ tst_QTouchEventWidget()
+ : QWidget()
+ {
+ reset();
+ }
+
+ void reset()
+ {
+ touchBeginPoints.clear();
+ touchUpdatePoints.clear();
+ touchEndPoints.clear();
+ seenTouchBegin = seenTouchUpdate = seenTouchEnd = false;
+ acceptTouchBegin = acceptTouchUpdate = acceptTouchEnd = true;
+ deleteInTouchBegin = deleteInTouchUpdate = deleteInTouchEnd = false;
+ }
+
+ bool event(QEvent *event)
+ {
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ if (seenTouchBegin) qWarning("TouchBegin: already seen a TouchBegin");
+ if (seenTouchUpdate) qWarning("TouchBegin: TouchUpdate cannot happen before TouchBegin");
+ if (seenTouchEnd) qWarning("TouchBegin: TouchEnd cannot happen before TouchBegin");
+ seenTouchBegin = !seenTouchBegin && !seenTouchUpdate && !seenTouchEnd;
+ touchBeginPoints = static_cast<QTouchEvent *>(event)->touchPoints();
+ event->setAccepted(acceptTouchBegin);
+ if (deleteInTouchBegin)
+ delete this;
+ break;
+ case QEvent::TouchUpdate:
+ if (!seenTouchBegin) qWarning("TouchUpdate: have not seen TouchBegin");
+ if (seenTouchEnd) qWarning("TouchUpdate: TouchEnd cannot happen before TouchUpdate");
+ seenTouchUpdate = seenTouchBegin && !seenTouchEnd;
+ touchUpdatePoints = static_cast<QTouchEvent *>(event)->touchPoints();
+ event->setAccepted(acceptTouchUpdate);
+ if (deleteInTouchUpdate)
+ delete this;
+ break;
+ case QEvent::TouchEnd:
+ if (!seenTouchBegin) qWarning("TouchEnd: have not seen TouchBegin");
+ if (seenTouchEnd) qWarning("TouchEnd: already seen a TouchEnd");
+ seenTouchEnd = seenTouchBegin && !seenTouchEnd;
+ touchEndPoints = static_cast<QTouchEvent *>(event)->touchPoints();
+ event->setAccepted(acceptTouchEnd);
+ if (deleteInTouchEnd)
+ delete this;
+ break;
+ default:
+ return QWidget::event(event);
+ }
+ return true;
+ }
+};
+
+class tst_QTouchEventGraphicsItem : public QGraphicsItem
+{
+public:
+ QList<QTouchEvent::TouchPoint> touchBeginPoints, touchUpdatePoints, touchEndPoints;
+ bool seenTouchBegin, seenTouchUpdate, seenTouchEnd;
+ int touchBeginCounter, touchUpdateCounter, touchEndCounter;
+ bool acceptTouchBegin, acceptTouchUpdate, acceptTouchEnd;
+ bool deleteInTouchBegin, deleteInTouchUpdate, deleteInTouchEnd;
+ tst_QTouchEventGraphicsItem **weakpointer;
+
+ tst_QTouchEventGraphicsItem()
+ : QGraphicsItem(), weakpointer(0)
+ {
+ reset();
+ }
+
+ ~tst_QTouchEventGraphicsItem()
+ {
+ if (weakpointer)
+ *weakpointer = 0;
+ }
+
+ void reset()
+ {
+ touchBeginPoints.clear();
+ touchUpdatePoints.clear();
+ touchEndPoints.clear();
+ seenTouchBegin = seenTouchUpdate = seenTouchEnd = false;
+ touchBeginCounter = touchUpdateCounter = touchEndCounter = 0;
+ acceptTouchBegin = acceptTouchUpdate = acceptTouchEnd = true;
+ deleteInTouchBegin = deleteInTouchUpdate = deleteInTouchEnd = false;
+ }
+
+ QRectF boundingRect() const { return QRectF(0, 0, 10, 10); }
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) { }
+
+ bool sceneEvent(QEvent *event)
+ {
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ if (seenTouchBegin) qWarning("TouchBegin: already seen a TouchBegin");
+ if (seenTouchUpdate) qWarning("TouchBegin: TouchUpdate cannot happen before TouchBegin");
+ if (seenTouchEnd) qWarning("TouchBegin: TouchEnd cannot happen before TouchBegin");
+ seenTouchBegin = !seenTouchBegin && !seenTouchUpdate && !seenTouchEnd;
+ ++touchBeginCounter;
+ touchBeginPoints = static_cast<QTouchEvent *>(event)->touchPoints();
+ event->setAccepted(acceptTouchBegin);
+ if (deleteInTouchBegin)
+ delete this;
+ break;
+ case QEvent::TouchUpdate:
+ if (!seenTouchBegin) qWarning("TouchUpdate: have not seen TouchBegin");
+ if (seenTouchEnd) qWarning("TouchUpdate: TouchEnd cannot happen before TouchUpdate");
+ seenTouchUpdate = seenTouchBegin && !seenTouchEnd;
+ ++touchUpdateCounter;
+ touchUpdatePoints = static_cast<QTouchEvent *>(event)->touchPoints();
+ event->setAccepted(acceptTouchUpdate);
+ if (deleteInTouchUpdate)
+ delete this;
+ break;
+ case QEvent::TouchEnd:
+ if (!seenTouchBegin) qWarning("TouchEnd: have not seen TouchBegin");
+ if (seenTouchEnd) qWarning("TouchEnd: already seen a TouchEnd");
+ seenTouchEnd = seenTouchBegin && !seenTouchEnd;
+ ++touchEndCounter;
+ touchEndPoints = static_cast<QTouchEvent *>(event)->touchPoints();
+ event->setAccepted(acceptTouchEnd);
+ if (deleteInTouchEnd)
+ delete this;
+ break;
+ default:
+ return QGraphicsItem::sceneEvent(event);
+ }
+ return true;
+ }
+};
+
+class tst_QTouchEvent : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QTouchEvent() { }
+ ~tst_QTouchEvent() { }
+
+private slots:
+ void touchDisabledByDefault();
+ void touchEventAcceptedByDefault();
+ void touchBeginPropagatesWhenIgnored();
+ void touchUpdateAndEndNeverPropagate();
+ void basicRawEventTranslation();
+ void multiPointRawEventTranslationOnTouchScreen();
+ void multiPointRawEventTranslationOnTouchPad();
+ void deleteInEventHandler();
+ void deleteInRawEventTranslation();
+ void crashInQGraphicsSceneAfterNotHandlingTouchBegin();
+ void touchBeginWithGraphicsWidget();
+};
+
+void tst_QTouchEvent::touchDisabledByDefault()
+{
+ // QWidget
+ {
+ // the widget attribute is not enabled by default
+ QWidget widget;
+ QVERIFY(!widget.testAttribute(Qt::WA_AcceptTouchEvents));
+
+ // events should not be accepted since they are not enabled
+ QList<QTouchEvent::TouchPoint> touchPoints;
+ touchPoints.append(QTouchEvent::TouchPoint(0));
+ QTouchEvent touchEvent(QEvent::TouchBegin,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointPressed,
+ touchPoints);
+ bool res = QApplication::sendEvent(&widget, &touchEvent);
+ QVERIFY(!res);
+ QVERIFY(!touchEvent.isAccepted());
+ }
+
+ // QGraphicsView
+ {
+ QGraphicsScene scene;
+ tst_QTouchEventGraphicsItem item;
+ QGraphicsView view(&scene);
+ scene.addItem(&item);
+ item.setPos(100, 100);
+ view.resize(200, 200);
+ view.fitInView(scene.sceneRect());
+
+ // touch events are not accepted by default
+ QVERIFY(!item.acceptTouchEvents());
+
+ // compose an event to the scene that is over the item
+ QTouchEvent::TouchPoint touchPoint(0);
+ touchPoint.setState(Qt::TouchPointPressed);
+ touchPoint.setPos(view.mapFromScene(item.mapToScene(item.boundingRect().center())));
+ touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint()));
+ touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint()));
+ QTouchEvent touchEvent(QEvent::TouchBegin,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointPressed,
+ (QList<QTouchEvent::TouchPoint>() << touchPoint));
+ bool res = QApplication::sendEvent(view.viewport(), &touchEvent);
+ QVERIFY(!res);
+ QVERIFY(!touchEvent.isAccepted());
+ QVERIFY(!item.seenTouchBegin);
+ }
+}
+
+void tst_QTouchEvent::touchEventAcceptedByDefault()
+{
+ // QWidget
+ {
+ // enabling touch events should automatically accept touch events
+ QWidget widget;
+ widget.setAttribute(Qt::WA_AcceptTouchEvents);
+
+ // QWidget handles touch event by converting them into a mouse event, so the event is both
+ // accepted and handled (res == true)
+ QList<QTouchEvent::TouchPoint> touchPoints;
+ touchPoints.append(QTouchEvent::TouchPoint(0));
+ QTouchEvent touchEvent(QEvent::TouchBegin,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointPressed,
+ touchPoints);
+ bool res = QApplication::sendEvent(&widget, &touchEvent);
+ QVERIFY(res);
+ QVERIFY(touchEvent.isAccepted());
+
+ // tst_QTouchEventWidget does handle, sending succeeds
+ tst_QTouchEventWidget touchWidget;
+ touchWidget.setAttribute(Qt::WA_AcceptTouchEvents);
+ touchEvent.ignore();
+ res = QApplication::sendEvent(&touchWidget, &touchEvent);
+ QVERIFY(res);
+ QVERIFY(touchEvent.isAccepted());
+ }
+
+ // QGraphicsView
+ {
+ QGraphicsScene scene;
+ tst_QTouchEventGraphicsItem item;
+ QGraphicsView view(&scene);
+ scene.addItem(&item);
+ item.setPos(100, 100);
+ view.resize(200, 200);
+ view.fitInView(scene.sceneRect());
+
+ // enabling touch events on the item also enables events on the viewport
+ item.setAcceptTouchEvents(true);
+ QVERIFY(view.viewport()->testAttribute(Qt::WA_AcceptTouchEvents));
+
+ // compose an event to the scene that is over the item
+ QTouchEvent::TouchPoint touchPoint(0);
+ touchPoint.setState(Qt::TouchPointPressed);
+ touchPoint.setPos(view.mapFromScene(item.mapToScene(item.boundingRect().center())));
+ touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint()));
+ touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint()));
+ QTouchEvent touchEvent(QEvent::TouchBegin,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointPressed,
+ (QList<QTouchEvent::TouchPoint>() << touchPoint));
+ bool res = QApplication::sendEvent(view.viewport(), &touchEvent);
+ QVERIFY(res);
+ QVERIFY(touchEvent.isAccepted());
+ QVERIFY(item.seenTouchBegin);
+ }
+}
+
+void tst_QTouchEvent::touchBeginPropagatesWhenIgnored()
+{
+ // QWidget
+ {
+ tst_QTouchEventWidget window, child, grandchild;
+ child.setParent(&window);
+ grandchild.setParent(&child);
+
+ // all widgets accept touch events, grandchild ignores, so child sees the event, but not window
+ window.setAttribute(Qt::WA_AcceptTouchEvents);
+ child.setAttribute(Qt::WA_AcceptTouchEvents);
+ grandchild.setAttribute(Qt::WA_AcceptTouchEvents);
+ grandchild.acceptTouchBegin = false;
+
+ QList<QTouchEvent::TouchPoint> touchPoints;
+ touchPoints.append(QTouchEvent::TouchPoint(0));
+ QTouchEvent touchEvent(QEvent::TouchBegin,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointPressed,
+ touchPoints);
+ bool res = QApplication::sendEvent(&grandchild, &touchEvent);
+ QVERIFY(res);
+ QVERIFY(touchEvent.isAccepted());
+ QVERIFY(grandchild.seenTouchBegin);
+ QVERIFY(child.seenTouchBegin);
+ QVERIFY(!window.seenTouchBegin);
+
+ // disable touch on grandchild. even though it doesn't accept it, child should still get the
+ // TouchBegin
+ grandchild.reset();
+ child.reset();
+ window.reset();
+ grandchild.setAttribute(Qt::WA_AcceptTouchEvents, false);
+
+ touchEvent.ignore();
+ res = QApplication::sendEvent(&grandchild, &touchEvent);
+ QVERIFY(res);
+ QVERIFY(touchEvent.isAccepted());
+ QVERIFY(!grandchild.seenTouchBegin);
+ QVERIFY(child.seenTouchBegin);
+ QVERIFY(!window.seenTouchBegin);
+ }
+
+ // QGraphicsView
+ {
+ QGraphicsScene scene;
+ tst_QTouchEventGraphicsItem root, child, grandchild;
+ QGraphicsView view(&scene);
+ scene.addItem(&root);
+ root.setPos(100, 100);
+ child.setParentItem(&root);
+ grandchild.setParentItem(&child);
+ view.resize(200, 200);
+ view.fitInView(scene.sceneRect());
+
+ // all items accept touch events, grandchild ignores, so child sees the event, but not root
+ root.setAcceptTouchEvents(true);
+ child.setAcceptTouchEvents(true);
+ grandchild.setAcceptTouchEvents(true);
+ grandchild.acceptTouchBegin = false;
+
+ // compose an event to the scene that is over the grandchild
+ QTouchEvent::TouchPoint touchPoint(0);
+ touchPoint.setState(Qt::TouchPointPressed);
+ touchPoint.setPos(view.mapFromScene(grandchild.mapToScene(grandchild.boundingRect().center())));
+ touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint()));
+ touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint()));
+ QTouchEvent touchEvent(QEvent::TouchBegin,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointPressed,
+ (QList<QTouchEvent::TouchPoint>() << touchPoint));
+ bool res = QApplication::sendEvent(view.viewport(), &touchEvent);
+ QVERIFY(res);
+ QVERIFY(touchEvent.isAccepted());
+ QVERIFY(grandchild.seenTouchBegin);
+ QVERIFY(child.seenTouchBegin);
+ QVERIFY(!root.seenTouchBegin);
+ }
+
+ // QGraphicsView
+ {
+ QGraphicsScene scene;
+ tst_QTouchEventGraphicsItem root, child, grandchild;
+ QGraphicsView view(&scene);
+ scene.addItem(&root);
+ root.setPos(100, 100);
+ child.setParentItem(&root);
+ grandchild.setParentItem(&child);
+ view.resize(200, 200);
+ view.fitInView(scene.sceneRect());
+
+ // leave touch disabled on grandchild. even though it doesn't accept it, child should
+ // still get the TouchBegin
+ root.setAcceptTouchEvents(true);
+ child.setAcceptTouchEvents(true);
+
+ // compose an event to the scene that is over the grandchild
+ QTouchEvent::TouchPoint touchPoint(0);
+ touchPoint.setState(Qt::TouchPointPressed);
+ touchPoint.setPos(view.mapFromScene(grandchild.mapToScene(grandchild.boundingRect().center())));
+ touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint()));
+ touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint()));
+ QTouchEvent touchEvent(QEvent::TouchBegin,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointPressed,
+ (QList<QTouchEvent::TouchPoint>() << touchPoint));
+ bool res = QApplication::sendEvent(view.viewport(), &touchEvent);
+ QVERIFY(res);
+ QVERIFY(touchEvent.isAccepted());
+ QVERIFY(!grandchild.seenTouchBegin);
+ QVERIFY(child.seenTouchBegin);
+ QVERIFY(!root.seenTouchBegin);
+ }
+}
+
+void tst_QTouchEvent::touchUpdateAndEndNeverPropagate()
+{
+ // QWidget
+ {
+ tst_QTouchEventWidget window, child;
+ child.setParent(&window);
+
+ window.setAttribute(Qt::WA_AcceptTouchEvents);
+ child.setAttribute(Qt::WA_AcceptTouchEvents);
+ child.acceptTouchUpdate = false;
+ child.acceptTouchEnd = false;
+
+ QList<QTouchEvent::TouchPoint> touchPoints;
+ touchPoints.append(QTouchEvent::TouchPoint(0));
+ QTouchEvent touchBeginEvent(QEvent::TouchBegin,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointPressed,
+ touchPoints);
+ bool res = QApplication::sendEvent(&child, &touchBeginEvent);
+ QVERIFY(res);
+ QVERIFY(touchBeginEvent.isAccepted());
+ QVERIFY(child.seenTouchBegin);
+ QVERIFY(!window.seenTouchBegin);
+
+ // send the touch update to the child, but ignore it, it doesn't propagate
+ QTouchEvent touchUpdateEvent(QEvent::TouchUpdate,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointMoved,
+ touchPoints);
+ res = QApplication::sendEvent(&child, &touchUpdateEvent);
+ QVERIFY(res);
+ QVERIFY(!touchUpdateEvent.isAccepted());
+ QVERIFY(child.seenTouchUpdate);
+ QVERIFY(!window.seenTouchUpdate);
+
+ // send the touch end, same thing should happen as with touch update
+ QTouchEvent touchEndEvent(QEvent::TouchEnd,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointReleased,
+ touchPoints);
+ res = QApplication::sendEvent(&child, &touchEndEvent);
+ QVERIFY(res);
+ QVERIFY(!touchEndEvent.isAccepted());
+ QVERIFY(child.seenTouchEnd);
+ QVERIFY(!window.seenTouchEnd);
+ }
+
+ // QGraphicsView
+ {
+ QGraphicsScene scene;
+ tst_QTouchEventGraphicsItem root, child, grandchild;
+ QGraphicsView view(&scene);
+ scene.addItem(&root);
+ root.setPos(100, 100);
+ child.setParentItem(&root);
+ grandchild.setParentItem(&child);
+ view.resize(200, 200);
+ view.fitInView(scene.sceneRect());
+
+ root.setAcceptTouchEvents(true);
+ child.setAcceptTouchEvents(true);
+ child.acceptTouchUpdate = false;
+ child.acceptTouchEnd = false;
+
+ // compose an event to the scene that is over the child
+ QTouchEvent::TouchPoint touchPoint(0);
+ touchPoint.setState(Qt::TouchPointPressed);
+ touchPoint.setPos(view.mapFromScene(grandchild.mapToScene(grandchild.boundingRect().center())));
+ touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint()));
+ touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint()));
+ QTouchEvent touchBeginEvent(QEvent::TouchBegin,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointPressed,
+ (QList<QTouchEvent::TouchPoint>() << touchPoint));
+ bool res = QApplication::sendEvent(view.viewport(), &touchBeginEvent);
+ QVERIFY(res);
+ QVERIFY(touchBeginEvent.isAccepted());
+ QVERIFY(child.seenTouchBegin);
+ QVERIFY(!root.seenTouchBegin);
+
+ // send the touch update to the child, but ignore it, it doesn't propagate
+ touchPoint.setState(Qt::TouchPointMoved);
+ QTouchEvent touchUpdateEvent(QEvent::TouchUpdate,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointMoved,
+ (QList<QTouchEvent::TouchPoint>() << touchPoint));
+ res = QApplication::sendEvent(view.viewport(), &touchUpdateEvent);
+ QVERIFY(res);
+ // the scene accepts the event, since it found an item to send the event to
+ QVERIFY(!touchUpdateEvent.isAccepted());
+ QVERIFY(child.seenTouchUpdate);
+ QVERIFY(!root.seenTouchUpdate);
+
+ // send the touch end, same thing should happen as with touch update
+ touchPoint.setState(Qt::TouchPointReleased);
+ QTouchEvent touchEndEvent(QEvent::TouchEnd,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointReleased,
+ (QList<QTouchEvent::TouchPoint>() << touchPoint));
+ res = QApplication::sendEvent(view.viewport(), &touchEndEvent);
+ QVERIFY(res);
+ // the scene accepts the event, since it found an item to send the event to
+ QVERIFY(!touchEndEvent.isAccepted());
+ QVERIFY(child.seenTouchEnd);
+ QVERIFY(!root.seenTouchEnd);
+ }
+}
+
+QPointF normalized(const QPointF &pos, const QRectF &rect)
+{
+ return QPointF(pos.x() / rect.width(), pos.y() / rect.height());
+}
+
+void tst_QTouchEvent::basicRawEventTranslation()
+{
+ tst_QTouchEventWidget touchWidget;
+ touchWidget.setAttribute(Qt::WA_AcceptTouchEvents);
+ touchWidget.setGeometry(100, 100, 400, 300);
+
+ QPointF pos = touchWidget.rect().center();
+ QPointF screenPos = touchWidget.mapToGlobal(pos.toPoint());
+ QPointF delta(10, 10);
+ QRectF screenGeometry = qApp->desktop()->screenGeometry(&touchWidget);
+
+ QTouchEvent::TouchPoint rawTouchPoint;
+ rawTouchPoint.setId(0);
+
+ // this should be translated to a TouchBegin
+ rawTouchPoint.setState(Qt::TouchPointPressed);
+ rawTouchPoint.setScreenPos(screenPos);
+ rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry));
+ qt_translateRawTouchEvent(&touchWidget,
+ QTouchEvent::TouchScreen,
+ QList<QTouchEvent::TouchPoint>() << rawTouchPoint);
+ QVERIFY(touchWidget.seenTouchBegin);
+ QVERIFY(!touchWidget.seenTouchUpdate);
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
+ QTouchEvent::TouchPoint touchBeginPoint = touchWidget.touchBeginPoints.first();
+ QCOMPARE(touchBeginPoint.id(), rawTouchPoint.id());
+ QCOMPARE(touchBeginPoint.state(), rawTouchPoint.state());
+ QCOMPARE(touchBeginPoint.pos(), pos);
+ QCOMPARE(touchBeginPoint.startPos(), pos);
+ QCOMPARE(touchBeginPoint.lastPos(), pos);
+ QCOMPARE(touchBeginPoint.scenePos(), rawTouchPoint.screenPos());
+ QCOMPARE(touchBeginPoint.startScenePos(), rawTouchPoint.screenPos());
+ QCOMPARE(touchBeginPoint.lastScenePos(), rawTouchPoint.screenPos());
+ QCOMPARE(touchBeginPoint.screenPos(), rawTouchPoint.screenPos());
+ QCOMPARE(touchBeginPoint.startScreenPos(), rawTouchPoint.screenPos());
+ QCOMPARE(touchBeginPoint.lastScreenPos(), rawTouchPoint.screenPos());
+ QCOMPARE(touchBeginPoint.normalizedPos(), rawTouchPoint.normalizedPos());
+ QCOMPARE(touchBeginPoint.startNormalizedPos(), touchBeginPoint.normalizedPos());
+ QCOMPARE(touchBeginPoint.lastNormalizedPos(), touchBeginPoint.normalizedPos());
+ QCOMPARE(touchBeginPoint.rect(), QRectF(pos, QSizeF(0, 0)));
+ QCOMPARE(touchBeginPoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0)));
+ QCOMPARE(touchBeginPoint.sceneRect(), touchBeginPoint.screenRect());
+ QCOMPARE(touchBeginPoint.pressure(), qreal(1.));
+
+ // moving the point should translate to TouchUpdate
+ rawTouchPoint.setState(Qt::TouchPointMoved);
+ rawTouchPoint.setScreenPos(screenPos + delta);
+ rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry));
+ qt_translateRawTouchEvent(&touchWidget,
+ QTouchEvent::TouchScreen,
+ QList<QTouchEvent::TouchPoint>() << rawTouchPoint);
+ QVERIFY(touchWidget.seenTouchBegin);
+ QVERIFY(touchWidget.seenTouchUpdate);
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QCOMPARE(touchWidget.touchUpdatePoints.count(), 1);
+ QTouchEvent::TouchPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first();
+ QCOMPARE(touchUpdatePoint.id(), rawTouchPoint.id());
+ QCOMPARE(touchUpdatePoint.state(), rawTouchPoint.state());
+ QCOMPARE(touchUpdatePoint.pos(), pos + delta);
+ QCOMPARE(touchUpdatePoint.startPos(), pos);
+ QCOMPARE(touchUpdatePoint.lastPos(), pos);
+ QCOMPARE(touchUpdatePoint.scenePos(), rawTouchPoint.screenPos());
+ QCOMPARE(touchUpdatePoint.startScenePos(), screenPos);
+ QCOMPARE(touchUpdatePoint.lastScenePos(), screenPos);
+ QCOMPARE(touchUpdatePoint.screenPos(), rawTouchPoint.screenPos());
+ QCOMPARE(touchUpdatePoint.startScreenPos(), screenPos);
+ QCOMPARE(touchUpdatePoint.lastScreenPos(), screenPos);
+ QCOMPARE(touchUpdatePoint.normalizedPos(), rawTouchPoint.normalizedPos());
+ QCOMPARE(touchUpdatePoint.startNormalizedPos(), touchBeginPoint.normalizedPos());
+ QCOMPARE(touchUpdatePoint.lastNormalizedPos(), touchBeginPoint.normalizedPos());
+ QCOMPARE(touchUpdatePoint.rect(), QRectF(pos + delta, QSizeF(0, 0)));
+ QCOMPARE(touchUpdatePoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0)));
+ QCOMPARE(touchUpdatePoint.sceneRect(), touchUpdatePoint.screenRect());
+ QCOMPARE(touchUpdatePoint.pressure(), qreal(1.));
+
+ // releasing the point translates to TouchEnd
+ rawTouchPoint.setState(Qt::TouchPointReleased);
+ rawTouchPoint.setScreenPos(screenPos + delta + delta);
+ rawTouchPoint.setNormalizedPos(normalized(rawTouchPoint.pos(), screenGeometry));
+ qt_translateRawTouchEvent(&touchWidget,
+ QTouchEvent::TouchScreen,
+ QList<QTouchEvent::TouchPoint>() << rawTouchPoint);
+ QVERIFY(touchWidget.seenTouchBegin);
+ QVERIFY(touchWidget.seenTouchUpdate);
+ QVERIFY(touchWidget.seenTouchEnd);
+ QCOMPARE(touchWidget.touchEndPoints.count(), 1);
+ QTouchEvent::TouchPoint touchEndPoint = touchWidget.touchEndPoints.first();
+ QCOMPARE(touchEndPoint.id(), rawTouchPoint.id());
+ QCOMPARE(touchEndPoint.state(), rawTouchPoint.state());
+ QCOMPARE(touchEndPoint.pos(), pos + delta + delta);
+ QCOMPARE(touchEndPoint.startPos(), pos);
+ QCOMPARE(touchEndPoint.lastPos(), pos + delta);
+ QCOMPARE(touchEndPoint.scenePos(), rawTouchPoint.screenPos());
+ QCOMPARE(touchEndPoint.startScenePos(), screenPos);
+ QCOMPARE(touchEndPoint.lastScenePos(), screenPos + delta);
+ QCOMPARE(touchEndPoint.screenPos(), rawTouchPoint.screenPos());
+ QCOMPARE(touchEndPoint.startScreenPos(), screenPos);
+ QCOMPARE(touchEndPoint.lastScreenPos(), screenPos + delta);
+ QCOMPARE(touchEndPoint.normalizedPos(), rawTouchPoint.normalizedPos());
+ QCOMPARE(touchEndPoint.startNormalizedPos(), touchBeginPoint.normalizedPos());
+ QCOMPARE(touchEndPoint.lastNormalizedPos(), touchUpdatePoint.normalizedPos());
+ QCOMPARE(touchEndPoint.rect(), QRectF(pos + delta + delta, QSizeF(0, 0)));
+ QCOMPARE(touchEndPoint.screenRect(), QRectF(rawTouchPoint.screenPos(), QSizeF(0, 0)));
+ QCOMPARE(touchEndPoint.sceneRect(), touchEndPoint.screenRect());
+ QCOMPARE(touchEndPoint.pressure(), qreal(0.));
+}
+
+void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
+{
+ tst_QTouchEventWidget touchWidget;
+ touchWidget.setAttribute(Qt::WA_AcceptTouchEvents);
+ touchWidget.setGeometry(100, 100, 400, 300);
+
+ tst_QTouchEventWidget leftWidget;
+ leftWidget.setParent(&touchWidget);
+ leftWidget.setAttribute(Qt::WA_AcceptTouchEvents);
+ leftWidget.setGeometry(0, 100, 100, 100);
+ leftWidget.show();
+
+ tst_QTouchEventWidget rightWidget;
+ rightWidget.setParent(&touchWidget);
+ rightWidget.setAttribute(Qt::WA_AcceptTouchEvents);
+ rightWidget.setGeometry(300, 100, 100, 100);
+ rightWidget.show();
+
+ QPointF leftPos = leftWidget.rect().center();
+ QPointF rightPos = rightWidget.rect().center();
+ QPointF centerPos = touchWidget.rect().center();
+ QPointF leftScreenPos = leftWidget.mapToGlobal(leftPos.toPoint());
+ QPointF rightScreenPos = rightWidget.mapToGlobal(rightPos.toPoint());
+ QPointF centerScreenPos = touchWidget.mapToGlobal(centerPos.toPoint());
+ QPointF delta(10, 10);
+ QRectF screenGeometry = qApp->desktop()->screenGeometry(&touchWidget);
+
+ QList<QTouchEvent::TouchPoint> rawTouchPoints;
+ rawTouchPoints.append(QTouchEvent::TouchPoint(0));
+ rawTouchPoints.append(QTouchEvent::TouchPoint(1));
+
+ // generate TouchBegins on both leftWidget and rightWidget
+ rawTouchPoints[0].setState(Qt::TouchPointPressed);
+ rawTouchPoints[0].setScreenPos(leftScreenPos);
+ rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry));
+ rawTouchPoints[1].setState(Qt::TouchPointPressed);
+ rawTouchPoints[1].setScreenPos(rightScreenPos);
+ rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry));
+ qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints);
+ QVERIFY(!touchWidget.seenTouchBegin);
+ QVERIFY(!touchWidget.seenTouchUpdate);
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QVERIFY(leftWidget.seenTouchBegin);
+ QVERIFY(!leftWidget.seenTouchUpdate);
+ QVERIFY(!leftWidget.seenTouchEnd);
+ QVERIFY(rightWidget.seenTouchBegin);
+ QVERIFY(!rightWidget.seenTouchUpdate);
+ QVERIFY(!rightWidget.seenTouchEnd);
+ QCOMPARE(leftWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(rightWidget.touchBeginPoints.count(), 1);
+ {
+ QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchBeginPoints.first();
+ QCOMPARE(leftTouchPoint.id(), rawTouchPoints[0].id());
+ QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state());
+ QCOMPARE(leftTouchPoint.pos(), leftPos);
+ QCOMPARE(leftTouchPoint.startPos(), leftPos);
+ QCOMPARE(leftTouchPoint.lastPos(), leftPos);
+ QCOMPARE(leftTouchPoint.scenePos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.startScenePos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.lastScenePos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.screenPos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.startScreenPos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.lastScreenPos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.normalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.startNormalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.lastNormalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.rect(), QRectF(leftPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.sceneRect(), QRectF(leftScreenPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.screenRect(), QRectF(leftScreenPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.pressure(), qreal(1.));
+
+ QTouchEvent::TouchPoint rightTouchPoint = rightWidget.touchBeginPoints.first();
+ QCOMPARE(rightTouchPoint.id(), rawTouchPoints[1].id());
+ QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state());
+ QCOMPARE(rightTouchPoint.pos(), rightPos);
+ QCOMPARE(rightTouchPoint.startPos(), rightPos);
+ QCOMPARE(rightTouchPoint.lastPos(), rightPos);
+ QCOMPARE(rightTouchPoint.scenePos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.startScenePos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.lastScenePos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.screenPos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.startScreenPos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.lastScreenPos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.normalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.startNormalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.lastNormalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.rect(), QRectF(rightPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.sceneRect(), QRectF(rightScreenPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.screenRect(), QRectF(rightScreenPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.pressure(), qreal(1.));
+ }
+
+ // generate TouchUpdates on both leftWidget and rightWidget
+ rawTouchPoints[0].setState(Qt::TouchPointMoved);
+ rawTouchPoints[0].setScreenPos(centerScreenPos);
+ rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry));
+ rawTouchPoints[1].setState(Qt::TouchPointMoved);
+ rawTouchPoints[1].setScreenPos(centerScreenPos);
+ rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry));
+ qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints);
+ QVERIFY(!touchWidget.seenTouchBegin);
+ QVERIFY(!touchWidget.seenTouchUpdate);
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QVERIFY(leftWidget.seenTouchBegin);
+ QVERIFY(leftWidget.seenTouchUpdate);
+ QVERIFY(!leftWidget.seenTouchEnd);
+ QVERIFY(rightWidget.seenTouchBegin);
+ QVERIFY(rightWidget.seenTouchUpdate);
+ QVERIFY(!rightWidget.seenTouchEnd);
+ QCOMPARE(leftWidget.touchUpdatePoints.count(), 1);
+ QCOMPARE(rightWidget.touchUpdatePoints.count(), 1);
+ {
+ QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchUpdatePoints.first();
+ QCOMPARE(leftTouchPoint.id(), rawTouchPoints[0].id());
+ QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state());
+ QCOMPARE(leftTouchPoint.pos(), QPointF(leftWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(leftTouchPoint.startPos(), leftPos);
+ QCOMPARE(leftTouchPoint.lastPos(), leftPos);
+ QCOMPARE(leftTouchPoint.scenePos(), centerScreenPos);
+ QCOMPARE(leftTouchPoint.startScenePos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.lastScenePos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.screenPos(), centerScreenPos);
+ QCOMPARE(leftTouchPoint.startScreenPos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.lastScreenPos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.normalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.startNormalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.lastNormalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.rect(), QRectF(leftWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.pressure(), qreal(1.));
+
+ QTouchEvent::TouchPoint rightTouchPoint = rightWidget.touchUpdatePoints.first();
+ QCOMPARE(rightTouchPoint.id(), rawTouchPoints[1].id());
+ QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state());
+ QCOMPARE(rightTouchPoint.pos(), QPointF(rightWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(rightTouchPoint.startPos(), rightPos);
+ QCOMPARE(rightTouchPoint.lastPos(), rightPos);
+ QCOMPARE(rightTouchPoint.scenePos(), centerScreenPos);
+ QCOMPARE(rightTouchPoint.startScenePos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.lastScenePos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.screenPos(), centerScreenPos);
+ QCOMPARE(rightTouchPoint.startScreenPos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.lastScreenPos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.normalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.startNormalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.lastNormalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.rect(), QRectF(rightWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.pressure(), qreal(1.));
+ }
+
+ // generate TouchEnds on both leftWidget and rightWidget
+ rawTouchPoints[0].setState(Qt::TouchPointReleased);
+ rawTouchPoints[0].setScreenPos(centerScreenPos);
+ rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry));
+ rawTouchPoints[1].setState(Qt::TouchPointReleased);
+ rawTouchPoints[1].setScreenPos(centerScreenPos);
+ rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry));
+ qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints);
+ QVERIFY(!touchWidget.seenTouchBegin);
+ QVERIFY(!touchWidget.seenTouchUpdate);
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QVERIFY(leftWidget.seenTouchBegin);
+ QVERIFY(leftWidget.seenTouchUpdate);
+ QVERIFY(leftWidget.seenTouchEnd);
+ QVERIFY(rightWidget.seenTouchBegin);
+ QVERIFY(rightWidget.seenTouchUpdate);
+ QVERIFY(rightWidget.seenTouchEnd);
+ QCOMPARE(leftWidget.touchEndPoints.count(), 1);
+ QCOMPARE(rightWidget.touchEndPoints.count(), 1);
+ {
+ QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchEndPoints.first();
+ QCOMPARE(leftTouchPoint.id(), rawTouchPoints[0].id());
+ QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state());
+ QCOMPARE(leftTouchPoint.pos(), QPointF(leftWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(leftTouchPoint.startPos(), leftPos);
+ QCOMPARE(leftTouchPoint.lastPos(), leftTouchPoint.pos());
+ QCOMPARE(leftTouchPoint.scenePos(), centerScreenPos);
+ QCOMPARE(leftTouchPoint.startScenePos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.lastScenePos(), leftTouchPoint.scenePos());
+ QCOMPARE(leftTouchPoint.screenPos(), centerScreenPos);
+ QCOMPARE(leftTouchPoint.startScreenPos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.lastScreenPos(), leftTouchPoint.screenPos());
+ QCOMPARE(leftTouchPoint.normalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.startNormalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.lastNormalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.rect(), QRectF(leftWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.pressure(), qreal(0.));
+
+ QTouchEvent::TouchPoint rightTouchPoint = rightWidget.touchEndPoints.first();
+ QCOMPARE(rightTouchPoint.id(), rawTouchPoints[1].id());
+ QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state());
+ QCOMPARE(rightTouchPoint.pos(), QPointF(rightWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(rightTouchPoint.startPos(), rightPos);
+ QCOMPARE(rightTouchPoint.lastPos(), rightTouchPoint.pos());
+ QCOMPARE(rightTouchPoint.scenePos(), centerScreenPos);
+ QCOMPARE(rightTouchPoint.startScenePos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.lastScenePos(), rightTouchPoint.scenePos());
+ QCOMPARE(rightTouchPoint.screenPos(), centerScreenPos);
+ QCOMPARE(rightTouchPoint.startScreenPos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.lastScreenPos(), rightTouchPoint.screenPos());
+ QCOMPARE(rightTouchPoint.normalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.startNormalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.lastNormalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.rect(), QRectF(rightWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.pressure(), qreal(0.));
+ }
+}
+
+void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
+{
+ tst_QTouchEventWidget touchWidget;
+ touchWidget.setAttribute(Qt::WA_AcceptTouchEvents);
+ touchWidget.setGeometry(100, 100, 400, 300);
+
+ tst_QTouchEventWidget leftWidget;
+ leftWidget.setParent(&touchWidget);
+ leftWidget.setAttribute(Qt::WA_AcceptTouchEvents);
+ leftWidget.setGeometry(0, 100, 100, 100);
+ leftWidget.show();
+
+ tst_QTouchEventWidget rightWidget;
+ rightWidget.setParent(&touchWidget);
+ rightWidget.setAttribute(Qt::WA_AcceptTouchEvents);
+ rightWidget.setGeometry(300, 100, 100, 100);
+ rightWidget.show();
+
+ QPointF leftPos = leftWidget.rect().center();
+ QPointF rightPos = rightWidget.rect().center();
+ QPointF centerPos = touchWidget.rect().center();
+ QPointF leftScreenPos = leftWidget.mapToGlobal(leftPos.toPoint());
+ QPointF rightScreenPos = rightWidget.mapToGlobal(rightPos.toPoint());
+ QPointF centerScreenPos = touchWidget.mapToGlobal(centerPos.toPoint());
+ QPointF delta(10, 10);
+ QRectF screenGeometry = qApp->desktop()->screenGeometry(&touchWidget);
+
+ QList<QTouchEvent::TouchPoint> rawTouchPoints;
+ rawTouchPoints.append(QTouchEvent::TouchPoint(0));
+ rawTouchPoints.append(QTouchEvent::TouchPoint(1));
+
+ // generate TouchBegin on leftWidget only
+ rawTouchPoints[0].setState(Qt::TouchPointPressed);
+ rawTouchPoints[0].setScreenPos(leftScreenPos);
+ rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry));
+ rawTouchPoints[1].setState(Qt::TouchPointPressed);
+ rawTouchPoints[1].setScreenPos(rightScreenPos);
+ rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry));
+ qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints);
+ QVERIFY(!touchWidget.seenTouchBegin);
+ QVERIFY(!touchWidget.seenTouchUpdate);
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QVERIFY(leftWidget.seenTouchBegin);
+ QVERIFY(!leftWidget.seenTouchUpdate);
+ QVERIFY(!leftWidget.seenTouchEnd);
+ QVERIFY(!rightWidget.seenTouchBegin);
+ QVERIFY(!rightWidget.seenTouchUpdate);
+ QVERIFY(!rightWidget.seenTouchEnd);
+ QCOMPARE(leftWidget.touchBeginPoints.count(), 2);
+ QCOMPARE(rightWidget.touchBeginPoints.count(), 0);
+ {
+ QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchBeginPoints.at(0);
+ QCOMPARE(leftTouchPoint.id(), rawTouchPoints[0].id());
+ QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state());
+ QCOMPARE(leftTouchPoint.pos(), leftPos);
+ QCOMPARE(leftTouchPoint.startPos(), leftPos);
+ QCOMPARE(leftTouchPoint.lastPos(), leftPos);
+ QCOMPARE(leftTouchPoint.scenePos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.startScenePos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.lastScenePos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.screenPos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.startScreenPos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.lastScreenPos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.normalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.startNormalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.lastNormalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.rect(), QRectF(leftPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.sceneRect(), QRectF(leftScreenPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.screenRect(), QRectF(leftScreenPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.pressure(), qreal(1.));
+
+ QTouchEvent::TouchPoint rightTouchPoint = leftWidget.touchBeginPoints.at(1);
+ QCOMPARE(rightTouchPoint.id(), rawTouchPoints[1].id());
+ QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state());
+ QCOMPARE(rightTouchPoint.pos(), QPointF(leftWidget.mapFromGlobal(rightScreenPos.toPoint())));
+ QCOMPARE(rightTouchPoint.startPos(), QPointF(leftWidget.mapFromGlobal(rightScreenPos.toPoint())));
+ QCOMPARE(rightTouchPoint.lastPos(), QPointF(leftWidget.mapFromGlobal(rightScreenPos.toPoint())));
+ QCOMPARE(rightTouchPoint.scenePos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.startScenePos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.lastScenePos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.screenPos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.startScreenPos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.lastScreenPos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.normalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.startNormalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.lastNormalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.rect(), QRectF(leftWidget.mapFromGlobal(rightScreenPos.toPoint()), QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.sceneRect(), QRectF(rightScreenPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.screenRect(), QRectF(rightScreenPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.pressure(), qreal(1.));
+ }
+
+ // generate TouchUpdate on leftWidget
+ rawTouchPoints[0].setState(Qt::TouchPointMoved);
+ rawTouchPoints[0].setScreenPos(centerScreenPos);
+ rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry));
+ rawTouchPoints[1].setState(Qt::TouchPointMoved);
+ rawTouchPoints[1].setScreenPos(centerScreenPos);
+ rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry));
+ qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints);
+ QVERIFY(!touchWidget.seenTouchBegin);
+ QVERIFY(!touchWidget.seenTouchUpdate);
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QVERIFY(leftWidget.seenTouchBegin);
+ QVERIFY(leftWidget.seenTouchUpdate);
+ QVERIFY(!leftWidget.seenTouchEnd);
+ QVERIFY(!rightWidget.seenTouchBegin);
+ QVERIFY(!rightWidget.seenTouchUpdate);
+ QVERIFY(!rightWidget.seenTouchEnd);
+ QCOMPARE(leftWidget.touchUpdatePoints.count(), 2);
+ QCOMPARE(rightWidget.touchUpdatePoints.count(), 0);
+ {
+ QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchUpdatePoints.at(0);
+ QCOMPARE(leftTouchPoint.id(), rawTouchPoints[0].id());
+ QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state());
+ QCOMPARE(leftTouchPoint.pos(), QPointF(leftWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(leftTouchPoint.startPos(), leftPos);
+ QCOMPARE(leftTouchPoint.lastPos(), leftPos);
+ QCOMPARE(leftTouchPoint.scenePos(), centerScreenPos);
+ QCOMPARE(leftTouchPoint.startScenePos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.lastScenePos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.screenPos(), centerScreenPos);
+ QCOMPARE(leftTouchPoint.startScreenPos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.lastScreenPos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.normalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.startNormalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.lastNormalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.rect(), QRectF(leftWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.pressure(), qreal(1.));
+
+ QTouchEvent::TouchPoint rightTouchPoint = leftWidget.touchUpdatePoints.at(1);
+ QCOMPARE(rightTouchPoint.id(), rawTouchPoints[1].id());
+ QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state());
+ QCOMPARE(rightTouchPoint.pos(), QPointF(leftWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(rightTouchPoint.startPos(), QPointF(leftWidget.mapFromGlobal(rightScreenPos.toPoint())));
+ QCOMPARE(rightTouchPoint.lastPos(), QPointF(leftWidget.mapFromGlobal(rightScreenPos.toPoint())));
+ QCOMPARE(rightTouchPoint.scenePos(), centerScreenPos);
+ QCOMPARE(rightTouchPoint.startScenePos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.lastScenePos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.screenPos(), centerScreenPos);
+ QCOMPARE(rightTouchPoint.startScreenPos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.lastScreenPos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.normalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.startNormalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.lastNormalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.rect(), QRectF(leftWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.pressure(), qreal(1.));
+ }
+
+ // generate TouchEnd on leftWidget
+ rawTouchPoints[0].setState(Qt::TouchPointReleased);
+ rawTouchPoints[0].setScreenPos(centerScreenPos);
+ rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry));
+ rawTouchPoints[1].setState(Qt::TouchPointReleased);
+ rawTouchPoints[1].setScreenPos(centerScreenPos);
+ rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry));
+ qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchPad, rawTouchPoints);
+ QVERIFY(!touchWidget.seenTouchBegin);
+ QVERIFY(!touchWidget.seenTouchUpdate);
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QVERIFY(leftWidget.seenTouchBegin);
+ QVERIFY(leftWidget.seenTouchUpdate);
+ QVERIFY(leftWidget.seenTouchEnd);
+ QVERIFY(!rightWidget.seenTouchBegin);
+ QVERIFY(!rightWidget.seenTouchUpdate);
+ QVERIFY(!rightWidget.seenTouchEnd);
+ QCOMPARE(leftWidget.touchEndPoints.count(), 2);
+ QCOMPARE(rightWidget.touchEndPoints.count(), 0);
+ {
+ QTouchEvent::TouchPoint leftTouchPoint = leftWidget.touchEndPoints.at(0);
+ QCOMPARE(leftTouchPoint.id(), rawTouchPoints[0].id());
+ QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state());
+ QCOMPARE(leftTouchPoint.pos(), QPointF(leftWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(leftTouchPoint.startPos(), leftPos);
+ QCOMPARE(leftTouchPoint.lastPos(), leftTouchPoint.pos());
+ QCOMPARE(leftTouchPoint.scenePos(), centerScreenPos);
+ QCOMPARE(leftTouchPoint.startScenePos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.lastScenePos(), leftTouchPoint.scenePos());
+ QCOMPARE(leftTouchPoint.screenPos(), centerScreenPos);
+ QCOMPARE(leftTouchPoint.startScreenPos(), leftScreenPos);
+ QCOMPARE(leftTouchPoint.lastScreenPos(), leftTouchPoint.screenPos());
+ QCOMPARE(leftTouchPoint.normalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.startNormalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.lastNormalizedPos(), rawTouchPoints[0].normalizedPos());
+ QCOMPARE(leftTouchPoint.rect(), QRectF(leftWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(leftTouchPoint.pressure(), qreal(0.));
+
+ QTouchEvent::TouchPoint rightTouchPoint = leftWidget.touchEndPoints.at(1);
+ QCOMPARE(rightTouchPoint.id(), rawTouchPoints[1].id());
+ QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state());
+ QCOMPARE(rightTouchPoint.pos(), QPointF(leftWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(rightTouchPoint.startPos(), QPointF(leftWidget.mapFromGlobal(rightScreenPos.toPoint())));
+ QCOMPARE(rightTouchPoint.lastPos(), rightTouchPoint.pos());
+ QCOMPARE(rightTouchPoint.scenePos(), centerScreenPos);
+ QCOMPARE(rightTouchPoint.startScenePos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.lastScenePos(), rightTouchPoint.scenePos());
+ QCOMPARE(rightTouchPoint.screenPos(), centerScreenPos);
+ QCOMPARE(rightTouchPoint.startScreenPos(), rightScreenPos);
+ QCOMPARE(rightTouchPoint.lastScreenPos(), rightTouchPoint.screenPos());
+ QCOMPARE(rightTouchPoint.normalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.startNormalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.lastNormalizedPos(), rawTouchPoints[1].normalizedPos());
+ QCOMPARE(rightTouchPoint.rect(), QRectF(leftWidget.mapFromParent(centerPos.toPoint()), QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.sceneRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.screenRect(), QRectF(centerScreenPos, QSizeF(0, 0)));
+ QCOMPARE(rightTouchPoint.pressure(), qreal(0.));
+ }
+}
+
+void tst_QTouchEvent::deleteInEventHandler()
+{
+ // QWidget
+ {
+ QWidget window;
+ tst_QTouchEventWidget *child1, *child2, *child3;
+ child1 = new tst_QTouchEventWidget;
+ child2 = new tst_QTouchEventWidget;
+ child3 = new tst_QTouchEventWidget;
+ child1->setParent(&window);
+ child2->setParent(&window);
+ child3->setParent(&window);
+ child1->setAttribute(Qt::WA_AcceptTouchEvents);
+ child2->setAttribute(Qt::WA_AcceptTouchEvents);
+ child3->setAttribute(Qt::WA_AcceptTouchEvents);
+ child1->deleteInTouchBegin = true;
+ child2->deleteInTouchUpdate = true;
+ child3->deleteInTouchEnd = true;
+
+ QList<QTouchEvent::TouchPoint> touchPoints;
+ touchPoints.append(QTouchEvent::TouchPoint(0));
+ QTouchEvent touchBeginEvent(QEvent::TouchBegin,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointPressed,
+ touchPoints);
+ QTouchEvent touchUpdateEvent(QEvent::TouchUpdate,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointStationary,
+ touchPoints);
+ QTouchEvent touchEndEvent(QEvent::TouchEnd,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointReleased,
+ touchPoints);
+ QWeakPointer<QWidget> p;
+ bool res;
+
+ touchBeginEvent.ignore();
+ p = child1;
+ res = QApplication::sendEvent(child1, &touchBeginEvent);
+ // event is handled, but widget should be deleted
+ QVERIFY(res && touchBeginEvent.isAccepted() && p.isNull());
+
+ touchBeginEvent.ignore();
+ p = child2;
+ res = QApplication::sendEvent(child2, &touchBeginEvent);
+ QVERIFY(res && touchBeginEvent.isAccepted() && !p.isNull());
+ touchUpdateEvent.ignore();
+ res = QApplication::sendEvent(child2, &touchUpdateEvent);
+ QVERIFY(res && touchUpdateEvent.isAccepted() && p.isNull());
+
+ touchBeginEvent.ignore();
+ p = child3;
+ res = QApplication::sendEvent(child3, &touchBeginEvent);
+ QVERIFY(res && touchBeginEvent.isAccepted() && !p.isNull());
+ touchUpdateEvent.ignore();
+ res = QApplication::sendEvent(child3, &touchUpdateEvent);
+ QVERIFY(res && touchUpdateEvent.isAccepted() && !p.isNull());
+ touchEndEvent.ignore();
+ res = QApplication::sendEvent(child3, &touchEndEvent);
+ QVERIFY(res && touchEndEvent.isAccepted() && p.isNull());
+ }
+
+ // QGraphicsView
+ {
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+ tst_QTouchEventGraphicsItem *root, *child1, *child2, *child3;
+ root = new tst_QTouchEventGraphicsItem;
+ child1 = new tst_QTouchEventGraphicsItem;
+ child2 = new tst_QTouchEventGraphicsItem;
+ child3 = new tst_QTouchEventGraphicsItem;
+ child1->setParentItem(root);
+ child2->setParentItem(root);
+ child3->setParentItem(root);
+ child1->setZValue(1.);
+ child2->setZValue(0.);
+ child3->setZValue(-1.);
+ child1->setAcceptTouchEvents(true);
+ child2->setAcceptTouchEvents(true);
+ child3->setAcceptTouchEvents(true);
+ child1->deleteInTouchBegin = true;
+ child2->deleteInTouchUpdate = true;
+ child3->deleteInTouchEnd = true;
+
+ scene.addItem(root);
+ view.resize(200, 200);
+ view.fitInView(scene.sceneRect());
+
+ QTouchEvent::TouchPoint touchPoint(0);
+ touchPoint.setState(Qt::TouchPointPressed);
+ touchPoint.setPos(view.mapFromScene(child1->mapToScene(child1->boundingRect().center())));
+ touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint()));
+ touchPoint.setScenePos(view.mapToScene(touchPoint.pos().toPoint()));
+ QList<QTouchEvent::TouchPoint> touchPoints;
+ touchPoints.append(touchPoint);
+ QTouchEvent touchBeginEvent(QEvent::TouchBegin,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointPressed,
+ touchPoints);
+ touchPoints[0].setState(Qt::TouchPointMoved);
+ QTouchEvent touchUpdateEvent(QEvent::TouchUpdate,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointMoved,
+ touchPoints);
+ touchPoints[0].setState(Qt::TouchPointReleased);
+ QTouchEvent touchEndEvent(QEvent::TouchEnd,
+ QTouchEvent::TouchScreen,
+ Qt::NoModifier,
+ Qt::TouchPointReleased,
+ touchPoints);
+ bool res;
+
+ child1->weakpointer = &child1;
+ touchBeginEvent.ignore();
+ res = QApplication::sendEvent(view.viewport(), &touchBeginEvent);
+ QVERIFY(res && touchBeginEvent.isAccepted() && !child1);
+ touchUpdateEvent.ignore();
+ res = QApplication::sendEvent(view.viewport(), &touchUpdateEvent);
+ QVERIFY(res && touchUpdateEvent.isAccepted() && !child1);
+ touchEndEvent.ignore();
+ res = QApplication::sendEvent(view.viewport(), &touchEndEvent);
+ QVERIFY(res && touchUpdateEvent.isAccepted() && !child1);
+
+ child2->weakpointer = &child2;
+ touchBeginEvent.ignore();
+ res = QApplication::sendEvent(view.viewport(), &touchBeginEvent);
+ QVERIFY(res && touchBeginEvent.isAccepted() && child2);
+ touchUpdateEvent.ignore();
+ res = QApplication::sendEvent(view.viewport(), &touchUpdateEvent);
+ QVERIFY(res && !touchUpdateEvent.isAccepted() && !child2);
+ touchEndEvent.ignore();
+ res = QApplication::sendEvent(view.viewport(), &touchEndEvent);
+ QVERIFY(res && !touchUpdateEvent.isAccepted() && !child2);
+
+ child3->weakpointer = &child3;
+ res = QApplication::sendEvent(view.viewport(), &touchBeginEvent);
+ QVERIFY(res && touchBeginEvent.isAccepted() && child3);
+ res = QApplication::sendEvent(view.viewport(), &touchUpdateEvent);
+ QVERIFY(res && !touchUpdateEvent.isAccepted() && child3);
+ res = QApplication::sendEvent(view.viewport(), &touchEndEvent);
+ QVERIFY(res && !touchEndEvent.isAccepted() && !child3);
+
+ delete root;
+ }
+}
+
+void tst_QTouchEvent::deleteInRawEventTranslation()
+{
+ tst_QTouchEventWidget touchWidget;
+ touchWidget.setAttribute(Qt::WA_AcceptTouchEvents);
+ touchWidget.setGeometry(100, 100, 300, 300);
+
+ tst_QTouchEventWidget *leftWidget = new tst_QTouchEventWidget;
+ leftWidget->setParent(&touchWidget);
+ leftWidget->setAttribute(Qt::WA_AcceptTouchEvents);
+ leftWidget->setGeometry(0, 100, 100, 100);
+ leftWidget->deleteInTouchBegin = true;
+ leftWidget->show();
+
+ tst_QTouchEventWidget *centerWidget = new tst_QTouchEventWidget;
+ centerWidget->setParent(&touchWidget);
+ centerWidget->setAttribute(Qt::WA_AcceptTouchEvents);
+ centerWidget->setGeometry(100, 100, 100, 100);
+ centerWidget->deleteInTouchUpdate = true;
+ centerWidget->show();
+
+ tst_QTouchEventWidget *rightWidget = new tst_QTouchEventWidget;
+ rightWidget->setParent(&touchWidget);
+ rightWidget->setAttribute(Qt::WA_AcceptTouchEvents);
+ rightWidget->setGeometry(200, 100, 100, 100);
+ rightWidget->deleteInTouchEnd = true;
+ rightWidget->show();
+
+ QPointF leftPos = leftWidget->rect().center();
+ QPointF centerPos = centerWidget->rect().center();
+ QPointF rightPos = rightWidget->rect().center();
+ QPointF leftScreenPos = leftWidget->mapToGlobal(leftPos.toPoint());
+ QPointF centerScreenPos = centerWidget->mapToGlobal(centerPos.toPoint());
+ QPointF rightScreenPos = rightWidget->mapToGlobal(rightPos.toPoint());
+ QRectF screenGeometry = qApp->desktop()->screenGeometry(&touchWidget);
+
+ QWeakPointer<QWidget> pl = leftWidget, pc = centerWidget, pr = rightWidget;
+
+ QList<QTouchEvent::TouchPoint> rawTouchPoints;
+ rawTouchPoints.append(QTouchEvent::TouchPoint(0));
+ rawTouchPoints.append(QTouchEvent::TouchPoint(1));
+ rawTouchPoints.append(QTouchEvent::TouchPoint(2));
+ rawTouchPoints[0].setState(Qt::TouchPointPressed);
+ rawTouchPoints[0].setScreenPos(leftScreenPos);
+ rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry));
+ rawTouchPoints[1].setState(Qt::TouchPointPressed);
+ rawTouchPoints[1].setScreenPos(centerScreenPos);
+ rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry));
+ rawTouchPoints[2].setState(Qt::TouchPointPressed);
+ rawTouchPoints[2].setScreenPos(rightScreenPos);
+ rawTouchPoints[2].setNormalizedPos(normalized(rawTouchPoints[2].pos(), screenGeometry));
+
+ // generate begin events on all widgets, the left widget should die
+ qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints);
+ QVERIFY(pl.isNull() && !pc.isNull() && !pr.isNull());
+
+ // generate update events on all widget, the center widget should die
+ rawTouchPoints[0].setState(Qt::TouchPointMoved);
+ rawTouchPoints[1].setState(Qt::TouchPointMoved);
+ rawTouchPoints[2].setState(Qt::TouchPointMoved);
+ qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints);
+
+ // generate end events on all widget, the right widget should die
+ rawTouchPoints[0].setState(Qt::TouchPointReleased);
+ rawTouchPoints[1].setState(Qt::TouchPointReleased);
+ rawTouchPoints[2].setState(Qt::TouchPointReleased);
+ qt_translateRawTouchEvent(&touchWidget, QTouchEvent::TouchScreen, rawTouchPoints);
+}
+
+void tst_QTouchEvent::crashInQGraphicsSceneAfterNotHandlingTouchBegin()
+{
+ QGraphicsRectItem *rect = new QGraphicsRectItem(0, 0, 100, 100);
+ rect->setAcceptTouchEvents(true);
+
+ QGraphicsRectItem *mainRect = new QGraphicsRectItem(0, 0, 100, 100, rect);
+ mainRect->setBrush(Qt::lightGray);
+
+ QGraphicsRectItem *button = new QGraphicsRectItem(-20, -20, 40, 40, mainRect);
+ button->setPos(50, 50);
+ button->setBrush(Qt::darkGreen);
+
+ QGraphicsView view;
+ QGraphicsScene scene;
+ scene.addItem(rect);
+ scene.setSceneRect(0,0,100,100);
+ view.setScene(&scene);
+
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+
+ QPoint centerPos = view.mapFromScene(rect->boundingRect().center());
+ // Touch the button
+ QTest::touchEvent(view.viewport()).press(0, centerPos);
+ QTest::touchEvent(view.viewport()).release(0, centerPos);
+ // Touch outside of the button
+ QTest::touchEvent(view.viewport()).press(0, view.mapFromScene(QPoint(10, 10)));
+ QTest::touchEvent(view.viewport()).release(0, view.mapFromScene(QPoint(10, 10)));
+}
+
+void tst_QTouchEvent::touchBeginWithGraphicsWidget()
+{
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+ tst_QTouchEventGraphicsItem *root;
+ root = new tst_QTouchEventGraphicsItem;
+ root->setAcceptTouchEvents(true);
+ scene.addItem(root);
+
+ QGraphicsWidget *glassWidget = new QGraphicsWidget;
+ glassWidget->setMinimumSize(100, 100);
+ scene.addItem(glassWidget);
+
+ view.resize(200, 200);
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+ view.fitInView(scene.sceneRect());
+
+ QTest::touchEvent()
+ .press(0, view.mapFromScene(root->mapToScene(3,3)), view.viewport());
+ QTest::touchEvent()
+ .stationary(0)
+ .press(1, view.mapFromScene(root->mapToScene(6,6)), view.viewport());
+ QTest::touchEvent()
+ .release(0, view.mapFromScene(root->mapToScene(3,3)), view.viewport())
+ .release(1, view.mapFromScene(root->mapToScene(6,6)), view.viewport());
+
+ QCOMPARE(root->touchBeginCounter, 1);
+ QCOMPARE(root->touchUpdateCounter, 1);
+ QCOMPARE(root->touchEndCounter, 1);
+ QCOMPARE(root->touchUpdatePoints.size(), 2);
+
+ root->reset();
+ glassWidget->setWindowFlags(Qt::Window); // make the glassWidget a panel
+
+ QTest::touchEvent()
+ .press(0, view.mapFromScene(root->mapToScene(3,3)), view.viewport());
+ QTest::touchEvent()
+ .stationary(0)
+ .press(1, view.mapFromScene(root->mapToScene(6,6)), view.viewport());
+ QTest::touchEvent()
+ .release(0, view.mapFromScene(root->mapToScene(3,3)), view.viewport())
+ .release(1, view.mapFromScene(root->mapToScene(6,6)), view.viewport());
+
+ QCOMPARE(root->touchBeginCounter, 0);
+ QCOMPARE(root->touchUpdateCounter, 0);
+ QCOMPARE(root->touchEndCounter, 0);
+
+
+ delete root;
+ delete glassWidget;
+}
+
+QTEST_MAIN(tst_QTouchEvent)
+
+#include "tst_qtouchevent.moc"