#include <QMenu>
#include <QWidgetAction>
#include <QDesktopWidget>
+#include <QPainter>
#ifdef Q_WS_X11
# include <X11/Xlib.h>
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
-
- CONNECT( THEMIM->getIM(), cachingChanged( float ),
- this, setCaching( float ) );
CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
this, setDisplayPosition( float, int64_t, int ) );
}
}
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 );
psz_time, ( !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;
+ timestr.sprintf( " %s%s/%s ", (b_remainingTime && cachedLength) ? "-" : "",
+ psz_time, ( !cachedLength && time ) ? "--:--" : psz_length );
+
+ setText( timestr );
}
+
void TimeLabel::toggleTimeDisplay()
{
b_remainingTime = !b_remainingTime;
}
-void TimeLabel::setCaching( float f_cache )
+CacheLabel::CacheLabel( intf_thread_t *_p_intf, QWidget *parent )
+ : QLabel( parent ), p_intf( _p_intf ), cached( 0.f )
{
- QString amount;
- amount.sprintf("Buff: %i%%", (int)(100*f_cache) );
- setText( amount );
+ setText( qtr( "Buffering..." ) );
+ setMinimumWidth( 70 );
+ setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
+ setAlignment( Qt::AlignCenter );
+
+ CONNECT( THEMIM->getIM(), cachingChanged( float ),
+ this, showCaching( float ) );
+ CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
+ this, hideCaching() );
}
+void CacheLabel::showCaching( float _cached )
+{
+ cached = _cached;
+ show();
+ update(); //in case we are already visible
+}
+void CacheLabel::hideCaching()
+{
+ hide();
+}
+
+void CacheLabel::paintEvent( QPaintEvent* event )
+{
+ QRect r( rect() );
+ r.setWidth( r.width() * cached );
+ QPainter p( this );
+ p.setOpacity( 0.4 );
+ p.fillRect( r, palette().color( QPalette::Highlight ) );
+
+ QLabel::paintEvent( event );
+}
private:
intf_thread_t *p_intf;
bool b_remainingTime;
+ int cachedLength;
+ char psz_length[MSTRTIME_MAX_SIZE];
+ char psz_time[MSTRTIME_MAX_SIZE];
void toggleTimeDisplay();
signals:
void timeLabelDoubleClicked();
private slots:
void setDisplayPosition( float pos, int64_t time, int length );
- void setCaching( float );
+ void setDisplayPosition( float pos );
};
class SpeedLabel : public QLabel
SpeedControlWidget *speedControl;
};
+class CacheLabel : public QLabel
+{
+ Q_OBJECT
+public:
+ CacheLabel( intf_thread_t *, QWidget * );
+private slots:
+ void showCaching( float );
+ void hideCaching();
+private:
+ void paintEvent( QPaintEvent* );
+ intf_thread_t *p_intf;
+ float cached;
+};
+
/******************** Speed Control Widgets ****************/
class SpeedControlWidget : public QFrame
{
{
if( hasInput() )
var_SetFloat( p_input, "position", new_pos );
+ emit seekRequested( new_pos );
}
/* User togglePlayPause */
signals:
/// Send new position, new time and new length
void positionUpdated( float , int64_t, int );
+ void seekRequested( float pos );
void rateChanged( int );
void nameChanged( const QString& );
/// Used to signal whether we should show navigation buttons
nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
| Qt::TextSelectableByKeyboard );
SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
+ CacheLabel *cacheLabel = new CacheLabel( p_intf, this );
+ cacheLabel->hide();
/* Styling those labels */
timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
+ cacheLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
/* and adding those */
statusBarr->addWidget( nameLabel, 8 );
+ statusBarr->addPermanentWidget( cacheLabel, 0 );
statusBarr->addPermanentWidget( speedLabel, 0 );
statusBarr->addPermanentWidget( timeLabel, 0 );
CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
this, showCryptedLabel( bool ) );
+
+ connect( THEMIM->getIM(), SIGNAL(seekRequested(float)),
+ timeLabel, SLOT(setDisplayPosition(float)) );
}
#ifdef WIN32
cryptedLabel->setVisible( b_show );
}
+void MainInterface::showBuffering( float f_cache )
+{
+ QString amount = QString("Buffering: %1%").arg( (int)(100*f_cache) );
+ statusBar()->showMessage( amount, 1000 );
+}
+
/*****************************************************************************
* Systray Icon and Systray Menu
*****************************************************************************/
void handleKeyPress( QKeyEvent * );
+ void showBuffering( float );
+
signals:
void askGetVideo( WId *p_id, int *pi_x, int *pi_y,
unsigned *pi_width, unsigned *pi_height );