summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorjasplin <qt-info@nokia.com>2009-04-20 12:24:08 (GMT)
committerjasplin <qt-info@nokia.com>2009-04-20 13:02:05 (GMT)
commit031adeaf42ddaef8d01338f6c59ba97170be5d53 (patch)
treee6eb11ed75e2d9015f51000c138399593c6a4af9 /tests
parentbeb6912526766edd7e8a9f9876d82272f798dbc3 (diff)
downloadQt-031adeaf42ddaef8d01338f6c59ba97170be5d53.zip
Qt-031adeaf42ddaef8d01338f6c59ba97170be5d53.tar.gz
Qt-031adeaf42ddaef8d01338f6c59ba97170be5d53.tar.bz2
Fixed key sequence eating behavior for QShortcut and QAction.
A disabled QShortcut should eat its key sequence even for complex sequences like "Ctrl-E 1". For example, a line edit with such a shortcut should not display 1 after typing "Ctrl-E" and then "1". The patch achieves this essentially by moving more of the decision making (of whether to eat the key secuence) from shortcutmap.cpp to qhortcut.cpp. Moreover, an invisible QAction should not eat any of its key sequences (primary nor alternates). In the example above, the line edit would display 1 when typing this sequence for an invisible action. The patch achieves this by temporarily unregistering all of the action's shortcuts while the action is invisible. Reviewed-by: mariusSO Task-number: 251246
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qaction/tst_qaction.cpp33
-rw-r--r--tests/auto/qshortcut/tst_qshortcut.cpp7
2 files changed, 36 insertions, 4 deletions
diff --git a/tests/auto/qaction/tst_qaction.cpp b/tests/auto/qaction/tst_qaction.cpp
index 34f2dfd..8e4ae86 100644
--- a/tests/auto/qaction/tst_qaction.cpp
+++ b/tests/auto/qaction/tst_qaction.cpp
@@ -46,6 +46,7 @@
#include <qevent.h>
#include <qaction.h>
#include <qmenu.h>
+#include <qlineedit.h>
//TESTED_CLASS=
//TESTED_FILES=
@@ -74,6 +75,7 @@ private slots:
void setStandardKeys();
void alternateShortcuts();
void enabledVisibleInteraction();
+ void invisibleActionWithComplexShortcut();
void task200823_tooltip();
private:
@@ -322,5 +324,36 @@ void tst_QAction::task200823_tooltip()
QCOMPARE(action->toolTip(), ref);
}
+void tst_QAction::invisibleActionWithComplexShortcut()
+{
+ QAction action(0);
+ action.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_E, Qt::Key_1));
+
+ QLineEdit edit;
+ edit.addAction(&action);
+ edit.show();
+ QTest::qWait(100);
+
+ QSignalSpy spy(&action, SIGNAL(triggered()));
+
+ action.setVisible(true);
+ QTest::keyPress(&edit, Qt::Key_E, Qt::ControlModifier);
+ QTest::keyRelease(&edit, Qt::Key_E, Qt::ControlModifier);
+ QTest::keyPress(&edit, Qt::Key_1, Qt::NoModifier);
+ QTest::keyRelease(&edit, Qt::Key_1, Qt::NoModifier);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(edit.text(), QLatin1String(""));
+
+ edit.clear();
+ spy.clear();
+ action.setVisible(false);
+ QTest::keyPress(&edit, Qt::Key_E, Qt::ControlModifier);
+ QTest::keyRelease(&edit, Qt::Key_E, Qt::ControlModifier);
+ QTest::keyPress(&edit, Qt::Key_1, Qt::NoModifier);
+ QTest::keyRelease(&edit, Qt::Key_1, Qt::NoModifier);
+ QCOMPARE(spy.count(), 0);
+ QCOMPARE(edit.text(), QLatin1String("1"));
+}
+
QTEST_MAIN(tst_QAction)
#include "tst_qaction.moc"
diff --git a/tests/auto/qshortcut/tst_qshortcut.cpp b/tests/auto/qshortcut/tst_qshortcut.cpp
index 69ebf74..cd80204 100644
--- a/tests/auto/qshortcut/tst_qshortcut.cpp
+++ b/tests/auto/qshortcut/tst_qshortcut.cpp
@@ -987,17 +987,16 @@ void tst_QShortcut::keypressConsumption()
cut1->setEnabled(false);
cut2->setEnabled(false);
- // Make sure keypresses is passed on, since all multiple keysequences
- // with Ctrl+I are disabled
+ edit->clear();
sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0); // Send key to edit
QCOMPARE( currentResult, NoResult );
QCOMPARE( ambigResult, NoResult );
- QVERIFY(edit->toPlainText().endsWith("<Ctrl+I>"));
+ QVERIFY(edit->toPlainText().isEmpty());
sendKeyEvents(edit, Qt::Key_A, 'a'); // Send key to edit
QCOMPARE( currentResult, NoResult );
QCOMPARE( ambigResult, NoResult );
- QVERIFY(edit->toPlainText().endsWith("<Ctrl+I>a"));
+ QVERIFY(edit->toPlainText().isEmpty());
clearAllShortcuts();
}