diff options
Diffstat (limited to 'src/webwindow/rekonqmenu.cpp')
-rw-r--r-- | src/webwindow/rekonqmenu.cpp | 60 |
1 files changed, 11 insertions, 49 deletions
diff --git a/src/webwindow/rekonqmenu.cpp b/src/webwindow/rekonqmenu.cpp index 6973a1b7..a89d883e 100644 --- a/src/webwindow/rekonqmenu.cpp +++ b/src/webwindow/rekonqmenu.cpp @@ -41,63 +41,25 @@ RekonqMenu::RekonqMenu(QWidget *parent) } -void RekonqMenu::setButtonWidget(QWidget *w) -{ - m_button = w; -} - - void RekonqMenu::showEvent(QShowEvent* event) { KMenu::showEvent(event); - if (m_button.isNull()) - return; - - kDebug() << "but: " << m_button.data(); - kDebug() << "but w: " << m_button.data()->width(); - kDebug() << "but h: " << m_button.data()->height(); - // Adjust the position of the menu to be shown within the // rekonq window to reduce the cases that sub-menus might overlap // the right screen border. - QPoint pos; - if (layoutDirection() == Qt::RightToLeft) - { - pos = m_button.data()->mapToGlobal(QPoint(0, m_button.data()->height())); - } - else - { - pos = m_button.data()->mapToGlobal(QPoint(m_button.data()->width(), m_button.data()->height())); - pos.rx() -= width(); - } + QPoint position = pos(); + int y = position.y(); - // Assure that the menu is not shown outside the screen boundaries and - // that it does not overlap with the parent button. - const QRect screen = QApplication::desktop()->screenGeometry(QCursor::pos()); - if (pos.x() < screen.x()) - { - pos.rx() = screen.x(); - } - else - { - if (pos.x() + width() > screen.x() + screen.width()) - { - pos.rx() = screen.x() + screen.width() - width(); - } - } + int w = width(); - if (pos.y() < screen.y()) - { - pos.ry() = screen.y(); - } - else - { - if (pos.y() + height() > screen.y() + screen.height()) - { - pos.ry() = m_button.data()->mapToGlobal(QPoint(0, 0)).y() + height(); - } - } + QWidget *parentWidget = qobject_cast<QWidget *>(parent()); + QPoint widgetGlobalPos = parentWidget->mapToGlobal(QPoint(0,0)); + int pw = parentWidget->width(); + int px = widgetGlobalPos.x(); + + QPoint newPosition = QPoint(px + pw - w, y); - move(pos); + // Finally, move it there... + move(newPosition); } |