]> git.sesse.net Git - vlc/commitdiff
Some cleanup, start integrating audio visualizations
authorClément Stenac <zorglub@videolan.org>
Fri, 22 Sep 2006 15:20:02 +0000 (15:20 +0000)
committerClément Stenac <zorglub@videolan.org>
Fri, 22 Sep 2006 15:20:02 +0000 (15:20 +0000)
modules/gui/qt4/components/interface_widgets.cpp
modules/gui/qt4/input_manager.hpp
modules/gui/qt4/main_interface.cpp
modules/gui/qt4/main_interface.hpp
modules/gui/qt4/ui/main_interface.ui

index 2e5e81c307b06b2a6ab919281be414da239ffedc..5815ebffedac18dd8cb4cf93153f60e425633194 100644 (file)
@@ -150,12 +150,13 @@ VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
 {
     setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
     QHBoxLayout *layout = new QHBoxLayout( this );
+    layout->setMargin( 0 );
     QPushButton *prevButton = new QPushButton( "Prev" );
     QPushButton *nextButton = new QPushButton( "Next");
     layout->addWidget( prevButton );
     layout->addWidget( nextButton );
     setLayout( layout );
-    setMaximumHeight( 30 );
+    setMaximumHeight( 35 );
 }
 
 VisualSelector::~VisualSelector()
index 60ef8175ad652e9cc920a6a98734f7ca4210f5bd..0f9427bf288c232608dce8a102c7d8add4923f18 100644 (file)
@@ -35,6 +35,8 @@ public:
     virtual ~InputManager();
 
     void delInput();
+    bool hasAudio() { return b_has_audio; }
+    bool hasVideo() { return b_has_video; }
     bool b_has_audio, b_has_video, b_had_audio, b_had_video;
 private:
     intf_thread_t *p_intf;
index 33888fae5bb6cac530b9a550e6b30b0439ef43ab..e3ff231d2b67292169be46ab8717461ed8cdd936 100644 (file)
     ui.button##Button->setIcon( QIcon( ":/pixmaps/"#image ) ); \
     ui.button##Button->setToolTip( tooltip );
 
+#define VISIBLE(i) (i && i->isVisible())
+
+#define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
+#define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
+#define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
+
+#define DS(i) i.width(),i.height()
+
 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
                              vlc_value_t, void *);
 /* Video handling */
@@ -110,13 +118,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     CONNECT( slider, sliderDragged( float ),
              THEMIM->getIM(), sliderUpdate( float ) );
 
-    /* Actions */
-    BUTTONACT( ui.playButton, play() );
-    BUTTONACT( ui.stopButton, stop() );
-    BUTTONACT( ui.nextButton, next() );
-    BUTTONACT( ui.prevButton, prev() );
-    BUTTONACT( ui.playlistButton, playlist() );
-
     var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
     var_AddCallback( p_intf, "interaction", InteractCallback, this );
     p_intf->b_interaction = VLC_TRUE;
@@ -143,28 +144,23 @@ void MainInterface::handleMainUi( QSettings *settings )
     ui.hboxLayout->insertWidget( 0, slider );
 
     BUTTON_SET( prev, previous.png, qtr( "Previous" ) );
+    BUTTONACT( ui.prevButton, prev() );
     BUTTON_SET( next, next.png , qtr( "Next" ) );
+    BUTTONACT( ui.nextButton, next() );
     BUTTON_SET( play, play.png , qtr( "Play" ) );
+    BUTTONACT( ui.playButton, play() );
     BUTTON_SET( stop, stop.png , qtr( "Stop" )  );
-    ui.discFrame->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
+    BUTTONACT( ui.stopButton, stop() );
 
-#define SET( button, image ) ui.button##Button->setText(""); \
-    ui.button##Button->setIcon( QIcon( ":/pixmaps/"#image ) );
-    SET( prev, previous.png );
-    SET( next, next.png );
-    SET( play, play.png );
-    SET( stop, stop.png );
-    SET( playlist, volume-low.png );
-#undef SET
+    BUTTON_SET( visual,  stop.png, qtr( "Audio visualizations" ) );
+    BUTTONACT( ui.visualButton, visual() );
 
     /* Volume */
-    ui.volLowLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
-    ui.volHighLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
+    ui.volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
     ui.volumeSlider->setMaximum( 100 );
-
-    VolumeClickHandler *h = new VolumeClickHandler( this );
-    ui.volLowLabel->installEventFilter(h);
-    ui.volHighLabel->installEventFilter(h);
+    ui.volMuteLabel->setToolTip( qtr( "Mute" ) );
+    VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
+    ui.volMuteLabel->installEventFilter(h);
     ui.volumeSlider->setFocusPolicy( Qt::NoFocus );
 
     /* Fetch configuration from settings and vlc config */
@@ -172,16 +168,37 @@ void MainInterface::handleMainUi( QSettings *settings )
     if( config_GetInt( p_intf, "embedded-video" ) )
         videoEmbeddedFlag = true;
 
+    alwaysVideoFlag = false;
+    if( videoEmbeddedFlag && config_GetInt( p_intf, "qt-always-video" ))
+        alwaysVideoFlag = true;
+
     playlistEmbeddedFlag = true;
     /// \todo fetch playlist settings
+
     BUTTON_SET( playlist, volume-low.png, playlistEmbeddedFlag ?
                                                 qtr( "Show playlist" ) :
                                                 qtr( "Open playlist" ) );
+    BUTTONACT( ui.playlistButton, playlist() );
 
     /* Set initial size */
     resize ( PREF_W, PREF_H );
 
     addSize = QSize( ui.vboxLayout->margin() * 2, PREF_H );
+
+    visualSelector = new VisualSelector( p_intf );
+    ui.vboxLayout->insertWidget( 0, visualSelector );
+    visualSelector->hide();
+
+    if( alwaysVideoFlag )
+    {
+        bgWidget = new BackgroundWidget( p_intf );
+        bgWidget->widgetSize = settings->value( "backgroundSize",
+                                                QSize( 200, 200 ) ).toSize();
+        bgWidget->resize( bgWidget->widgetSize );
+        bgWidget->updateGeometry();
+        ui.vboxLayout->insertWidget( 0, bgWidget );
+    }
+
     if( videoEmbeddedFlag )
     {
         videoWidget = new VideoWidget( p_intf );
@@ -192,22 +209,10 @@ void MainInterface::handleMainUi( QSettings *settings )
         p_intf->pf_request_window  = ::DoRequest;
         p_intf->pf_release_window  = ::DoRelease;
         p_intf->pf_control_window  = ::DoControl;
-
-        if( config_GetInt( p_intf, "qt-always-video" ))
-        {
-            bgWidget = new BackgroundWidget( p_intf );
-            bgWidget->widgetSize = settings->value( "backgroundSize",
-                                                QSize( 200, 200 ) ).toSize();
-            ui.vboxLayout->insertWidget( 0, bgWidget );
-        }
     }
-//    visualSelector = new VisualSelector( p_intf );
-//    visualSelector->hide();
 
     calculateInterfaceSize();
-    fprintf( stderr, "Resize to %ix%i\n", mainSize.width(), mainSize.height() );
     resize( mainSize );
-    mainSize = size();
 
     setMinimumSize( PREF_W, addSize.height() );
 }
@@ -218,14 +223,13 @@ void MainInterface::handleMainUi( QSettings *settings )
 void MainInterface::calculateInterfaceSize()
 {
     int width = 0, height = 0;
-    fprintf( stderr, "Calculating size\n" );
-    if( bgWidget && bgWidget->isVisible() )
+    if( VISIBLE( bgWidget ) )
     {
         width = bgWidget->widgetSize.width();
         height = bgWidget->widgetSize.height();
         assert( !(playlistWidget && playlistWidget->isVisible() ) );
     }
-    else if( playlistWidget && playlistWidget->isVisible() )
+    else if( VISIBLE( playlistWidget ) )
     {
         width = playlistWidget->widgetSize.width();
         height = playlistWidget->widgetSize.height();
@@ -235,55 +239,40 @@ void MainInterface::calculateInterfaceSize()
     {
         width =  videoWidget->widgetSize.width() ;
         height = videoWidget->widgetSize.height();
-        fprintf( stderr, "Video Size %ix%i\n", videoWidget->widgetSize.width(), videoWidget->widgetSize.height() );
+        fprintf( stderr, "Video Size %ix%i\n", DS( videoWidget->widgetSize ) );
     }
     else
     {
         width = PREF_W - addSize.width();
         height = PREF_H - addSize.height();
     }
-    fprintf( stderr, "Setting to %ix%i\n", width + addSize.width() , height + addSize.height() );
-    mainSize.setWidth( width + addSize.width() );
-    mainSize.setHeight( height + addSize.height() );
+    if( VISIBLE( visualSelector ) )
+        height += visualSelector->height();
+
+    fprintf( stderr, "Setting to %ix%i\n",
+                     width + addSize.width() , height + addSize.height() );
+
+    mainSize = QSize( width + addSize.width(), height + addSize.height() );
 }
 
 void MainInterface::resizeEvent( QResizeEvent *e )
 {
-    fprintf( stderr, "Resize event to %ix%i\n", e->size().width(), e->size().height() );
-    /* Width : Always passed to all children. We are guaranteed it will
-     *         not go below PREF_W
-     * Height : Only passed to the only visible child
-     */
-    if( videoWidget )
+    fprintf( stderr, "Resize event to %ix%i\n", DS( e->size() ) );
+    videoWidget->widgetSize.setWidth(  e->size().width() - addSize.width() );
+    if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
     {
-        videoWidget->widgetSize.setWidth( e->size().width() -
-                                           addSize.width() );
-        if( videoIsActive && videoWidget->widgetSize.height() > 1 )
-        {
-            videoWidget->widgetSize.setHeight( e->size().height() -
-                                              addSize.height() );
-            videoWidget->updateGeometry();
-        }
-        fprintf( stderr, "Video set to %ix%i\n",
-                videoWidget->widgetSize.width(),
-                videoWidget->widgetSize.height() );
+        SET_WH( videoWidget, e->size().width() - addSize.width(),
+                             e->size().height()  - addSize.height() );
+        videoWidget->updateGeometry();
+        fprintf( stderr, "Video set to %ix%i\n", DS( videoWidget->widgetSize) );
     }
-    if( playlistWidget )
+    if( VISIBLE( playlistWidget ) )
     {
-       if( playlistWidget->isVisible() )
-        {
-        playlistWidget->widgetSize.setWidth( e->size().width() -
-                                              addSize.width() );
-            playlistWidget->widgetSize.setHeight( e->size().height() -
-                                                 addSize.height() );
-            playlistWidget->updateGeometry();
-        }
-        fprintf( stderr, "Playlist set to %ix%i\n",playlistWidget->widgetSize.width(), playlistWidget->widgetSize.height() );
+        SET_WH( playlistWidget , e->size().width() - addSize.width(),
+                                 e->size().height() - addSize.height() );
+        playlistWidget->updateGeometry();
+        fprintf( stderr, "PL set to %ix%i\n",DS(playlistWidget->widgetSize ) );
     }
-//  videoWidget->widgetSize.setHeight( e->size().height() - addSize.height() );
-//  videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
-//  videoWidget->updateGeometry() ;
 }
 
 void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
@@ -294,16 +283,28 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
     if( ret )
     {
         videoIsActive = true;
-        if( playlistWidget && playlistWidget->isVisible() )
+        if( VISIBLE( playlistWidget ) )
         {
             embeddedPlaylistWasActive = true;
             playlistWidget->hide();
         }
-        if( bgWidget && bgWidget->isVisible() )
+        bool bgWasVisible = false;
+        if( VISIBLE( bgWidget) )
         {
+            bgWasVisible = true;
             bgWidget->hide();
         }
-        videoWidget->widgetSize = QSize( *pi_width, *pi_height );
+        if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
+        {
+            videoWidget->widgetSize = QSize( *pi_width, *pi_height );
+        }
+        else /* Background widget available, use its size */
+        {
+            /* Ok, our visualizations are bad, so don't do this for the moment
+             * use the requested size anyway */
+            // videoWidget->widgetSize = bgWidget->widgeTSize;
+            videoWidget->widgetSize = QSize( *pi_width, *pi_height );
+        }
         videoWidget->updateGeometry(); /// FIXME: Needed ?
         need_components_update = true;
     }
@@ -359,6 +360,25 @@ int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
     return i_ret;
 }
 
+void MainInterface::visual()
+{
+    if( !VISIBLE( visualSelector) )
+    {
+        visualSelector->show();
+        if( !THEMIM->getIM()->hasVideo() )
+        {
+            /* Show the background widget */
+        }
+    }
+    else
+    {
+        /* Stop any currently running visualization */
+        visualSelector->hide();
+    }
+    calculateInterfaceSize();
+    resize( mainSize );
+}
+
 void MainInterface::playlist()
 {
     // Toggle the playlist dialog
@@ -382,7 +402,7 @@ void MainInterface::playlist()
         playlistWidget->hide();
     }
     /// Todo, reset its size ?
-    if( playlistWidget->isVisible() )
+    if( VISIBLE( playlistWidget) )
     {
         fprintf( stderr, "hiding playlist\n" );
         playlistWidget->hide();
@@ -404,6 +424,7 @@ void MainInterface::playlist()
             videoWidget->resize( videoWidget->widgetSize );
             videoWidget->updateGeometry();
         }
+        if( VISIBLE( bgWidget ) ) bgWidget->hide();
     }
 
     calculateInterfaceSize();
index cfad5c50e08eb060ed895c2b1fb59018a7dfa78f..8a11a46bf9cd5f0aff6fa69981d8240f8dc4aa35 100644 (file)
@@ -49,8 +49,6 @@ class MainInterface : public QVLCMW
 public:
     MainInterface( intf_thread_t *);
     virtual ~MainInterface();
-
-
     void *requestVideo( vout_thread_t *p_nvout, int *pi_x,
                         int *pi_y, unsigned int *pi_width,
                         unsigned int *pi_height );
@@ -80,6 +78,7 @@ private:
 
     bool                 playlistEmbeddedFlag;
     bool                 videoEmbeddedFlag;
+    bool                 alwaysVideoFlag;
 
     InputManager        *main_input_manager;
     InputSlider         *slider;
@@ -97,6 +96,7 @@ private slots:
     void prev();
     void next();
     void playlist();
+    void visual();
     void updateVolume( int sliderVolume );
 };
 
@@ -104,24 +104,21 @@ private slots:
 class VolumeClickHandler : public QObject
 {
 public:
-    VolumeClickHandler( MainInterface *_m ) :QObject(_m) {m = _m; }
+    VolumeClickHandler( intf_thread_t *_p_intf, MainInterface *_m ) :QObject(_m)
+    {m = _m; p_intf = _p_intf; }
     virtual ~VolumeClickHandler() {};
     bool eventFilter( QObject *obj, QEvent *e )
     {
         if (e->type() == QEvent::MouseButtonPress )
         {
-            if( obj->objectName() == "volLowLabel" )
-            {
-                m->ui.volumeSlider->setValue( 0 );
-            }
-            else
-                m->ui.volumeSlider->setValue( 100 );
+            aout_VolumeMute( p_intf, NULL );
             return true;
         }
         return false;
     }
 private:
     MainInterface *m;
+    intf_thread_t *p_intf;
 };
 
 #endif
index 15b4e60ee429955a08329f9f13b106d62d7502a4..2f7f00e7074949f153f29845bd5443ef1b81ada8 100644 (file)
       </spacer>
      </item>
      <item>
-      <widget class="QLabel" name="volLowLabel" >
+      <widget class="QLabel" name="volMuteLabel" >
        <property name="text" >
         <string/>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QLabel" name="volHighLabel" >
+      <widget class="QPushButton" name="visualButton" >
        <property name="text" >
         <string/>
        </property>
      <item>
       <widget class="QPushButton" name="playlistButton" >
        <property name="text" >
-        <string> </string>
+        <string/>
        </property>
       </widget>
      </item>