[vlc-commits] qt: uniformize menu creation

Pierre Lamot git at videolan.org
Mon Oct 12 11:45:09 CEST 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Mon Oct  5 16:05:44 2020 +0200| [d3f65b6027623462407832b71f159fdb4539f78c] | committer: Pierre Lamot

qt: uniformize menu creation

  all menus can be created by passing a given QMenu

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d3f65b6027623462407832b71f159fdb4539f78c
---

 modules/gui/qt/menus/menus.cpp            |  6 ++----
 modules/gui/qt/menus/menus.hpp            | 10 ++++++++--
 modules/gui/qt/menus/qml_menu_wrapper.cpp |  8 ++++----
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/modules/gui/qt/menus/menus.cpp b/modules/gui/qt/menus/menus.cpp
index aceeb6dade..f846e2a3a7 100644
--- a/modules/gui/qt/menus/menus.cpp
+++ b/modules/gui/qt/menus/menus.cpp
@@ -201,9 +201,8 @@ void VLCMenuBar::createMenuBar( MainInterface *mi,
  * Media ( File ) Menu
  * Opening, streaming and quit
  **/
-QMenu *VLCMenuBar::FileMenu( intf_thread_t *p_intf, QWidget *parent, MainInterface *mi )
+QMenu *VLCMenuBar::FileMenu( intf_thread_t *p_intf, QMenu *menu, MainInterface *mi )
 {
-    QMenu *menu = new QMenu( parent );
     QAction *action;
 
     addDPStaticEntry( menu, qtr( "Open &File..." ),
@@ -575,9 +574,8 @@ QMenu *VLCMenuBar::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
 /**
  * Help/About Menu
 **/
-QMenu *VLCMenuBar::HelpMenu( QWidget *parent )
+QMenu *VLCMenuBar::HelpMenu( QMenu *menu )
 {
-    QMenu *menu = new QMenu( parent );
     addDPStaticEntry( menu, qtr( "&Help" ) ,
         ":/menu/help.svg", &DialogsProvider::helpDialog, "F1" );
 #ifdef UPDATE_CHECK
diff --git a/modules/gui/qt/menus/menus.hpp b/modules/gui/qt/menus/menus.hpp
index 9af7c349b7..d434f54788 100644
--- a/modules/gui/qt/menus/menus.hpp
+++ b/modules/gui/qt/menus/menus.hpp
@@ -61,7 +61,10 @@ public:
 
 protected:
     /* All main Menus */
-    static QMenu *FileMenu( intf_thread_t *, QWidget *, MainInterface * mi = NULL );
+    static QMenu *FileMenu( intf_thread_t *, QMenu *, MainInterface * mi = NULL );
+    static QMenu *FileMenu( intf_thread_t *p_intf, QWidget * parent, MainInterface * mi = NULL ){
+        return FileMenu(p_intf, new QMenu(parent), mi);
+    }
 
     static QMenu *ToolsMenu( intf_thread_t *, QMenu * );
     static QMenu *ToolsMenu( intf_thread_t * p_intf, QWidget *parent )
@@ -92,7 +95,10 @@ protected:
         return AudioMenu( p_intf, new QMenu( parent ) );
     }
 
-    static QMenu *HelpMenu( QWidget * );
+    static QMenu *HelpMenu( QMenu *menu );
+    static QMenu *HelpMenu( QWidget *parent ) {
+        return HelpMenu( new QMenu( parent ) );
+    }
 
     /* Popups Menus */
     static void PopupMenuStaticEntries( QMenu *menu );
diff --git a/modules/gui/qt/menus/qml_menu_wrapper.cpp b/modules/gui/qt/menus/qml_menu_wrapper.cpp
index ecd98bbf34..01a85ba730 100644
--- a/modules/gui/qt/menus/qml_menu_wrapper.cpp
+++ b/modules/gui/qt/menus/qml_menu_wrapper.cpp
@@ -66,8 +66,8 @@ void QmlGlobalMenu::popup(QPoint pos)
     m_menu = new QMenu();
     QMenu* submenu;
 
-    QAction* fileMenu = m_menu->addMenu(FileMenu( p_intf, m_menu, p_intf->p_sys->p_mi ));
-    fileMenu->setText(qtr( "&Media" ));
+    submenu = m_menu->addMenu(qtr( "&Media" ));
+    FileMenu( p_intf, submenu, p_intf->p_sys->p_mi );
 
     /* Dynamic menus, rebuilt before being showed */
     submenu = m_menu->addMenu(qtr( "P&layback" ));
@@ -89,8 +89,8 @@ void QmlGlobalMenu::popup(QPoint pos)
     submenu = m_menu->addMenu(qtr( "V&iew" ));
     ViewMenu( p_intf, submenu, p_intf->p_sys->p_mi );
 
-    QAction* helpMenu = m_menu->addMenu( HelpMenu(m_menu) );
-    helpMenu->setText(qtr( "&Help" ));
+    submenu = m_menu->addMenu(qtr( "&Help" ));
+    HelpMenu(submenu);
 
     m_menu->popup(pos);
 }



More information about the vlc-commits mailing list