-ToolBarMenu::ToolBarMenu(QWidget* parent) :
- KMenu(parent)
-{
-}
-
-ToolBarMenu::~ToolBarMenu()
-{
-}
-
-void ToolBarMenu::showEvent(QShowEvent* event)
-{
- KMenu::showEvent(event);
-
- // Adjust the position of the menu to be shown within the
- // Dolphin window to reduce the cases that sub-menus might overlap
- // the right screen border.
- QPoint pos;
- QWidget* button = parentWidget();
- if (layoutDirection() == Qt::RightToLeft) {
- pos = button->mapToGlobal(QPoint(0, button->height()));
- } else {
- pos = button->mapToGlobal(QPoint(button->width(), button->height()));
- pos.rx() -= width();
- }
-
- // 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();
- }
-
- if (pos.y() < screen.y()) {
- pos.ry() = screen.y();
- } else if (pos.y() + height() > screen.y() + screen.height()) {
- pos.ry() = button->mapToGlobal(QPoint(0, 0)).y() - height();
- }
-
- move(pos);
-}
-