[vlc-devel] [PATCH 04/16] Add Enable Dual Subtitles item to QT Subtitles menu

Roland Bewick roland.bewick at gmail.com
Tue May 21 20:08:28 CEST 2019


---
 modules/gui/qt/components/player_controller.cpp   | 20 +++++++++++++++++++-
 modules/gui/qt/components/player_controller.hpp   |  4 ++++
 modules/gui/qt/components/player_controller_p.hpp |  3 ++-
 modules/gui/qt/main_interface.cpp                 | 12 ++++++++++++
 modules/gui/qt/main_interface.hpp                 |  5 +++++
 modules/gui/qt/qml/menus/SubtitleMenu.qml         |  8 ++++++++
 6 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/modules/gui/qt/components/player_controller.cpp b/modules/gui/qt/components/player_controller.cpp
index 994ba6dae4..011f9916f6 100644
--- a/modules/gui/qt/components/player_controller.cpp
+++ b/modules/gui/qt/components/player_controller.cpp
@@ -607,6 +607,16 @@ static void on_player_associated_subs_fps_changed(vlc_player_t *, float subs_fps
     });
 }
 
+static void on_player_dual_subtitles_enabled_changed(vlc_player_t *, bool enabled, void *data)
+{
+    PlayerControllerPrivate* that = static_cast<PlayerControllerPrivate*>(data);
+    msg_Dbg( that->p_intf, "on_dual_subtitles_enabled_changed");
+    that->callAsync([that,enabled] (){
+        that->m_dualSubtitlesEnabled = enabled;
+        emit that->q_func()->dualSubtitlesEnabledChanged( enabled );
+    });
+}
+
 void on_player_renderer_changed(vlc_player_t *, vlc_renderer_item_t *new_item, void *data)
 {
     VLC_UNUSED(new_item);
@@ -818,7 +828,7 @@ static const struct vlc_player_cbs player_cbs = {
     on_player_audio_delay_changed,
     on_player_subtitle_delay_changed,
     on_player_associated_subs_fps_changed,
-    NULL, //on_player_dual_subtitles_enabled_changed,
+    on_player_dual_subtitles_enabled_changed,
     on_player_renderer_changed,
     on_player_record_changed,
     on_player_signal_changed,
@@ -1056,6 +1066,13 @@ void PlayerController::setSubtitleFPS(float fps)
     vlc_player_SetAssociatedSubsFPS( d->m_player, fps );
 }
 
+void PlayerController::setDualSubtitlesEnabled(bool enabled)
+{
+    Q_D(PlayerController);
+    vlc_player_locker lock{ d->m_player };
+    vlc_player_SetDualSubtitlesEnabled( d->m_player, enabled );
+}
+
 //TITLE/CHAPTER/MENU
 
 void PlayerController::sectionPrev()
@@ -1472,6 +1489,7 @@ PRIMITIVETYPE_GETTER(bool, isPausable, m_capabilities & VLC_INPUT_CAPABILITIES_P
 PRIMITIVETYPE_GETTER(bool, isRecordable, m_capabilities & VLC_INPUT_CAPABILITIES_RECORDABLE)
 PRIMITIVETYPE_GETTER(bool, isRateChangable, m_capabilities & VLC_INPUT_CAPABILITIES_CHANGE_RATE)
 PRIMITIVETYPE_GETTER(float, getSubtitleFPS, m_subtitleFPS)
+PRIMITIVETYPE_GETTER(bool, areDualSubtitlesEnabled, m_dualSubtitlesEnabled)
 PRIMITIVETYPE_GETTER(bool, hasVideoOutput, m_hasVideo)
 PRIMITIVETYPE_GETTER(float, getBuffering, m_buffering)
 PRIMITIVETYPE_GETTER(PlayerController::MediaStopAction, getMediaStopAction, m_mediaStopAction)
diff --git a/modules/gui/qt/components/player_controller.hpp b/modules/gui/qt/components/player_controller.hpp
index cdf7c8129d..dc474d836f 100644
--- a/modules/gui/qt/components/player_controller.hpp
+++ b/modules/gui/qt/components/player_controller.hpp
@@ -125,6 +125,7 @@ public:
     Q_PROPERTY(VLCTick audioDelay READ getAudioDelay WRITE setAudioDelay NOTIFY audioDelayChanged)
     Q_PROPERTY(VLCTick subtitleDelay READ getSubtitleDelay WRITE setSubtitleDelay NOTIFY subtitleDelayChanged)
     Q_PROPERTY(float subtitleFPS READ getSubtitleFPS WRITE setSubtitleFPS NOTIFY subtitleFPSChanged)
+    Q_PROPERTY(bool dualSubtitlesEnabled READ areDualSubtitlesEnabled WRITE setDualSubtitlesEnabled NOTIFY dualSubtitlesEnabledChanged)
 
     //title/chapters/menu
     Q_PROPERTY(TitleListModel* titles READ getTitles CONSTANT)
@@ -271,6 +272,8 @@ public slots:
     void setSubtitleDelay( VLCTick );
     float getSubtitleFPS( ) const;
     void setSubtitleFPS( float );
+    bool areDualSubtitlesEnabled() const;
+    void setDualSubtitlesEnabled( bool );
 
     //title/chapters/menu
     TitleListModel* getTitles();
@@ -353,6 +356,7 @@ signals:
     void audioDelayChanged(VLCTick);
     void subtitleDelayChanged(VLCTick);
     void subtitleFPSChanged(float);
+    void dualSubtitlesEnabledChanged(bool);
 
     //title/chapters/menu
     void hasTitlesChanged( bool );
diff --git a/modules/gui/qt/components/player_controller_p.hpp b/modules/gui/qt/components/player_controller_p.hpp
index 3a52205aa2..c03da62da7 100644
--- a/modules/gui/qt/components/player_controller_p.hpp
+++ b/modules/gui/qt/components/player_controller_p.hpp
@@ -91,7 +91,8 @@ public:
 
     VLCTick      m_audioDelay = 0;
     VLCTick      m_subtitleDelay = 0;
-    float           m_subtitleFPS = 1.0;
+    float        m_subtitleFPS = 1.0;
+    bool         m_dualSubtitlesEnabled = false;
 
     //title/chapters/menu
     TitleListModel m_titleList;
diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index ef185c3f25..4aa8256f51 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -130,6 +130,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ),
     i_kc_offset          = false;
     b_maximizedView      = false;
     b_isWindowTiled      = false;
+    b_dualSubtitlesEnabled = false;
 
     /**
      *  Configuration and settings
@@ -204,6 +205,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ),
         connect( THEMIM, &PlayerController::nameChanged, this, &MainInterface::setVLCWindowsTitle );
     }
     connect( THEMIM, &PlayerController::inputChanged, this, &MainInterface::onInputChanged );
+    connect( THEMIM, &PlayerController::dualSubtitlesEnabledChanged, this, &MainInterface::setDualSubtitlesEnabled);
 
     /* END CONNECTS ON IM */
 
@@ -550,6 +552,16 @@ void MainInterface::setInterfaceAlwaysOnTop( bool on_top )
     emit interfaceAlwaysOnTopChanged(on_top);
 }
 
+void MainInterface::setDualSubtitlesEnabled( bool enabled )
+{
+    if( b_dualSubtitlesEnabled != enabled )
+    {
+        b_dualSubtitlesEnabled = enabled;
+        THEMIM->setDualSubtitlesEnabled(enabled);
+        emit dualSubtitlesEnabledChanged(enabled);
+    }
+}
+
 /* Asynchronous calls for video window contrlos */
 int MainInterface::enableVideo( vout_window_t *p_wnd,
                                  const vout_window_cfg_t *cfg )
diff --git a/modules/gui/qt/main_interface.hpp b/modules/gui/qt/main_interface.hpp
index 3ceb91b40f..eab8500db9 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -66,6 +66,7 @@ class MainInterface : public QVLCMW
     Q_PROPERTY(bool interfaceAlwaysOnTop READ isInterfaceAlwaysOnTop WRITE setInterfaceAlwaysOnTop NOTIFY interfaceAlwaysOnTopChanged)
     Q_PROPERTY(bool interfaceFullScreen READ isInterfaceFullScreen WRITE setInterfaceFullScreen NOTIFY interfaceFullScreenChanged)
     Q_PROPERTY(bool hasEmbededVideo READ hasEmbededVideo NOTIFY hasEmbededVideoChanged)
+    Q_PROPERTY(bool dualSubtitlesEnabled READ areDualSubtitlesEnabled WRITE setDualSubtitlesEnabled NOTIFY dualSubtitlesEnabledChanged)
     Q_PROPERTY(VLCVarChoiceModel* extraInterfaces READ getExtraInterfaces CONSTANT)
 
 public:
@@ -113,6 +114,7 @@ public:
     bool isInterfaceFullScreen() { return b_interfaceFullScreen; }
     bool isInterfaceAlwaysOnTop() { return b_interfaceOnTop; }
     bool hasEmbededVideo() { return m_hasEmbededVideo; }
+    bool areDualSubtitlesEnabled() { return b_dualSubtitlesEnabled; }
     QList<QQmlError> qmlErrors() const;
 
 protected:
@@ -137,6 +139,7 @@ protected:
 
     /* */
     void setInterfaceFullScreen( bool );
+    void setDualSubtitlesEnabled( bool );
     void computeMinimumSize();
 
     /* */
@@ -187,6 +190,7 @@ protected:
     bool                 b_plDocked;            ///< Is the playlist docked ?
 
     bool                 b_hasPausedWhenMinimized;
+    bool                 b_dualSubtitlesEnabled;
 
     static const Qt::Key kc[10]; /* easter eggs */
     int i_kc_offset;
@@ -245,6 +249,7 @@ signals:
     void interfaceAlwaysOnTopChanged(bool);
     void interfaceFullScreenChanged(bool);
     void hasEmbededVideoChanged(bool);
+    void dualSubtitlesEnabledChanged(bool);
 };
 
 #endif
diff --git a/modules/gui/qt/qml/menus/SubtitleMenu.qml b/modules/gui/qt/qml/menus/SubtitleMenu.qml
index 7ac1a9da29..0c74076516 100644
--- a/modules/gui/qt/qml/menus/SubtitleMenu.qml
+++ b/modules/gui/qt/qml/menus/SubtitleMenu.qml
@@ -32,4 +32,12 @@ Utils.MenuExt {
         enabled: player.isPlaying
         model: player.subtitleTracks
     }
+
+    Action {
+        text: qsTr("&Enable Dual Subtitles")
+        checkable: true
+        enabled: player.isPlaying
+        checked: rootWindow.dualSubtitlesEnabled
+        onTriggered: rootWindow.dualSubtitlesEnabled = !rootWindow.dualSubtitlesEnabled
+    }
 }
-- 
2.11.0



More information about the vlc-devel mailing list