From 285ce9a19f2dd16f0aca650b52ac25daf6656b09 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Thu, 14 May 2009 21:28:30 +0200 Subject: Connecting to focusChanged in order to ask the freshly focussed widget for its actions. --- src/gui/widgets/qsoftkeystack.cpp | 26 ++++++++++++++++++++++++++ src/gui/widgets/qsoftkeystack.h | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/src/gui/widgets/qsoftkeystack.cpp b/src/gui/widgets/qsoftkeystack.cpp index 687b236..61f7b64 100644 --- a/src/gui/widgets/qsoftkeystack.cpp +++ b/src/gui/widgets/qsoftkeystack.cpp @@ -41,6 +41,8 @@ #include "qsoftkeystack.h" #include "qsoftkeystack_p.h" +#include "qapplication.h" +#include "qmainwindow.h" QSoftKeyStackPrivate::QSoftKeyStackPrivate() { @@ -76,6 +78,7 @@ void QSoftKeyStackPrivate::pop() QSoftKeyStack::QSoftKeyStack(QWidget *parent) : QObject(*new QSoftKeyStackPrivate, parent) { + connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), SLOT(handleFocusChanged(QWidget*, QWidget*))); } QSoftKeyStack::~QSoftKeyStack() @@ -100,3 +103,26 @@ void QSoftKeyStack::pop() d->pop(); } +void QSoftKeyStack::handleFocusChanged(QWidget *old, QWidget *now) +{ + if (!now) + return; + bool nowInOurMainWindow = false; + const QMainWindow *ourMainWindow = qobject_cast(parent()); + Q_ASSERT(ourMainWindow); + + // "ourMainWindow" in parent chain of "now"? Isn't there a helper in Qt for this? + QWidget *nowParent = now; + while (nowParent = nowParent->parentWidget()) { + if (nowParent == ourMainWindow) { + nowInOurMainWindow = true; + break; + } + } + + if (!nowInOurMainWindow) + return; + + QList actions = now->actions(); + // Do something with these actions. +} diff --git a/src/gui/widgets/qsoftkeystack.h b/src/gui/widgets/qsoftkeystack.h index ca06072..d126b32 100644 --- a/src/gui/widgets/qsoftkeystack.h +++ b/src/gui/widgets/qsoftkeystack.h @@ -57,6 +57,7 @@ class QSoftKeyAction; class Q_GUI_EXPORT QSoftKeyStack : public QObject { + Q_OBJECT public: QSoftKeyStack(QWidget *parent); ~QSoftKeyStack(); @@ -67,6 +68,9 @@ public: void handleSoftKeyPress(int command); +private Q_SLOTS: + void handleFocusChanged(QWidget *old, QWidget *now); + private: Q_DECLARE_PRIVATE(QSoftKeyStack) Q_DISABLE_COPY(QSoftKeyStack) -- cgit v0.12