src/gui/kernel/qsoftkeymanager_s60.cpp
changeset 22 79de32ba3296
parent 19 fcece45ef507
child 23 89e065397ea6
equal deleted inserted replaced
19:fcece45ef507 22:79de32ba3296
   310 }
   310 }
   311 
   311 
   312 bool QSoftKeyManagerPrivateS60::setRightSoftkey(CEikButtonGroupContainer &cba)
   312 bool QSoftKeyManagerPrivateS60::setRightSoftkey(CEikButtonGroupContainer &cba)
   313 {
   313 {
   314     if (!setSoftkey(cba, QAction::NegativeSoftKey, RSK_POSITION)) {
   314     if (!setSoftkey(cba, QAction::NegativeSoftKey, RSK_POSITION)) {
   315         Qt::WindowType windowType = Qt::Window;
   315         const Qt::WindowType windowType = initialSoftKeySource
   316         QAction *action = requestedSoftKeyActions.value(0);
   316             ? initialSoftKeySource->window()->windowType() : Qt::Window;
   317         if (action) {
       
   318             QWidget *actionParent = action->parentWidget();
       
   319             Q_ASSERT_X(actionParent, Q_FUNC_INFO, "No parent set for softkey action!");
       
   320 
       
   321             QWidget *actionWindow = actionParent->window();
       
   322             Q_ASSERT_X(actionWindow, Q_FUNC_INFO, "Softkey action does not have window!");
       
   323             windowType = actionWindow->windowType();
       
   324         }
       
   325 
       
   326         if (windowType != Qt::Dialog && windowType != Qt::Popup) {
   317         if (windowType != Qt::Dialog && windowType != Qt::Popup) {
   327             QString text(QSoftKeyManager::tr("Exit"));
   318             QString text(QSoftKeyManager::tr("Exit"));
   328             TPtrC nativeText = qt_QString2TPtrC(text);
   319             TPtrC nativeText = qt_QString2TPtrC(text);
   329             if (cbaHasImage[RSK_POSITION]) {
   320             if (cbaHasImage[RSK_POSITION]) {
   330                 EikSoftkeyImage::SetLabel(&cba, false);
   321                 EikSoftkeyImage::SetLabel(&cba, false);
   372     setSoftkeys(*nativeContainer);
   363     setSoftkeys(*nativeContainer);
   373 
   364 
   374     nativeContainer->DrawDeferred(); // 3.1 needs an extra invitation
   365     nativeContainer->DrawDeferred(); // 3.1 needs an extra invitation
   375 }
   366 }
   376 
   367 
       
   368 static void resetMenuBeingConstructed(TAny* /*aAny*/)
       
   369 {
       
   370     S60->menuBeingConstructed = false;
       
   371 }
       
   372 
       
   373 void QSoftKeyManagerPrivateS60::tryDisplayMenuBarL()
       
   374 {
       
   375     CleanupStack::PushL(TCleanupItem(resetMenuBeingConstructed, NULL));
       
   376     S60->menuBeingConstructed = true;
       
   377     S60->menuBar()->TryDisplayMenuBarL();
       
   378     CleanupStack::PopAndDestroy(); // Reset menuBeingConstructed to false in all cases
       
   379 }
       
   380 
   377 bool QSoftKeyManagerPrivateS60::handleCommand(int command)
   381 bool QSoftKeyManagerPrivateS60::handleCommand(int command)
   378 {
   382 {
   379     QAction *action = realSoftKeyActions.value(command);
   383     QAction *action = realSoftKeyActions.value(command);
   380     if (action) {
   384     if (action) {
   381         QVariant property = action->property(MENU_ACTION_PROPERTY);
   385         QVariant property = action->property(MENU_ACTION_PROPERTY);
   382         if (property.isValid() && property.toBool()) {
   386         if (property.isValid() && property.toBool()) {
   383             QT_TRAP_THROWING(S60->menuBar()->TryDisplayMenuBarL());
   387             QT_TRAP_THROWING(tryDisplayMenuBarL());
   384         } else if (action->menu()) {
   388         } else if (action->menu()) {
   385             // TODO: This is hack, in order to use exising QMenuBar implementation for Symbian
   389             // TODO: This is hack, in order to use exising QMenuBar implementation for Symbian
   386             // menubar needs to have widget to which it is associated. Since we want to associate
   390             // menubar needs to have widget to which it is associated. Since we want to associate
   387             // menubar to action (which is inherited from QObejct), we create and associate QWidget
   391             // menubar to action (which is inherited from QObject), we create and associate QWidget
   388             // to action and pass that for QMenuBar. This associates the menubar to action, and we
   392             // to action and pass that for QMenuBar. This associates the menubar to action, and we
   389             // can have own menubar for each action.
   393             // can have own menubar for each action.
   390             QWidget *actionContainer = action->property("_q_action_widget").value<QWidget*>();
   394             QWidget *actionContainer = action->property("_q_action_widget").value<QWidget*>();
   391             if(!actionContainer) {
   395             if(!actionContainer) {
   392                 actionContainer = new QWidget(action->parentWidget());
   396                 actionContainer = new QWidget(action->parentWidget());
   401                 QVariant v;
   405                 QVariant v;
   402                 v.setValue(actionContainer);
   406                 v.setValue(actionContainer);
   403                 action->setProperty("_q_action_widget", v);
   407                 action->setProperty("_q_action_widget", v);
   404             }
   408             }
   405             qt_symbian_next_menu_from_action(actionContainer);
   409             qt_symbian_next_menu_from_action(actionContainer);
   406             QT_TRAP_THROWING(S60->menuBar()->TryDisplayMenuBarL());
   410             QT_TRAP_THROWING(tryDisplayMenuBarL());
   407         } else {
   411         }
   408             Q_ASSERT(action->softKeyRole() != QAction::NoSoftKey);
   412 
   409             QWidget *actionParent = action->parentWidget();
   413         Q_ASSERT(action->softKeyRole() != QAction::NoSoftKey);
   410             Q_ASSERT_X(actionParent, Q_FUNC_INFO, "No parent set for softkey action!");
   414         QWidget *actionParent = action->parentWidget();
   411             if (actionParent->isEnabled()) {
   415         Q_ASSERT_X(actionParent, Q_FUNC_INFO, "No parent set for softkey action!");
   412                 action->activate(QAction::Trigger);
   416         if (actionParent->isEnabled()) {
   413                 return true;
   417             action->activate(QAction::Trigger);
   414             }
   418             return true;
   415         }
   419         }
   416     }
   420     }
   417     return false;
   421     return false;
   418 }
   422 }
   419 
   423