diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2012-11-03 09:27:38 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2012-12-10 02:48:06 +0100 |
commit | ccc770e5ae12314f18505f37d91f8b9acc3ec61c (patch) | |
tree | 6bcb6be3b27961ef9d8d9c9a7740e38dbcf39dba /src | |
parent | Fix and improve rekonq tools menu (diff) | |
download | rekonq-ccc770e5ae12314f18505f37d91f8b9acc3ec61c.tar.xz |
Fix tools menu position
Diffstat (limited to 'src')
-rw-r--r-- | src/webwindow/rekonqmenu.cpp | 60 | ||||
-rw-r--r-- | src/webwindow/rekonqmenu.h | 8 |
2 files changed, 11 insertions, 57 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); } 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 <KMenu> -// Qt Includes -#include <QWeakPointer> - // 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<QWidget> m_button; }; #endif // REKONQ_MENU_H |