src/gui/widgets/qmenubar.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
child 18 2f34d5167611
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   330 
   330 
   331         QRect adjustedActionRect = actionRect(action);
   331         QRect adjustedActionRect = actionRect(action);
   332         QPoint pos(q->mapToGlobal(QPoint(adjustedActionRect.left(), adjustedActionRect.bottom() + 1)));
   332         QPoint pos(q->mapToGlobal(QPoint(adjustedActionRect.left(), adjustedActionRect.bottom() + 1)));
   333         QSize popup_size = activeMenu->sizeHint();
   333         QSize popup_size = activeMenu->sizeHint();
   334 
   334 
   335         QRect screenRect = QApplication::desktop()->screenGeometry(pos);
   335         //we put the popup menu on the screen containing the bottom-center of the action rect
       
   336         QRect screenRect = QApplication::desktop()->screenGeometry(pos + QPoint(adjustedActionRect.width() / 2, 0));
       
   337         pos = QPoint(qMax(pos.x(), screenRect.x()), qMax(pos.y(), screenRect.y()));
   336 
   338 
   337         const bool fitUp = (q->mapToGlobal(adjustedActionRect.topLeft()).y() >= popup_size.height());
   339         const bool fitUp = (q->mapToGlobal(adjustedActionRect.topLeft()).y() >= popup_size.height());
   338         const bool fitDown = (pos.y() + popup_size.height() <= screenRect.bottom());
   340         const bool fitDown = (pos.y() + popup_size.height() <= screenRect.bottom());
       
   341         const bool rtl = q->isRightToLeft();
   339         const int actionWidth = adjustedActionRect.width();
   342         const int actionWidth = adjustedActionRect.width();
   340 
   343 
   341         if (!fitUp && !fitDown) { //we should shift the menu
   344         if (!fitUp && !fitDown) { //we should shift the menu
   342             bool shouldShiftToRight = !q->isRightToLeft();
   345             bool shouldShiftToRight = !rtl;
   343             if (q->isRightToLeft() && popup_size.width() > pos.x())
   346             if (rtl && popup_size.width() > pos.x())
   344                 shouldShiftToRight = true;
   347                 shouldShiftToRight = true;
   345             else if (actionWidth + popup_size.width() + pos.x() > screenRect.right())
   348             else if (actionWidth + popup_size.width() + pos.x() > screenRect.right())
   346                 shouldShiftToRight = false;
   349                 shouldShiftToRight = false;
   347 
   350 
   348             if (shouldShiftToRight)
   351             if (shouldShiftToRight) {
   349                 pos.rx() += actionWidth;
   352                 pos.rx() += actionWidth + (rtl ? popup_size.width() : 0);
   350             else
   353             } else {
   351                 pos.rx() -= popup_size.width();
   354                 //shift to left
   352         } else if (q->isRightToLeft()) {
   355                 if (!rtl)
   353             pos.setX(pos.x()-(popup_size.width() - actionWidth));
   356                     pos.rx() -= popup_size.width();
   354         }
   357             }
   355 
   358         } else if (rtl) {
   356         if(pos.x() < screenRect.x()) {
   359             pos.rx() += actionWidth;
   357             pos.setX(screenRect.x());
       
   358         } else {
       
   359             const int off = pos.x()+popup_size.width() - screenRect.right();
       
   360             if(off > 0)
       
   361                 pos.setX(qMax(screenRect.x(), pos.x()-off));
       
   362 
       
   363         }
   360         }
   364 
   361 
   365         if(!defaultPopDown || (fitUp && !fitDown))
   362         if(!defaultPopDown || (fitUp && !fitDown))
   366             pos.setY(qMax(screenRect.y(), q->mapToGlobal(QPoint(0, adjustedActionRect.top()-popup_size.height())).y()));
   363             pos.setY(qMax(screenRect.y(), q->mapToGlobal(QPoint(0, adjustedActionRect.top()-popup_size.height())).y()));
   367         activeMenu->popup(pos);
   364         activeMenu->popup(pos);
   736 #ifdef Q_WS_WINCE
   733 #ifdef Q_WS_WINCE
   737     if (qt_wince_is_mobile()) {
   734     if (qt_wince_is_mobile()) {
   738         wceCreateMenuBar(q->parentWidget());
   735         wceCreateMenuBar(q->parentWidget());
   739         if(wce_menubar)
   736         if(wce_menubar)
   740             q->hide();
   737             q->hide();
       
   738     }
       
   739     else {
       
   740         QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
   741     }
   741     }
   742 #endif
   742 #endif
   743 #ifdef Q_WS_S60
   743 #ifdef Q_WS_S60
   744     symbianCreateMenuBar(q->parentWidget());
   744     symbianCreateMenuBar(q->parentWidget());
   745     if(symbian_menubar)
   745     if(symbian_menubar)
  1487 #endif
  1487 #endif
  1488         d->_q_updateLayout();
  1488         d->_q_updateLayout();
  1489     break;
  1489     break;
  1490     case QEvent::ShortcutOverride: {
  1490     case QEvent::ShortcutOverride: {
  1491         QKeyEvent *kev = static_cast<QKeyEvent*>(e);
  1491         QKeyEvent *kev = static_cast<QKeyEvent*>(e);
  1492         if (kev->key() == Qt::Key_Escape) {
  1492         //we only filter out escape if there is a current action
       
  1493         if (kev->key() == Qt::Key_Escape && d->currentAction) {
  1493             e->accept();
  1494             e->accept();
  1494             return true;
  1495             return true;
  1495         }
  1496         }
  1496     }
  1497     }
  1497     break;
  1498     break;
  1935         return;
  1936         return;
  1936 #ifdef Q_WS_WINCE
  1937 #ifdef Q_WS_WINCE
  1937     if (qt_wince_is_mobile())
  1938     if (qt_wince_is_mobile())
  1938         if (d->defaultAction) {
  1939         if (d->defaultAction) {
  1939             disconnect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction()));
  1940             disconnect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction()));
  1940             disconnect(d->defaultAction, SIGNAL(destroyed ()), this, SLOT(_q_updateDefaultAction()));
  1941             disconnect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction()));
  1941         }
  1942         }
  1942 #endif
  1943 #endif
  1943     d->defaultAction = act;
  1944     d->defaultAction = act;
  1944 #ifdef Q_WS_WINCE
  1945 #ifdef Q_WS_WINCE
  1945     if (qt_wince_is_mobile())
  1946     if (qt_wince_is_mobile())