main_interface.cpp 4.91 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

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

zorglub's avatar
zorglub committed
42 43 44 45
    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
46 47 48 49
    ui.prevButton->setText( "" );
    ui.nextButton->setText( "" );
    ui.playButton->setText( "" ); 
    ui.stopButton->setText( "" ); 
zorglub's avatar
Icons  
zorglub committed
50 51 52 53 54 55 56
    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" ) );

57 58 59 60 61 62
//    if( config_GetInt( p_intf, "embedded" ) )
    {
        videoWidget = new VideoWidget( p_intf );
        videoWidget->resize( 1,1 );
        ui.vboxLayout->insertWidget( 0, videoWidget );
    }
zorglub's avatar
zorglub committed
63 64

    readSettings( "MainWindow" , QSize( 500, 131) );
zorglub's avatar
Icons  
zorglub committed
65 66

    //QVLCMenu::createMenuBar();
zorglub's avatar
zorglub committed
67 68

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

zorglub's avatar
zorglub committed
71
    /* Get timer updates */
zorglub's avatar
zorglub committed
72 73
    connect( DialogsProvider::getInstance(NULL)->fixed_timer,
             SIGNAL( timeout() ), this, SLOT(updateOnTimer() ) );
zorglub's avatar
zorglub committed
74

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

zorglub's avatar
zorglub committed
86 87 88 89 90
    /* 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
91 92 93

    connect( ui.playlistButton, SLOT(clicked() ), 
             DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
zorglub's avatar
zorglub committed
94 95 96 97 98
}

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

100 101 102 103 104 105 106
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
107 108
void MainInterface::stop()
{
109
    playlist_Stop( THEPL );
zorglub's avatar
zorglub committed
110 111 112
}
void MainInterface::play()
{
113
    playlist_Play( THEPL );
zorglub's avatar
zorglub committed
114 115 116
}
void MainInterface::prev()
{
117
    playlist_Prev( THEPL );
zorglub's avatar
zorglub committed
118 119 120
}
void MainInterface::next()
{
121
    playlist_Next( THEPL );
zorglub's avatar
zorglub committed
122 123 124 125 126 127 128 129 130 131 132 133
}

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
134 135
void MainInterface::updateOnTimer()
{
zorglub's avatar
zorglub committed
136 137 138 139 140 141 142 143 144 145
    if( p_intf->b_die )
    {
        QApplication::quit();
    }
}

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