[vlc-commits] [Git][videolan/vlc][master] 5 commits: qt/qml_menu_wrapper: Create QmlMenuPositioner
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Mon Apr 25 06:43:05 UTC 2022
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
7ca5c99b by Benjamin Arnaud at 2022-04-25T06:07:27+00:00
qt/qml_menu_wrapper: Create QmlMenuPositioner
- - - - -
b0eef8d6 by Benjamin Arnaud at 2022-04-25T06:07:27+00:00
qt/QmlBookmarkMenu: Add the 'above' implementation
- - - - -
02300755 by Benjamin Arnaud at 2022-04-25T06:07:27+00:00
qt/QmlRendererMenu: Add the 'above' implementation
- - - - -
2813007e by Benjamin Arnaud at 2022-04-25T06:07:27+00:00
qml/BookmarkButton: Update menu placement
- - - - -
803ba0d8 by Benjamin Arnaud at 2022-04-25T06:07:27+00:00
qml/RendererButton: Update menu placement
- - - - -
4 changed files:
- modules/gui/qt/menus/qml_menu_wrapper.cpp
- modules/gui/qt/menus/qml_menu_wrapper.hpp
- modules/gui/qt/player/qml/controlbarcontrols/BookmarkButton.qml
- modules/gui/qt/player/qml/controlbarcontrols/RendererButton.qml
Changes:
=====================================
modules/gui/qt/menus/qml_menu_wrapper.cpp
=====================================
@@ -384,6 +384,48 @@ void QmlMenuBar::onMenuClosed()
emit menuClosed();
}
+// QmlMenuPositioner
+
+/* explicit */ QmlMenuPositioner::QmlMenuPositioner(QObject * parent) : QObject(parent) {}
+
+// Interface
+
+void QmlMenuPositioner::popup(QMenu * menu, const QPoint & position, bool above)
+{
+ menu->removeEventFilter(this);
+
+ if (above == false)
+ {
+ menu->popup(position);
+
+ return;
+ }
+
+ m_position = position;
+
+ menu->installEventFilter(this);
+
+ // NOTE: QMenu::height() returns an invalid height until the initial popup call.
+ menu->popup(position);
+}
+
+// Public events
+
+bool QmlMenuPositioner::eventFilter(QObject * object, QEvent * event)
+{
+ if (event->type() == QEvent::Resize)
+ {
+ QMenu * menu = static_cast<QMenu *> (object);
+
+ int x = m_position.x();
+ int y = m_position.y();
+
+ menu->move(QPoint(x, y - menu->height()));
+ }
+
+ return QObject::eventFilter(object, event);
+}
+
// QmlBookmarkMenu
/* explicit */ QmlBookmarkMenu::QmlBookmarkMenu(QObject * parent) : QObject(parent) {}
@@ -396,7 +438,7 @@ QmlBookmarkMenu::~QmlBookmarkMenu()
// Interface
-/* Q_INVOKABLE */ void QmlBookmarkMenu::popup(QPoint pos)
+/* Q_INVOKABLE */ void QmlBookmarkMenu::popup(const QPoint & position, bool above)
{
if (m_ctx == nullptr || m_player == nullptr)
return;
@@ -468,7 +510,7 @@ QmlBookmarkMenu::~QmlBookmarkMenu()
bookmarks->select(bookmarks->index(index, 0));
});
- m_menu->popup(pos);
+ m_positioner.popup(m_menu, position, above);
}
// QmlRendererMenu
@@ -483,7 +525,7 @@ QmlRendererMenu::~QmlRendererMenu()
// Interface
-/* Q_INVOKABLE */ void QmlRendererMenu::popup(QPoint pos)
+/* Q_INVOKABLE */ void QmlRendererMenu::popup(const QPoint & position, bool above)
{
if (m_ctx == nullptr)
return;
@@ -496,7 +538,7 @@ QmlRendererMenu::~QmlRendererMenu()
connect(m_menu, &QMenu::aboutToHide, this, &QmlRendererMenu::aboutToHide);
connect(m_menu, &QMenu::aboutToShow, this, &QmlRendererMenu::aboutToShow);
- m_menu->popup(pos);
+ m_positioner.popup(m_menu, position, above);
}
BaseMedialibMenu::BaseMedialibMenu(QObject* parent)
=====================================
modules/gui/qt/menus/qml_menu_wrapper.hpp
=====================================
@@ -180,6 +180,21 @@ private:
QmlMenuBar* m_menubar = nullptr;
};
+class QmlMenuPositioner : public QObject
+{
+public:
+ explicit QmlMenuPositioner(QObject * parent = nullptr);
+
+public: // Interface
+ void popup(QMenu * menu, const QPoint & position, bool above);
+
+public: // Events
+ bool eventFilter(QObject * object, QEvent * event);
+
+private:
+ QPoint m_position;
+};
+
class QmlBookmarkMenu : public QObject
{
Q_OBJECT
@@ -194,13 +209,15 @@ public:
~QmlBookmarkMenu();
public: // Interface
- Q_INVOKABLE void popup(QPoint pos);
+ Q_INVOKABLE void popup(const QPoint & position, bool above = false);
signals:
void aboutToHide();
void aboutToShow();
private:
+ QmlMenuPositioner m_positioner;
+
QMenu * m_menu = nullptr;
};
@@ -216,13 +233,15 @@ public:
~QmlRendererMenu();
public: // Interface
- Q_INVOKABLE void popup(QPoint pos);
+ Q_INVOKABLE void popup(const QPoint & position, bool above = false);
signals:
void aboutToHide();
void aboutToShow();
private:
+ QmlMenuPositioner m_positioner;
+
RendererMenu * m_menu = nullptr;
};
=====================================
modules/gui/qt/player/qml/controlbarcontrols/BookmarkButton.qml
=====================================
@@ -31,8 +31,8 @@ Widgets.IconControlButton {
iconText: VLCIcons.bookmark
text: I18n.qtr("Bookmarks")
- // NOTE: We want to pop the menu after the button.
- onClicked: menu.popup(this.mapToGlobal(width, 0))
+ // NOTE: We want to pop the menu above the button.
+ onClicked: menu.popup(this.mapToGlobal(0, 0), true)
QmlBookmarkMenu {
id: menu
=====================================
modules/gui/qt/player/qml/controlbarcontrols/RendererButton.qml
=====================================
@@ -31,8 +31,8 @@ Widgets.IconControlButton {
iconText: VLCIcons.renderer
text: I18n.qtr("Renderer")
- // NOTE: We want to pop the menu after the button.
- onClicked: menu.popup(this.mapToGlobal(width, 0))
+ // NOTE: We want to pop the menu above the button.
+ onClicked: menu.popup(this.mapToGlobal(0, 0), true)
QmlRendererMenu {
id: menu
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/26a7249a5c7e1fa7a3247f40e149b2c89433a695...803ba0d8ed7e112b74cd1521c9b32e9ccec76101
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/26a7249a5c7e1fa7a3247f40e149b2c89433a695...803ba0d8ed7e112b74cd1521c9b32e9ccec76101
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