gototime.cpp 3.74 KB
Newer Older
1
/*****************************************************************************
Pere Orga's avatar
Pere Orga committed
2
 * gototime.cpp : GotoTime and About dialogs
3
 ****************************************************************************
4
 * Copyright (C) 2007 the VideoLAN team
5
 * $Id$
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *
 * Authors: 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.
 *****************************************************************************/
23
24
25
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
26
27
28

#include "dialogs/gototime.hpp"

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
29
#include "input_manager.hpp"
30
31
32

#include <QTabWidget>
#include <QLabel>
33
34
#include <QTimeEdit>
#include <QGroupBox>
35
#include <QDialogButtonBox>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
36
#include <QPushButton>
37

38
39
GotoTimeDialog::GotoTimeDialog( intf_thread_t *_p_intf)
               : QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf )
40
{
41
    setWindowFlags( Qt::Tool );
42
    setWindowTitle( qtr( "Go to Time" ) );
Nick Pope's avatar
Nick Pope committed
43
    setWindowRole( "vlc-goto-time" );
44

45
    QGridLayout *mainLayout = new QGridLayout( this );
46
    mainLayout->setSizeConstraint( QLayout::SetFixedSize );
47

48
49
50
51
    QPushButton *gotoButton = new QPushButton( qtr( "&Go" ) );
    QPushButton *cancelButton = new QPushButton( qtr( "&Cancel" ) );
    QDialogButtonBox *buttonBox = new QDialogButtonBox;

52
    gotoButton->setDefault( true );
53
54
    buttonBox->addButton( gotoButton, QDialogButtonBox::AcceptRole );
    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
63
64
    timeEdit->setAlignment( Qt::AlignRight );
    timeEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );

65
66
67
    QPushButton *resetButton = new QPushButton( QIcon(":/update"), "" );
    resetButton->setToolTip( qtr("Reset") );

68
69
    mainLayout->addWidget( timeIntro, 0, 0, 1, 1 );
    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
75
    BUTTONACT( gotoButton, close() );
    BUTTONACT( cancelButton, cancel() );
76
    BUTTONACT( resetButton, reset() );
77
78

    QVLCTools::restoreWidgetPosition( p_intf, "gototimedialog", this );
79
80
81
82
}

GotoTimeDialog::~GotoTimeDialog()
{
83
    QVLCTools::saveWidgetPosition( p_intf, "gototimedialog", this );
84
85
}

86
87
88
89
90
91
92
93
94
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();
95
96
    if(isVisible())
        activateWindow();
97
98
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
99
100
void GotoTimeDialog::cancel()
{
101
    reset();
102
    toggleVisible();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
103
104
}

105
106
void GotoTimeDialog::close()
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
107
108
    if ( THEMIM->getIM()->hasInput() )
    {
109
110
111
        int64_t i_time = (int64_t)
            ( QTime( 0, 0, 0 ).msecsTo( timeEdit->time() ) ) * 1000;
        var_SetTime( THEMIM->getInput(), "time", i_time );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
112
    }
113
    toggleVisible();
114
115
116
117
}

void GotoTimeDialog::reset()
{
118
    timeEdit->setTime( QTime( 0, 0, 0) );
119
}