[vlc-commits] Qt(Dialog provider): Add support for key accelerators

Erwan Tulou git at videolan.org
Sun Jul 13 13:56:37 CEST 2014


vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Fri Jul 11 17:48:06 2014 +0200| [01f2d198c11044816c1782bdfc3fe35c0ae813e2] | committer: Erwan Tulou

Qt(Dialog provider): Add support for key accelerators

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

 include/vlc_interface.h              |    1 +
 modules/gui/qt4/dialogs_provider.cpp |   78 ++++++++++++++++++++++++++++++----
 modules/gui/qt4/dialogs_provider.hpp |    7 +++
 modules/gui/qt4/menus.cpp            |   28 ++++++------
 modules/gui/qt4/menus.hpp            |    8 ++--
 5 files changed, 97 insertions(+), 25 deletions(-)

diff --git a/include/vlc_interface.h b/include/vlc_interface.h
index e98be12..d47f842 100644
--- a/include/vlc_interface.h
+++ b/include/vlc_interface.h
@@ -172,6 +172,7 @@ typedef enum vlc_dialog {
 
     INTF_DIALOG_FILE_GENERIC = 30,
     INTF_DIALOG_INTERACTION = 50,
+    INTF_DIALOG_SENDKEY = 51,
 
     INTF_DIALOG_UPDATEVLC = 90,
     INTF_DIALOG_VLM,
diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index 23c336d..5729a7f 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -34,6 +34,7 @@
 #include "menus.hpp"
 #include "recents.hpp"
 #include "util/qt_dirs.hpp"
+#include "util/customwidgets.hpp" /* VLCKeyToString() */
 #include "main_interface.hpp"
 
 /* The dialogs */
@@ -68,7 +69,11 @@
 DialogsProvider* DialogsProvider::instance = NULL;
 
 DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
-                                  QObject( NULL ), p_intf( _p_intf )
+                                  QObject( NULL ), p_intf( _p_intf ),
+                                  popupMenu( NULL ),
+                                  videoPopupMenu( NULL ),
+                                  audioPopupMenu( NULL ),
+                                  miscPopupMenu( NULL )
 {
     b_isDying = false;
 
@@ -103,10 +108,10 @@ DialogsProvider::~DialogsProvider()
     delete menusUpdateMapper;
     delete SDMapper;
 
-    VLCMenuBar::PopupMenu( p_intf, false );
-    VLCMenuBar::AudioPopupMenu( p_intf, false );
-    VLCMenuBar::VideoPopupMenu( p_intf, false );
-    VLCMenuBar::MiscPopupMenu( p_intf, false );
+    delete popupMenu;
+    delete videoPopupMenu;
+    delete audioPopupMenu;
+    delete miscPopupMenu;
 }
 
 void DialogsProvider::quit()
@@ -148,18 +153,44 @@ void DialogsProvider::customEvent( QEvent *event )
            bookmarksDialog(); break;
         case INTF_DIALOG_EXTENDED:
            extendedDialog(); break;
+        case INTF_DIALOG_SENDKEY:
+           sendKey( de->i_arg ); break;
 #ifdef ENABLE_VLM
         case INTF_DIALOG_VLM:
            vlmDialog(); break;
 #endif
         case INTF_DIALOG_POPUPMENU:
-           VLCMenuBar::PopupMenu( p_intf, (de->i_arg != 0) ); break;
+        {
+           delete popupMenu; popupMenu = NULL;
+           bool show = (de->i_arg != 0);
+           if( show )
+               popupMenu = VLCMenuBar::PopupMenu( p_intf, show );
+           break;
+        }
         case INTF_DIALOG_AUDIOPOPUPMENU:
-           VLCMenuBar::AudioPopupMenu( p_intf, (de->i_arg != 0) ); break;
+        {
+           delete audioPopupMenu; audioPopupMenu = NULL;
+           bool show = (de->i_arg != 0);
+           if( show )
+               audioPopupMenu = VLCMenuBar::AudioPopupMenu( p_intf, show );
+           break;
+        }
         case INTF_DIALOG_VIDEOPOPUPMENU:
-           VLCMenuBar::VideoPopupMenu( p_intf, (de->i_arg != 0) ); break;
+        {
+           delete videoPopupMenu; videoPopupMenu = NULL;
+           bool show = (de->i_arg != 0);
+           if( show )
+               videoPopupMenu = VLCMenuBar::VideoPopupMenu( p_intf, show );
+           break;
+        }
         case INTF_DIALOG_MISCPOPUPMENU:
-           VLCMenuBar::MiscPopupMenu( p_intf, (de->i_arg != 0) ); break;
+        {
+           delete miscPopupMenu; miscPopupMenu = NULL;
+           bool show = (de->i_arg != 0);
+           if( show )
+               miscPopupMenu = VLCMenuBar::MiscPopupMenu( p_intf, show );
+           break;
+        }
         case INTF_DIALOG_WIZARD:
         case INTF_DIALOG_STREAMWIZARD:
             openAndStreamingDialogs(); break;
@@ -760,3 +791,32 @@ void DialogsProvider::SDMenuAction( const QString& data )
         playlist_ServicesDiscoveryRemove( THEPL, qtu( data ) );
 }
 
+void DialogsProvider::sendKey( int key )
+{
+     // translate from a vlc keycode into a Qt sequence
+     QKeySequence kseq0( VLCKeyToString( key, true ) );
+
+     if( popupMenu == NULL )
+     {
+         // make sure at least a non visible popupmenu is available
+         popupMenu = VLCMenuBar::PopupMenu( p_intf, false );
+         if( unlikely( popupMenu == NULL ) )
+             return;
+     }
+
+     // test against key accelerators from the popupmenu
+     QList<QAction*> actions = popupMenu->findChildren<QAction*>();
+     for( int i = 0; i < actions.size(); i++ )
+     {
+         QAction* action = actions.at(i);
+         QKeySequence kseq = action->shortcut();
+         if( kseq == kseq0 )
+         {
+             action->trigger();
+             return;
+         }
+     }
+
+     // forward key to vlc core when not a key accelerator
+     var_SetInteger( p_intf->p_libvlc, "key-pressed", key );
+}
diff --git a/modules/gui/qt4/dialogs_provider.hpp b/modules/gui/qt4/dialogs_provider.hpp
index 990590b..a475b19 100644
--- a/modules/gui/qt4/dialogs_provider.hpp
+++ b/modules/gui/qt4/dialogs_provider.hpp
@@ -104,6 +104,12 @@ private:
     static DialogsProvider *instance;
 
     intf_thread_t *p_intf;
+
+    QMenu* popupMenu;
+    QMenu* videoPopupMenu;
+    QMenu* audioPopupMenu;
+    QMenu* miscPopupMenu;
+
     QWidget* root;
     bool b_isDying;
 
@@ -120,6 +126,7 @@ public slots:
     void extendedDialog();
     void synchroDialog();
     void messagesDialog();
+    void sendKey( int key );
 #ifdef ENABLE_VLM
     void vlmDialog();
 #endif
diff --git a/modules/gui/qt4/menus.cpp b/modules/gui/qt4/menus.cpp
index 0935346..279ff0f 100644
--- a/modules/gui/qt4/menus.cpp
+++ b/modules/gui/qt4/menus.cpp
@@ -396,7 +396,7 @@ QMenu *VLCMenuBar::FileMenu( intf_thread_t *p_intf, QWidget *parent, MainInterfa
     action->setCheckable( true );
     action->setChecked( THEMIM->getPlayExitState() );
 
-    if( mi->getSysTray() )
+    if( mi && mi->getSysTray() )
     {
         action = menu->addAction( qtr( "Close to systray"), mi,
                                  SLOT( toggleUpdateSystrayMenu() ) );
@@ -786,10 +786,7 @@ QMenu *VLCMenuBar::HelpMenu( QWidget *parent )
  * Popup menus - Right Click menus                                           *
  *****************************************************************************/
 #define POPUP_BOILERPLATE \
-    static QMenu* menu = NULL;  \
-    delete menu; menu = NULL; \
-    if( !show ) \
-        return; \
+    QMenu* menu;  \
     QVector<vlc_object_t *> objects; \
     QVector<const char *> varnames; \
     input_thread_t *p_input = THEMIM->getInput();
@@ -797,7 +794,8 @@ QMenu *VLCMenuBar::HelpMenu( QWidget *parent )
 #define CREATE_POPUP \
     menu = new QMenu(); \
     Populate( p_intf, menu, varnames, objects ); \
-    menu->popup( QCursor::pos() ); \
+    if( show ) \
+        menu->popup( QCursor::pos() ); \
 
 void VLCMenuBar::PopupMenuPlaylistEntries( QMenu *menu,
                                         intf_thread_t *p_intf,
@@ -944,25 +942,27 @@ void VLCMenuBar::PopupMenuStaticEntries( QMenu *menu )
 }
 
 /* Video Tracks and Subtitles tracks */
-void VLCMenuBar::VideoPopupMenu( intf_thread_t *p_intf, bool show )
+QMenu* VLCMenuBar::VideoPopupMenu( intf_thread_t *p_intf, bool show )
 {
     POPUP_BOILERPLATE
     if( p_input )
         VideoAutoMenuBuilder( THEPL, p_input, objects, varnames );
     CREATE_POPUP
+    return menu;
 }
 
 /* Audio Tracks */
-void VLCMenuBar::AudioPopupMenu( intf_thread_t *p_intf, bool show )
+QMenu* VLCMenuBar::AudioPopupMenu( intf_thread_t *p_intf, bool show )
 {
     POPUP_BOILERPLATE
     if( p_input )
         AudioAutoMenuBuilder( p_input, objects, varnames );
     CREATE_POPUP
+    return menu;
 }
 
 /* Navigation stuff, and general menus ( open ), used only for skins */
-void VLCMenuBar::MiscPopupMenu( intf_thread_t *p_intf, bool show )
+QMenu* VLCMenuBar::MiscPopupMenu( intf_thread_t *p_intf, bool show )
 {
     POPUP_BOILERPLATE
 
@@ -984,11 +984,13 @@ void VLCMenuBar::MiscPopupMenu( intf_thread_t *p_intf, bool show )
     menu->addSeparator();
     PopupMenuStaticEntries( menu );
 
-    menu->popup( QCursor::pos() );
+    if( show )
+        menu->popup( QCursor::pos() );
+    return menu;
 }
 
 /* Main Menu that sticks everything together  */
-void VLCMenuBar::PopupMenu( intf_thread_t *p_intf, bool show )
+QMenu* VLCMenuBar::PopupMenu( intf_thread_t *p_intf, bool show )
 {
     POPUP_BOILERPLATE
 
@@ -1113,7 +1115,9 @@ void VLCMenuBar::PopupMenu( intf_thread_t *p_intf, bool show )
     /* Static entries for ending, like open */
     PopupMenuStaticEntries( menu );
 
-    menu->popup( QCursor::pos() );
+    if( show )
+        menu->popup( QCursor::pos() );
+    return menu;
 }
 
 #undef CREATE_POPUP
diff --git a/modules/gui/qt4/menus.hpp b/modules/gui/qt4/menus.hpp
index 3b39c7b..b02e939 100644
--- a/modules/gui/qt4/menus.hpp
+++ b/modules/gui/qt4/menus.hpp
@@ -78,10 +78,10 @@ public:
     static void createMenuBar( MainInterface *mi, intf_thread_t * );
 
     /* Popups Menus */
-    static void PopupMenu( intf_thread_t *, bool );
-    static void AudioPopupMenu( intf_thread_t *, bool );
-    static void VideoPopupMenu( intf_thread_t *, bool );
-    static void MiscPopupMenu( intf_thread_t *, bool );
+    static QMenu* PopupMenu( intf_thread_t *, bool );
+    static QMenu* AudioPopupMenu( intf_thread_t *, bool );
+    static QMenu* VideoPopupMenu( intf_thread_t *, bool );
+    static QMenu* MiscPopupMenu( intf_thread_t *, bool );
 
     /* Systray */
     static void updateSystrayMenu( MainInterface *, intf_thread_t  *,



More information about the vlc-commits mailing list