interface_widgets.cpp 36 KB
Newer Older
1
/*****************************************************************************
2
 * interface_widgets.cpp : Custom widgets for the main interface
3
 ****************************************************************************
4
 * Copyright ( C ) 2006 the VideoLAN team
5
 * $Id$
6 7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Jean-Baptiste Kempf <jb@videolan.org>
9
 *          Rafaël Carré <funman@videolanorg>
10
 *          Ilkka Ollakka <ileoo@videolan.org>
11 12 13 14
 *
 * 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
15
 * ( at your option ) any later version.
16 17 18 19 20 21 22 23 24 25
 *
 * 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.
 *****************************************************************************/
26

27 28 29
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
30

31
#include "dialogs_provider.hpp"
32
#include "components/interface_widgets.hpp"
33
#include "main_interface.hpp"
34
#include "input_manager.hpp"
35
#include "menus.hpp"
36
#include "util/input_slider.hpp"
37
#include "util/customwidgets.hpp"
Clément Stenac's avatar
Clément Stenac committed
38
#include <vlc_vout.h>
39

Clément Stenac's avatar
Clément Stenac committed
40 41
#include <QLabel>
#include <QSpacerItem>
Clément Stenac's avatar
Clément Stenac committed
42
#include <QCursor>
Clément Stenac's avatar
Clément Stenac committed
43
#include <QPushButton>
44
#include <QToolButton>
45
#include <QHBoxLayout>
Clément Stenac's avatar
Clément Stenac committed
46
#include <QMenu>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
47 48
#include <QPalette>
#include <QResizeEvent>
49
#include <QDate>
50

51 52 53 54
/**********************************************************************
 * Video Widget. A simple frame on which video is drawn
 * This class handles resize issues
 **********************************************************************/
55 56 57 58 59
static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
                        unsigned int *, unsigned int * );
static void DoRelease( intf_thread_t *, void * );
static int DoControl( intf_thread_t *, void *, int, va_list );

60
VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
61
{
62
    /* Init */
63
    vlc_mutex_init( &lock );
64
    p_vout = NULL;
65
    hide(); setMinimumSize( 16, 16 );
66 67
    videoSize.rwidth() = -1;
    videoSize.rheight() = -1;
68

69 70 71 72 73 74 75
    /* Black background is more coherent for a Video Widget IMVHO */
    QPalette plt =  palette();
    plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
    plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
    setPalette( plt );

    /* The core can ask through a callback to show the video */
76
    CONNECT( this, askVideoWidgetToShow(), this, show() );
77 78
    /* The core can ask through a callback to resize the video */
   // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
}

VideoWidget::~VideoWidget()
{
    vlc_mutex_lock( &lock );
    if( p_vout )
    {
        if( !p_intf->psz_switch_intf )
        {
            if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
                vout_Control( p_vout, VOUT_REPARENT );
        }
        else
        {
            if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
                vout_Control( p_vout, VOUT_CLOSE );
        }
    }
    vlc_mutex_unlock( &lock );
    vlc_mutex_destroy( &lock );
}

101
/**
102
 * Request the video to avoid the conflicts
103
 **/
104
void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
105 106
                           unsigned int *pi_width, unsigned int *pi_height )
{
107
    msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
108
    emit askVideoWidgetToShow();
109 110 111 112 113 114
    if( p_vout )
    {
        msg_Dbg( p_intf, "embedded video already in use" );
        return NULL;
    }
    p_vout = p_nvout;
115
    return ( void* )winId();
116 117
}

118
/* Set the Widget to the correct Size */
119 120
/* Function has to be called by the parent
   Parent has to care about resizing himself*/
121
void VideoWidget::SetSizing( unsigned int w, unsigned int h )
122
{
123 124 125 126
    msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
    videoSize.rwidth() = w;
    videoSize.rheight() = h;
    updateGeometry(); // Needed for deinterlace
127 128
}

129
void VideoWidget::release( void *p_win )
130
{
131
    msg_Dbg( p_intf, "Video is non needed anymore" );
132
    p_vout = NULL;
133 134 135 136
    videoSize.rwidth() = 0;
    videoSize.rheight() = 0;
    hide();
    updateGeometry(); // Needed for deinterlace
137
}
138

139 140 141 142
QSize VideoWidget::sizeHint() const
{
    return videoSize;
}
143

144 145
/**********************************************************************
 * Background Widget. Show a simple image background. Currently,
146
 * it's album art if present or cone.
147
 **********************************************************************/
148 149 150 151
#define ICON_SIZE 128
#define MAX_BG_SIZE 400
#define MIN_BG_SIZE 64

152 153
BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
                 :QWidget( NULL ), p_intf( _p_i )
154
{
155
    /* We should use that one to take the more size it can */
156
//    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
157

158
    /* A dark background */
Clément Stenac's avatar
Clément Stenac committed
159
    setAutoFillBackground( true );
160 161 162 163 164
    plt =  palette();
    plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
    plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
    setPalette( plt );

165
    /* A cone in the middle */
166
    label = new QLabel;
167
    label->setMargin( 5 );
168 169
    label->setMaximumHeight( MAX_BG_SIZE );
    label->setMaximumWidth( MAX_BG_SIZE );
170 171
    label->setMinimumHeight( MIN_BG_SIZE );
    label->setMinimumWidth( MIN_BG_SIZE );
172 173 174 175
    if( QDate::currentDate().dayOfYear() >= 354 )
        label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
    else
        label->setPixmap( QPixmap( ":/vlc128.png" ) );
176

177 178 179 180
    QGridLayout *backgroundLayout = new QGridLayout( this );
    backgroundLayout->addWidget( label, 0, 1 );
    backgroundLayout->setColumnStretch( 0, 1 );
    backgroundLayout->setColumnStretch( 2, 1 );
181

182
    CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
183 184
}

Clément Stenac's avatar
Clément Stenac committed
185
BackgroundWidget::~BackgroundWidget()
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
186 187 188
{
}

189 190 191 192 193 194 195 196
void BackgroundWidget::resizeEvent( QResizeEvent * event )
{
    if( event->size().height() <= MIN_BG_SIZE )
        label->hide();
    else
        label->show();
}

197
void BackgroundWidget::updateArt( QString url )
198
{
199
    if( url.isEmpty() )
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
200
    {
201 202 203 204
        if( QDate::currentDate().dayOfYear() >= 354 )
            label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
        else
            label->setPixmap( QPixmap( ":/vlc128.png" ) );
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
205 206
        return;
    }
207
    else
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
208
    {
209
        label->setPixmap( QPixmap( url ) );
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
210
    }
211 212
}

213 214 215 216
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
{
    QVLCMenu::PopupMenu( p_intf, true );
}
217

Clément Stenac's avatar
Clément Stenac committed
218 219 220 221
/**********************************************************************
 * Visualization selector panel
 **********************************************************************/
VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
222
                                QFrame( NULL ), p_intf( _p_i )
Clément Stenac's avatar
Clément Stenac committed
223 224
{
    QHBoxLayout *layout = new QHBoxLayout( this );
225
    layout->setMargin( 0 );
Clément Stenac's avatar
Clément Stenac committed
226
    QPushButton *prevButton = new QPushButton( "Prev" );
227
    QPushButton *nextButton = new QPushButton( "Next" );
Clément Stenac's avatar
Clément Stenac committed
228 229
    layout->addWidget( prevButton );
    layout->addWidget( nextButton );
Clément Stenac's avatar
Clément Stenac committed
230 231

    layout->addItem( new QSpacerItem( 40,20,
232 233
                              QSizePolicy::Expanding, QSizePolicy::Minimum ) );
    layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
Clément Stenac's avatar
Clément Stenac committed
234 235 236 237 238 239 240

    current = new QLabel( qtr( "None" ) );
    layout->addWidget( current );

    BUTTONACT( prevButton, prev() );
    BUTTONACT( nextButton, next() );

Clément Stenac's avatar
Clément Stenac committed
241
    setLayout( layout );
242
    setMaximumHeight( 35 );
Clément Stenac's avatar
Clément Stenac committed
243 244 245 246 247 248
}

VisualSelector::~VisualSelector()
{
}

Clément Stenac's avatar
Clément Stenac committed
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
void VisualSelector::prev()
{
    char *psz_new = aout_VisualPrev( p_intf );
    if( psz_new )
    {
        current->setText( qfu( psz_new ) );
        free( psz_new );
    }
}

void VisualSelector::next()
{
    char *psz_new = aout_VisualNext( p_intf );
    if( psz_new )
    {
        current->setText( qfu( psz_new ) );
        free( psz_new );
    }
}

/**********************************************************************
270
 * TEH controls
Clément Stenac's avatar
Clément Stenac committed
271
 **********************************************************************/
272 273 274 275 276 277

#define setupSmallButton( aButton ){  \
    aButton->setMaximumSize( QSize( 26, 26 ) ); \
    aButton->setMinimumSize( QSize( 26, 26 ) ); \
    aButton->setIconSize( QSize( 20, 20 ) ); }

278
AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
Clément Stenac's avatar
Clément Stenac committed
279 280
                                           QFrame( NULL ), p_intf( _p_i )
{
281 282 283
    QHBoxLayout *advLayout = new QHBoxLayout( this );
    advLayout->setMargin( 0 );
    advLayout->setSpacing( 0 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
284
    advLayout->setAlignment( Qt::AlignBottom );
Clément Stenac's avatar
Clément Stenac committed
285

286
    /* A to B Button */
287
    ABButton = new QPushButton( "AB" );
Lukas Durfina's avatar
Lukas Durfina committed
288
    setupSmallButton( ABButton );
289
    advLayout->addWidget( ABButton );
290
    BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
291
    timeA = timeB = 0;
292 293
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
             this, AtoBLoop( float, int, int ) );
294
#if 0
295 296 297 298 299
    frameButton = new QPushButton( "Fr" );
    frameButton->setMaximumSize( QSize( 26, 26 ) );
    frameButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( frameButton );
    BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
300
#endif
301 302

    recordButton = new QPushButton( "R" );
Lukas Durfina's avatar
Lukas Durfina committed
303
    setupSmallButton( recordButton );
304
    advLayout->addWidget( recordButton );
305
    BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
306
            qtr( "Record" ), record() );
307

308
    /* Snapshot Button */
309
    snapshotButton = new QPushButton( "S" );
Lukas Durfina's avatar
Lukas Durfina committed
310
    setupSmallButton( snapshotButton );
311 312
    advLayout->addWidget( snapshotButton );
    BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
Clément Stenac's avatar
Clément Stenac committed
313 314
}

315
AdvControlsWidget::~AdvControlsWidget()
316
{}
Clément Stenac's avatar
Clément Stenac committed
317

318
void AdvControlsWidget::enableInput( bool enable )
Clément Stenac's avatar
Clément Stenac committed
319
{
320 321
    ABButton->setEnabled( enable );
    recordButton->setEnabled( enable );
Clément Stenac's avatar
Clément Stenac committed
322
}
323

324
void AdvControlsWidget::enableVideo( bool enable )
Clément Stenac's avatar
Clément Stenac committed
325 326
{
    snapshotButton->setEnabled( enable );
327
#if 0
328
    frameButton->setEnabled( enable );
329
#endif
Clément Stenac's avatar
Clément Stenac committed
330 331
}

332
void AdvControlsWidget::snapshot()
Clément Stenac's avatar
Clément Stenac committed
333
{
334 335
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
336
    if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
Clément Stenac's avatar
Clément Stenac committed
337 338
}

339
/* Function called when the button is clicked() */
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
void AdvControlsWidget::fromAtoB()
{
    if( !timeA )
    {
        timeA = var_GetTime( THEMIM->getInput(), "time"  );
        ABButton->setText( "A->..." );
        return;
    }
    if( !timeB )
    {
        timeB = var_GetTime( THEMIM->getInput(), "time"  );
        var_SetTime( THEMIM->getInput(), "time" , timeA );
        ABButton->setText( "A<=>B" );
        return;
    }
    timeA = 0;
    timeB = 0;
    ABButton->setText( "AB" );
}
359

360
/* Function called regularly when in an AtoB loop */
361 362 363 364
void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
{
    if( timeB )
    {
365
        if( i_time >= (int)(timeB/1000000) )
366 367 368
            var_SetTime( THEMIM->getInput(), "time" , timeA );
    }
}
369

370
/* FIXME Record function */
371
void AdvControlsWidget::record(){}
372

373
#if 0
374
//FIXME Frame by frame function
375
void AdvControlsWidget::frame(){}
376
#endif
377

378 379 380
/*****************************
 * DA Control Widget !
 *****************************/
381
ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
382
                                MainInterface *_p_mi,
383
                                bool b_advControls,
Lukas Durfina's avatar
Lukas Durfina committed
384 385 386
                                bool b_shiny,
                                bool b_fsCreation) :
                                QFrame( _p_mi ), p_intf( _p_i )
387
{
Lukas Durfina's avatar
Lukas Durfina committed
388 389
    controlLayout = new QGridLayout( );

390
    controlLayout->setSpacing( 0 );
391
    controlLayout->setLayoutMargins( 9, 6, 9, 6, 6 );
392

Lukas Durfina's avatar
Lukas Durfina committed
393 394 395
    if( !b_fsCreation )
        setLayout( controlLayout );

396
    setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
397

398 399
    /** The main Slider **/
    slider = new InputSlider( Qt::Horizontal, NULL );
400
    controlLayout->addWidget( slider, 0, 1, 1, 16 );
401 402
    /* Update the position when the IM has changed */
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
403
             slider, setPosition( float, int, int ) );
404 405 406 407
    /* And update the IM, when the position has changed */
    CONNECT( slider, sliderDragged( float ),
             THEMIM->getIM(), sliderUpdate( float ) );

408
    /** Slower and faster Buttons **/
409 410
    slowerButton = new QToolButton;
    slowerButton->setAutoRaise( true );
411
    slowerButton->setMaximumSize( QSize( 26, 20 ) );
412

413
    BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
414 415
    controlLayout->addWidget( slowerButton, 0, 0 );

416 417
    fasterButton = new QToolButton;
    fasterButton->setAutoRaise( true );
418
    fasterButton->setMaximumSize( QSize( 26, 20 ) );
419

420
    BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
421
    controlLayout->addWidget( fasterButton, 0, 17 );
422

423 424 425 426
    /* advanced Controls handling */
    b_advancedVisible = b_advControls;

    advControls = new AdvControlsWidget( p_intf );
427
    controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
428 429
    if( !b_advancedVisible ) advControls->hide();

430
    /** Disc and Menus handling */
431
    discFrame = new QWidget( this );
432

433 434 435
    QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
    discLayout->setSpacing( 0 );
    discLayout->setMargin( 0 );
436

437
    prevSectionButton = new QPushButton( discFrame );
438
    setupSmallButton( prevSectionButton );
439 440
    discLayout->addWidget( prevSectionButton );

441
    menuButton = new QPushButton( discFrame );
442 443 444
    setupSmallButton( menuButton );
    discLayout->addWidget( menuButton );

445
    nextSectionButton = new QPushButton( discFrame );
446
    setupSmallButton( nextSectionButton );
447 448
    discLayout->addWidget( nextSectionButton );

449
    controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
450 451 452 453 454

    BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
    BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
    BUTTON_SET_IMG( menuButton, "", previous.png, "" );

455
    discFrame->hide();
456 457 458

    /* Change the navigation button display when the IM navigation changes */
    CONNECT( THEMIM->getIM(), navigationChanged( int ),
459
             this, setNavigation( int ) );
460 461 462 463 464 465 466
    /* Changes the IM navigation when triggered on the nav buttons */
    CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
             sectionPrev() );
    CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
             sectionNext() );
    CONNECT( menuButton, clicked(), THEMIM->getIM(),
             sectionMenu() );
467
    /**
468
     * Telextext QFrame
469
     * TODO: Merge with upper menu in a StackLayout
470
     **/
471
#ifdef ZVBI_COMPILED
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
    telexFrame = new QWidget( this );
    QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
    telexLayout->setSpacing( 0 );
    telexLayout->setMargin( 0 );

    QToolButton *telexOn = new QToolButton;
    telexOn->setText( qtr( "On" ) );
    setupSmallButton( telexOn );
    telexLayout->addWidget( telexOn );

    QToolButton *telexTransparent = new QToolButton;
    telexTransparent->setText( qtr( "Transparent" ) );
    setupSmallButton( telexTransparent );
    telexLayout->addWidget( telexTransparent );

487
    QSpinBox *telexPage = new QSpinBox;
488
    telexPage->setRange( 0, 999 );
489
    telexPage->setValue( 100 );
490 491
    telexPage->setAccelerated( true );
    telexPage->setWrapping( true );
492
    telexPage->setAlignment( Qt::AlignRight );
493
    telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
494 495 496
    telexLayout->addWidget( telexPage );

    controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
497
    telexFrame->hide();
498 499 500 501 502 503 504 505 506

    CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
             telexGotoPage( int ) );
    CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
             telexToggle( bool ) );
    CONNECT( telexTransparent, clicked( bool ),
             THEMIM->getIM(), telexSetTransparency( bool ) );
    CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
             telexFrame, setVisible( bool ) );
507
#endif
508

509
    /** Play Buttons **/
510
    QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
511 512 513 514
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );

    /* Play */
515
    playButton = new QPushButton;
516
    playButton->setSizePolicy( sizePolicy );
517 518
    playButton->setMaximumSize( QSize( 36, 36 ) );
    playButton->setMinimumSize( QSize( 36, 36 ) );
519
    playButton->setIconSize( QSize( 30, 30 ) );
520

521
    controlLayout->addWidget( playButton, 2, 0, 2, 2 );
522

523 524
    controlLayout->setColumnMinimumWidth( 2, 20 );
    controlLayout->setColumnStretch( 2, 0 );
525 526

    /** Prev + Stop + Next Block **/
Lukas Durfina's avatar
Lukas Durfina committed
527
    controlButLayout = new QHBoxLayout;
528 529 530 531 532
    controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */

    /* Prev */
    QPushButton *prevButton = new QPushButton;
    prevButton->setSizePolicy( sizePolicy );
533
    setupSmallButton( prevButton );
534 535 536 537 538 539

    controlButLayout->addWidget( prevButton );

    /* Stop */
    QPushButton *stopButton = new QPushButton;
    stopButton->setSizePolicy( sizePolicy );
540
    setupSmallButton( stopButton );
541 542 543 544 545 546

    controlButLayout->addWidget( stopButton );

    /* next */
    QPushButton *nextButton = new QPushButton;
    nextButton->setSizePolicy( sizePolicy );
547
    setupSmallButton( nextButton );
548 549 550 551

    controlButLayout->addWidget( nextButton );

    /* Add this block to the main layout */
Lukas Durfina's avatar
Lukas Durfina committed
552 553
    if( !b_fsCreation )
        controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
554

555
    BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
556
    BUTTON_SET_ACT_I( prevButton, "" , previous.png,
557 558 559
                      qtr( "Previous" ), prev() );
    BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
    BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
560

561 562 563 564
    controlLayout->setColumnMinimumWidth( 7, 20 );
    controlLayout->setColumnStretch( 7, 0 );
    controlLayout->setColumnStretch( 8, 0 );
    controlLayout->setColumnStretch( 9, 0 );
565

566 567 568
    /*
     * Other first Line buttons
     */
569 570 571
    /** Fullscreen/Visualisation **/
    fullscreenButton = new QPushButton( "F" );
    BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
572
    setupSmallButton( fullscreenButton );
573
    controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
574

575 576
    /** Playlist Button **/
    playlistButton = new QPushButton;
577
    setupSmallButton( playlistButton );
578
    controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
579
    BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
580
    CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
581 582

    /** extended Settings **/
Lukas Durfina's avatar
Lukas Durfina committed
583
    extSettingsButton = new QPushButton;
584
    BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
585
            extSettings() );
586
    setupSmallButton( extSettingsButton );
587
    controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
588

589
    controlLayout->setColumnStretch( 13, 0 );
590
    controlLayout->setColumnMinimumWidth( 13, 24 );
591
    controlLayout->setColumnStretch( 14, 5 );
592

593
    /* Volume */
Lukas Durfina's avatar
Lukas Durfina committed
594
    hVolLabel = new VolumeClickHandler( p_intf, this );
595

596
    volMuteLabel = new QLabel;
597
    volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
598
    volMuteLabel->setToolTip( qtr( "Mute" ) );
599
    volMuteLabel->installEventFilter( hVolLabel );
600
    controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
601

602 603 604
    if( b_shiny )
    {
        volumeSlider = new SoundSlider( this,
605
            config_GetInt( p_intf, "volume-step" ),
606 607
            config_GetInt( p_intf, "qt-volume-complete" ),
            config_GetPsz( p_intf, "qt-slider-colours" ) );
608 609 610 611 612 613
    }
    else
    {
        volumeSlider = new QSlider( this );
        volumeSlider->setOrientation( Qt::Horizontal );
    }
614
    volumeSlider->setMaximumSize( QSize( 200, 40 ) );
615
    volumeSlider->setMinimumSize( QSize( 106, 30 ) );
616
    volumeSlider->setFocusPolicy( Qt::NoFocus );
617
    controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
618

619
    /* Set the volume from the config */
620 621
    volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
                              VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
622

623 624 625
    /* Force the update at build time in order to have a muted icon if needed */
    updateVolume( volumeSlider->value() );

626 627
    /* Volume control connection */
    CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
628
    CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
629 630

    updateInput();
631
}
632

633
ControlsWidget::~ControlsWidget()
634
{}
635

636 637 638 639 640 641 642
void ControlsWidget::stop()
{
    THEMIM->stop();
}

void ControlsWidget::play()
{
643
    if( THEPL->current.i_size == 0 )
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
    {
        /* The playlist is empty, open a file requester */
        THEDP->openFileDialog();
        setStatus( 0 );
        return;
    }
    THEMIM->togglePlayPause();
}

void ControlsWidget::prev()
{
    THEMIM->prev();
}

void ControlsWidget::next()
{
    THEMIM->next();
}

void ControlsWidget::setNavigation( int navigation )
{
665 666 667 668 669
#define HELP_MENU N_( "Menu" )
#define HELP_PCH N_( "Previous chapter" )
#define HELP_NCH N_( "Next chapter" )
#define HELP_PTR N_( "Previous track" )
#define HELP_NTR N_( "Next track" )
670 671 672 673 674 675

    // 1 = chapter, 2 = title, 0 = no
    if( navigation == 0 )
    {
        discFrame->hide();
    } else if( navigation == 1 ) {
676 677
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
678 679 680
        menuButton->show();
        discFrame->show();
    } else {
681 682
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
683 684 685 686 687 688
        menuButton->hide();
        discFrame->show();
    }
}

static bool b_my_volume;
689
void ControlsWidget::updateVolume( int i_sliderVolume )
690 691 692
{
    if( !b_my_volume )
    {
693
        int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
694 695
        aout_VolumeSet( p_intf, i_res );
    }
696 697
    if( i_sliderVolume == 0 )
        volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
698
    else if( i_sliderVolume < VOLUME_MAX / 3 )
699
        volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
700 701 702
    else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
        volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
    else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
703 704
}

705
void ControlsWidget::updateVolume()
706
{
707
    /* Audio part */
708 709
    audio_volume_t i_volume;
    aout_VolumeGet( p_intf, &i_volume );
710
    i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
711 712 713 714 715 716 717 718
    int i_gauge = volumeSlider->value();
    b_my_volume = false;
    if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
    {
        b_my_volume = true;
        volumeSlider->setValue( i_volume );
        b_my_volume = false;
    }
719
}
720

721 722
void ControlsWidget::updateInput()
{
723
    /* Activate the interface buttons according to the presence of the input */
724
    enableInput( THEMIM->getIM()->hasInput() );
725
    enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
726
}
727

728 729
void ControlsWidget::setStatus( int status )
{
730 731
    if( status == PLAYING_S ) /* Playing */
    {
732
        playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
733 734
        playButton->setToolTip( qtr( "Pause" ) );
    }
735
    else
736
    {
737
        playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
738 739
        playButton->setToolTip( qtr( "Play" ) );
    }
740
}
741

742 743
/**
 * TODO
744
 * This functions toggle the fullscreen mode
745
 * If there is no video, it should first activate Visualisations...
746
 *  This has also to be fixed in enableVideo()
747
 */
Clément Stenac's avatar
Clément Stenac committed
748 749
void ControlsWidget::fullscreen()
{
750 751
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
752
    if( p_vout)
753
    {
754
        var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
755
        vlc_object_release( p_vout );
756
    }
757 758 759 760 761 762
}

void ControlsWidget::extSettings()
{
    THEDP->extendedDialog();
}
Clément Stenac's avatar
Clément Stenac committed
763

764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
void ControlsWidget::slower()
{
    THEMIM->getIM()->slower();
}

void ControlsWidget::faster()
{
    THEMIM->getIM()->faster();
}

void ControlsWidget::enableInput( bool enable )
{
    slowerButton->setEnabled( enable );
    slider->setEnabled( enable );
    fasterButton->setEnabled( enable );
779 780 781

    /* Advanced Buttons too */
    advControls->enableInput( enable );
782 783
}

784
void ControlsWidget::enableVideo( bool enable )
785
{
786 787
    // TODO Later make the fullscreenButton toggle Visualisation and so on.
    fullscreenButton->setEnabled( enable );
788 789 790

    /* Advanced Buttons too */
    advControls->enableVideo( enable );
791 792
}

793 794 795 796 797 798 799 800 801 802 803 804
void ControlsWidget::toggleAdvanced()
{
    if( !VISIBLE( advControls ) )
    {
        advControls->show();
        b_advancedVisible = true;
    }
    else
    {
        advControls->hide();
        b_advancedVisible = false;
    }
805
    emit advancedControlsToggled( b_advancedVisible );
806
}
807

808

Lukas Durfina's avatar
Lukas Durfina committed
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
/**********************************************************************
 * Fullscrenn control widget
 **********************************************************************/
FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
        MainInterface *_p_mi, bool b_advControls, bool b_shiny )
        : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
        i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
        b_mouseIsOver( false )
{
    setWindowFlags( Qt::ToolTip );

    setFrameShape( QFrame::StyledPanel );
    setFrameStyle( QFrame::Sunken );
    setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );

    QGridLayout *fsLayout = new QGridLayout( this );
    controlLayout->setSpacing( 0 );
826
    controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
Lukas Durfina's avatar
Lukas Durfina committed
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841

    fsLayout->addWidget( slowerButton, 0, 0 );
    slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
    fsLayout->addWidget( slider, 0, 1, 1, 6 );
    fsLayout->addWidget( fasterButton, 0, 7 );

    fsLayout->addWidget( volMuteLabel, 1, 0);
    fsLayout->addWidget( volumeSlider, 1, 1 );

    fsLayout->addLayout( controlButLayout, 1, 2 );

    fsLayout->addWidget( playButton, 1, 3 );

    fsLayout->addWidget( discFrame, 1, 4 );

842
    #ifdef ZVBI_COMPILED
Lukas Durfina's avatar
Lukas Durfina committed
843
    fsLayout->addWidget( telexFrame, 1, 5 );
844
    #endif
Lukas Durfina's avatar
Lukas Durfina committed
845 846 847 848 849 850 851 852 853 854 855

    fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );

    fsLayout->addWidget( fullscreenButton, 1, 7 );

    /* hiding timer */
    p_hideTimer = new QTimer( this );
    CONNECT( p_hideTimer, timeout(), this, hideFSControllerWidget() );
    p_hideTimer->setSingleShot( true );

    /* slow hiding timer */
856
#if HAVE_TRANSPARENCY
Lukas Durfina's avatar
Lukas Durfina committed
857 858
    p_slowHideTimer = new QTimer( this );
    CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
859
#endif
Lukas Durfina's avatar
Lukas Durfina committed
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901

    adjustSize ();  /* need to get real width and height for moving */

    /* center down */
    QDesktopWidget * p_desktop = QApplication::desktop();

    move( p_desktop->width() / 2 - width() / 2,
          p_desktop->height() - height() );

    #ifdef WIN32TRICK
    setWindowOpacity( 0.0 );
    fscHidden = true;
    show();
    #endif
}

FullscreenControllerWidget::~FullscreenControllerWidget()
{
}

/**
 * Hide fullscreen controller
 * FIXME: under windows it have to be done by moving out of screen
 *        because hide() doesnt work
 */
void FullscreenControllerWidget::hideFSControllerWidget()
{
    #ifdef WIN32TRICK
    fscHidden = true;
    setWindowOpacity( 0.0 );    // simulate hidding
    #else
    hide();
    #endif
}

/**
 * Hidding fullscreen controller slowly
 * Linux: need composite manager
 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
 */
void FullscreenControllerWidget::slowHideFSC()
{
902
#if HAVE_TRANSPARENCY
Lukas Durfina's avatar
Lukas Durfina committed
903 904 905 906 907 908 909 910
    static bool first_call = true;

    if ( first_call )
    {
        first_call = false