forked from qt-creator/qt-creator
Cleanup popup menu position.
The menus on toolbuttons are not placed next to the menu, like other toolbuttons, instead of being opened at mouse position. The code is similar to the code in QToolButton implementation. Change-Id: I7893b0badcd35e00d0c6a27749d2bcf0b6f1d44b Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
committed by
Eike Ziller
parent
0aa702c7ac
commit
d77d8fba43
@@ -44,6 +44,39 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
|
||||||
|
/*! Opens a menu at the specified widget position.
|
||||||
|
* This functions computes the position where to show the menu, and opens it with
|
||||||
|
* QMenu::exec().
|
||||||
|
* \param menu The menu to open
|
||||||
|
* \param widget The widget next to which to open the menu
|
||||||
|
*/
|
||||||
|
static void execMenuAtWidget(QMenu *menu, QWidget *widget)
|
||||||
|
{
|
||||||
|
QPoint p;
|
||||||
|
QRect screen = qApp->desktop()->availableGeometry(widget);
|
||||||
|
QSize sh = menu->sizeHint();
|
||||||
|
QRect rect = widget->rect();
|
||||||
|
if (widget->isRightToLeft()) {
|
||||||
|
if (widget->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) {
|
||||||
|
p = widget->mapToGlobal(rect.bottomRight());
|
||||||
|
} else {
|
||||||
|
p = widget->mapToGlobal(rect.topRight() - QPoint(0, sh.height()));
|
||||||
|
}
|
||||||
|
p.rx() -= sh.width();
|
||||||
|
} else {
|
||||||
|
if (widget->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) {
|
||||||
|
p = widget->mapToGlobal(rect.bottomLeft());
|
||||||
|
} else {
|
||||||
|
p = widget->mapToGlobal(rect.topLeft() - QPoint(0, sh.height()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width()));
|
||||||
|
p.ry() += 1;
|
||||||
|
|
||||||
|
menu->exec(p);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class Utils::FancyLineEdit
|
\class Utils::FancyLineEdit
|
||||||
@@ -111,8 +144,7 @@ bool FancyLineEditPrivate::eventFilter(QObject *obj, QEvent *event)
|
|||||||
case QEvent::FocusIn:
|
case QEvent::FocusIn:
|
||||||
if (m_menuTabFocusTrigger[buttonIndex] && m_menu[buttonIndex]) {
|
if (m_menuTabFocusTrigger[buttonIndex] && m_menu[buttonIndex]) {
|
||||||
m_lineEdit->setFocus();
|
m_lineEdit->setFocus();
|
||||||
m_menu[buttonIndex]->exec(m_iconbutton[buttonIndex]->mapToGlobal(
|
execMenuAtWidget(m_menu[buttonIndex], m_iconbutton[buttonIndex]);
|
||||||
m_iconbutton[buttonIndex]->rect().center()));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -172,7 +204,7 @@ void FancyLineEdit::iconClicked()
|
|||||||
if (index == -1)
|
if (index == -1)
|
||||||
return;
|
return;
|
||||||
if (d->m_menu[index]) {
|
if (d->m_menu[index]) {
|
||||||
d->m_menu[index]->exec(QCursor::pos());
|
execMenuAtWidget(d->m_menu[index], button);
|
||||||
} else {
|
} else {
|
||||||
emit buttonClicked((Side)index);
|
emit buttonClicked((Side)index);
|
||||||
if (index == Left)
|
if (index == Left)
|
||||||
|
|||||||
Reference in New Issue
Block a user