main_interface.cpp 5.05 KB
Newer Older
zorglub's avatar
zorglub committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************
 * main_inteface.cpp : Main interface
 ****************************************************************************
 * Copyright (C) 2000-2005 the VideoLAN team
 * $Id: wxwidgets.cpp 15731 2006-05-25 14:43:53Z zorglub $
 *
 * Authors: Clément Stenac <zorglub@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
#include "qt4.hpp"
zorglub's avatar
zorglub committed
24
#include "main_interface.hpp"
zorglub's avatar
zorglub committed
25
#include "input_manager.hpp"
26
#include "util/input_slider.hpp"
zorglub's avatar
zorglub committed
27
#include "util/qvlcframe.hpp"
zorglub's avatar
zorglub committed
28
#include "dialogs_provider.hpp"
29
#include "components/video_widget.hpp"
zorglub's avatar
zorglub committed
30
#include <QCloseEvent>
31
#include <assert.h>
zorglub's avatar
zorglub committed
32
#include <QPushButton>
zorglub's avatar
zorglub committed
33

34 35
MainInterface::MainInterface( intf_thread_t *_p_intf ) : QMainWindow(),
                                                         p_intf( _p_intf )
zorglub's avatar
zorglub committed
36
{
37 38 39 40
    /* All UI stuff */
    QVLCFrame::fixStyle( this );
    QWidget *main = new QWidget( this );
    setCentralWidget( main );
zorglub's avatar
zorglub committed
41
    setWindowTitle( QString::fromUtf8( _("VLC media player") ) );
42
    ui.setupUi( centralWidget() );
zorglub's avatar
Icons  
zorglub committed
43

zorglub's avatar
zorglub committed
44 45 46 47
    slider = new InputSlider( Qt::Horizontal, ui.sliderBox );
    QVBoxLayout *box_layout = new QVBoxLayout();
    box_layout->addWidget( slider );
    ui.sliderBox->setLayout( box_layout );
zorglub's avatar
zorglub committed
48 49 50 51
    ui.prevButton->setText( "" );
    ui.nextButton->setText( "" );
    ui.playButton->setText( "" ); 
    ui.stopButton->setText( "" ); 
zorglub's avatar
Icons  
zorglub committed
52 53 54 55 56 57 58
    ui.prevButton->setIcon( QIcon( ":/pixmaps/previous.png" ) );
    ui.nextButton->setIcon( QIcon( ":/pixmaps/next.png" ) );
    ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
    ui.stopButton->setIcon( QIcon( ":/pixmaps/stop.png" ) );
    ui.volLowLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
    ui.volHighLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );

59 60 61 62 63 64 65 66 67 68

//    if( config_GetInt( p_intf, "embedded" ) )
    {
        videoWidget = new VideoWidget( p_intf );
        videoWidget->resize( 1,1 );
        ui.vboxLayout->insertWidget( 0, videoWidget );
    }
    resize( QSize( 500, 121 ) );
    i_saved_width = width();
    i_saved_height = height();
zorglub's avatar
Icons  
zorglub committed
69 70

    //QVLCMenu::createMenuBar();
zorglub's avatar
zorglub committed
71 72

    /* Init input manager */
73
    MainInputManager::getInstance( p_intf );
zorglub's avatar
zorglub committed
74

zorglub's avatar
zorglub committed
75
    /* Get timer updates */
zorglub's avatar
zorglub committed
76 77
    connect( DialogsProvider::getInstance(NULL)->fixed_timer,
             SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
zorglub's avatar
zorglub committed
78

zorglub's avatar
zorglub committed
79
    /* Connect the input manager to the GUI elements it manages */
80 81
    connect( MainInputManager::getInstance( p_intf )->getIM(),
             SIGNAL(positionUpdated( float, int, int ) ),
zorglub's avatar
zorglub committed
82 83
             slider, SLOT( setPosition( float,int, int ) ) );
    connect( slider, SIGNAL( sliderDragged( float ) ),
84 85 86 87
             MainInputManager::getInstance( p_intf )->getIM(),
             SLOT( sliderUpdate( float ) ) );
    connect( MainInputManager::getInstance( p_intf )->getIM(),
             SIGNAL( positionUpdated( float, int, int ) ),
zorglub's avatar
zorglub committed
88
             this, SLOT( setDisplay( float, int, int ) ) );
89

zorglub's avatar
zorglub committed
90 91 92 93 94
    /* Actions */
    connect( ui.playButton, SLOT( clicked() ), this, SLOT( play() ) );
    connect( ui.stopButton, SLOT( clicked() ), this, SLOT( stop() ) );
    connect( ui.nextButton, SLOT( clicked() ), this, SLOT( next() ) );
    connect( ui.prevButton, SLOT( clicked() ), this, SLOT( prev() ) );
zorglub's avatar
zorglub committed
95 96 97

    connect( ui.playlistButton, SLOT(clicked() ), 
             DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
zorglub's avatar
zorglub committed
98 99 100 101 102
}

MainInterface::~MainInterface()
{
}
zorglub's avatar
zorglub committed
103

104 105 106 107 108 109 110
QSize MainInterface::sizeHint() const
{
    int i_width = __MAX( i_saved_width, p_intf->p_sys->p_video->i_video_width );
    return QSize( i_width, i_saved_height +
                             p_intf->p_sys->p_video->i_video_height );
}

zorglub's avatar
zorglub committed
111 112
void MainInterface::stop()
{
113
    playlist_Stop( THEPL );
zorglub's avatar
zorglub committed
114 115 116
}
void MainInterface::play()
{
117
    playlist_Play( THEPL );
zorglub's avatar
zorglub committed
118 119 120
}
void MainInterface::prev()
{
121
    playlist_Prev( THEPL );
zorglub's avatar
zorglub committed
122 123 124
}
void MainInterface::next()
{
125
    playlist_Next( THEPL );
zorglub's avatar
zorglub committed
126 127 128 129 130 131 132 133 134 135 136 137
}

void MainInterface::setDisplay( float pos, int time, int length )
{
    char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
    secstotimestr( psz_length, length );
    secstotimestr( psz_time, time );
    QString title;
    title.sprintf( "%s/%s", psz_time, psz_length );
    ui.sliderBox->setTitle( title );
}

zorglub's avatar
zorglub committed
138 139
void MainInterface::updateOnTimer()
{
zorglub's avatar
zorglub committed
140 141 142 143 144 145 146 147 148 149
    if( p_intf->b_die )
    {
        QApplication::quit();
    }
}

void MainInterface::closeEvent( QCloseEvent *e )
{
    hide();
    p_intf->b_die = VLC_TRUE;
zorglub's avatar
zorglub committed
150
}