From ccc770e5ae12314f18505f37d91f8b9acc3ec61c Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 3 Nov 2012 09:27:38 +0100 Subject: Fix tools menu position --- src/webwindow/rekonqmenu.cpp | 60 ++++++++------------------------------------ src/webwindow/rekonqmenu.h | 8 ------ 2 files changed, 11 insertions(+), 57 deletions(-) (limited to 'src/webwindow') 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(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); } diff --git a/src/webwindow/rekonqmenu.h b/src/webwindow/rekonqmenu.h index 24aaba91..a9422dcf 100644 --- a/src/webwindow/rekonqmenu.h +++ b/src/webwindow/rekonqmenu.h @@ -36,9 +36,6 @@ // KDE Includes #include -// Qt Includes -#include - // Forward Declarations class QWidget; @@ -55,13 +52,8 @@ class REKONQ_TESTS_EXPORT RekonqMenu : public KMenu public: RekonqMenu(QWidget *parent); - void setButtonWidget(QWidget *); - protected: virtual void showEvent(QShowEvent* event); - -private: - QWeakPointer m_button; }; #endif // REKONQ_MENU_H -- cgit v1.2.1