diff options
-rw-r--r-- | src/gui/kernel/qsoftkeymanager.cpp | 12 | ||||
-rw-r--r-- | tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp | 36 |
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" |