[vlc-devel] [PATCH] Qt4: UI enhancements
Edward Wang
edward.c.wang at compdigitec.com
Sat Dec 31 16:18:16 CET 2011
This patch adds separate elapsed and total/remaining labels, as well as a
horizontal speed slider with doublespinbox.
Thanks,
Edward Wang
---
modules/gui/qt4/components/controller.cpp | 16 ++++-
modules/gui/qt4/components/controller.hpp | 5 +-
modules/gui/qt4/components/interface_widgets.cpp | 91 +++++++++++++++++----
modules/gui/qt4/components/interface_widgets.hpp | 18 ++++-
modules/gui/qt4/dialogs/toolbar.cpp | 12 +++
modules/gui/qt4/main_interface.cpp | 2 +-
6 files changed, 120 insertions(+), 24 deletions(-)
diff --git a/modules/gui/qt4/components/controller.cpp b/modules/gui/qt4/components/controller.cpp
index 22d3792..6a4bfac 100644
--- a/modules/gui/qt4/components/controller.cpp
+++ b/modules/gui/qt4/components/controller.cpp
@@ -380,7 +380,7 @@ QWidget *AbstractController::createWidget( buttonType_e button, int options )
break;
case TIME_LABEL:
{
- TimeLabel *timeLabel = new TimeLabel( p_intf );
+ TimeLabel *timeLabel = new TimeLabel( p_intf, TimeLabel::Both );
widget = timeLabel;
}
break;
@@ -468,6 +468,20 @@ QWidget *AbstractController::createWidget( buttonType_e button, int options )
case ASPECT_RATIO_COMBOBOX:
widget = new AspectRatioComboBox( p_intf );
break;
+ case SPEED_LABEL:
+ {
+ SpeedLabel* label = new SpeedLabel( p_intf, this );
+ label->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
+ label->setLineWidth( 1 );
+ widget = label;
+ }
+ 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;
diff --git a/modules/gui/qt4/components/controller.hpp b/modules/gui/qt4/components/controller.hpp
index 96d53c0..1f0743d 100644
--- a/modules/gui/qt4/components/controller.hpp
+++ b/modules/gui/qt4/components/controller.hpp
@@ -37,7 +37,7 @@
#define MAIN_TB1_DEFAULT "64;39;64;38;65"
#define MAIN_TB2_DEFAULT "0-2;64;3;1;4;64;7;9;64;10;20;19;64-4;37;65;35-4"
#define ADV_TB_DEFAULT "12;11;13;14"
-#define INPT_TB_DEFAULT "5-1;15-1;33;6-1"
+#define INPT_TB_DEFAULT "43;33;44;42"
#define FSC_TB_DEFAULT "0-2;64;3;1;4;64;37;64;38;64;8;65;25;35-4;34"
#define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a medium")
@@ -100,6 +100,9 @@ typedef enum buttonType_e
ADVANCED_CONTROLLER,
PLAYBACK_BUTTONS,
ASPECT_RATIO_COMBOBOX,
+ SPEED_LABEL,
+ TIME_LABEL_ELAPSED,
+ TIME_LABEL_REMAINING,
SPECIAL_MAX,
WIDGET_SPACER = 0x40,
diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp
index e384092..c83fd48 100644
--- a/modules/gui/qt4/components/interface_widgets.cpp
+++ b/modules/gui/qt4/components/interface_widgets.cpp
@@ -383,15 +383,15 @@ void SpeedLabel::setRate( float rate )
SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i, QWidget *_parent )
: QFrame( _parent ), p_intf( _p_i )
{
- QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
+ QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Maximum );
sizePolicy.setHorizontalStretch( 0 );
sizePolicy.setVerticalStretch( 0 );
speedSlider = new QSlider( this );
speedSlider->setSizePolicy( sizePolicy );
- speedSlider->setMaximumSize( QSize( 80, 200 ) );
- speedSlider->setOrientation( Qt::Vertical );
- speedSlider->setTickPosition( QSlider::TicksRight );
+ speedSlider->setMinimumSize( QSize( 200, 24 ) );
+ speedSlider->setOrientation( Qt::Horizontal );
+ speedSlider->setTickPosition( QSlider::TicksAbove );
speedSlider->setRange( -34, 34 );
speedSlider->setSingleStep( 1 );
@@ -408,11 +408,24 @@ SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i, QWidget *_parent )
CONNECT( normalSpeedButton, clicked(), this, resetRate() );
- QVBoxLayout *speedControlLayout = new QVBoxLayout( this );
+ spinBox = new QDoubleSpinBox();
+ spinBox->setDecimals( 2 );
+ spinBox->setMaximum( 32 );
+ spinBox->setMinimum( 0.03F );
+ spinBox->setSingleStep( 0.10F );
+ spinBox->setAlignment( Qt::AlignRight );
+
+ CONNECT( spinBox, valueChanged( double ), this, updateSpinBoxRate( double ) );
+
+ QVBoxLayout* speedControlLayout = new QVBoxLayout( this );
+ QHBoxLayout* hboxLayout = new QHBoxLayout();
+ hboxLayout->addWidget( spinBox );
+ hboxLayout->addWidget( normalSpeedButton );
speedControlLayout->setContentsMargins( 4, 4, 4, 4 );
speedControlLayout->setSpacing( 4 );
speedControlLayout->addWidget( speedSlider );
- speedControlLayout->addWidget( normalSpeedButton );
+ speedControlLayout->addLayout( hboxLayout );
+ speedControlLayout->setAlignment( hboxLayout, Qt::AlignHCenter );
lastValue = 0;
@@ -422,6 +435,7 @@ SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i, QWidget *_parent )
void SpeedControlWidget::activateOnState()
{
speedSlider->setEnabled( THEMIM->getIM()->hasInput() );
+ spinBox->setEnabled( THEMIM->getIM()->hasInput() );
}
void SpeedControlWidget::updateControls( float rate )
@@ -446,6 +460,7 @@ void SpeedControlWidget::updateControls( float rate )
lastValue = sliderValue;
speedSlider->setValue( sliderValue );
+ spinBox->setValue( rate );
}
void SpeedControlWidget::updateRate( int sliderValue )
@@ -457,6 +472,12 @@ void SpeedControlWidget::updateRate( int sliderValue )
int rate = INPUT_RATE_DEFAULT / speed;
THEMIM->getIM()->setRate(rate);
+ spinBox->setValue( var_InheritFloat( THEPL, "rate" ) );
+}
+
+void SpeedControlWidget::updateSpinBoxRate( double r )
+{
+ var_SetFloat( THEPL, "rate", r );
}
void SpeedControlWidget::resetRate()
@@ -512,17 +533,33 @@ void CoverArtLabel::askForUpdate()
THEMIM->getIM()->requestArtUpdate();
}
-TimeLabel::TimeLabel( intf_thread_t *_p_intf )
+TimeLabel::TimeLabel( intf_thread_t *_p_intf, TimeLabel::Display _displayType )
: QLabel(), p_intf( _p_intf ), bufTimer( new QTimer(this) ),
- buffering( false ), showBuffering(false), bufVal( -1 )
+ buffering( false ), showBuffering(false), bufVal( -1 ), displayType( _displayType )
{
b_remainingTime = false;
- setText( " --:--/--:-- " );
+ switch( _displayType ) {
+ case TimeLabel::Elapsed:
+ setText( " --:-- " );
+ setToolTip( qtr("Elapsed time") );
+ break;
+ case TimeLabel::Remaining:
+ setText( " --:-- " );
+ setToolTip( qtr("Total/Remaining time")
+ + QString("\n-")
+ + qtr("Click to toggle between total and remaining time")
+ );
+ break;
+ case TimeLabel::Both:
+ setText( " --:--/--:-- " );
+ setToolTip( QString( "- " )
+ + qtr( "Click to toggle between elapsed and remaining time" )
+ + QString( "\n- " )
+ + qtr( "Double click to jump to a chosen time position" ) );
+ break;
+ }
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(), positionUpdated( float, int64_t, int ),
@@ -530,6 +567,8 @@ TimeLabel::TimeLabel( intf_thread_t *_p_intf )
CONNECT( THEMIM->getIM(), cachingChanged( float ),
this, updateBuffering( float ) );
CONNECT( bufTimer, timeout(), this, updateBuffering() );
+
+ this->setContentsMargins( 4, 0, 4, 0 );
}
void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
@@ -539,7 +578,10 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
if( pos == -1.f )
{
- setText( " --:--/--:-- " );
+ if( displayType == TimeLabel::Both )
+ setText( " --:--/--:-- " );
+ else
+ setText( " --:-- " );
return;
}
@@ -548,14 +590,27 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
secstotimestr( psz_length, length );
secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
: time );
-
- QString timestr = QString( " %1%2/%3 " )
+ switch( displayType )
+ {
+ case TimeLabel::Elapsed:
+ setText( QString(" ") + QString( psz_time ) + QString(" ") );
+ break;
+ case TimeLabel::Remaining:
+ if( b_remainingTime )
+ setText( QString(" -") + QString( psz_time ) + QString(" ") );
+ else
+ setText( QString(" ") + QString( psz_length ) + QString(" ") );
+ break;
+ case TimeLabel::Both:
+ default:
+ QString timestr = QString( " %1%2/%3 " )
.arg( QString( (b_remainingTime && length) ? "-" : "" ) )
.arg( QString( psz_time ) )
.arg( QString( ( !length && time ) ? "--:--" : psz_length ) );
- setText( timestr );
-
+ setText( timestr );
+ break;
+ }
cachedLength = length;
}
diff --git a/modules/gui/qt4/components/interface_widgets.hpp b/modules/gui/qt4/components/interface_widgets.hpp
index a2ce18f..3026243 100644
--- a/modules/gui/qt4/components/interface_widgets.hpp
+++ b/modules/gui/qt4/components/interface_widgets.hpp
@@ -122,15 +122,24 @@ class TimeLabel : public QLabel
{
Q_OBJECT
public:
- TimeLabel( intf_thread_t *_p_intf );
+ enum Display
+ {
+ Elapsed,
+ Remaining,
+ Both
+ };
+
+ TimeLabel( intf_thread_t *_p_intf, TimeLabel::Display _displayType );
protected:
virtual void mousePressEvent( QMouseEvent *event )
{
+ if( displayType == TimeLabel::Elapsed ) return;
toggleTimeDisplay();
event->accept();
}
virtual void mouseDoubleClickEvent( QMouseEvent *event )
{
+ if( displayType != TimeLabel::Both ) return;
event->accept();
toggleTimeDisplay();
emit timeLabelDoubleClicked();
@@ -144,6 +153,7 @@ private:
bool buffering;
bool showBuffering;
float bufVal;
+ TimeLabel::Display displayType;
char psz_length[MSTRTIME_MAX_SIZE];
char psz_time[MSTRTIME_MAX_SIZE];
@@ -188,8 +198,9 @@ public:
SpeedControlWidget( intf_thread_t *, QWidget * );
void updateControls( float );
private:
- intf_thread_t *p_intf;
- QSlider *speedSlider;
+ intf_thread_t* p_intf;
+ QSlider* speedSlider;
+ QDoubleSpinBox* spinBox;
int lastValue;
public slots:
@@ -197,6 +208,7 @@ public slots:
private slots:
void updateRate( int );
+ void updateSpinBoxRate( double );
void resetRate();
};
diff --git a/modules/gui/qt4/dialogs/toolbar.cpp b/modules/gui/qt4/dialogs/toolbar.cpp
index 43ebf09..bd1e982 100644
--- a/modules/gui/qt4/dialogs/toolbar.cpp
+++ b/modules/gui/qt4/dialogs/toolbar.cpp
@@ -449,6 +449,18 @@ WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
widget = new AspectRatioComboBox( p_intf );
widgetItem->setText( qtr("Aspect ratio selector") );
break;
+ case SPEED_LABEL:
+ widget = new SpeedLabel( p_intf, this );
+ widgetItem->setText( qtr("Speed selector") );
+ break;
+ case TIME_LABEL_ELAPSED:
+ widget = new QLabel( "2:42", this );
+ widgetItem->setText( qtr("Elasped time") );
+ break;
+ case TIME_LABEL_REMAINING:
+ widget = new QLabel( "-2:42", this );
+ widgetItem->setText( qtr("Total/Remaining time") );
+ break;
default:
msg_Warn( p_intf, "This should not happen %i", i );
break;
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 19c65a8..21a8c9c 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -458,7 +458,7 @@ inline void MainInterface::createStatusBar()
/* Widgets Creation*/
QStatusBar *statusBarr = statusBar();
- TimeLabel *timeLabel = new TimeLabel( p_intf );
+ TimeLabel *timeLabel = new TimeLabel( p_intf, TimeLabel::Both );
nameLabel = new QLabel( this );
nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
| Qt::TextSelectableByKeyboard );
--
1.7.5.4
More information about the vlc-devel
mailing list