src/gui/widgets/qmenubar.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
    69 
    69 
    70 #ifdef Q_WS_WINCE
    70 #ifdef Q_WS_WINCE
    71 extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp
    71 extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp
    72 #endif
    72 #endif
    73 
    73 
       
    74 #ifdef QT_SOFTKEYS_ENABLED
       
    75 #include <private/qsoftkeymanager_p.h>
       
    76 #endif
       
    77 
    74 QT_BEGIN_NAMESPACE
    78 QT_BEGIN_NAMESPACE
    75 
    79 
    76 class QMenuBarExtension : public QToolButton
    80 class QMenuBarExtension : public QToolButton
    77 {
    81 {
    78 public:
    82 public:
   665     \header \i String matches \i Placement \i Notes
   669     \header \i String matches \i Placement \i Notes
   666     \row \i about.*
   670     \row \i about.*
   667          \i Application Menu | About <application name>
   671          \i Application Menu | About <application name>
   668          \i The application name is fetched from the \c {Info.plist} file
   672          \i The application name is fetched from the \c {Info.plist} file
   669             (see note below). If this entry is not found no About item
   673             (see note below). If this entry is not found no About item
   670             will appear in the Application Menu. 
   674             will appear in the Application Menu.
   671     \row \i config, options, setup, settings or preferences
   675     \row \i config, options, setup, settings or preferences
   672          \i Application Menu | Preferences
   676          \i Application Menu | Preferences
   673          \i If this entry is not found the Settings item will be disabled
   677          \i If this entry is not found the Settings item will be disabled
   674     \row \i quit or exit
   678     \row \i quit or exit
   675          \i Application Menu | Quit <application name>
   679          \i Application Menu | Quit <application name>
   738     }
   742     }
   739     else {
   743     else {
   740         QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
   744         QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
   741     }
   745     }
   742 #endif
   746 #endif
   743 #ifdef Q_WS_S60
       
   744     symbianCreateMenuBar(q->parentWidget());
       
   745     if(symbian_menubar)
       
   746         q->hide();
       
   747 #endif
       
   748 
       
   749     q->setBackgroundRole(QPalette::Button);
   747     q->setBackgroundRole(QPalette::Button);
   750     oldWindow = oldParent = 0;
   748     oldWindow = oldParent = 0;
   751 #ifdef QT3_SUPPORT
   749 #ifdef QT3_SUPPORT
   752     doAutoResize = false;
   750     doAutoResize = false;
       
   751 #endif
       
   752 #ifdef QT_SOFTKEYS_ENABLED
       
   753     menuBarAction = 0;
   753 #endif
   754 #endif
   754     handleReparent();
   755     handleReparent();
   755     q->setMouseTracking(q->style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, q));
   756     q->setMouseTracking(q->style()->styleHint(QStyle::SH_MenuBar_MouseTracking, 0, q));
   756 
   757 
   757     extension = new QMenuBarExtension(q);
   758     extension = new QMenuBarExtension(q);
  1382 #ifdef Q_WS_WINCE
  1383 #ifdef Q_WS_WINCE
  1383     if (qt_wince_is_mobile() && wce_menubar)
  1384     if (qt_wince_is_mobile() && wce_menubar)
  1384         wce_menubar->rebuild();
  1385         wce_menubar->rebuild();
  1385 #endif
  1386 #endif
  1386 #ifdef Q_WS_S60
  1387 #ifdef Q_WS_S60
  1387     if (symbian_menubar)
  1388 
       
  1389     // Construct symbian_menubar when this code path is entered first time
       
  1390     // and when newParent != NULL
       
  1391     if (!symbian_menubar)
       
  1392         symbianCreateMenuBar(newParent);
       
  1393 
       
  1394     // Reparent and rebuild menubar when parent is changed
       
  1395     if (symbian_menubar) {
       
  1396         if (oldParent != newParent)
       
  1397             reparentMenuBar(oldParent, newParent);
       
  1398         q->hide();
  1388         symbian_menubar->rebuild();
  1399         symbian_menubar->rebuild();
  1389 #endif
  1400     }
  1390 
  1401 
       
  1402 #ifdef QT_SOFTKEYS_ENABLED
       
  1403     // Constuct menuBarAction when this code path is entered first time
       
  1404     if (!menuBarAction) {
       
  1405         if (newParent) {
       
  1406             menuBarAction = QSoftKeyManager::createAction(QSoftKeyManager::MenuSoftKey, newParent);
       
  1407             newParent->addAction(menuBarAction);
       
  1408         }
       
  1409     } else {
       
  1410         // If reparenting i.e. we already have menuBarAction, remove it from old parent
       
  1411         // and add for a new parent
       
  1412         if (oldParent)
       
  1413             oldParent->removeAction(menuBarAction);
       
  1414         if (newParent)
       
  1415             newParent->addAction(menuBarAction);
       
  1416     }
       
  1417 #endif // QT_SOFTKEYS_ENABLED
       
  1418 #endif // Q_WS_S60
  1391 }
  1419 }
  1392 
  1420 
  1393 #ifdef QT3_SUPPORT
  1421 #ifdef QT3_SUPPORT
  1394 /*!
  1422 /*!
  1395     Sets whether the menu bar should automatically resize itself
  1423     Sets whether the menu bar should automatically resize itself
  1438         d->handleReparent();
  1466         d->handleReparent();
  1439     } else if (e->type() == QEvent::FontChange
  1467     } else if (e->type() == QEvent::FontChange
  1440                || e->type() == QEvent::ApplicationFontChange) {
  1468                || e->type() == QEvent::ApplicationFontChange) {
  1441         d->itemsDirty = true;
  1469         d->itemsDirty = true;
  1442         d->updateGeometries();
  1470         d->updateGeometries();
  1443     }
  1471 #ifdef QT_SOFTKEYS_ENABLED
       
  1472     } else if (e->type() == QEvent::LanguageChange) {
       
  1473         if (d->menuBarAction)
       
  1474             d->menuBarAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::MenuSoftKey));
       
  1475 #endif
       
  1476     }
       
  1477 
  1444     QWidget::changeEvent(e);
  1478     QWidget::changeEvent(e);
  1445 }
  1479 }
  1446 
  1480 
  1447 /*!
  1481 /*!
  1448   \reimp
  1482   \reimp