[vlc-devel] commit: Qt: allow loop/repeat button to be in a toolbar (part 2) ( Jean-Baptiste Kempf )

git version control git at videolan.org
Fri Dec 4 07:21:47 CET 2009


vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Sun Nov 29 23:16:16 2009 +0100| [6b65c19e602b04d0b5bba4febf9ea95eca404c72] | committer: Jean-Baptiste Kempf 

Qt: allow loop/repeat button to be in a toolbar (part 2)

Action and states consistency

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

 modules/gui/qt4/components/controller.cpp        |    4 ++
 modules/gui/qt4/components/controller_widget.cpp |   21 ++-------
 modules/gui/qt4/components/controller_widget.hpp |    4 +-
 modules/gui/qt4/input_manager.cpp                |   57 ++++++++++++++++++++++
 modules/gui/qt4/input_manager.hpp                |   11 ++++
 5 files changed, 78 insertions(+), 19 deletions(-)

diff --git a/modules/gui/qt4/components/controller.cpp b/modules/gui/qt4/components/controller.cpp
index 4c5ffc0..0f688be 100644
--- a/modules/gui/qt4/components/controller.cpp
+++ b/modules/gui/qt4/components/controller.cpp
@@ -372,6 +372,10 @@ QWidget *AbstractController::createWidget( buttonType_e button, int options )
         setupButton( loopButton );
         loopButton->setToolTip( qtr( "Click to toggle between loop one, loop all" ) );
         loopButton->setCheckable( true );
+        loopButton->updateIcons( NORMAL );
+        CONNECT( THEMIM, repeatLoopChanged( int ), loopButton, updateIcons( int ) );
+        CONNECT( loopButton, clicked(), THEMIM, loopRepeatLoopStatus() );
+        widget = loopButton;
         }
         break;
     default:
diff --git a/modules/gui/qt4/components/controller_widget.cpp b/modules/gui/qt4/components/controller_widget.cpp
index c7746ac..aa377ba 100644
--- a/modules/gui/qt4/components/controller_widget.cpp
+++ b/modules/gui/qt4/components/controller_widget.cpp
@@ -235,22 +235,9 @@ void AtoB_Button::setIcons( bool timeA, bool timeB )
     }
 }
 
-void LoopButton::update()
+void LoopButton::updateIcons( int value )
 {
-/*    if( model->hasRepeat() )
-    {
-        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) );
-        repeatButton->setChecked( true );
-    }
-    else if( model->hasLoop() )
-    {
-        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_all" ) );
-        repeatButton->setChecked( true );
-    }
-    else
-    {
-        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) );
-        repeatButton->setChecked( false );
-    }*/
-    //BUTTONACT( repeatButton, toggleRepeat() );
+    setChecked( value != NORMAL );
+    setIcon( ( value == REPEAT_ALL ) ? QIcon( ":/buttons/playlist/repeat_all" )
+                                     : QIcon( ":/buttons/playlist/repeat_one" ) );
 }
diff --git a/modules/gui/qt4/components/controller_widget.hpp b/modules/gui/qt4/components/controller_widget.hpp
index 092730b..9714c05 100644
--- a/modules/gui/qt4/components/controller_widget.hpp
+++ b/modules/gui/qt4/components/controller_widget.hpp
@@ -56,8 +56,8 @@ private slots:
 class LoopButton : public QToolButton
 {
     Q_OBJECT
-private slots:
-    void update();
+public slots:
+    void updateIcons( int );
 };
 
 class AtoB_Button : public QToolButton
diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp
index 7f65ff0..177b0b1 100644
--- a/modules/gui/qt4/input_manager.cpp
+++ b/modules/gui/qt4/input_manager.cpp
@@ -48,6 +48,10 @@ static int VolumeChanged( vlc_object_t *, const char *,
 
 static int RandomChanged( vlc_object_t *, const char *,
                         vlc_value_t, vlc_value_t, void * );
+static int LoopChanged( vlc_object_t *, const char *,
+                        vlc_value_t, vlc_value_t, void * );
+static int RepeatChanged( vlc_object_t *, const char *,
+                        vlc_value_t, vlc_value_t, void * );
 
 
 static int InputEvent( vlc_object_t *, const char *,
@@ -893,6 +897,8 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
     var_AddCallback( THEPL, "playlist-item-append", PLItemAppended, this );
     var_AddCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
     var_AddCallback( THEPL, "random", RandomChanged, this );
+    var_AddCallback( THEPL, "repeat", RepeatChanged, this );
+    var_AddCallback( THEPL, "loop", LoopChanged, this );
 
     var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
 
@@ -932,6 +938,10 @@ MainInputManager::~MainInputManager()
     var_DelCallback( THEPL, "item-current", PLItemChanged, this );
     var_DelCallback( THEPL, "playlist-item-append", PLItemAppended, this );
     var_DelCallback( THEPL, "playlist-item-deleted", PLItemRemoved, this );
+    var_DelCallback( THEPL, "random", RandomChanged, this );
+    var_DelCallback( THEPL, "repeat", RepeatChanged, this );
+    var_DelCallback( THEPL, "loop", LoopChanged, this );
+
 }
 
 vout_thread_t* MainInputManager::getVout()
@@ -967,6 +977,10 @@ void MainInputManager::customEvent( QEvent *event )
     case RandomChanged_Type:
         emit randomChanged( var_GetBool( THEPL, "random" ) );
         return;
+    case LoopChanged_Type:
+    case RepeatChanged_Type:
+        notifyRepeatLoop();
+        return;
     default:
         if( type != ItemChanged_Type ) return;
     }
@@ -1042,6 +1056,28 @@ void MainInputManager::toggleRandom()
     var_ToggleBool( THEPL, "random" );
 }
 
+void MainInputManager::notifyRepeatLoop()
+{
+    int i_value = var_GetBool( THEPL, "loop" ) * REPEAT_ONE
+              + var_GetBool( THEPL, "repeat" ) * REPEAT_ALL;
+
+    emit repeatLoopChanged( i_value );
+}
+
+void MainInputManager::loopRepeatLoopStatus()
+{
+    /* Toggle Normal -> Loop -> Repeat -> Normal ... */
+    if( var_GetBool( THEPL, "repeat" ) )
+        var_SetBool( THEPL, "repeat", false );
+    else if( var_GetBool( THEPL, "loop" ) )
+    {
+        var_SetBool( THEPL, "loop", false );
+        var_SetBool( THEPL, "repeat", true );
+    }
+    else
+        var_SetBool( THEPL, "loop", true );
+}
+
 void MainInputManager::activatePlayQuit( bool b_exit )
 {
     var_SetBool( THEPL, "play-and-exit", b_exit );
@@ -1097,3 +1133,24 @@ static int RandomChanged
     QApplication::postEvent( mim, event );
     return VLC_SUCCESS;
 }
+
+/* Probably could be merged with next callback */
+static int LoopChanged
+( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
+{
+    MainInputManager *mim = static_cast<MainInputManager*>(data);
+
+    IMEvent *event = new IMEvent( LoopChanged_Type );
+    QApplication::postEvent( mim, event );
+    return VLC_SUCCESS;
+}
+
+static int RepeatChanged
+( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
+{
+    MainInputManager *mim = static_cast<MainInputManager*>(data);
+
+    IMEvent *event = new IMEvent( RepeatChanged_Type );
+    QApplication::postEvent( mim, event );
+    return VLC_SUCCESS;
+}
diff --git a/modules/gui/qt4/input_manager.hpp b/modules/gui/qt4/input_manager.hpp
index 98f5c1d..03a7f35 100644
--- a/modules/gui/qt4/input_manager.hpp
+++ b/modules/gui/qt4/input_manager.hpp
@@ -58,6 +58,8 @@ enum {
     RecordingEvent_Type,
     ProgramChanged_Type,
     RandomChanged_Type,
+    LoopChanged_Type,
+    RepeatChanged_Type,
 /*    SignalChanged_Type, */
 
     FullscreenControlToggle_Type = QEvent::User + IMEventType + 20,
@@ -66,6 +68,11 @@ enum {
     FullscreenControlPlanHide_Type,
 };
 
+enum { NORMAL,    /* loop: 0, repeat: 0 */
+       REPEAT_ONE,/* loop: 1, repeat: 0 */
+       REPEAT_ALL,/* loop: 0, repeat: 1 */
+};
+
 class IMEvent : public QEvent
 {
 friend class InputManager;
@@ -257,6 +264,7 @@ private:
     input_thread_t          *p_input;
     intf_thread_t           *p_intf;
 
+    void notifyRepeatLoop();
 public slots:
     void togglePlayPause();
     void toggleRandom();
@@ -265,12 +273,15 @@ public slots:
     void prev();
     void activatePlayQuit( bool );
 
+    void loopRepeatLoopStatus();
+
 signals:
     void inputChanged( input_thread_t * );
     void volumeChanged();
     void playlistItemAppended( int itemId, int parentId );
     void playlistItemRemoved( int itemId );
     void randomChanged( bool );
+    void repeatLoopChanged( int );
 };
 
 #endif




More information about the vlc-devel mailing list