/*****************************************************************************
* interface_widgets.cpp : Custom widgets for the main interface
****************************************************************************
- * Copyright (C) 2006-2008 the VideoLAN team
+ * Copyright (C) 2006-2010 the VideoLAN team
* $Id$
*
* Authors: Clément Stenac <zorglub@videolan.org>
#endif
#include "components/interface_widgets.hpp"
+#include "dialogs_provider.hpp"
+#include "util/customwidgets.hpp" // qtEventToVLCKey, QVLCStackedWidget
#include "menus.hpp" /* Popup menu on bgWidget */
#include <QLabel>
#include <QToolButton>
#include <QPalette>
+#include <QEvent>
#include <QResizeEvent>
#include <QDate>
#include <QMenu>
#include <QWidgetAction>
#include <QDesktopWidget>
+#include <QPainter>
+#include <QTimer>
+#include <QSlider>
+#include <QBitmap>
#ifdef Q_WS_X11
# include <X11/Xlib.h>
#endif
#include <math.h>
+#include <assert.h>
class ReparentableWidget : public QWidget
{
VideoWidget *owner;
public:
ReparentableWidget( VideoWidget *owner ) : owner( owner )
- {
- }
-
-protected:
- void keyPressEvent( QKeyEvent *e )
- {
- emit owner->keyPressed( e );
- }
+ {}
};
/**********************************************************************
, reparentable( NULL )
{
/* Set the policy to expand in both directions */
-// setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
+ // setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
layout = new QHBoxLayout( this );
layout->setContentsMargins( 0, 0, 0, 0 );
* mode, and within the root window (NULL parent) in full-screen mode.
*/
reparentable = new ReparentableWidget( this );
+ reparentable->installEventFilter(this );
QLayout *innerLayout = new QHBoxLayout( reparentable );
innerLayout->setContentsMargins( 0, 0, 0, 0 );
{
if (reparentable->windowState() & Qt::WindowFullScreen )
return;
- msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
- videoSize.setWidth( w );
- videoSize.setHeight( h );
if( !isVisible() ) show();
- updateGeometry(); // Needed for deinterlace
+ resize( w, h );
+ emit sizeChanged( w, h );
+ /* Work-around a bug?misconception? that would happen when vout core resize
+ twice to the same size and would make the vout not centered.
+ This cause a small flicker.
+ See #3621
+ */
+ if( size().width() == w && size().height() == h )
+ updateGeometry();
videoSync();
}
QRect screenres = QApplication::desktop()->screenGeometry( numscreen );
- reparentable->setParent( NULL, newflags );
- reparentable->setWindowState( newstate );
/* To be sure window is on proper-screen in xinerama */
if( !screenres.contains( reparentable->pos() ) )
{
msg_Dbg( p_intf, "Moving video to correct screen");
reparentable->move( QPoint( screenres.x(), screenres.y() ) );
}
+ reparentable->setParent( NULL, newflags );
+ reparentable->setWindowState( newstate );
+
+ /* FIXME: inherit from the vout window, not the interface */
+ char *title = var_InheritString( p_intf, "video-title" );
+ reparentable->setWindowTitle( qfu(title ? title : _("Video")) );
+ free( title );
+
reparentable->show();
}
else
msg_Dbg( p_intf, "Video is not needed anymore" );
//layout->removeWidget( reparentable );
-#ifdef WIN32
- /* Come back to default thumbnail for Windows 7 taskbar */
- LPTASKBARLIST3 p_taskbl;
- OSVERSIONINFO winVer;
- winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
- {
- CoInitialize( 0 );
-
- if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
- NULL, CLSCTX_INPROC_SERVER,
- &IID_ITaskbarList3,
- (void **)&p_taskbl) )
- {
- p_taskbl->vt->HrInit(p_taskbl);
-
- HWND hroot = GetAncestor(reparentable->winId(),GA_ROOT);
-
- if (S_OK != p_taskbl->vt->SetThumbnailClip(p_taskbl, hroot, NULL))
- msg_Err(p_intf, "SetThumbNailClip failed");
- msg_Err(p_intf, "Releasing taskbar | root handle = %08x", hroot);
- p_taskbl->vt->Release(p_taskbl);
- }
- CoUninitialize();
- }
-#endif
-
- delete reparentable;
+ reparentable->deleteLater();
reparentable = NULL;
- videoSize = QSize();
updateGeometry();
hide();
}
-
-QSize VideoWidget::sizeHint() const
+#undef KeyPress
+bool VideoWidget::eventFilter(QObject *obj, QEvent *event)
{
- return videoSize;
+ if( obj == reparentable )
+ {
+ if (event->type() == QEvent::Close)
+ {
+ THEDP->quit();
+ return true;
+ }
+ else if( event->type() == QEvent::KeyPress )
+ {
+ emit keyPressed( static_cast<QKeyEvent *>(event) );
+ return true;
+ }
+ else if( event->type() == QEvent::Wheel )
+ {
+ int i_vlckey = qtWheelEventToVLCKey( static_cast<QWheelEvent *>(event) );
+ var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
+ return true;
+ }
+ }
+ return false;
}
/**********************************************************************
* Background Widget. Show a simple image background. Currently,
* it's album art if present or cone.
**********************************************************************/
-#define ICON_SIZE 128
-#define MAX_BG_SIZE 400
-#define MIN_BG_SIZE 128
BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
- :QWidget( NULL ), p_intf( _p_i )
+ :QWidget( NULL ), p_intf( _p_i ), b_expandPixmap( false )
{
- /* We should use that one to take the more size it can */
- setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
-
/* A dark background */
setAutoFillBackground( true );
QPalette plt = palette();
plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
setPalette( plt );
- /* A cone in the middle */
- label = new QLabel;
- label->setMargin( 5 );
-/* label->setMaximumHeight( MAX_BG_SIZE );
- label->setMaximumWidth( MAX_BG_SIZE );
- label->setMinimumHeight( MIN_BG_SIZE );
- label->setMinimumWidth( MIN_BG_SIZE );*/
- label->setAlignment( Qt::AlignCenter );
- if( QDate::currentDate().dayOfYear() >= 354 )
- label->setPixmap( QPixmap( ":/logo/vlc128-christmas.png" ) );
- else
- label->setPixmap( QPixmap( ":/logo/vlc128.png" ) );
-
- QGridLayout *backgroundLayout = new QGridLayout( this );
- backgroundLayout->addWidget( label, 0, 1 );
- backgroundLayout->setColumnStretch( 0, 1 );
- backgroundLayout->setColumnStretch( 2, 1 );
+ /* Init the cone art */
+ updateArt( "" );
CONNECT( THEMIM->getIM(), artChanged( QString ),
this, updateArt( const QString& ) );
}
-BackgroundWidget::~BackgroundWidget()
-{}
-
-void BackgroundWidget::resizeEvent( QResizeEvent * event )
-{
- if( event->size().height() <= MIN_BG_SIZE )
- label->hide();
- else
- label->show();
-}
-
void BackgroundWidget::updateArt( const QString& url )
{
- if( url.isEmpty() )
+ if ( !url.isEmpty() )
{
+ pixmapUrl = url;
+ }
+ else
+ { /* Xmas joke */
if( QDate::currentDate().dayOfYear() >= 354 )
- label->setPixmap( QPixmap( ":/logo/vlc128-christmas.png" ) );
+ pixmapUrl = QString( ":/logo/vlc128-christmas.png" );
else
- label->setPixmap( QPixmap( ":/logo/vlc128.png" ) );
+ pixmapUrl = QString( ":/logo/vlc128.png" );
}
- else
+ update();
+}
+
+void BackgroundWidget::paintEvent( QPaintEvent *e )
+{
+ int i_maxwidth, i_maxheight;
+ QPixmap pixmap = QPixmap( pixmapUrl );
+ QPainter painter(this);
+ QBitmap pMask;
+ float f_alpha = 1.0;
+
+ i_maxwidth = std::min( maximumWidth(), width() ) - MARGIN * 2;
+ i_maxheight = std::min( maximumHeight(), height() ) - MARGIN * 2;
+
+ if ( height() > MARGIN * 2 )
{
- QPixmap pixmap( url );
- if( pixmap.width() > label->maximumWidth() ||
- pixmap.height() > label->maximumHeight() )
+ /* Scale down the pixmap if the widget is too small */
+ if( pixmap.width() > i_maxwidth || pixmap.height() > i_maxheight )
{
- pixmap = pixmap.scaled( label->maximumWidth(),
- label->maximumHeight(), Qt::KeepAspectRatio );
+ pixmap = pixmap.scaled( i_maxwidth, i_maxheight,
+ Qt::KeepAspectRatio, Qt::SmoothTransformation );
+ }
+ else
+ if ( b_expandPixmap &&
+ pixmap.width() < width() && pixmap.height() < height() )
+ {
+ /* Scale up the pixmap to fill widget's size */
+ f_alpha = ( (float) pixmap.height() / (float) height() );
+ pixmap = pixmap.scaled(
+ width() - MARGIN * 2,
+ height() - MARGIN * 2,
+ Qt::KeepAspectRatio,
+ ( f_alpha < .2 )? /* Don't waste cpu when not visible */
+ Qt::SmoothTransformation:
+ Qt::FastTransformation
+ );
+ /* Non agressive alpha compositing when sizing up */
+ pMask = QBitmap( pixmap.width(), pixmap.height() );
+ pMask.fill( QColor::fromRgbF( 1.0, 1.0, 1.0, f_alpha ) );
+ pixmap.setMask( pMask );
}
- label->setPixmap( pixmap );
+ painter.drawPixmap(
+ MARGIN + ( i_maxwidth - pixmap.width() ) /2,
+ MARGIN + ( i_maxheight - pixmap.height() ) /2,
+ pixmap);
}
+ QWidget::paintEvent( e );
}
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
}
#endif
-SpeedLabel::SpeedLabel( intf_thread_t *_p_intf, const QString& text,
- QWidget *parent )
- : QLabel( text, parent ), p_intf( _p_intf )
+SpeedLabel::SpeedLabel( intf_thread_t *_p_intf, QWidget *parent )
+ : QLabel( parent ), p_intf( _p_intf )
{
- setToolTip( qtr( "Current playback speed.\nClick to adjust" ) );
+ tooltipStringPattern = qtr( "Current playback speed: %1\nClick to adjust" );
/* Create the Speed Control Widget */
speedControl = new SpeedControlWidget( p_intf, this );
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() );
+ CONNECT( THEMIM->getIM(), rateChanged( float ), this, setRate( float ) );
+ DCONNECT( THEMIM, inputChanged( input_thread_t * ),
+ speedControl, activateOnState() );
+ setRate( var_InheritFloat( p_intf, "rate" ) );
}
+
SpeedLabel::~SpeedLabel()
{
- delete speedControl;
- delete speedControlMenu;
+ 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 )
+void SpeedLabel::setRate( float rate )
{
QString str;
- str.setNum( ( 1000 / (double)rate ), 'f', 2 );
+ str.setNum( rate, 'f', 2 );
str.append( "x" );
setText( str );
- setToolTip( str );
+ setToolTip( tooltipStringPattern.arg( str ) );
speedControl->updateControls( rate );
}
speedControlLayout->addWidget( speedSlider );
speedControlLayout->addWidget( normalSpeedButton );
+ lastValue = 0;
+
activateOnState();
}
speedSlider->setEnabled( THEMIM->getIM()->hasInput() );
}
-void SpeedControlWidget::updateControls( int rate )
+void SpeedControlWidget::updateControls( float rate )
{
if( speedSlider->isSliderDown() )
{
return;
}
- double value = 17 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
+ double value = 17 * log( rate ) / log( 2 );
int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
if( sliderValue < speedSlider->minimum() )
{
sliderValue = speedSlider->maximum();
}
+ lastValue = sliderValue;
- //Block signals to avoid feedback loop
- speedSlider->blockSignals( true );
speedSlider->setValue( sliderValue );
- speedSlider->blockSignals( false );
}
void SpeedControlWidget::updateRate( int sliderValue )
{
+ if( sliderValue == lastValue )
+ return;
+
double speed = pow( 2, (double)sliderValue / 17 );
int rate = INPUT_RATE_DEFAULT / speed;
void CoverArtLabel::showArtUpdate( const QString& url )
{
QPixmap pix;
- if( !url.isEmpty() && pix.load( url ) )
+ if( !url.isEmpty() && pix.load( url ) )
{
pix = pix.scaled( maximumWidth(), maximumHeight(),
- Qt::KeepAspectRatioByExpanding );
+ Qt::KeepAspectRatioByExpanding,
+ Qt::SmoothTransformation );
}
else
{
THEMIM->getIM()->requestArtUpdate();
}
-TimeLabel::TimeLabel( intf_thread_t *_p_intf ) :QLabel(), p_intf( _p_intf )
+TimeLabel::TimeLabel( intf_thread_t *_p_intf )
+ : QLabel(), p_intf( _p_intf ), bufTimer( new QTimer(this) ),
+ buffering( false ), showBuffering(false), bufVal( -1 )
{
- b_remainingTime = false;
- setText( " --:--/--:-- " );
- setAlignment( Qt::AlignRight | Qt::AlignVCenter );
- setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
-
+ b_remainingTime = false;
+ setText( " --:--/--:-- " );
+ setAlignment( Qt::AlignRight | Qt::AlignVCenter );
+ setToolTip( QString( "- " )
+ + qtr( "Click to toggle between elapsed and remaining time" )
+ + QString( "\n- " )
+ + qtr( "Double click to jump to a chosen time position" ) );
+ bufTimer->setSingleShot( true );
- CONNECT( THEMIM->getIM(), cachingChanged( float ),
- this, setCaching( float ) );
- CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
- this, setDisplayPosition( float, int64_t, int ) );
+ CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
+ this, setDisplayPosition( float, int64_t, int ) );
+ CONNECT( THEMIM->getIM(), cachingChanged( float ),
+ this, updateBuffering( float ) );
+ CONNECT( bufTimer, timeout(), this, updateBuffering() );
}
void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
{
+ showBuffering = false;
+ bufTimer->stop();
+
if( pos == -1.f )
{
setText( " --:--/--:-- " );
}
int time = t / 1000000;
- char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
+
secstotimestr( psz_length, length );
secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
: time );
- QString timestr;
- timestr.sprintf( " %s%s/%s ", (b_remainingTime && length) ? "-" : "",
- psz_time, ( !length && time ) ? "--:--" : psz_length );
+ QString timestr = QString( " %1%2/%3 " )
+ .arg( QString( (b_remainingTime && length) ? "-" : "" ) )
+ .arg( QString( psz_time ) )
+ .arg( QString( ( !length && time ) ? "--:--" : psz_length ) );
setText( timestr );
+
+ cachedLength = length;
}
+void TimeLabel::setDisplayPosition( float pos )
+{
+ if( pos == -1.f || cachedLength == 0 )
+ {
+ setText( " --:--/--:-- " );
+ return;
+ }
+
+ int time = pos * cachedLength;
+ secstotimestr( psz_time,
+ ( b_remainingTime && cachedLength ?
+ cachedLength - time : time ) );
+ QString timestr = QString( " %1%2/%3 " )
+ .arg( QString( (b_remainingTime && cachedLength) ? "-" : "" ) )
+ .arg( QString( psz_time ) )
+ .arg( QString( ( !cachedLength && time ) ? "--:--" : psz_length ) );
+
+ setText( timestr );
+}
+
+
void TimeLabel::toggleTimeDisplay()
{
b_remainingTime = !b_remainingTime;
}
-void TimeLabel::setCaching( float f_cache )
+
+void TimeLabel::updateBuffering( float _buffered )
{
- QString amount;
- amount.sprintf("Buff: %i%%", (int)(100*f_cache) );
- setText( amount );
+ bufVal = _buffered;
+ if( !buffering || bufVal == 0 )
+ {
+ showBuffering = false;
+ buffering = true;
+ bufTimer->start(200);
+ }
+ else if( bufVal == 1 )
+ {
+ showBuffering = buffering = false;
+ bufTimer->stop();
+ }
+ update();
}
+void TimeLabel::updateBuffering()
+{
+ showBuffering = true;
+ update();
+}
+void TimeLabel::paintEvent( QPaintEvent* event )
+{
+ if( showBuffering )
+ {
+ QRect r( rect() );
+ r.setLeft( r.width() * bufVal );
+ QPainter p( this );
+ p.setOpacity( 0.4 );
+ p.fillRect( r, palette().color( QPalette::Highlight ) );
+ }
+ QLabel::paintEvent( event );
+}