[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: implement StringListMenu

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Jul 3 14:24:36 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
eac090ad by Prince Gupta at 2021-07-03T12:08:21+00:00
qt: implement StringListMenu

- - - - -
7fe7a536 by Prince Gupta at 2021-07-03T12:08:21+00:00
qml/NetworkAddressBar: use native menu

- - - - -


4 changed files:

- modules/gui/qt/maininterface/mainui.cpp
- modules/gui/qt/menus/qml_menu_wrapper.cpp
- modules/gui/qt/menus/qml_menu_wrapper.hpp
- modules/gui/qt/network/qml/NetworkAddressbar.qml


Changes:

=====================================
modules/gui/qt/maininterface/mainui.cpp
=====================================
@@ -251,6 +251,7 @@ void MainUI::registerQMLTypes()
     qmlRegisterSingletonType("org.videolan.vlc", 0, 1, "PlayerListModel", PlayerControlbarModel::getPlaylistIdentifierListModel);
 
     qRegisterMetaType<QmlMainContext*>();
+    qmlRegisterType<StringListMenu>( "org.videolan.vlc", 0, 1, "StringListMenu" );
     qmlRegisterType<QmlGlobalMenu>( "org.videolan.vlc", 0, 1, "QmlGlobalMenu" );
     qmlRegisterType<QmlMenuBar>( "org.videolan.vlc", 0, 1, "QmlMenuBar" );
     qmlRegisterType<NetworkMediaContextMenu>( "org.videolan.vlc", 0, 1, "NetworkMediaContextMenu" );


=====================================
modules/gui/qt/menus/qml_menu_wrapper.cpp
=====================================
@@ -44,6 +44,24 @@ static inline void addSubMenu( QMenu *func, QString title, QMenu *bar ) {
     bar->addMenu( func);
 }
 
+
+void StringListMenu::popup(const QPoint &point, const QVariantList &stringList)
+{
+    QMenu *m = new QMenu;
+    m->setAttribute(Qt::WA_DeleteOnClose);
+
+    for (int i = 0; i != stringList.size(); ++i)
+    {
+        const auto str = stringList[i].toString();
+        m->addAction(str, this, [this, i, str]()
+        {
+            emit selected(i, str);
+        });
+    }
+
+    m->popup(point);
+}
+
 QmlGlobalMenu::QmlGlobalMenu(QObject *parent)
     : VLCMenuBar(parent)
 {


=====================================
modules/gui/qt/menus/qml_menu_wrapper.hpp
=====================================
@@ -54,6 +54,21 @@ class PlaylistListModel;
     private: \
     type m_##name = defaultValue;
 
+
+class StringListMenu : public QObject
+{
+    Q_OBJECT
+
+public:
+    using QObject::QObject;
+
+    Q_INVOKABLE void popup(const QPoint &point, const QVariantList &stringList);
+
+signals:
+    void selected(int index, const QString &str);
+};
+
+
 //inherit VLCMenuBar so we can access menu creation functions
 class QmlGlobalMenu : public VLCMenuBar
 {


=====================================
modules/gui/qt/network/qml/NetworkAddressbar.qml
=====================================
@@ -26,6 +26,8 @@ import org.videolan.vlc 0.1
 import "qrc:///style/"
 import "qrc:///widgets/" as Widgets
 
+import org.videolan.vlc 0.1
+
 Control {
     id: control
 
@@ -47,7 +49,6 @@ Control {
                               contentItem.forceActiveFocus()
 
     function changeTree(newTree) {
-        popup.close()
         history.push(["mc", "network", {
                           "tree": newTree
                       }])
@@ -124,7 +125,7 @@ Control {
             Keys.priority: Keys.AfterItem
             Keys.onPressed: Navigation.defaultKeyAction(event)
 
-            onClicked: popup.open()
+            onClicked: popup.show()
         }
 
         Repeater {
@@ -206,110 +207,21 @@ Control {
         }
     }
 
-    Popup {
+    StringListMenu {
         id: popup
 
-        y: menuButton.height + VLCStyle.margin_xxsmall
-        closePolicy: Popup.CloseOnPressOutside | Popup.CloseOnEscape
-        width: VLCStyle.dp(150, VLCStyle.scale)
-        implicitHeight: contentItem.implicitHeight + padding * 2
-        leftPadding: 0
-        rightPadding: 0
+        function show() {
+            var model = control._menuModel.map(function (modelData) {
+                return modelData.display
+            })
 
-        onOpened: {
-            updateBgRect()
+            var point = control.mapToGlobal(0, menuButton.height + VLCStyle.margin_xxsmall)
 
-            menuButton.Navigation.downItem= optionList
-            menuButton.highlighted = true
-            optionList.forceActiveFocus()
+            popup.popup(point, model)
         }
 
-        onClosed: {
-            menuButton.Navigation.downItem = null
-            menuButton.highlighted = false
-            menuButton.forceActiveFocus()
-        }
-
-        contentItem: ListView {
-            id: optionList
-
-            implicitHeight: contentHeight
-            model: control._menuModel
-            spacing: VLCStyle.margin_xxxsmall
-            delegate: ItemDelegate {
-                id: delegate
-
-                text: modelData.display
-                width: parent.width
-                background: Rectangle {
-                    color: VLCStyle.colors.accent
-                    visible: parent.hovered || parent.activeFocus
-                }
-
-                contentItem: Widgets.ListLabel {
-                    text: delegate.text
-                }
-
-                onClicked: {
-                    changeTree(modelData.tree)
-                }
-            }
-        }
-
-        function updateBgRect() {
-            glassEffect.popupGlobalPos = g_root.mapFromItem(control, popup.x, popup.y)
-        }
-
-        background: Rectangle {
-            border.width: VLCStyle.dp(1)
-            border.color: VLCStyle.colors.accent
-
-            Widgets.FrostedGlassEffect {
-                id: glassEffect
-                source: g_root
-
-                anchors.fill: parent
-                anchors.margins: VLCStyle.dp(1)
-
-                property point popupGlobalPos
-                sourceRect: Qt.rect(popupGlobalPos.x, popupGlobalPos.y,
-                                    glassEffect.width, glassEffect.height)
-
-                tint: VLCStyle.colors.bg
-                tintStrength: 0.3
-            }
-        }
-
-        Connections {
-            target: mainInterfaceRect
-
-            enabled: popup.visible
-
-            onWidthChanged: {
-                popup.updateBgRect()
-            }
-
-            onHeightChanged: {
-                popup.updateBgRect()
-            }
-        }
-
-        Connections {
-            target: mainInterface
-
-            enabled: popup.visible
-
-            onIntfScaleFactorChanged: {
-                popup.updateBgRect()
-            }
-        }
-
-        Connections {
-            target: playlistColumn
-
-            onWidthChanged: {
-                popup.updateBgRect()
-            }
+        onSelected: {
+            changeTree(control._menuModel[index].tree)
         }
     }
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/dd2456bf56ffa9abbf6d7a154cf686deffacfc54...7fe7a536a54d21b49720b9e5a542d51744238671

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/dd2456bf56ffa9abbf6d7a154cf686deffacfc54...7fe7a536a54d21b49720b9e5a542d51744238671
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list