src/gui/widgets/qmenubar.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
--- a/src/gui/widgets/qmenubar.cpp	Tue Feb 02 00:43:10 2010 +0200
+++ b/src/gui/widgets/qmenubar.cpp	Wed Mar 31 11:06:36 2010 +0300
@@ -1,6 +1,6 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
 **
@@ -71,6 +71,10 @@
 extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp
 #endif
 
+#ifdef QT_SOFTKEYS_ENABLED
+#include <private/qsoftkeymanager_p.h>
+#endif
+
 QT_BEGIN_NAMESPACE
 
 class QMenuBarExtension : public QToolButton
@@ -667,7 +671,7 @@
          \i Application Menu | About <application name>
          \i The application name is fetched from the \c {Info.plist} file
             (see note below). If this entry is not found no About item
-            will appear in the Application Menu. 
+            will appear in the Application Menu.
     \row \i config, options, setup, settings or preferences
          \i Application Menu | Preferences
          \i If this entry is not found the Settings item will be disabled
@@ -740,17 +744,14 @@
         QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
     }
 #endif
-#ifdef Q_WS_S60
-    symbianCreateMenuBar(q->parentWidget());
-    if(symbian_menubar)
-        q->hide();
-#endif
-
     q->setBackgroundRole(QPalette::Button);
     oldWindow = oldParent = 0;
 #ifdef QT3_SUPPORT
     doAutoResize = false;
 #endif
+#ifdef QT_SOFTKEYS_ENABLED
+    menuBarAction = 0;
+#endif
     handleReparent();
     q->setMouseTracking(q->style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, q));
 
@@ -1384,10 +1385,37 @@
         wce_menubar->rebuild();
 #endif
 #ifdef Q_WS_S60
-    if (symbian_menubar)
+
+    // Construct symbian_menubar when this code path is entered first time
+    // and when newParent != NULL
+    if (!symbian_menubar)
+        symbianCreateMenuBar(newParent);
+
+    // Reparent and rebuild menubar when parent is changed
+    if (symbian_menubar) {
+        if (oldParent != newParent)
+            reparentMenuBar(oldParent, newParent);
+        q->hide();
         symbian_menubar->rebuild();
-#endif
+    }
 
+#ifdef QT_SOFTKEYS_ENABLED
+    // Constuct menuBarAction when this code path is entered first time
+    if (!menuBarAction) {
+        if (newParent) {
+            menuBarAction = QSoftKeyManager::createAction(QSoftKeyManager::MenuSoftKey, newParent);
+            newParent->addAction(menuBarAction);
+        }
+    } else {
+        // If reparenting i.e. we already have menuBarAction, remove it from old parent
+        // and add for a new parent
+        if (oldParent)
+            oldParent->removeAction(menuBarAction);
+        if (newParent)
+            newParent->addAction(menuBarAction);
+    }
+#endif // QT_SOFTKEYS_ENABLED
+#endif // Q_WS_S60
 }
 
 #ifdef QT3_SUPPORT
@@ -1440,7 +1468,13 @@
                || e->type() == QEvent::ApplicationFontChange) {
         d->itemsDirty = true;
         d->updateGeometries();
+#ifdef QT_SOFTKEYS_ENABLED
+    } else if (e->type() == QEvent::LanguageChange) {
+        if (d->menuBarAction)
+            d->menuBarAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::MenuSoftKey));
+#endif
     }
+
     QWidget::changeEvent(e);
 }