summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlessandro Portale <aportale@trolltech.com>2009-05-14 19:28:30 (GMT)
committerAlessandro Portale <aportale@trolltech.com>2009-05-14 19:28:30 (GMT)
commit285ce9a19f2dd16f0aca650b52ac25daf6656b09 (patch)
treefff437a45d71fcd6ae37f145df3f12a7c995768f /src
parent99d848f54c34aaa935d67ec406352bbafef03ae9 (diff)
downloadQt-285ce9a19f2dd16f0aca650b52ac25daf6656b09.zip
Qt-285ce9a19f2dd16f0aca650b52ac25daf6656b09.tar.gz
Qt-285ce9a19f2dd16f0aca650b52ac25daf6656b09.tar.bz2
Connecting to focusChanged in order to ask the freshly focussed widget for
its actions.
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/qsoftkeystack.cpp26
-rw-r--r--src/gui/widgets/qsoftkeystack.h4
2 files changed, 30 insertions, 0 deletions
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<const QMainWindow*>(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<QAction*> 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)