summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-04-20 19:23:14 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2018-04-20 20:06:18 +0000
commit100ebf1c97dec1fcfea29d790c07993d071cbb3f (patch)
treeb1f12ddf8834ba77f2143344008b0e9f673cdda1 /tests
parentf35f282c4f0ef11dc35bc9120852ff9e77f85297 (diff)
parent6f45fda50b6dbb0704a71a15f38d44027b4b1816 (diff)
Merge "Merge remote-tracking branch 'origin/5.11' into dev" into refs/staging/dev
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/kernel/qwindow/BLACKLIST3
-rw-r--r--tests/auto/widgets/kernel/qaction/tst_qaction.cpp37
-rw-r--r--tests/manual/shortcuts/main.cpp304
3 files changed, 154 insertions, 190 deletions
diff --git a/tests/auto/gui/kernel/qwindow/BLACKLIST b/tests/auto/gui/kernel/qwindow/BLACKLIST
index e55bf77403..cd1cb99c3c 100644
--- a/tests/auto/gui/kernel/qwindow/BLACKLIST
+++ b/tests/auto/gui/kernel/qwindow/BLACKLIST
@@ -23,3 +23,6 @@ osx-10.12 ci
[testInputEvents]
rhel-7.4
+[isActive]
+# QTBUG-67768
+ubuntu
diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
index ddf9ccb416..3d68e42baf 100644
--- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
+++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
@@ -67,6 +67,7 @@ private slots:
void keysequence(); // QTBUG-53381
void disableShortcutsWithBlockedWidgets_data();
void disableShortcutsWithBlockedWidgets();
+ void shortcutFromKeyEvent(); // QTBUG-48325
private:
int m_lastEventType;
@@ -509,5 +510,41 @@ void tst_QAction::disableShortcutsWithBlockedWidgets()
QCOMPARE(spy.count(), 0);
}
+class ShortcutOverrideWidget : public QWidget
+{
+public:
+ ShortcutOverrideWidget(QWidget *parent = 0) : QWidget(parent), shortcutOverrideCount(0) {}
+ int shortcutOverrideCount;
+protected:
+ bool event(QEvent *e)
+ {
+ if (e->type() == QEvent::ShortcutOverride)
+ ++shortcutOverrideCount;
+ return QWidget::event(e);
+ }
+};
+
+// Test that a key press event sent with sendEvent() still gets handled as a possible
+// ShortcutOverride event first before passing it on as a normal KeyEvent.
+void tst_QAction::shortcutFromKeyEvent()
+{
+ ShortcutOverrideWidget testWidget;
+ QAction action;
+ action.setShortcut(Qt::Key_1);
+ testWidget.addAction(&action);
+ testWidget.show();
+ QSignalSpy spy(&action, &QAction::triggered);
+ QVERIFY(spy.isValid());
+ QVERIFY(QTest::qWaitForWindowActive(&testWidget));
+ QCOMPARE(testWidget.shortcutOverrideCount, 0);
+
+ // Don't use the QTest::keyPress approach as this will take the
+ // shortcut route for us
+ QKeyEvent e(QEvent::KeyPress, Qt::Key_1, Qt::NoModifier);
+ QApplication::sendEvent(&testWidget, &e);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(testWidget.shortcutOverrideCount, 1);
+}
+
QTEST_MAIN(tst_QAction)
#include "tst_qaction.moc"
diff --git a/tests/manual/shortcuts/main.cpp b/tests/manual/shortcuts/main.cpp
index 849f8728b3..acc2a2525c 100644
--- a/tests/manual/shortcuts/main.cpp
+++ b/tests/manual/shortcuts/main.cpp
@@ -28,6 +28,7 @@
#include <QApplication>
#include <QVBoxLayout>
+#include <QGridLayout>
#include <QWidget>
#include <QLabel>
#include <QPushButton>
@@ -36,200 +37,123 @@
class ShortcutTester : public QWidget
{
public:
- ShortcutTester() {
- setupLayout();
- }
-protected:
- void setupLayout()
+ ShortcutTester()
{
- QVBoxLayout *layout = new QVBoxLayout(this);
- setLayout(layout);
-
- QLabel *testPurpose = new QLabel();
- testPurpose->setWordWrap(true);
- testPurpose->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Expanding);
- testPurpose->setText("This test come in handy to verify shortcuts under different "
- "keyboard layouts - qwerty, dvorak, non-latin (russian, arabic), etc.");
- layout->addWidget(testPurpose);
-
- QKeySequence altShiftG(Qt::AltModifier + Qt::ShiftModifier + Qt::Key_G);
- QPushButton *_altShiftG = new QPushButton(altShiftG.toString());
- _altShiftG->setShortcut(altShiftG);
- layout->addWidget(_altShiftG);
-
- QKeySequence altG(Qt::AltModifier + Qt::Key_G);
- QPushButton *_altG = new QPushButton(altG.toString());
- _altG->setShortcut(altG);
- layout->addWidget(_altG);
-
- QKeySequence ctrlShiftR(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_R);
- QPushButton *_ctrlShiftR = new QPushButton(ctrlShiftR.toString());
- _ctrlShiftR->setShortcut(ctrlShiftR);
- layout->addWidget(_ctrlShiftR);
-
- QKeySequence ctrlR(Qt::ControlModifier + Qt::Key_R);
- QPushButton *_ctrlR = new QPushButton(ctrlR.toString());
- _ctrlR->setShortcut(ctrlR);
- layout->addWidget(_ctrlR);
-
- QKeySequence ctrlReturn(Qt::ControlModifier + Qt::Key_Return);
- QPushButton *_ctrlReturn = new QPushButton(ctrlReturn.toString());
- _ctrlReturn->setShortcut(ctrlReturn);
- layout->addWidget(_ctrlReturn);
-
- QKeySequence ctrlEnter(Qt::ControlModifier + Qt::Key_Enter);
- QPushButton *_ctrlEnter = new QPushButton(ctrlEnter.toString());
- _ctrlEnter->setShortcut(ctrlEnter);
- layout->addWidget(_ctrlEnter);
-
- QKeySequence ctrlShiftAltR(Qt::ControlModifier + Qt::ShiftModifier + Qt::AltModifier + Qt::Key_R);
- QPushButton *_ctrlShiftAltR = new QPushButton(ctrlShiftAltR.toString());
- _ctrlShiftAltR->setShortcut(ctrlShiftAltR);
- layout->addWidget(_ctrlShiftAltR);
-
- QKeySequence shift5(Qt::ShiftModifier + Qt::Key_5);
- QPushButton *_shift5 = new QPushButton(shift5.toString());
- _shift5->setShortcut(shift5);
- layout->addWidget(_shift5);
-
- QKeySequence shiftPercent(Qt::ShiftModifier + Qt::Key_Percent);
- QPushButton *_shiftPercent = new QPushButton(shiftPercent.toString());
- _shiftPercent->setShortcut(shiftPercent);
- layout->addWidget(_shiftPercent);
-
- QKeySequence percent(Qt::Key_Percent);
- QPushButton *_percent = new QPushButton(percent.toString());
- _percent->setShortcut(percent);
- layout->addWidget(_percent);
-
- QKeySequence key5(Qt::Key_5);
- QPushButton *_key5 = new QPushButton(key5.toString());
- _key5->setShortcut(key5);
- layout->addWidget(_key5);
-
- QKeySequence keyQ(Qt::Key_Q);
- QPushButton *_keyQ = new QPushButton(keyQ.toString());
- _keyQ->setShortcut(keyQ);
- layout->addWidget(_keyQ);
-
- QKeySequence ctrlPercent(Qt::ControlModifier + Qt::Key_Percent);
- QPushButton *_ctrlPercent = new QPushButton(ctrlPercent.toString());
- _ctrlPercent->setShortcut(ctrlPercent);
- layout->addWidget(_ctrlPercent);
-
- QKeySequence ctrlShift5(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_5);
- QPushButton *_ctrlShift5 = new QPushButton(ctrlShift5.toString());
- _ctrlShift5->setShortcut(ctrlShift5);
- layout->addWidget(_ctrlShift5);
-
- QKeySequence ctrl5(Qt::ControlModifier + Qt::Key_5);
- QPushButton *_ctrl5 = new QPushButton(ctrl5.toString());
- _ctrl5->setShortcut(ctrl5);
- layout->addWidget(_ctrl5);
-
- QKeySequence alt5(Qt::AltModifier + Qt::Key_5);
- QPushButton *_alt5 = new QPushButton(alt5.toString());
- _alt5->setShortcut(alt5);
- layout->addWidget(_alt5);
-
- QKeySequence ctrlPlus(Qt::ControlModifier + Qt::Key_Plus);
- QPushButton *_ctrlPlus = new QPushButton(ctrlPlus.toString());
- _ctrlPlus->setShortcut(ctrlPlus);
- layout->addWidget(_ctrlPlus);
-
- QKeySequence ctrlShiftPlus(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_Plus);
- QPushButton *_ctrlShiftPlus = new QPushButton(ctrlShiftPlus.toString());
- _ctrlShiftPlus->setShortcut(ctrlShiftPlus);
- layout->addWidget(_ctrlShiftPlus);
-
- QKeySequence ctrlY(Qt::ControlModifier + Qt::Key_Y);
- QPushButton *_ctrlY = new QPushButton(ctrlY.toString());
- _ctrlY->setShortcut(ctrlY);
- layout->addWidget(_ctrlY);
-
- QKeySequence shiftComma(Qt::ShiftModifier + Qt::Key_Comma);
- QPushButton *_shiftComma = new QPushButton(shiftComma.toString());
- _shiftComma->setShortcut(shiftComma);
- layout->addWidget(_shiftComma);
-
- QKeySequence ctrlComma(Qt::ControlModifier + Qt::Key_Comma);
- QPushButton *_ctrlComma = new QPushButton(ctrlComma.toString());
- _ctrlComma->setShortcut(ctrlComma);
- layout->addWidget(_ctrlComma);
-
- QKeySequence ctrlSlash(Qt::ControlModifier + Qt::Key_Slash);
- QPushButton *_ctrlSlash = new QPushButton(ctrlSlash.toString());
- _ctrlSlash->setShortcut(ctrlSlash);
- layout->addWidget(_ctrlSlash);
-
- QKeySequence ctrlBackslash(Qt::ControlModifier + Qt::Key_Backslash);
- QPushButton *_ctrlBackslash = new QPushButton(ctrlBackslash.toString());
- _ctrlBackslash->setShortcut(ctrlBackslash);
- layout->addWidget(_ctrlBackslash);
-
- QKeySequence metaShiftA(Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_A);
- QPushButton *_metaShiftA = new QPushButton(metaShiftA.toString());
- _metaShiftA->setShortcut(metaShiftA);
- layout->addWidget(_metaShiftA);
-
- QKeySequence metaShift5(Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_5);
- QPushButton *_metaShift5 = new QPushButton(metaShift5.toString());
- _metaShift5->setShortcut(metaShift5);
- layout->addWidget(_metaShift5);
-
- QKeySequence ctrlBracketRigth(Qt::ControlModifier + Qt::Key_BracketRight);
- QPushButton *_ctrlBracketRigth = new QPushButton(ctrlBracketRigth.toString());
- _ctrlBracketRigth->setShortcut(ctrlBracketRigth);
- layout->addWidget(_ctrlBracketRigth);
-
- QKeySequence shiftF3(Qt::ShiftModifier + Qt::Key_F3);
- QPushButton *_shiftF3 = new QPushButton(shiftF3.toString());
- _shiftF3->setShortcut(shiftF3);
- layout->addWidget(_shiftF3);
-
- QKeySequence ctrlF3(Qt::ControlModifier + Qt::Key_F3);
- QPushButton *_ctrlF3 = new QPushButton(ctrlF3.toString());
- _ctrlF3->setShortcut(ctrlF3);
- layout->addWidget(_ctrlF3);
-
- QKeySequence euro(0x20AC); // EURO SIGN e.g. US (with euro on 5) on 3rd keyboard level
- QPushButton *_euro = new QPushButton(euro.toString());
- _euro->setShortcut(euro);
- layout->addWidget(_euro);
-
- QKeySequence ctrlEuro(Qt::ControlModifier + 0x20AC);
- QPushButton *_ctrlEuro = new QPushButton(ctrlEuro.toString());
- _ctrlEuro->setShortcut(ctrlEuro);
- layout->addWidget(_ctrlEuro);
-
- // with german (neo 2) layout on linux under ISO_Level3_Shift + ISO_Level5_Shift + I
- QKeySequence greekPsi(QString(QStringLiteral("\u03A8")));
- QPushButton *_greekPsi = new QPushButton(greekPsi.toString());
- _greekPsi->setShortcut(greekPsi);
- layout->addWidget(_greekPsi);
-
- layout->addWidget(new QLabel("Norwegian layout"));
- // LATIN SMALL LETTER O WITH STROKE
- QKeySequence norwegianO(QString(QStringLiteral("\u00F8")));
- QPushButton *_norwegianO = new QPushButton(norwegianO.toString());
- _norwegianO->setShortcut(norwegianO);
- layout->addWidget(_norwegianO);
-
- layout->addWidget(new QLabel("Russian layout"));
- // CYRILLIC SMALL LETTER ZHE
- QKeySequence zhe(QString(QStringLiteral("\u0436")));
- QPushButton *_zhe = new QPushButton(zhe.toString());
- _zhe->setShortcut(zhe);
- layout->addWidget(_zhe);
-
- // for sequence definitons see qplatformtheme.cpp
- layout->addWidget(new QLabel("QKeySequence::StandardKey(s)"));
- QPushButton *_open = new QPushButton("Open");
- _open->setShortcut(QKeySequence::Open); // Qt::CTRL | Qt::Key_O
- layout->addWidget(_open);
+ const QString title = QLatin1String(QT_VERSION_STR) + QLatin1Char(' ')
+ + qApp->platformName();
+ setWindowTitle(title);
+ setupLayout();
}
+
+private:
+ void setupLayout();
+ void addToGrid(QWidget *w, int &row, int col);
+ void addShortcutToGrid(const QKeySequence &k, int &row, int col);
+ void addShortcutToGrid(int key, int &row, int col)
+ { addShortcutToGrid(QKeySequence(key), row, col); }
+
+ QGridLayout *m_gridLayout = new QGridLayout;
};
+inline void ShortcutTester::addToGrid(QWidget *w, int &row, int col)
+{
+ m_gridLayout->addWidget(w, row++, col);
+}
+
+void ShortcutTester::addShortcutToGrid(const QKeySequence &k, int &row, int col)
+{
+ QPushButton *button = new QPushButton(k.toString());
+ button->setShortcut(k);
+ addToGrid(button, row, col);
+}
+
+void addShortcutToGrid(int key, int &row, int col);
+
+void ShortcutTester::setupLayout()
+{
+ QVBoxLayout *layout = new QVBoxLayout(this);
+
+ QLabel *testPurpose = new QLabel();
+ testPurpose->setWordWrap(true);
+ testPurpose->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Expanding);
+ testPurpose->setText("This test come in handy to verify shortcuts under different "
+ "keyboard layouts - qwerty, dvorak, non-latin (russian, arabic), etc.");
+ layout->addWidget(testPurpose);
+
+ layout->addLayout(m_gridLayout);
+
+ int row = 0;
+ int col = 0;
+
+ const int keys1[] = {
+ Qt::AltModifier + Qt::ShiftModifier + Qt::Key_G,
+ Qt::AltModifier + Qt::Key_G,
+ Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_R,
+ Qt::ControlModifier + Qt::Key_R,
+ Qt::ControlModifier + Qt::Key_Return, Qt::ControlModifier + Qt::Key_Enter,
+ Qt::ControlModifier + Qt::ShiftModifier + Qt::AltModifier + Qt::Key_R,
+ Qt::ShiftModifier + Qt::Key_5, Qt::ShiftModifier + Qt::Key_Percent,
+ Qt::Key_Percent, Qt::Key_5, Qt::Key_Q
+ };
+
+ for (int k : keys1)
+ addShortcutToGrid(k, row, col);
+
+ row = 0;
+ col++;
+
+ const int keys2[] = {
+ Qt::ControlModifier + Qt::Key_Percent,
+ Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_5,
+ Qt::ControlModifier + Qt::Key_5, Qt::AltModifier + Qt::Key_5,
+ Qt::ControlModifier + Qt::Key_Plus,
+ Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_Plus,
+ Qt::ControlModifier + Qt::Key_Y, Qt::ShiftModifier + Qt::Key_Comma,
+ Qt::ControlModifier + Qt::Key_Comma, Qt::ControlModifier + Qt::Key_Slash,
+ Qt::ControlModifier + Qt::Key_Backslash
+ };
+
+ for (int k : keys2)
+ addShortcutToGrid(k, row, col);
+
+ row = 0;
+ col++;
+
+ const int keys3[] = {
+ Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_A,
+ Qt::MetaModifier + Qt::ShiftModifier + Qt::Key_5,
+ Qt::ControlModifier + Qt::Key_BracketRight,
+ Qt::ShiftModifier + Qt::Key_F3,
+ Qt::ControlModifier + Qt::Key_F3,
+ 0x20AC, // EURO SIGN e.g. US (with euro on 5) on 3rd keyboard level
+ Qt::ControlModifier + 0x20AC
+ };
+
+ for (int k : keys3)
+ addShortcutToGrid(k, row, col);
+
+ // with german (neo 2) layout on linux under ISO_Level3_Shift + ISO_Level5_Shift + I
+ const QKeySequence greekPsi(QString(QStringLiteral("\u03A8")));
+ addShortcutToGrid(greekPsi, row, col);
+
+ row = 0;
+ col++;
+
+ addToGrid(new QLabel("Norwegian layout"), row, col);
+ // LATIN SMALL LETTER O WITH STROKE
+ QKeySequence norwegianO(QString(QStringLiteral("\u00F8")));
+ addShortcutToGrid(norwegianO, row, col);
+
+ addToGrid(new QLabel("Russian layout"), row, col);
+ // CYRILLIC SMALL LETTER ZHE
+ QKeySequence zhe(QString(QStringLiteral("\u0436")));
+ addShortcutToGrid(zhe, row, col);
+
+ // for sequence definitons see qplatformtheme.cpp
+ addToGrid(new QLabel("QKeySequence::StandardKey(s)"), row, col);
+ addShortcutToGrid(QKeySequence(QKeySequence::Open), row, col); // Qt::CTRL | Qt::Key_O
+}
+
int main(int argc, char *argv[])
{
QApplication a(argc, argv);