interface_widgets.cpp 27.8 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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
29

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

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

50 51 52 53
/**********************************************************************
 * Video Widget. A simple frame on which video is drawn
 * This class handles resize issues
 **********************************************************************/
54 55 56 57 58
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 );

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

68 69 70 71 72 73 74
    /* 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 */
75
    CONNECT( this, askVideoWidgetToShow(), this, show() );
76 77
    /* The core can ask through a callback to resize the video */
   // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
}

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 );
}

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

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

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

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

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

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

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

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

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

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

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

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

196
void BackgroundWidget::updateArt( QString url )
197
{
198
    if( url.isEmpty() )
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
199
    {
200 201 202 203
        if( QDate::currentDate().dayOfYear() >= 354 )
            label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
        else
            label->setPixmap( QPixmap( ":/vlc128.png" ) );
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
204 205
        return;
    }
206
    else
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
207
    {
208
        label->setPixmap( QPixmap( url ) );
209
        msg_Dbg( p_intf, "changing input b_need_update done ");
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 );
Clément Stenac's avatar
Clément Stenac committed
284

285
    /* A to B Button */
286 287 288 289
    ABButton = new QPushButton( "AB" );
    ABButton->setMaximumSize( QSize( 26, 26 ) );
    ABButton->setIconSize( QSize( 20, 20 ) );
    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 303 304 305

    recordButton = new QPushButton( "R" );
    recordButton->setMaximumSize( QSize( 26, 26 ) );
    recordButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( recordButton );
306
    BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
307
            qtr( "Record" ), record() );
308

309
    /* Snapshot Button */
310 311 312 313 314
    snapshotButton = new QPushButton( "S" );
    snapshotButton->setMaximumSize( QSize( 26, 26 ) );
    snapshotButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( snapshotButton );
    BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
Clément Stenac's avatar
Clément Stenac committed
315 316
}

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

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

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

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

341
/* Function called when the button is clicked() */
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
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" );
}
361

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

372
/* FIXME Record function */
373
void AdvControlsWidget::record(){}
374

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

380 381 382
/*****************************
 * DA Control Widget !
 *****************************/
383
ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
384
                                MainInterface *_p_mi,
385 386
                                bool b_advControls,
                                bool b_shiny ) :
387
                                QFrame( NULL ), p_intf( _p_i )
388 389
{
    controlLayout = new QGridLayout( this );
390
    controlLayout->setSpacing( 0 );
391 392 393 394 395
#if QT43
    controlLayout->setContentsMargins( 9, 6, 9, 6 );
#else
    controlLayout->setMargin( 6 );
#endif
396 397

    setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
398

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

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

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

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

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

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

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

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

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

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

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

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

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

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

456
    discFrame->hide();
457 458 459

    /* Change the navigation button display when the IM navigation changes */
    CONNECT( THEMIM->getIM(), navigationChanged( int ),
460
             this, setNavigation( int ) );
461 462 463 464 465 466 467
    /* 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() );
468
    /**
469
     * Telextext QFrame
470
     * TODO: Merge with upper menu in a StackLayout
471
     **/
472
#ifdef ZVBI_COMPILED
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
    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 );

488
    QSpinBox *telexPage = new QSpinBox;
489
    telexPage->setRange( 0, 999 );
490
    telexPage->setValue( 100 );
491 492 493 494
    telexPage->setAlignment( Qt::AlignRight );
    telexLayout->addWidget( telexPage );

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

    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 ) );
505
#endif
506

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

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

519
    controlLayout->addWidget( playButton, 2, 0, 2, 2 );
520

521 522
    controlLayout->setColumnMinimumWidth( 2, 20 );
    controlLayout->setColumnStretch( 2, 0 );
523 524 525 526 527 528 529 530

    /** Prev + Stop + Next Block **/
    QHBoxLayout *controlButLayout = new QHBoxLayout;
    controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */

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

    controlButLayout->addWidget( prevButton );

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

    controlButLayout->addWidget( stopButton );

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

    controlButLayout->addWidget( nextButton );

    /* Add this block to the main layout */
550
    controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
551

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

558 559 560 561
    controlLayout->setColumnMinimumWidth( 7, 20 );
    controlLayout->setColumnStretch( 7, 0 );
    controlLayout->setColumnStretch( 8, 0 );
    controlLayout->setColumnStretch( 9, 0 );
562

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

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

    /** extended Settings **/
    QPushButton *extSettingsButton = new QPushButton( "F" );
581
    BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
582
            extSettings() );
583
    setupSmallButton( extSettingsButton );
584
    controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
585

586
    controlLayout->setColumnStretch( 13, 0 );
587
    controlLayout->setColumnMinimumWidth( 13, 24 );
588
    controlLayout->setColumnStretch( 14, 5 );
589

590
    /* Volume */
591
    VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
592

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

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

615
    /* Set the volume from the config */
616 617
    volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
                              VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
618

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

622 623
    /* Volume control connection */
    CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
624
    CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
625 626

    updateInput();
627
}
628

629
ControlsWidget::~ControlsWidget()
630
{}
631

632 633 634 635 636 637 638
void ControlsWidget::stop()
{
    THEMIM->stop();
}

void ControlsWidget::play()
{
639
    if( THEPL->current.i_size == 0 )
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
    {
        /* 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 )
{
661 662 663 664 665
#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" )
666 667 668 669 670 671

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

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

701
void ControlsWidget::updateVolume()
702
{
703
    /* Audio part */
704 705
    audio_volume_t i_volume;
    aout_VolumeGet( p_intf, &i_volume );
706
    i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
707 708 709 710 711 712 713 714
    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;
    }
715
}
716

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

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

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

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

760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
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 );
775 776 777

    /* Advanced Buttons too */
    advControls->enableInput( enable );
778 779
}

780
void ControlsWidget::enableVideo( bool enable )
781
{
782 783
    // TODO Later make the fullscreenButton toggle Visualisation and so on.
    fullscreenButton->setEnabled( enable );
784 785 786

    /* Advanced Buttons too */
    advControls->enableVideo( enable );
787 788
}

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

804

805 806 807 808 809
/**********************************************************************
 * Speed control widget
 **********************************************************************/
SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
                             QFrame( NULL ), p_intf( _p_i )
810
{
811
    QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
812 813
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );
814

815 816 817 818 819 820
    speedSlider = new QSlider;
    speedSlider->setSizePolicy( sizePolicy );
    speedSlider->setMaximumSize( QSize( 80, 200 ) );
    speedSlider->setOrientation( Qt::Vertical );
    speedSlider->setTickPosition( QSlider::TicksRight );

821
    speedSlider->setRange( -100, 100 );
822 823 824
    speedSlider->setSingleStep( 10 );
    speedSlider->setPageStep( 20 );
    speedSlider->setTickInterval( 20 );
825

826
    CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
827

828
    QToolButton *normalSpeedButton = new QToolButton( this );
829
    normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
830 831
    normalSpeedButton->setAutoRaise( true );
    normalSpeedButton->setText( "N" );
832
    normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
833

834
    CONNECT( normalSpeedButton, clicked(), this, resetRate() );
835

836
    QVBoxLayout *speedControlLayout = new QVBoxLayout;
837 838 839
    speedControlLayout->addWidget( speedSlider );
    speedControlLayout->addWidget( normalSpeedButton );
    setLayout( speedControlLayout );
840 841 842
}

SpeedControlWidget::~SpeedControlWidget()
843
{}
844

845 846 847 848 849
void SpeedControlWidget::setEnable( bool b_enable )
{
    speedSlider->setEnabled( b_enable );
}

850 851 852
#define RATE_SLIDER_MAXIMUM 3.0
#define RATE_SLIDER_MINIMUM 0.3
#define RATE_SLIDER_LENGTH 100.0
853 854 855

void SpeedControlWidget::updateControls( int rate )
{
856 857 858 859 860
    if( speedSlider->isSliderDown() )
    {
        //We don't want to change anything if the user is using the slider
        return;
    }
861

862 863
    int sliderValue;
    double speed = INPUT_RATE_DEFAULT / (double)rate;
864

865
    if( rate >= INPUT_RATE_DEFAULT )
866
    {
867 868 869 870 871 872 873
        if( speed < RATE_SLIDER_MINIMUM )
        {
            sliderValue = speedSlider->minimum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
874
                                        / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
875 876 877 878 879 880 881 882 883 884 885
        }
    }
    else
    {
        if( speed > RATE_SLIDER_MAXIMUM )
        {
            sliderValue = speedSlider->maximum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
Jean-Baptiste Kempf's avatar