fix absolute screen position for menu position
This commit is contained in:
parent
af189dff04
commit
708be449c3
@ -165,7 +165,52 @@ void QMenuProxy::open(int x, int y)
|
||||
m_menu->addAction (item);
|
||||
}
|
||||
|
||||
QPoint screenPos = QApplication::activeWindow()->mapToGlobal(QPoint(x, y));
|
||||
QPoint screenPos;
|
||||
|
||||
QGraphicsObject *parentItem;
|
||||
if (m_visualParent) {
|
||||
parentItem = qobject_cast<QGraphicsObject *>(m_visualParent.data());
|
||||
} else {
|
||||
parentItem = qobject_cast<QGraphicsObject *>(parent());
|
||||
}
|
||||
|
||||
if (!parentItem || !parentItem->scene()) {
|
||||
open(0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QGraphicsView*> views = parentItem->scene()->views();
|
||||
|
||||
if (views.size() < 1) {
|
||||
open(0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
QGraphicsView *view = 0;
|
||||
if (views.size() == 1) {
|
||||
view = views[0];
|
||||
} else {
|
||||
QGraphicsView *found = 0;
|
||||
QGraphicsView *possibleFind = 0;
|
||||
foreach (QGraphicsView *v, views) {
|
||||
if (v->sceneRect().intersects(parentItem->sceneBoundingRect()) ||
|
||||
v->sceneRect().contains(parentItem->scenePos())) {
|
||||
if (v->isActiveWindow()) {
|
||||
found = v;
|
||||
} else {
|
||||
possibleFind = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
view = found ? found : possibleFind;
|
||||
}
|
||||
|
||||
if (view) {
|
||||
screenPos = view->mapToGlobal(view->mapFromScene(parentItem->scenePos()+ QPoint(x, y)));
|
||||
} else {
|
||||
screenPos = QApplication::activeWindow()->mapToGlobal(QPoint(x, y));
|
||||
}
|
||||
|
||||
m_menu->popup(screenPos);
|
||||
m_status = DialogStatus::Open;
|
||||
emit statusChanged();
|
||||
|
Loading…
Reference in New Issue
Block a user