src/gui/kernel/qsoftkeymanager.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
child 22 79de32ba3296
--- a/src/gui/kernel/qsoftkeymanager.cpp	Fri Apr 16 15:50:13 2010 +0300
+++ b/src/gui/kernel/qsoftkeymanager.cpp	Mon May 03 13:17:34 2010 +0300
@@ -115,6 +115,8 @@
         break;
     }
     action->setSoftKeyRole(softKeyRole);
+    action->setVisible(false);
+    setForceEnabledInSoftkeys(action);
     return action;
 }
 
@@ -168,25 +170,55 @@
 {
     Q_D(QSoftKeyManager);
     bool ret = false;
-    QList<QAction*> actions = source.actions();
-    for (int i = 0; i < actions.count(); ++i) {
-        if (actions.at(i)->softKeyRole() != QAction::NoSoftKey) {
-            d->requestedSoftKeyActions.insert(level, actions.at(i));
+    foreach(QAction *action, source.actions()) {
+        if (action->softKeyRole() != QAction::NoSoftKey
+            && (action->isVisible() || isForceEnabledInSofkeys(action))) {
+            d->requestedSoftKeyActions.insert(level, action);
             ret = true;
         }
     }
     return ret;
 }
 
+
+static bool isChildOf(const QWidget *c, const QWidget *p)
+{
+    while (c) {
+        if (c == p)
+            return true;
+        c = c->parentWidget();
+    }
+    return false;
+}
+
 QWidget *QSoftKeyManager::softkeySource(QWidget *previousSource, bool& recursiveMerging)
 {
     Q_D(QSoftKeyManager);
     QWidget *source = NULL;
     if (!previousSource) {
         // Initial source is primarily focuswidget and secondarily activeWindow
-        source = QApplication::focusWidget();
-        if (!source)
-            source = QApplication::activeWindow();
+        QWidget *focus = QApplication::focusWidget();
+        QWidget *popup = QApplication::activePopupWidget();
+        if (popup) {
+            if (isChildOf(focus, popup))
+                source = focus;
+            else
+                source = popup;
+        }
+        if (!source) {
+            QWidget *modal = QApplication::activeModalWidget();
+            if (modal) {
+                if (isChildOf(focus, modal))
+                    source = focus;
+                else
+                    source = modal;
+            }
+        }
+        if (!source) {
+            source = focus;
+            if (!source)
+                source = QApplication::activeWindow();
+        }
     } else {
         // Softkey merging is based on four criterias
         // 1. Implicit merging is used whenever focus widget does not specify any softkeys
@@ -220,6 +252,20 @@
     return true;
 }
 
+void QSoftKeyManager::setForceEnabledInSoftkeys(QAction *action)
+{
+    action->setProperty(FORCE_ENABLED_PROPERTY, QVariant(true));
+}
+
+bool QSoftKeyManager::isForceEnabledInSofkeys(QAction *action)
+{
+    bool ret = false;
+    QVariant property = action->property(FORCE_ENABLED_PROPERTY);
+    if (property.isValid() && property.toBool())
+        ret = true;
+    return ret;
+}
+
 bool QSoftKeyManager::event(QEvent *e)
 {
 #ifndef QT_NO_ACTION