]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/controller.cpp
Qt4: update avcodec-hw prefs
[vlc] / modules / gui / qt4 / components / controller.cpp
index 22ec4cd8e6ffe0aaa2cf0d617796e456c18c4fd5..44de18a6fe77b3a2eea170df2a5f5ae862f24745 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Controller.cpp : Controller for the main interface
+ * controller.cpp : Controller for the main interface
  ****************************************************************************
  * Copyright (C) 2006-2009 the VideoLAN team
  * $Id$
@@ -109,7 +109,7 @@ void AbstractController::setupButton( QAbstractButton *aButton )
 /* Open the generic config line for the toolbar, parse it
  * and create the widgets accordingly */
 void AbstractController::parseAndCreate( const QString& config,
-                                         QBoxLayout *controlLayout )
+                                         QBoxLayout *newControlLayout )
 {
     QStringList list = config.split( ";", QString::SkipEmptyParts ) ;
     for( int i = 0; i < list.count(); i++ )
@@ -126,7 +126,7 @@ void AbstractController::parseAndCreate( const QString& config,
         buttonType_e i_type = (buttonType_e)list2.at( 0 ).toInt( &ok );
         if( !ok )
         {
-            msg_Warn( p_intf, "Parsing error 2. Please report this." );
+            msg_Warn( p_intf, "Parsing error 2. Please, report this." );
             continue;
         }
 
@@ -137,19 +137,20 @@ void AbstractController::parseAndCreate( const QString& config,
             {
                 msg_Warn( p_intf, "Parsing error 3. Please, report this." );
                 continue;
-            }        }
+            }
+        }
 
-        createAndAddWidget( controlLayout, -1, i_type, i_option );
+        createAndAddWidget( newControlLayout, -1, i_type, i_option );
     }
 
     if( buttonGroupLayout )
     {
-        controlLayout->addLayout( buttonGroupLayout );
+        newControlLayout->addLayout( buttonGroupLayout );
         buttonGroupLayout = NULL;
     }
 }
 
-void AbstractController::createAndAddWidget( QBoxLayout *controlLayout,
+void AbstractController::createAndAddWidget( QBoxLayout *controlLayout_,
                                              int i_index,
                                              buttonType_e i_type,
                                              int i_option )
@@ -159,18 +160,18 @@ void AbstractController::createAndAddWidget( QBoxLayout *controlLayout,
     /* Close the current buttonGroup if we have a special widget or a spacer */
     if( buttonGroupLayout && i_type > BUTTON_MAX )
     {
-        controlLayout->addLayout( buttonGroupLayout );
+        controlLayout_->addLayout( buttonGroupLayout );
         buttonGroupLayout = NULL;
     }
 
     /* Special case for SPACERS, who aren't QWidgets */
     if( i_type == WIDGET_SPACER )
     {
-        controlLayout->addSpacing( 12 );
+        controlLayout_->addSpacing( 12 );
     }
     else if(  i_type == WIDGET_SPACER_EXTEND )
     {
-        controlLayout->addStretch( 12 );
+        controlLayout_->addStretch( 12 );
     }
     else
     {
@@ -190,7 +191,7 @@ void AbstractController::createAndAddWidget( QBoxLayout *controlLayout,
         }
         else /* Special widgets */
         {
-            controlLayout->addWidget( widg );
+            controlLayout_->addWidget( widg );
         }
     }
 }
@@ -303,6 +304,10 @@ QWidget *AbstractController::createWidget( buttonType_e button, int options )
         ENABLE_ON_VIDEO( FULLSCREENButton );
         }
         break;
+    case FULLWIDTH_BUTTON: {
+            NORMAL_BUTTON( FULLWIDTH );
+        }
+        break;
     case EXTENDED_BUTTON:{
         NORMAL_BUTTON( EXTENDED );
         }
@@ -341,9 +346,9 @@ QWidget *AbstractController::createWidget( buttonType_e button, int options )
         }
         break;
     case INPUT_SLIDER: {
-        SeekSlider *slider = new SeekSlider( Qt::Horizontal, NULL );
+        SeekSlider *slider = new SeekSlider( Qt::Horizontal, NULL, !b_shiny );
         SeekPoints *chapters = new SeekPoints( this, p_intf );
-        CONNECT( THEMIM->getIM(), titleChanged( bool ), chapters, update() );
+        CONNECT( THEMIM->getIM(), chapterChanged( bool ), chapters, update() );
         slider->setChapters( chapters );
 
         /* Update the position when the IM has changed */
@@ -354,6 +359,9 @@ QWidget *AbstractController::createWidget( buttonType_e button, int options )
                  THEMIM->getIM(), sliderUpdate( float ) );
         CONNECT( THEMIM->getIM(), cachingChanged( float ),
                  slider, updateBuffering( float ) );
+        /* Give hint to disable slider's interactivity when useless */
+        CONNECT( THEMIM->getIM(), inputCanSeek( bool ),
+                 slider, setSeekable( bool ) );
         widget = slider;
         }
         break;
@@ -460,6 +468,19 @@ QWidget *AbstractController::createWidget( buttonType_e button, int options )
         CONNECT_MAP_SET( play, PLAY_ACTION );
         }
         break;
+    case ASPECT_RATIO_COMBOBOX:
+        widget = new AspectRatioComboBox( p_intf );
+        widget->setMinimumHeight( 26 );
+        break;
+    case SPEED_LABEL:
+        widget = new SpeedLabel( p_intf, this );
+        break;
+    case TIME_LABEL_ELAPSED:
+        widget = new TimeLabel( p_intf, TimeLabel::Elapsed );
+        break;
+    case TIME_LABEL_REMAINING:
+        widget = new TimeLabel( p_intf, TimeLabel::Remaining );
+        break;
     default:
         msg_Warn( p_intf, "This should not happen %i", button );
         break;
@@ -527,9 +548,9 @@ QFrame *AbstractController::discFrame()
 
     /* Change the navigation button display when the IM
        navigation changes */
-    CONNECT( THEMIM->getIM(), titleChanged( bool ),
-            discFrame, setVisible( bool ) );
     CONNECT( THEMIM->getIM(), chapterChanged( bool ),
+            discFrame, setVisible( bool ) );
+    CONNECT( THEMIM->getIM(), titleChanged( bool ),
             menuButton, setVisible( bool ) );
     /* Changes the IM navigation when triggered on the nav buttons */
     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
@@ -630,19 +651,19 @@ ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
     setStyleSheet( "background: red ");
 #endif
     setAttribute( Qt::WA_MacBrushedMetal);
-    QVBoxLayout *controlLayout = new QVBoxLayout( this );
-    controlLayout->setContentsMargins( 4, 1, 0, 0 );
+    controlLayout = new QVBoxLayout( this );
+    controlLayout->setContentsMargins( 3, 1, 0, 1 );
     controlLayout->setSpacing( 0 );
     QHBoxLayout *controlLayout1 = new QHBoxLayout;
     controlLayout1->setSpacing( 0 ); controlLayout1->setMargin( 0 );
 
-    QString line1 = getSettings()->value( "MainToolbar1", MAIN_TB1_DEFAULT )
+    QString line1 = getSettings()->value( "MainWindow/MainToolbar1", MAIN_TB1_DEFAULT )
                                         .toString();
     parseAndCreate( line1, controlLayout1 );
 
     QHBoxLayout *controlLayout2 = new QHBoxLayout;
     controlLayout2->setSpacing( 0 ); controlLayout2->setMargin( 0 );
-    QString line2 = getSettings()->value( "MainToolbar2", MAIN_TB2_DEFAULT )
+    QString line2 = getSettings()->value( "MainWindow/MainToolbar2", MAIN_TB2_DEFAULT )
                                         .toString();
     parseAndCreate( line2, controlLayout2 );
 
@@ -676,7 +697,7 @@ AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
 #endif
 
 
-    QString line = getSettings()->value( "AdvToolbar", ADV_TB_DEFAULT )
+    QString line = getSettings()->value( "MainWindow/AdvToolbar", ADV_TB_DEFAULT )
         .toString();
     parseAndCreate( line, controlLayout );
 }
@@ -692,7 +713,7 @@ InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i, QWidget *_parent
     setStyleSheet( "background: green ");
 #endif
 
-    QString line = getSettings()->value( "InputToolbar", INPT_TB_DEFAULT ).toString();
+    QString line = getSettings()->value( "MainWindow/InputToolbar", INPT_TB_DEFAULT ).toString();
     parseAndCreate( line, controlLayout );
 }
 /**********************************************************************
@@ -718,7 +739,9 @@ FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i, QWi
     vout.clear();
 
     setWindowFlags( Qt::ToolTip );
-    setMinimumWidth( 600 );
+    setMinimumWidth( FSC_WIDTH );
+    setMinimumHeight( FSC_HEIGHT );
+    isWideFSC = false;
 
     setFrameShape( QFrame::StyledPanel );
     setFrameStyle( QFrame::Sunken );
@@ -754,47 +777,67 @@ FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i, QWi
               this, setVoutList( vout_thread_t **, int ) );
 
     /* First Move */
-    QRect rect1 = getSettings()->value( "FullScreen/screen" ).toRect();
-    QPoint pos1 = getSettings()->value( "FullScreen/pos" ).toPoint();
-    int number =  var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
-    if( number == -1 || number > QApplication::desktop()->numScreens() )
-        number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
-
-    QRect rect = QApplication::desktop()->screenGeometry( number );
-    if( rect == rect1 && rect.contains( pos1, true ) )
-    {
-        move( pos1 );
-        i_screennumber = number;
-        screenRes = QApplication::desktop()->screenGeometry(number);
-    }
-    else
-    {
-        centerFSC( number );
-    }
-
+    previousPosition = getSettings()->value( "FullScreen/pos" ).toPoint();
+    screenRes = getSettings()->value( "FullScreen/screen" ).toRect();
+    isWideFSC = getSettings()->value( "FullScreen/wide" ).toBool();
+    i_screennumber = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
 }
 
 FullscreenControllerWidget::~FullscreenControllerWidget()
 {
-    QPoint pos1 = pos();
-    QRect rect1 = QApplication::desktop()->screenGeometry( pos1 );
-    getSettings()->setValue( "FullScreen/pos", pos1 );
-    getSettings()->setValue( "FullScreen/screen", rect1 );
+    getSettings()->setValue( "FullScreen/pos", previousPosition );
+    getSettings()->setValue( "FullScreen/screen", screenRes );
+    getSettings()->setValue( "FullScreen/wide", isWideFSC );
 
     setVoutList( NULL, 0 );
     vlc_mutex_destroy( &lock );
 }
 
+void FullscreenControllerWidget::restoreFSC()
+{
+    if( !isWideFSC )
+    {
+        /* Restore half-bar and re-centre if needed */
+        setMinimumWidth( FSC_WIDTH );
+        adjustSize();
+
+        QRect currentRes = QApplication::desktop()->screenGeometry( targetScreen() );
+
+        if( currentRes == screenRes &&
+            QApplication::desktop()->screen()->geometry().contains( previousPosition, true ) )
+        {
+            /* Restore to the last known position */
+            move( previousPosition );
+        }
+        else
+        {
+            /* FSC is out of screen or screen resolution changed */
+            msg_Dbg( p_intf, "Recentering the Fullscreen Controller" );
+            centerFSC( targetScreen() );
+            screenRes = currentRes;
+            previousPosition = pos();
+        }
+    }
+    else
+    {
+        /* Dock at the bottom of the screen */
+        updateFullwidthGeometry( targetScreen() );
+    }
+
+#ifdef Q_WS_X11
+    // Tell kwin that we do not want a shadow around the fscontroller
+    setMask( QRegion( 0, 0, width(), height() ) );
+#endif
+}
+
 void FullscreenControllerWidget::centerFSC( int number )
 {
-    screenRes = QApplication::desktop()->screenGeometry(number);
+    QRect currentRes = QApplication::desktop()->screenGeometry( number );
 
     /* screen has changed, calculate new position */
-    QPoint pos = QPoint( screenRes.x() + (screenRes.width() / 2) - (sizeHint().width() / 2),
-            screenRes.y() + screenRes.height() - sizeHint().height());
+    QPoint pos = QPoint( currentRes.x() + (currentRes.width() / 2) - (width() / 2),
+            currentRes.y() + currentRes.height() - height());
     move( pos );
-
-    i_screennumber = number;
 }
 
 /**
@@ -802,26 +845,12 @@ void FullscreenControllerWidget::centerFSC( int number )
  */
 void FullscreenControllerWidget::showFSC()
 {
-    adjustSize();
-
-    int number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
-
-    if( number != i_screennumber ||
-        screenRes != QApplication::desktop()->screenGeometry(number) )
-    {
-        centerFSC( number );
-        msg_Dbg( p_intf, "Recentering the Fullscreen Controller" );
-    }
+    restoreFSC();
 
 #if HAVE_TRANSPARENCY
     setWindowOpacity( f_opacity );
 #endif
 
-#ifdef Q_WS_X11
-    // Tell kwin that we do not want a shadow around the fscontroller
-    setMask( QRegion( 0, 0, width(), height() ) );
-#endif
-
     show();
 }
 
@@ -875,6 +904,29 @@ void FullscreenControllerWidget::slowHideFSC()
 #endif
 }
 
+void FullscreenControllerWidget::updateFullwidthGeometry( int number )
+{
+    QRect screenGeometry = QApplication::desktop()->screenGeometry( number );
+    setMinimumWidth( screenGeometry.width() );
+    setGeometry( screenGeometry.x(), screenGeometry.y() + screenGeometry.height() - FSC_HEIGHT, screenGeometry.width(), FSC_HEIGHT );
+    adjustSize();
+}
+
+void FullscreenControllerWidget::toggleFullwidth()
+{
+    /* Toggle isWideFSC switch */
+    isWideFSC = !isWideFSC;
+
+    restoreFSC();
+}
+
+int FullscreenControllerWidget::targetScreen()
+{
+    if( i_screennumber == -1 || i_screennumber > QApplication::desktop()->numScreens() )
+        return QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
+    return i_screennumber;
+}
+
 /**
  * event handling
  * events: show, hide, start timer for hiding
@@ -886,7 +938,7 @@ void FullscreenControllerWidget::customEvent( QEvent *event )
     switch( (int)event->type() )
     {
         /* This is used when the 'i' hotkey is used, to force quick toggle */
-        case FullscreenControlToggle_Type:
+        case IMEvent::FullscreenControlToggle:
             vlc_mutex_lock( &lock );
             b_fs = b_fullscreen;
             vlc_mutex_unlock( &lock );
@@ -903,7 +955,7 @@ void FullscreenControllerWidget::customEvent( QEvent *event )
             }
             break;
         /* Event called to Show the FSC on mouseChanged() */
-        case FullscreenControlShow_Type:
+        case IMEvent::FullscreenControlShow:
             vlc_mutex_lock( &lock );
             b_fs = b_fullscreen;
             vlc_mutex_unlock( &lock );
@@ -913,12 +965,12 @@ void FullscreenControllerWidget::customEvent( QEvent *event )
 
             break;
         /* Start the timer to hide later, called usually with above case */
-        case FullscreenControlPlanHide_Type:
+        case IMEvent::FullscreenControlPlanHide:
             if( !b_mouse_over ) // Only if the mouse is not over FSC
                 planHideFSC();
             break;
         /* Hide */
-        case FullscreenControlHide_Type:
+        case IMEvent::FullscreenControlHide:
             hideFSC();
             break;
         default:
@@ -953,6 +1005,7 @@ void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
  */
 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
 {
+    if( isWideFSC ) return;
     i_mouse_last_x = event->globalX();
     i_mouse_last_y = event->globalY();
     event->accept();
@@ -960,9 +1013,13 @@ void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
 
 void FullscreenControllerWidget::mouseReleaseEvent( QMouseEvent *event )
 {
+    if( isWideFSC ) return;
     i_mouse_last_x = -1;
     i_mouse_last_y = -1;
     event->accept();
+
+    // Save the new FSC position
+    previousPosition = pos();
 }
 
 /**
@@ -1008,7 +1065,7 @@ static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object
 
     vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
 
-    msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
+    msg_Dbg( p_vout, "Qt: Fullscreen state changed" );
     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
 
     p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
@@ -1117,7 +1174,7 @@ void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
                 FullscreenControllerWidgetMouseMoved, this );
 
         /* Force fs hiding */
-        IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
+        IMEvent *eHide = new IMEvent( IMEvent::FullscreenControlHide, 0 );
         QApplication::postEvent( this, eHide );
     }
     vlc_mutex_unlock( &lock );
@@ -1145,11 +1202,11 @@ void FullscreenControllerWidget::mouseChanged( vout_thread_t *, int i_mousex, in
     if( b_toShow )
     {
         /* Show event */
-        IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
+        IMEvent *eShow = new IMEvent( IMEvent::FullscreenControlShow, 0 );
         QApplication::postEvent( this, eShow );
 
         /* Plan hide event */
-        IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
+        IMEvent *eHide = new IMEvent( IMEvent::FullscreenControlPlanHide, 0 );
         QApplication::postEvent( this, eHide );
     }
 }