[vlc-commits] [Git][videolan/vlc][master] qt/QmlMenuPositioner: Fix the QMenu positioning
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Fri May 13 08:00:37 UTC 2022
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
1f9699c6 by Benjamin Arnaud at 2022-05-13T07:36:31+00:00
qt/QmlMenuPositioner: Fix the QMenu positioning
- - - - -
1 changed file:
- modules/gui/qt/menus/qml_menu_wrapper.cpp
Changes:
=====================================
modules/gui/qt/menus/qml_menu_wrapper.cpp
=====================================
@@ -35,7 +35,9 @@
#include "playlist/playlist_model.hpp"
#include "dialogs/dialogs_provider.hpp"
+// Qt includes
#include <QSignalMapper>
+#include <QScreen>
namespace
{
@@ -386,12 +388,28 @@ bool QmlMenuPositioner::eventFilter(QObject * object, QEvent * event)
{
if (event->type() == QEvent::Resize)
{
+ QScreen * screen = QGuiApplication::screenAt(m_position);
+
+ if (screen == nullptr)
+ return QObject::eventFilter(object, event);
+
QMenu * menu = static_cast<QMenu *> (object);
- int x = m_position.x();
- int y = m_position.y();
+ int width = menu->width();
+ int height = menu->height();
+
+ QRect geometry = screen->availableGeometry();
+
+ int x = geometry.x();
+ int y = geometry.y();
+
+ // NOTE: We want a position within the screen boundaries.
+
+ x = qBound(x, m_position.x(), x + geometry.width() - width);
+
+ y = qBound(y, m_position.y() - height, y + geometry.height() - height);
- menu->move(QPoint(x, y - menu->height()));
+ menu->move(QPoint(x, y));
}
return QObject::eventFilter(object, event);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/1f9699c67e292bf0242126b0e5bccdc17b95e06b
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/1f9699c67e292bf0242126b0e5bccdc17b95e06b
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list