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); |
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()) |