From 9d78e1132427ec803f08b2861ab27587ca72cfbf Mon Sep 17 00:00:00 2001 From: Jason Barron Date: Tue, 16 Jun 2009 11:45:30 +0200 Subject: Update softkeys correctly when no focus widget is present. In the case where there is no focus widget present, the button group container should be updated with the softkeys from the currently active window if it has softkeys. This patch enables this behavior. Also modify QMainWindow such that the soft keys are updated when the main window becomes the active window and not only when the menu bar is set. At the moment, this creates a new QAction and this should be changed since it will continuously grow the memory. As a final fix, move the soft key setting out of setFocus() because it is much to early. At the point, the widget does not know for certain that it actually will get focus since it could be disabled or have a focus proxy. --- src/gui/kernel/qapplication_s60.cpp | 7 ++++--- src/gui/kernel/qwidget.cpp | 12 +++++++++--- src/gui/widgets/qmainwindow.cpp | 11 ++++++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 4c008fb..42faf98 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -1072,9 +1072,10 @@ void QApplication::symbianHandleCommand(int command) default: if (command >= SOFTKEYSTART && command <= SOFTKEYEND) { int index= command-SOFTKEYSTART; - QWidget* focused = QApplication::focusWidget(); - const QList& softKeys = focused->softKeys(); - Q_ASSERT(index& softKeys = softKeySource->softKeys(); + Q_ASSERT(index < softKeys.count()); softKeys.at(index)->activate(QAction::Trigger); } else diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index a83a79f..8d2569e 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -5781,7 +5781,6 @@ bool QWidget::hasFocus() const void QWidget::setFocus(Qt::FocusReason reason) { Q_D(QWidget); - d->setSoftKeys_sys(softKeys()); if (!isEnabled()) return; @@ -7733,6 +7732,7 @@ bool QWidget::event(QEvent *event) #if defined(Q_WS_WIN) QInputContextPrivate::updateImeStatus(this, true); #endif + d->setSoftKeys_sys(softKeys()); focusInEvent((QFocusEvent*)event); break; @@ -7885,6 +7885,10 @@ bool QWidget::event(QEvent *event) if (w && w->isVisible() && !w->isWindow()) QApplication::sendEvent(w, event); } + + if (isWindow() && isActiveWindow()) + d->setSoftKeys_sys(softKeys()); + break; } case QEvent::LanguageChange: @@ -11617,7 +11621,8 @@ void QWidget::setSoftKey(QAction *softKey) d->softKeys.clear(); if (softKey) d->softKeys.append(softKey); - if (QApplication::focusWidget() == this) + if ((!QApplication::focusWidget() && this == QApplication::activeWindow()) + || QApplication::focusWidget() == this) d->setSoftKeys_sys(this->softKeys()); } @@ -11634,7 +11639,8 @@ void QWidget::setSoftKeys(const QList &softKeys) d->softKeys.clear(); d->softKeys = softKeys; - if ((QApplication::focusWidget() == this) || (QApplication::focusWidget()==0)) + if ((!QApplication::focusWidget() && this == QApplication::activeWindow()) + || QApplication::focusWidget() == this) d->setSoftKeys_sys(this->softKeys()); } diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index 2f3b412..5f8371c 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -1396,7 +1396,16 @@ bool QMainWindow::event(QEvent *event) } break; #endif - +#ifndef QT_NO_MENUBAR + case QEvent::WindowActivate: + if (d->layout->menuBar()) { + // ### TODO: This is evil, there is no need to create a new action every time + QAction* menu = new QAction(QString::fromLatin1("Menu"), this); + menu->setSoftKeyRole(QAction::MenuSoftKey); + setSoftKey(menu); + } + break; +#endif default: break; } -- cgit v0.12