summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlessandro Portale <aportale@trolltech.com>2009-05-26 18:59:55 (GMT)
committerAlessandro Portale <aportale@trolltech.com>2009-05-26 18:59:55 (GMT)
commit52071c71ddfde1354e6c17737660a3d161d0bc89 (patch)
tree4565792986d23cf67e7087a69e0130986f0b454e /src
parent257c14452fb02f845b30f1c4a03470d94435d6fa (diff)
downloadQt-52071c71ddfde1354e6c17737660a3d161d0bc89.zip
Qt-52071c71ddfde1354e6c17737660a3d161d0bc89.tar.gz
Qt-52071c71ddfde1354e6c17737660a3d161d0bc89.tar.bz2
Introducing QKeyEventSoftKey helper class.
It maps softkeys to actual key events. Making it easy and non-intrusive to add softkey usage to existing widgets.
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/qsoftkeystack.cpp24
-rw-r--r--src/gui/widgets/qsoftkeystack_p.h14
2 files changed, 38 insertions, 0 deletions
diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp
index 0054c6b..3591dc1 100644
--- a/src/gui/widgets/qsoftkeystack.cpp
+++ b/src/gui/widgets/qsoftkeystack.cpp
@@ -43,6 +43,7 @@
#include "qsoftkeystack_p.h"
#include "qapplication.h"
#include "qmainwindow.h"
+#include "qevent.h"
static bool isSame(const QSoftkeySet& a, const QSoftkeySet& b)
{
@@ -228,3 +229,26 @@ void QSoftKeyStackPrivate::setNativeSoftKeys()
{
}
#endif // !defined(Q_WS_S60)
+
+QKeyEventSoftKey::QKeyEventSoftKey(QSoftKeyAction *softKeyAction, Qt::Key key, QObject *parent)
+ : QObject(parent)
+ , m_softKeyAction(softKeyAction)
+ , m_key(key)
+{
+}
+
+void QKeyEventSoftKey::addSoftKey(QSoftKeyAction::StandardRole standardRole, Qt::Key key, QWidget *actionWidget)
+{
+ QSoftKeyStack *stack = QSoftKeyStack::softKeyStackOfWidget(actionWidget);
+ if (!stack)
+ return;
+ QSoftKeyAction *action = new QSoftKeyAction(standardRole, actionWidget);
+ QKeyEventSoftKey *softKey = new QKeyEventSoftKey(action, key, actionWidget);
+ connect(action, SIGNAL(triggered()), softKey, SLOT(sendKeyEvent()));
+ stack->push(action);
+}
+
+void QKeyEventSoftKey::sendKeyEvent()
+{
+ QApplication::postEvent(parent(), new QKeyEvent(QEvent::KeyPress, m_key, Qt::NoModifier));
+}
diff --git a/src/gui/widgets/qsoftkeystack_p.h b/src/gui/widgets/qsoftkeystack_p.h
index b698178..e728cbb 100644
--- a/src/gui/widgets/qsoftkeystack_p.h
+++ b/src/gui/widgets/qsoftkeystack_p.h
@@ -70,6 +70,7 @@ QT_BEGIN_NAMESPACE
class QSoftKeyStackPrivate : public QObjectPrivate
{
+ Q_DECLARE_PUBLIC(QSoftKeyStack);
public:
QSoftKeyStackPrivate();
~QSoftKeyStackPrivate();
@@ -91,6 +92,19 @@ private:
QStack <QSoftkeySet> softKeyStack;
};
+class QKeyEventSoftKey : QObject
+{
+ Q_OBJECT
+public:
+ QKeyEventSoftKey(QSoftKeyAction *softKeyAction, Qt::Key key, QObject *parent);
+ static void addSoftKey(QSoftKeyAction::StandardRole standardRole, Qt::Key key, QWidget *actionWidget);
+private:
+ QSoftKeyAction *m_softKeyAction;
+ Qt::Key m_key;
+private Q_SLOTS:
+ void sendKeyEvent();
+};
+
QT_END_NAMESPACE
#endif // QSOFTKEYSTACK_P_H