From 4f9f85cee93ebd226bf596f71ba9941a48596547 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 20 Mar 2009 22:17:44 +0000 Subject: [PATCH] don't let the popups escape from their containment resolves part of 184983 CCBUG:184983 svn path=/trunk/KDE/kdelibs/; revision=942063 --- corona.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/corona.cpp b/corona.cpp index 8c3edab21..6346c0515 100644 --- a/corona.cpp +++ b/corona.cpp @@ -494,16 +494,42 @@ QPoint Corona::popupPosition(const QGraphicsItem *item, const QSize &s) switch (loc) { case BottomEdge: - pos = QPoint(pos.x(), v->geometry().y() - s.height()); + case TopEdge: { + //TODO: following line makes them centered. + //could make it better or worse, must be decided + //pos.setX(pos.x() + item->boundingRect().width()/2 - s.width()/2); + if (pos.x() + s.width() > v->geometry().right()) { + pos.setX(v->geometry().right() - s.width()); + } else { + pos.setX(qMax(pos.x(), v->geometry().left())); + } + break; + } + case LeftEdge: + case RightEdge: { + //pos.setY(pos.y() + item->boundingRect().height()/2 - s.height()/2); + if (pos.y() + s.height() > v->geometry().bottom()) { + pos.setY(v->geometry().bottom() - s.height()); + } else { + pos.setY(qMax(pos.y(), v->geometry().top())); + } + break; + } + default: + break; + } + switch (loc) { + case BottomEdge: + pos.setY(v->geometry().y() - s.height()); break; case TopEdge: - pos = QPoint(pos.x(), v->geometry().bottom()); + pos.setY(v->geometry().bottom()); break; case LeftEdge: - pos = QPoint(v->geometry().right(), pos.y()); + pos.setX(v->geometry().right()); break; case RightEdge: - pos = QPoint(v->geometry().x() - s.width(), pos.y()); + pos.setX(v->geometry().x() - s.width()); break; default: if (pos.y() - s.height() > 0) {