[vlc-devel] [PATCH] Qt4: Add dialog to set specific playback speed

Edward Wang edward.c.wang at compdigitec.com
Thu Dec 29 02:29:02 CET 2011


This patch adds a dialog to be able to set a specific playback speed (e.g. 0.97x or 1.01x) instead of fumbling around with the small slider to get a desired value.
Fixes bug #5734.
Thanks,
	Edward Wang

---
 modules/gui/qt4/Modules.am                       |    7 +-
 modules/gui/qt4/components/interface_widgets.cpp |    6 +-
 modules/gui/qt4/components/interface_widgets.hpp |    9 ++-
 modules/gui/qt4/dialogs/setspeed.cpp             |  110 ++++++++++++++++++++++
 modules/gui/qt4/dialogs/setspeed.hpp             |   50 ++++++++++
 modules/gui/qt4/dialogs_provider.cpp             |    6 +
 modules/gui/qt4/dialogs_provider.hpp             |    1 +
 modules/gui/qt4/main_interface.cpp               |    1 +
 8 files changed, 186 insertions(+), 4 deletions(-)
 create mode 100644 modules/gui/qt4/dialogs/setspeed.cpp
 create mode 100644 modules/gui/qt4/dialogs/setspeed.hpp

diff --git a/modules/gui/qt4/Modules.am b/modules/gui/qt4/Modules.am
index 22c2277..56510f5 100644
--- a/modules/gui/qt4/Modules.am
+++ b/modules/gui/qt4/Modules.am
@@ -38,6 +38,7 @@ nodist_SOURCES_qt4 = \
 		dialogs/convert.moc.cpp \
 		dialogs/help.moc.cpp \
 		dialogs/gototime.moc.cpp \
+		dialogs/setspeed.moc.cpp \
 		dialogs/toolbar.moc.cpp \
 		dialogs/open.moc.cpp \
 		dialogs/openurl.moc.cpp \
@@ -245,8 +246,8 @@ endif
 	$(AM_V_at)sed -e 's/Q_(\"_(\\\"\(.*\)\\\")"/Q_("\1"/' $@.tmp >$@
 	$(AM_V_at)rm -f $@.tmp

-.mm.lo:
-	$(top_builddir)/libtool --verbose --mode=compile $(CXX) $(objcxxflags) -DQ_WS_MAC -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_builddir) $(CXXFLAGS_qt4) -c $< -o $@
+.mm.lo:
+	$(top_builddir)/libtool --verbose --mode=compile $(CXX) $(objcxxflags) -DQ_WS_MAC -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_builddir) $(CXXFLAGS_qt4) -c $< -o $@

 SOURCES_qt4 = 	qt4.cpp \
 		menus.cpp \
@@ -273,6 +274,7 @@ SOURCES_qt4 = 	qt4.cpp \
 		dialogs/convert.cpp \
 		dialogs/help.cpp \
 		dialogs/gototime.cpp \
+		dialogs/setspeed.cpp \
 		dialogs/toolbar.cpp \
 		dialogs/open.cpp \
 		dialogs/openurl.cpp \
@@ -351,6 +353,7 @@ noinst_HEADERS = \
 	dialogs/convert.hpp \
 	dialogs/help.hpp \
 	dialogs/gototime.hpp \
+	dialogs/setspeed.hpp \
 	dialogs/toolbar.hpp \
 	dialogs/open.hpp \
 	dialogs/openurl.hpp \
diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp
index e384092..eae1890 100644
--- a/modules/gui/qt4/components/interface_widgets.cpp
+++ b/modules/gui/qt4/components/interface_widgets.cpp
@@ -333,7 +333,11 @@ void VisualSelector::next()
 SpeedLabel::SpeedLabel( intf_thread_t *_p_intf, QWidget *parent )
            : QLabel( parent ), p_intf( _p_intf )
 {
-    tooltipStringPattern = qtr( "Current playback speed: %1\nClick to adjust" );
+    tooltipStringPattern = qtr( "Current playback speed: %1" ) +
+                           QString("\n- ") +
+                           qtr( "Click to adjust" ) +
+                           QString("\n- ") +
+                           qtr( "Right click to set a specific playback speed" );

     /* Create the Speed Control Widget */
     speedControl = new SpeedControlWidget( p_intf, this );
diff --git a/modules/gui/qt4/components/interface_widgets.hpp b/modules/gui/qt4/components/interface_widgets.hpp
index a2ce18f..75b7ec8 100644
--- a/modules/gui/qt4/components/interface_widgets.hpp
+++ b/modules/gui/qt4/components/interface_widgets.hpp
@@ -164,12 +164,19 @@ class SpeedLabel : public QLabel
 public:
     SpeedLabel( intf_thread_t *, QWidget * );
     virtual ~SpeedLabel();
+signals:
+    void speedLabelRightClicked();

 protected:
     virtual void mousePressEvent ( QMouseEvent * event )
     {
-        showSpeedMenu( event->pos() );
+        if( event->button() == Qt::RightButton ) {
+            emit speedLabelRightClicked();
+        } else {
+            showSpeedMenu( event->pos() );
+        }
     }
+
 private slots:
     void showSpeedMenu( QPoint );
     void setRate( float );
diff --git a/modules/gui/qt4/dialogs/setspeed.cpp b/modules/gui/qt4/dialogs/setspeed.cpp
new file mode 100644
index 0000000..eccceb4
--- /dev/null
+++ b/modules/gui/qt4/dialogs/setspeed.cpp
@@ -0,0 +1,110 @@
+/*****************************************************************************
+ * setspeed.cpp : Set speed dialog
+ ****************************************************************************
+ * Copyright (C) 2011 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Edward Wang <edward.c.wang (at) compdigitec.com>
+ *          Jean-Baptiste Kempf <jb (at) videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "dialogs/setspeed.hpp"
+
+#include "input_manager.hpp"
+
+#include <QTabWidget>
+#include <QLabel>
+#include <QDoubleSpinBox>
+#include <QGroupBox>
+#include <QDialogButtonBox>
+#include <QPushButton>
+
+SetSpeedDialog::SetSpeedDialog( intf_thread_t* _p_intf)
+               : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
+{
+    setWindowFlags( Qt::Tool );
+    setWindowTitle( qtr( "Set playback speed" ) );
+    setWindowRole( "vlc-set-time" );
+
+    QGridLayout* mainLayout = new QGridLayout( this );
+    mainLayout->setSizeConstraint( QLayout::SetFixedSize );
+
+    QPushButton* setButton = new QPushButton( qtr( "&Set" ) );
+    QPushButton* cancelButton = new QPushButton( qtr( "&Cancel" ) );
+    QDialogButtonBox* buttonBox = new QDialogButtonBox;
+
+    setButton->setDefault( true );
+    buttonBox->addButton( setButton, QDialogButtonBox::AcceptRole );
+    buttonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
+
+    QLabel* speedIntro = new QLabel( qtr( "Set playback speed" ) + ":" );
+    speedIntro->setWordWrap( true );
+    speedIntro->setAlignment( Qt::AlignCenter );
+
+    valueBox = new QDoubleSpinBox();
+    valueBox->setDecimals( 2 );
+    valueBox->setMaximum( 32 );
+    valueBox->setMinimum( 0.03F );
+    valueBox->setSingleStep( 0.10F );
+    valueBox->setAlignment( Qt::AlignRight );
+    valueBox->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
+
+    QPushButton* resetButton = new QPushButton( QIcon(":/update"), "" );
+    resetButton->setToolTip( qtr("Reset") );
+
+    mainLayout->addWidget( speedIntro, 0, 0, 1, 1 );
+    mainLayout->addWidget( valueBox, 0, 1, 1, 1 );
+    mainLayout->addWidget( resetButton, 0, 2, 1, 1 );
+
+    mainLayout->addWidget( buttonBox, 1, 0, 1, 3 );
+
+    BUTTONACT( setButton, close() );
+    BUTTONACT( cancelButton, cancel() );
+    BUTTONACT( resetButton, reset() );
+}
+
+SetSpeedDialog::~SetSpeedDialog()
+{
+}
+
+void SetSpeedDialog::toggleVisible()
+{
+    reset();
+    valueBox->setValue( var_InheritFloat( THEPL, "rate" ) );
+    QVLCDialog::toggleVisible();
+}
+
+void SetSpeedDialog::cancel()
+{
+    reset();
+    toggleVisible();
+}
+
+void SetSpeedDialog::close()
+{
+    if ( THEMIM->getIM()->hasInput() )
+        var_SetFloat( THEPL, "rate", valueBox->value() );
+    toggleVisible();
+}
+
+void SetSpeedDialog::reset()
+{
+    valueBox->setValue( 1.00F );
+}
diff --git a/modules/gui/qt4/dialogs/setspeed.hpp b/modules/gui/qt4/dialogs/setspeed.hpp
new file mode 100644
index 0000000..58e43d1
--- /dev/null
+++ b/modules/gui/qt4/dialogs/setspeed.hpp
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * setspeed.hpp : Set speed dialog
+ ****************************************************************************
+ * Copyright (C) 2011 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Edward Wang <edward.c.wang (at) compdigitec.com>
+ *          Jean-Baptiste Kempf <jb (at) videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef QVLC_SETSPEED_DIALOG_H_
+#define QVLC_SETSPEED_DIALOG_H_ 1
+
+#include "util/qvlcframe.hpp"
+#include "util/singleton.hpp"
+
+#include <QDoubleSpinBox>
+
+class SetSpeedDialog : public QVLCDialog, public Singleton<SetSpeedDialog>
+{
+    Q_OBJECT
+private:
+    SetSpeedDialog( intf_thread_t* );
+    virtual ~SetSpeedDialog();
+    QDoubleSpinBox* valueBox;
+private slots:
+    void close();
+    void cancel();
+    void reset();
+
+    friend class    Singleton<SetSpeedDialog>;
+public:
+    void toggleVisible();
+};
+
+#endif
diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index a18b4b6..b8f5cf4 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -50,6 +50,7 @@
 #include "dialogs/openurl.hpp"
 #include "dialogs/help.hpp"
 #include "dialogs/gototime.hpp"
+#include "dialogs/setspeed.hpp"
 #include "dialogs/podcast_configuration.hpp"
 #include "dialogs/toolbar.hpp"
 #include "dialogs/plugins.hpp"
@@ -220,6 +221,11 @@ void DialogsProvider::gotoTimeDialog()
     GotoTimeDialog::getInstance( p_intf )->toggleVisible();
 }

+void DialogsProvider::setSpeedDialog()
+{
+    SetSpeedDialog::getInstance( p_intf )->toggleVisible();
+}
+
 #ifdef ENABLE_VLM
 void DialogsProvider::vlmDialog()
 {
diff --git a/modules/gui/qt4/dialogs_provider.hpp b/modules/gui/qt4/dialogs_provider.hpp
index 7429057..d859647 100644
--- a/modules/gui/qt4/dialogs_provider.hpp
+++ b/modules/gui/qt4/dialogs_provider.hpp
@@ -139,6 +139,7 @@ public slots:
 #endif
     void aboutDialog();
     void gotoTimeDialog();
+    void setSpeedDialog();
     void podcastConfigureDialog();
     void toolbarDialog();
     void pluginDialog();
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 19c65a8..abf790a 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -463,6 +463,7 @@ inline void MainInterface::createStatusBar()
     nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
                                       | Qt::TextSelectableByKeyboard );
     SpeedLabel *speedLabel = new SpeedLabel( p_intf, this );
+    CONNECT( speedLabel, speedLabelRightClicked(), THEDP, setSpeedDialog() );

     /* Styling those labels */
     timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
--
1.7.5.4




More information about the vlc-devel mailing list