]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/gototime.cpp
qt4: save and restore the position of the GotoTime dialog
[vlc] / modules / gui / qt4 / dialogs / gototime.cpp
1 /*****************************************************************************
2  * gototime.cpp : GotoTime and About dialogs
3  ****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26
27 #include "dialogs/gototime.hpp"
28
29 #include "input_manager.hpp"
30
31 #include <QTabWidget>
32 #include <QLabel>
33 #include <QTimeEdit>
34 #include <QGroupBox>
35 #include <QDialogButtonBox>
36 #include <QPushButton>
37
38 GotoTimeDialog::GotoTimeDialog( intf_thread_t *_p_intf)
39                : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
40 {
41     setWindowFlags( Qt::Tool );
42     setWindowTitle( qtr( "Go to Time" ) );
43     setWindowRole( "vlc-goto-time" );
44
45     QGridLayout *mainLayout = new QGridLayout( this );
46     mainLayout->setSizeConstraint( QLayout::SetFixedSize );
47
48     QPushButton *gotoButton = new QPushButton( qtr( "&Go" ) );
49     QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
50     QDialogButtonBox *buttonBox = new QDialogButtonBox;
51
52     gotoButton->setDefault( true );
53     buttonBox->addButton( gotoButton, QDialogButtonBox::AcceptRole );
54     buttonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
55
56     QLabel *timeIntro = new QLabel( qtr( "Go to time" ) + ":" );
57     timeIntro->setWordWrap( true );
58     timeIntro->setAlignment( Qt::AlignCenter );
59
60     timeEdit = new QTimeEdit();
61     timeEdit->setDisplayFormat( "HH'H':mm'm':ss's'" );
62     timeEdit->setAlignment( Qt::AlignRight );
63     timeEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
64
65     QPushButton *resetButton = new QPushButton( QIcon(":/update"), "" );
66     resetButton->setToolTip( qtr("Reset") );
67
68     mainLayout->addWidget( timeIntro, 0, 0, 1, 1 );
69     mainLayout->addWidget( timeEdit, 0, 1, 1, 1 );
70     mainLayout->addWidget( resetButton, 0, 2, 1, 1 );
71
72     mainLayout->addWidget( buttonBox, 1, 0, 1, 3 );
73
74     BUTTONACT( gotoButton, close() );
75     BUTTONACT( cancelButton, cancel() );
76     BUTTONACT( resetButton, reset() );
77
78     QVLCTools::restoreWidgetPosition( p_intf, "gototimedialog", this );
79 }
80
81 GotoTimeDialog::~GotoTimeDialog()
82 {
83     QVLCTools::saveWidgetPosition( p_intf, "gototimedialog", this );
84 }
85
86 void GotoTimeDialog::toggleVisible()
87 {
88     reset();
89     if ( !isVisible() && THEMIM->getIM()->hasInput() )
90     {
91         int64_t i_time = var_GetTime( THEMIM->getInput(), "time" );
92         timeEdit->setTime( timeEdit->time().addSecs( i_time / 1000000 ) );
93     }
94     QVLCDialog::toggleVisible();
95     activateWindow ();
96 }
97
98 void GotoTimeDialog::cancel()
99 {
100     reset();
101     toggleVisible();
102 }
103
104 void GotoTimeDialog::close()
105 {
106     if ( THEMIM->getIM()->hasInput() )
107     {
108         int64_t i_time = (int64_t)
109             ( QTime( 0, 0, 0 ).msecsTo( timeEdit->time() ) ) * 1000;
110         var_SetTime( THEMIM->getInput(), "time", i_time );
111     }
112     toggleVisible();
113 }
114
115 void GotoTimeDialog::reset()
116 {
117     timeEdit->setTime( QTime( 0, 0, 0) );
118 }