]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/main_interface.cpp
Layout improvements
[vlc] / modules / gui / qt4 / main_interface.cpp
index 5efd4c1db85b5c79256358dd9c4e73d0e57fdede..763cc2dea60e9a22946f9dc8b8dc6255d9af6917 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * main_inteface.cpp : Main interface
  ****************************************************************************
- * Copyright (C) 2000-2005 the VideoLAN team
- * $Id: wxwidgets.cpp 15731 2006-05-25 14:43:53Z zorglub $
+ * Copyright (C) 2006 the VideoLAN team
+ * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
  *
 #include <QCloseEvent>
 #include <assert.h>
 #include <QPushButton>
+#include <QStatusBar>
+#include "menus.hpp"
+
+#define PREF_W 480
+#define PREF_H 125
+
+static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
+                             vlc_value_t, void *);
 
 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 {
@@ -39,10 +47,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     setWindowTitle( QString::fromUtf8( _("VLC media player") ) );
     ui.setupUi( centralWidget() );
 
-    slider = new InputSlider( Qt::Horizontal, ui.sliderBox );
-    QVBoxLayout *box_layout = new QVBoxLayout();
-    box_layout->addWidget( slider );
-    ui.sliderBox->setLayout( box_layout );
+    slider = new InputSlider( Qt::Horizontal, NULL );
+    ui.hboxLayout->insertWidget( 0, slider );
     ui.prevButton->setText( "" );
     ui.nextButton->setText( "" );
     ui.playButton->setText( "" ); 
@@ -54,34 +60,66 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     ui.volLowLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
     ui.volHighLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
 
+    QVLCMenu::createMenuBar( menuBar(), p_intf );
+
+    timeLabel = new QLabel( this );
+    nameLabel = new QLabel( this );
+    statusBar()->addWidget( nameLabel, 4 );
+    statusBar()->addPermanentWidget( timeLabel, 1 );
+
+    resize ( PREF_W, PREF_H );
 //    if( config_GetInt( p_intf, "embedded" ) )
+
     {
         videoWidget = new VideoWidget( p_intf );
-        videoWidget->resize( 1,1 );
+        if( config_GetInt( p_intf, "qt-always-video" ) )
+        {
+            QSettings settings( "VideoLAN", "VLC" );
+            settings.beginGroup( "MainWindow" );
+            videoSize = settings.value( "videoSize", QSize( 200, 200 ) ).
+                                                toSize();
+        } 
+        else
+            videoSize = QSize( 1,1 );
+        videoWidget->resize( videoSize );
         ui.vboxLayout->insertWidget( 0, videoWidget );
     }
+    fprintf( stderr, "Margin : %i\n",ui.vboxLayout->margin() );
+    readSettings( "MainWindow" );
+
+    addSize = QSize( ui.vboxLayout->margin() * 2, PREF_H );
+    
+    if( config_GetInt( p_intf, "qt-always-video" ) )
+        mainSize = videoSize + addSize;
+    else
+        mainSize = QSize( PREF_W, PREF_H );
+        
+    resize( mainSize );
+    mainSize = size();
 
-    readSettings( "MainWindow" , QSize( 500, 131) );
+    fprintf( stderr, "Size is %ix%i - Video %ix%i\n", mainSize.width(), mainSize.height(), videoSize.width(), videoSize.height() );
 
-    //QVLCMenu::createMenuBar();
+    fprintf( stderr, "Additional size around video %ix%i", addSize.width(), addSize.height() );
+    setMinimumSize( PREF_W, addSize.height() );
 
     /* Init input manager */
     MainInputManager::getInstance( p_intf );
 
     /* Get timer updates */
-    connect( DialogsProvider::getInstance(NULL)->fixed_timer,
-             SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
+    connect( THEDP->fixed_timer, SIGNAL( timeout() ),
+             this, SLOT(updateOnTimer() ) );
 
     /* Connect the input manager to the GUI elements it manages */
-    connect( MainInputManager::getInstance( p_intf )->getIM(),
-             SIGNAL(positionUpdated( float, int, int ) ),
+    connect( THEMIM->getIM(),SIGNAL(positionUpdated( float, int, int ) ),
              slider, SLOT( setPosition( float,int, int ) ) );
-    connect( slider, SIGNAL( sliderDragged( float ) ),
-             MainInputManager::getInstance( p_intf )->getIM(),
-             SLOT( sliderUpdate( float ) ) );
-    connect( MainInputManager::getInstance( p_intf )->getIM(),
-             SIGNAL( positionUpdated( float, int, int ) ),
+    connect( THEMIM->getIM(), SIGNAL( positionUpdated( float, int, int ) ),
              this, SLOT( setDisplay( float, int, int ) ) );
+    connect( THEMIM->getIM(), SIGNAL( nameChanged( QString ) ),
+             this, SLOT( setName( QString ) ) );
+    connect( THEMIM->getIM(), SIGNAL( statusChanged( int ) ),
+             this, SLOT( setStatus( int ) ) );
+    connect( slider, SIGNAL( sliderDragged( float ) ),
+             THEMIM->getIM(),SLOT( sliderUpdate( float ) ) );
 
     /* Actions */
     connect( ui.playButton, SLOT( clicked() ), this, SLOT( play() ) );
@@ -89,19 +127,33 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     connect( ui.nextButton, SLOT( clicked() ), this, SLOT( next() ) );
     connect( ui.prevButton, SLOT( clicked() ), this, SLOT( prev() ) );
 
-    connect( ui.playlistButton, SLOT(clicked() ), 
-             DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
+    connect( ui.playlistButton, SLOT(clicked()),
+             THEDP, SLOT( playlistDialog() ) );
+
+    var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
+    var_AddCallback( p_intf, "interaction", InteractCallback, this );
+    p_intf->b_interaction = VLC_TRUE;
 }
 
 MainInterface::~MainInterface()
 {
+    writeSettings( "MainWindow" );
+    if( config_GetInt( p_intf, "qt-always-video" ) )
+    {
+        QSettings s("VideoLAN", "VLC" );
+        s.beginGroup( "MainWindow" );
+        s.setValue( "videoSize", videoSize );
+        s.endGroup();
+    }
+    p_intf->b_interaction = VLC_FALSE;
+    var_DelCallback( p_intf, "interaction", InteractCallback, this );
 }
 
-QSize MainInterface::sizeHint() const
+void MainInterface::resizeEvent( QResizeEvent *e )
 {
-    int i_width = __MAX( i_saved_width, p_intf->p_sys->p_video->i_video_width );
-    return QSize( i_width, i_saved_height +
-                             p_intf->p_sys->p_video->i_video_height );
+    videoSize.setHeight( e->size().height() - addSize.height() );
+    videoSize.setWidth( e->size().width() - addSize.width() );
+    p_intf->p_sys->p_video->updateGeometry() ;
 }
 
 void MainInterface::stop()
@@ -110,7 +162,14 @@ void MainInterface::stop()
 }
 void MainInterface::play()
 {
-    playlist_Play( THEPL );
+    if( !THEPL->i_size || !THEPL->i_enabled )
+    {
+        /* The playlist is empty, open a file requester */
+        THEDP->openDialog();
+        setStatus( 0 );
+        return;
+    }
+    THEMIM->togglePlayPause();
 }
 void MainInterface::prev()
 {
@@ -128,7 +187,21 @@ void MainInterface::setDisplay( float pos, int time, int length )
     secstotimestr( psz_time, time );
     QString title;
     title.sprintf( "%s/%s", psz_time, psz_length );
-    ui.sliderBox->setTitle( title );
+    timeLabel->setText( title );
+}
+
+void MainInterface::setName( QString name )
+{
+    nameLabel->setText( name );
+}
+
+void MainInterface::setStatus( int status )
+{
+    fprintf( stderr, "Status is now %i\n", status );
+    if( status == 2 ) // Playing
+        ui.playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
+    else
+        ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
 }
 
 void MainInterface::updateOnTimer()
@@ -144,3 +217,16 @@ void MainInterface::closeEvent( QCloseEvent *e )
     hide();
     p_intf->b_die = VLC_TRUE;
 }
+
+static int InteractCallback( vlc_object_t *p_this,
+                             const char *psz_var, vlc_value_t old_val,
+                             vlc_value_t new_val, void *param )
+{
+    intf_dialog_args_t *p_arg = new intf_dialog_args_t;
+    p_arg->p_dialog = (interaction_dialog_t *)(new_val.p_address);
+    
+    MainInterface *p_interface = (MainInterface*)param;
+    DialogEvent *event = new DialogEvent( INTF_DIALOG_INTERACTION, 0, p_arg );
+    QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
+    return VLC_SUCCESS;
+}