]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/gototime.cpp
Qt(Dialog provider): Add support for key accelerators
[vlc] / modules / gui / qt4 / dialogs / gototime.cpp
index f3803a9c257a2cf72c45b28e72af7e419e6f82ad..77035fb05b73b219c6331320f9f92fab2fd1aced 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
- * GotoTime.cpp : GotoTime and About dialogs
+ * gototime.cpp : GotoTime and About dialogs
  ****************************************************************************
  * Copyright (C) 2007 the VideoLAN team
- * $Id: Messages.cpp 16024 2006-07-13 13:51:05Z xtophe $
+ * $Id$
  *
  * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
  *
  * 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/gototime.hpp"
 
-#include "dialogs_provider.hpp"
-#include "main_interface.hpp"
-#include "util/qvlcframe.hpp"
-#include "qt4.hpp"
 #include "input_manager.hpp"
 
 #include <QTabWidget>
-#include <QFile>
 #include <QLabel>
 #include <QTimeEdit>
 #include <QGroupBox>
 #include <QDialogButtonBox>
+#include <QPushButton>
 
-GotoTimeDialog *GotoTimeDialog::instance = NULL;
-
-GotoTimeDialog::GotoTimeDialog( intf_thread_t *_p_intf) :  QVLCFrame( _p_intf )
+GotoTimeDialog::GotoTimeDialog( intf_thread_t *_p_intf)
+               : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
 {
     setWindowFlags( Qt::Tool );
     setWindowTitle( qtr( "Go to Time" ) );
-    resize( 250, 180 );
+    setWindowRole( "vlc-goto-time" );
 
     QGridLayout *mainLayout = new QGridLayout( this );
+    mainLayout->setSizeConstraint( QLayout::SetFixedSize );
 
     QPushButton *gotoButton = new QPushButton( qtr( "&Go" ) );
     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
@@ -54,49 +53,52 @@ GotoTimeDialog::GotoTimeDialog( intf_thread_t *_p_intf) :  QVLCFrame( _p_intf )
     buttonBox->addButton( gotoButton, QDialogButtonBox::AcceptRole );
     buttonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
 
-    QGroupBox *timeGroupBox = new QGroupBox( qtr("Time") );
-    QGridLayout *boxLayout = new QGridLayout( timeGroupBox );
-
-    QLabel *timeIntro = new
-        QLabel( "Enter below the desired time you want to go in the media." );
+    QLabel *timeIntro = new QLabel( qtr( "Go to time" ) + ":" );
     timeIntro->setWordWrap( true );
     timeIntro->setAlignment( Qt::AlignCenter );
 
     timeEdit = new QTimeEdit();
-    timeEdit->setDisplayFormat( "hh : mm : ss" );
+    timeEdit->setDisplayFormat( "HH'H':mm'm':ss's'" );
     timeEdit->setAlignment( Qt::AlignRight );
     timeEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
 
-    QLabel *helpFormat = new QLabel( timeEdit->displayFormat() );
-    helpFormat->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
-
-    QSpacerItem *spacerBox = new QSpacerItem(20, 10, QSizePolicy::Minimum,
-                                        QSizePolicy::Fixed);
-
-    QSpacerItem *spacerItem = new QSpacerItem(20, 3, QSizePolicy::Minimum,
-                                        QSizePolicy::Expanding);
+    QPushButton *resetButton = new QPushButton( QIcon(":/update"), "" );
+    resetButton->setToolTip( qtr("Reset") );
 
-    boxLayout->addWidget( timeIntro, 0, 0, 1, 2 );
-    boxLayout->addItem( spacerBox, 1, 0, 1, 2 );
-    boxLayout->addWidget( timeEdit, 2, 0, 1, 1 );
-    boxLayout->addWidget( helpFormat, 2, 1, 1, 1 );
+    mainLayout->addWidget( timeIntro, 0, 0, 1, 1 );
+    mainLayout->addWidget( timeEdit, 0, 1, 1, 1 );
+    mainLayout->addWidget( resetButton, 0, 2, 1, 1 );
 
-    mainLayout->addWidget( timeGroupBox, 0, 0, 1, 4 );
-    mainLayout->addItem( spacerItem, 1, 0 );
-    mainLayout->addWidget( buttonBox, 2, 3 );
+    mainLayout->addWidget( buttonBox, 1, 0, 1, 3 );
 
     BUTTONACT( gotoButton, close() );
     BUTTONACT( cancelButton, cancel() );
+    BUTTONACT( resetButton, reset() );
+
+    QVLCTools::restoreWidgetPosition( p_intf, "gototimedialog", this );
 }
 
 GotoTimeDialog::~GotoTimeDialog()
 {
+    QVLCTools::saveWidgetPosition( p_intf, "gototimedialog", this );
+}
+
+void GotoTimeDialog::toggleVisible()
+{
+    reset();
+    if ( !isVisible() && THEMIM->getIM()->hasInput() )
+    {
+        int64_t i_time = var_GetTime( THEMIM->getInput(), "time" );
+        timeEdit->setTime( timeEdit->time().addSecs( i_time / 1000000 ) );
+    }
+    QVLCDialog::toggleVisible();
+    activateWindow ();
 }
 
 void GotoTimeDialog::cancel()
 {
-    timeEdit->setTime( QTime( 0, 0, 0) );
-    this->toggleVisible();
+    reset();
+    toggleVisible();
 }
 
 void GotoTimeDialog::close()
@@ -107,5 +109,10 @@ void GotoTimeDialog::close()
             ( QTime( 0, 0, 0 ).msecsTo( timeEdit->time() ) ) * 1000;
         var_SetTime( THEMIM->getInput(), "time", i_time );
     }
-    this->toggleVisible();
+    toggleVisible();
+}
+
+void GotoTimeDialog::reset()
+{
+    timeEdit->setTime( QTime( 0, 0, 0) );
 }