]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/controller_widget.cpp
Qt: various string fixes and consistencies in the ui
[vlc] / modules / gui / qt4 / components / controller_widget.cpp
index 688bb3d921a35155fd14adf9f85712a600e930a1..26fdcfc6aff27dcde85f52684e660f71a0dd4eb9 100644 (file)
@@ -26,6 +26,7 @@
 #endif
 
 #include "controller_widget.hpp"
+#include "controller.hpp"
 
 #include "input_manager.hpp"         /* Get notification of Volume Change */
 #include "util/input_slider.hpp"     /* SoundSlider */
 #include <QLabel>
 #include <QHBoxLayout>
 #include <QSpinBox>
+#include <QMenu>
+#include <QWidgetAction>
+#include <QMouseEvent>
 
 SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
-                          bool b_shiny )
-                         : b_my_volume( false ), QWidget( _parent )
+                          bool b_shiny, bool b_special )
+                         : QWidget( _parent ), b_my_volume( false ),
+                           p_intf( _p_intf)
 {
-    p_intf = _p_intf;
+    /* We need a layout for this widget */
     QHBoxLayout *layout = new QHBoxLayout( this );
     layout->setSpacing( 0 ); layout->setMargin( 0 );
-    hVolLabel = new VolumeClickHandler( p_intf, this );
 
+    /* We need a Label for the pix */
     volMuteLabel = new QLabel;
     volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
-    volMuteLabel->installEventFilter( hVolLabel );
+
+    /* We might need a subLayout too */
+    QVBoxLayout *subLayout;
+
+    volMuteLabel->installEventFilter( this );
+
+    /* Normal View, click on icon mutes */
+    if( !b_special )
+    {
+        volumeMenu = NULL; subLayout = NULL;
+    }
+    else
+    {
+        /* Special view, click on button shows the slider */
+        b_shiny = false;
+
+        QFrame *volumeControlWidget = new QFrame;
+        subLayout = new QVBoxLayout( volumeControlWidget );
+        subLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
+        volumeMenu = new QMenu( this );
+
+        QWidgetAction *widgetAction = new QWidgetAction( volumeControlWidget );
+        widgetAction->setDefaultWidget( volumeControlWidget );
+        volumeMenu->addAction( widgetAction );
+    }
+
+    /* And add the label */
     layout->addWidget( volMuteLabel );
 
+    /* Slider creation: shiny or clean */
     if( b_shiny )
     {
         volumeSlider = new SoundSlider( this,
@@ -59,13 +91,23 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
     }
     else
     {
-        volumeSlider = new QSlider( this );
-        volumeSlider->setOrientation( Qt::Horizontal );
+        volumeSlider = new QSlider( NULL );
+        volumeSlider->setOrientation( b_special ? Qt::Vertical
+                                                : Qt::Horizontal );
+        volumeSlider->setMaximum( config_GetInt( p_intf, "qt-volume-complete" )
+                                  ? 400 : 200 );
     }
-    volumeSlider->setMaximumSize( QSize( 200, 40 ) );
-    volumeSlider->setMinimumSize( QSize( 85, 30 ) );
+    if( volumeSlider->orientation() ==  Qt::Horizontal )
+    {
+        volumeSlider->setMaximumSize( QSize( 200, 40 ) );
+        volumeSlider->setMinimumSize( QSize( 85, 30 ) );
+    }
+
     volumeSlider->setFocusPolicy( Qt::NoFocus );
-    layout->addWidget( volumeSlider );
+    if( b_special )
+        subLayout->addWidget( volumeSlider );
+    else
+        layout->addWidget( volumeSlider );
 
     /* Set the volume from the config */
     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
@@ -106,7 +148,7 @@ void SoundWidget::updateVolume()
     /* Audio part */
     audio_volume_t i_volume;
     aout_VolumeGet( p_intf, &i_volume );
-    i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
+    i_volume = ( ( i_volume + 1 ) *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
     int i_gauge = volumeSlider->value();
     b_my_volume = false;
     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
@@ -117,19 +159,39 @@ void SoundWidget::updateVolume()
     }
 }
 
-void TeletextController::toggleTeletextTransparency( bool b_transparent )
+void SoundWidget::showVolumeMenu( QPoint pos )
 {
-    telexTransparent->setIcon( b_transparent ? QIcon( ":/tvtelx" )
-                                             : QIcon( ":/tvtelx-trans" ) );
+    volumeMenu->exec( QCursor::pos() - pos - QPoint( 0, volumeMenu->height()/2 )
+                          + QPoint( width(), height() /2) );
 }
 
-void TeletextController::enableTeletextButtons( bool b_enabled )
+bool SoundWidget::eventFilter( QObject *obj, QEvent *e )
 {
-    telexOn->setChecked( b_enabled );
-    telexTransparent->setEnabled( b_enabled );
-    telexPage->setEnabled( b_enabled );
+    VLC_UNUSED( obj );
+    if (e->type() == QEvent::MouseButtonPress  )
+    {
+        if( volumeSlider->orientation() ==  Qt::Vertical )
+        {
+            QMouseEvent *event = static_cast<QMouseEvent*>(e);
+            showVolumeMenu( event->pos() );
+        }
+        else
+        {
+            aout_VolumeMute( p_intf, NULL );
+        }
+        e->accept();
+        return true;
+    }
+    else
+    {
+        e->ignore();
+        return false;
+    }
 }
 
+/**
+ * Play Button
+ **/
 void PlayButton::updateButton( bool b_playing )
 {
     setIcon( b_playing ? QIcon( ":/pause_b" ) : QIcon( ":/play_b" ) );
@@ -157,16 +219,4 @@ void AtoB_Button::setIcons( bool timeA, bool timeB )
     }
 }
 
-bool VolumeClickHandler::eventFilter( QObject *obj, QEvent *e )
-{
-    if (e->type() == QEvent::MouseButtonPress  )
-    {
-        aout_VolumeMute( p_intf, NULL );
-        audio_volume_t i_volume;
-        aout_VolumeGet( p_intf, &i_volume );
-//        m->updateVolume( i_volume *  VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
-        return true;
-    }
-    return false;
-}