/*****************************************************************************
* interface_widgets.cpp : Custom widgets for the main interface
****************************************************************************
- * Copyright ( C ) 2006 the VideoLAN team
+ * Copyright (C) 2006-2008 the VideoLAN team
* $Id$
*
* Authors: Clément Stenac <zorglub@videolan.org>
# include "config.h"
#endif
-#include <vlc_vout.h>
-
-#include "dialogs_provider.hpp"
#include "components/interface_widgets.hpp"
-#include "main_interface.hpp"
-#include "input_manager.hpp"
-#include "menus.hpp"
-#include "util/input_slider.hpp"
-#include "util/customwidgets.hpp"
+
+#include "menus.hpp" /* Popup menu on bgWidget */
+
+#include <vlc_vout.h>
#include <QLabel>
-#include <QSpacerItem>
-#include <QCursor>
-#include <QPushButton>
#include <QToolButton>
-#include <QHBoxLayout>
-#include <QMenu>
#include <QPalette>
#include <QResizeEvent>
#include <QDate>
+#include <QMenu>
+#include <QWidgetAction>
#ifdef Q_WS_X11
# include <X11/Xlib.h>
#include <math.h>
-#define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media")
-
/**********************************************************************
* Video Widget. A simple frame on which video is drawn
* This class handles resize issues
Widgets with this attribute set do not participate in composition
management */
setAttribute( Qt::WA_PaintOnScreen, true );
-
- /* The core can ask through a callback to show the video. */
-#if HAS_QT43
- connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
- this, SLOT(SetSizing(unsigned int, unsigned int )),
- Qt::BlockingQueuedConnection );
-#else
-#warning This is broken. Fix it with a QEventLoop with a processEvents ()
- connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
- this, SLOT(SetSizing(unsigned int, unsigned int )) );
-#endif
}
void VideoWidget::paintEvent(QPaintEvent *ev)
/**
* Request the video to avoid the conflicts
**/
-void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
- unsigned int *pi_width, unsigned int *pi_height )
+WId VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
+ unsigned int *pi_width, unsigned int *pi_height,
+ bool b_keep_size )
{
msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
- emit askVideoWidgetToShow( *pi_width, *pi_height );
+
+ if( b_keep_size )
+ {
+ *pi_width = size().width();
+ *pi_height = size().height();
+ }
+
if( p_vout )
{
msg_Dbg( p_intf, "embedded video already in use" );
}
p_vout = p_nvout;
#ifndef NDEBUG
- msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
+ msg_Dbg( p_intf, "embedded video ready (handle %p)", (void *)winId() );
#endif
- return ( void* )winId();
+ return winId();
}
/* Set the Widget to the correct Size */
/* Function has to be called by the parent
- Parent has to care about resizing himself*/
+ Parent has to care about resizing itself */
void VideoWidget::SetSizing( unsigned int w, unsigned int h )
{
msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
videoSize.rwidth() = w;
videoSize.rheight() = h;
- if( isHidden() ) show();
+ if( !isVisible() ) show();
updateGeometry(); // Needed for deinterlace
}
-void VideoWidget::release( void *p_win )
+void VideoWidget::release( void )
{
msg_Dbg( p_intf, "Video is not needed anymore" );
p_vout = NULL;
backgroundLayout->setColumnStretch( 0, 1 );
backgroundLayout->setColumnStretch( 2, 1 );
- CONNECT( THEMIM->getIM(), artChanged( input_item_t* ),
- this, updateArt( input_item_t* ) );
+ CONNECT( THEMIM->getIM(), artChanged( QString ),
+ this, updateArt( const QString& ) );
}
BackgroundWidget::~BackgroundWidget()
label->show();
}
-void BackgroundWidget::updateArt( input_item_t *p_item )
+void BackgroundWidget::updateArt( const QString& url )
{
- QString url;
- if( p_item )
- {
- char *psz_art = input_item_GetArtURL( p_item );
- url = psz_art;
- free( psz_art );
- }
-
if( url.isEmpty() )
{
if( QDate::currentDate().dayOfYear() >= 354 )
}
else
{
- url = url.replace( "file://", QString("" ) );
- /* Taglib seems to define a attachment://, It won't work yet */
- url = url.replace( "attachment://", QString("" ) );
label->setPixmap( QPixmap( url ) );
}
}
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
{
QVLCMenu::PopupMenu( p_intf, true );
+ event->accept();
}
#if 0
+#include <QPushButton>
+#include <QHBoxLayout>
+
/**********************************************************************
* Visualization selector panel
**********************************************************************/
}
#endif
+SpeedLabel::SpeedLabel( intf_thread_t *_p_intf, const QString& text,
+ QWidget *parent )
+ : QLabel( text, parent ), p_intf( _p_intf )
+{
+ setToolTip( qtr( "Current playback speed.\nClick to adjust" ) );
+
+ /* Create the Speed Control Widget */
+ speedControl = new SpeedControlWidget( p_intf, this );
+ speedControlMenu = new QMenu( this );
+
+ QWidgetAction *widgetAction = new QWidgetAction( speedControl );
+ widgetAction->setDefaultWidget( speedControl );
+ speedControlMenu->addAction( widgetAction );
+
+ /* Change the SpeedRate in the Status Bar */
+ CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
+
+ CONNECT( THEMIM, inputChanged( input_thread_t * ),
+ speedControl, activateOnState() );
+
+}
+SpeedLabel::~SpeedLabel()
+{
+ delete speedControl;
+ delete speedControlMenu;
+}
+/****************************************************************************
+ * Small right-click menu for rate control
+ ****************************************************************************/
+void SpeedLabel::showSpeedMenu( QPoint pos )
+{
+ speedControlMenu->exec( QCursor::pos() - pos
+ + QPoint( 0, height() ) );
+}
+
+void SpeedLabel::setRate( int rate )
+{
+ QString str;
+ str.setNum( ( 1000 / (double)rate ), 'f', 2 );
+ str.append( "x" );
+ setText( str );
+ setToolTip( str );
+ speedControl->updateControls( rate );
+}
+
/**********************************************************************
* Speed control widget
**********************************************************************/
-SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
- QFrame( NULL ), p_intf( _p_i )
+SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i, QWidget *_parent )
+ : QFrame( _parent ), p_intf( _p_i )
{
QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
sizePolicy.setHorizontalStretch( 0 );
sizePolicy.setVerticalStretch( 0 );
- speedSlider = new QSlider;
+ speedSlider = new QSlider( this );
speedSlider->setSizePolicy( sizePolicy );
speedSlider->setMaximumSize( QSize( 80, 200 ) );
speedSlider->setOrientation( Qt::Vertical );
speedSlider->setTickPosition( QSlider::TicksRight );
- speedSlider->setRange( -24, 24 );
+ speedSlider->setRange( -34, 34 );
speedSlider->setSingleStep( 1 );
speedSlider->setPageStep( 1 );
- speedSlider->setTickInterval( 12 );
+ speedSlider->setTickInterval( 17 );
CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
CONNECT( normalSpeedButton, clicked(), this, resetRate() );
- QVBoxLayout *speedControlLayout = new QVBoxLayout;
+ QVBoxLayout *speedControlLayout = new QVBoxLayout( this );
speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
speedControlLayout->setSpacing( 4 );
speedControlLayout->addWidget( speedSlider );
speedControlLayout->addWidget( normalSpeedButton );
- setLayout( speedControlLayout );
-}
-SpeedControlWidget::~SpeedControlWidget()
-{}
+ activateOnState();
+}
-void SpeedControlWidget::setEnable( bool b_enable )
+void SpeedControlWidget::activateOnState()
{
- speedSlider->setEnabled( b_enable );
+ speedSlider->setEnabled( THEMIM->getIM()->hasInput() );
}
void SpeedControlWidget::updateControls( int rate )
return;
}
- double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
+ double value = 17 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
if( sliderValue < speedSlider->minimum() )
void SpeedControlWidget::updateRate( int sliderValue )
{
- double speed = pow( 2, (double)sliderValue / 12 );
+ double speed = pow( 2, (double)sliderValue / 17 );
int rate = INPUT_RATE_DEFAULT / speed;
THEMIM->getIM()->setRate(rate);
void SpeedControlWidget::resetRate()
{
- THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
-}
-
-
-
-static int downloadCoverCallback( vlc_object_t *p_this,
- char const *psz_var,
- vlc_value_t oldvar, vlc_value_t newvar,
- void *data )
-{
- if( !strcmp( psz_var, "item-change" ) )
- {
- CoverArtLabel *art = static_cast< CoverArtLabel* >( data );
- if( art )
- art->requestUpdate();
- }
- return VLC_SUCCESS;
+ THEMIM->getIM()->setRate( INPUT_RATE_DEFAULT );
}
-CoverArtLabel::CoverArtLabel( QWidget *parent,
- vlc_object_t *_p_this,
- input_item_t *_p_input )
- : QLabel( parent ), p_this( _p_this), p_input( _p_input ), prevArt()
+CoverArtLabel::CoverArtLabel( QWidget *parent, intf_thread_t *_p_i )
+ : QLabel( parent ), p_intf( _p_i )
{
setContextMenuPolicy( Qt::ActionsContextMenu );
CONNECT( this, updateRequested(), this, doUpdate() );
-
- playlist_t *p_playlist = pl_Hold( p_this );
- var_AddCallback( p_playlist, "item-change",
- downloadCoverCallback, this );
- pl_Release( p_this );
+ CONNECT( THEMIM->getIM(), artChanged( QString ),
+ this, doUpdate( const QString& ) );
setMinimumHeight( 128 );
setMinimumWidth( 128 );
setMaximumHeight( 128 );
setMaximumWidth( 128 );
setScaledContents( true );
+ QList< QAction* > artActions = actions();
+ QAction *action = new QAction( qtr( "Download cover art" ), this );
+ addAction( action );
+ CONNECT( action, triggered(), this, doUpdate() );
doUpdate();
}
-void CoverArtLabel::downloadCover()
+CoverArtLabel::~CoverArtLabel()
{
- if( p_input )
- {
- playlist_t *p_playlist = pl_Hold( p_this );
- playlist_AskForArtEnqueue( p_playlist, p_input );
- pl_Release( p_this );
- }
+ QList< QAction* > artActions = actions();
+ foreach( QAction *act, artActions )
+ removeAction( act );
}
-void CoverArtLabel::doUpdate()
+void CoverArtLabel::doUpdate( const QString& url )
{
- if( !p_input )
+ QPixmap pix;
+ if( !url.isEmpty() && pix.load( url ) )
{
- setPixmap( QPixmap( ":/noart.png" ) );
- QList< QAction* > artActions = actions();
- if( !artActions.isEmpty() )
- foreach( QAction *act, artActions )
- removeAction( act );
- prevArt = "";
+ setPixmap( pix );
}
else
{
- char *psz_meta = input_item_GetArtURL( p_input );
- if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
- {
- QString artUrl = qfu( psz_meta ).replace( "file://", "" );
- if( artUrl != prevArt )
- {
- QPixmap pix;
- if( pix.load( artUrl ) )
- setPixmap( pix );
- else
- {
- msg_Dbg( p_this, "Qt could not load image '%s'",
- qtu( artUrl ) );
- setPixmap( QPixmap( ":/noart.png" ) );
- }
- }
- QList< QAction* > artActions = actions();
- if( !artActions.isEmpty() )
- {
- foreach( QAction *act, artActions )
- removeAction( act );
- }
- prevArt = artUrl;
- }
- else
- {
- if( prevArt != "" )
- setPixmap( QPixmap( ":/noart.png" ) );
- prevArt = "";
- QList< QAction* > artActions = actions();
- if( artActions.isEmpty() )
- {
- QAction *action = new QAction( qtr( "Download cover art" ),
- this );
- addAction( action );
- CONNECT( action, triggered(),
- this, downloadCover() );
- }
- }
- free( psz_meta );
+ setPixmap( QPixmap( ":/noart.png" ) );
}
}
+void CoverArtLabel::doUpdate()
+{
+ THEMIM->getIM()->requestArtUpdate();
+}
+
TimeLabel::TimeLabel( intf_thread_t *_p_intf ) :QLabel(), p_intf( _p_intf )
{
b_remainingTime = false;
setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
+ CONNECT( THEMIM->getIM(), cachingChanged( float ),
+ this, setCaching( float ) );
CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
this, setDisplayPosition( float, int, int ) );
}
void TimeLabel::setDisplayPosition( float pos, int time, int length )
{
+ if( pos == -1.f )
+ {
+ setText( " --:--/--:-- " );
+ return;
+ }
+
char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
secstotimestr( psz_length, length );
secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
b_remainingTime = !b_remainingTime;
}
-bool VolumeClickHandler::eventFilter( QObject *obj, QEvent *e )
+void TimeLabel::setCaching( float f_cache )
{
- 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;
+ QString amount;
+ amount.setNum( (int)(100 * f_cache) );
+ msg_Dbg( p_intf, "New caching: %d", (int)(100*f_cache));
+ setText( "Buff: " + amount + "%" );
}
+