summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Barron <jbarron@trolltech.com>2009-09-28 09:54:06 (GMT)
committerJason Barron <jbarron@trolltech.com>2009-09-28 10:04:18 (GMT)
commitc912b0234ead0e35a969b5600a61c77b60e18aa6 (patch)
tree402e36ab7fc51708682f248887275aa52825b86d
parentf8188b14493eb3d01263be5fef4ea086d3a542a0 (diff)
downloadQt-c912b0234ead0e35a969b5600a61c77b60e18aa6.zip
Qt-c912b0234ead0e35a969b5600a61c77b60e18aa6.tar.gz
Qt-c912b0234ead0e35a969b5600a61c77b60e18aa6.tar.bz2
Make sure the correct soft key is triggered.
In cases where there are both softkey actions as well as "normal" actions, we need to be sure to skip over the none softkey actions since they should not be a part of the softkey framework and the 'index' will be out of sync. Reviewed-by: Sami Merila
-rw-r--r--src/gui/kernel/qsoftkeymanager.cpp12
-rw-r--r--tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp36
2 files changed, 45 insertions, 3 deletions
diff --git a/src/gui/kernel/qsoftkeymanager.cpp b/src/gui/kernel/qsoftkeymanager.cpp
index 45ecb5a..7874622 100644
--- a/src/gui/kernel/qsoftkeymanager.cpp
+++ b/src/gui/kernel/qsoftkeymanager.cpp
@@ -247,9 +247,15 @@ bool QSoftKeyManager::handleCommand(int command)
if (command >= s60CommandStart && QSoftKeyManagerPrivate::softKeySource) {
int index = command - s60CommandStart;
const QList<QAction*>& softKeys = QSoftKeyManagerPrivate::softKeySource->actions();
- if (index < softKeys.count()) {
- softKeys.at(index)->activate(QAction::Trigger);
- return true;
+ for (int i = 0, j = 0; i < softKeys.count(); ++i) {
+ QAction *action = softKeys.at(i);
+ if (action->softKeyRole() != QAction::NoSoftKey) {
+ if (j == index) {
+ action->activate(QAction::Trigger);
+ return true;
+ }
+ j++;
+ }
}
}
diff --git a/tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp b/tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp
index 81ef498..8788117 100644
--- a/tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp
+++ b/tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp
@@ -42,6 +42,8 @@
#include <QtTest/QtTest>
#include "qevent.h"
+#include "qdialog.h"
+#include "qdialogbuttonbox.h"
#include "private/qsoftkeymanager_p.h"
class tst_QSoftKeyManager : public QObject
@@ -59,6 +61,7 @@ public slots:
void cleanup();
private slots:
void updateSoftKeysCompressed();
+ void handleCommand();
};
class EventListener : public QObject
@@ -133,6 +136,39 @@ void tst_QSoftKeyManager::updateSoftKeysCompressed()
QVERIFY(listener.numUpdateSoftKeys == 1);
}
+/*
+ This tests that when the S60 environment sends us a command
+ that it actually gets mapped to the correct action.
+*/
+void tst_QSoftKeyManager::handleCommand()
+{
+ QDialog w;
+ QDialogButtonBox *buttons = new QDialogButtonBox(
+ QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+ Qt::Horizontal,
+ &w);
+
+ w.show();
+ QApplication::processEvents();
+
+ QCOMPARE(w.actions().count(), 2);
+
+ QSignalSpy spy0(w.actions()[0], SIGNAL(triggered()));
+ QSignalSpy spy1(w.actions()[1], SIGNAL(triggered()));
+
+ // These should work eventually, but do not yet
+// QTest::keyPress(&w, Qt::Key_Context1);
+// QTest::keyPress(&w, Qt::Key_Context2);
+
+ qApp->symbianHandleCommand(6000);
+ qApp->symbianHandleCommand(6001);
+
+ QApplication::processEvents();
+
+ QCOMPARE(spy0.count(), 1);
+ QCOMPARE(spy1.count(), 1);
+}
+
QTEST_MAIN(tst_QSoftKeyManager)
#include "tst_qsoftkeymanager.moc"