summaryrefslogtreecommitdiff
path: root/src/webwindow
diff options
context:
space:
mode:
Diffstat (limited to 'src/webwindow')
-rw-r--r--src/webwindow/rekonqmenu.cpp60
-rw-r--r--src/webwindow/rekonqmenu.h8
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