interface_widgets.cpp 27.4 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 26
 *
 * 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.
 *****************************************************************************/

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

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

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

56
VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
57 58 59
{
    vlc_mutex_init( p_intf, &lock );
    p_vout = NULL;
60 61 62 63
    hide(); setMinimumSize( 16, 16 );
 
   // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
    CONNECT( this, askVideoWidgetToShow(), this, show() );
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
}

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

QSize VideoWidget::sizeHint() const
{
89
    return widgetSize;
90 91
}

92 93 94
/**
 * Request the video to avoid the conflicts 
 **/
95
void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
96 97
                           unsigned int *pi_width, unsigned int *pi_height )
{
98
    emit askVideoWidgetToShow();
99 100 101 102 103 104
    if( p_vout )
    {
        msg_Dbg( p_intf, "embedded video already in use" );
        return NULL;
    }
    p_vout = p_nvout;
105
    return ( void* )winId();
106 107
}

108 109
/* Set the Widget to the correct Size */
void VideoWidget::SetSizing( unsigned int w, unsigned int h )
110
{
111
    widgetSize = QSize( w, h );
112 113 114 115
    resize( w, h );
    //updateGeometry(); // Needed for deinterlace
    msg_Dbg( p_intf, "%i %i", sizeHint().height(), sizeHint().width() );
    emit askResize();
116 117
}

118
void VideoWidget::release( void *p_win )
119
{
120
    p_vout = NULL;
121
}
122 123


124 125 126 127
/**********************************************************************
 * Background Widget. Show a simple image background. Currently,
 * it's a static cone.
 **********************************************************************/
128 129 130 131
#define ICON_SIZE 128
#define MAX_BG_SIZE 400
#define MIN_BG_SIZE 64

132 133 134
BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
                                        QFrame( NULL ), p_intf( _p_i )
{
135 136
    /* We should use that one to take the more size it can */
    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
137

138
    /* A dark background */
Clément Stenac's avatar
Clément Stenac committed
139
    setAutoFillBackground( true );
140 141 142 143 144
    plt =  palette();
    plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
    plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
    setPalette( plt );

145
    /* A cone in the middle */
146
    label = new QLabel;
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
147
    label->setScaledContents( true );
148
    label->setMargin( 5 );
149 150
    label->setMaximumHeight( MAX_BG_SIZE );
    label->setMaximumWidth( MAX_BG_SIZE );
151 152
    label->setMinimumHeight( MIN_BG_SIZE );
    label->setMinimumWidth( MIN_BG_SIZE );
153 154 155 156
    if( QDate::currentDate().dayOfYear() >= 354 )
        label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
    else
        label->setPixmap( QPixmap( ":/vlc128.png" ) );
157

158
    QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
159
    backgroundLayout->addWidget( label );
160 161

    resize( 300, 150 );
162
    updateGeometry();
163
    CONNECT( THEMIM, inputChanged( input_thread_t *), this, update( input_thread_t * ) );
164 165
}

Clément Stenac's avatar
Clément Stenac committed
166
BackgroundWidget::~BackgroundWidget()
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
167 168 169
{
}

170

171
void BackgroundWidget::update( input_thread_t *p_input )
172
{
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
173 174
    if( !p_input || p_input->b_dead )
    {
175 176 177 178
        if( QDate::currentDate().dayOfYear() >= 354 )
            label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
        else
            label->setPixmap( QPixmap( ":/vlc128.png" ) );
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
179 180 181 182
        return;
    }


183 184 185 186 187 188
    vlc_object_yield( p_input );
    char *psz_arturl = input_item_GetArtURL( input_GetItem(p_input) );
    vlc_object_release( p_input );
    QString url = qfu( psz_arturl );
    QString arturl = url.replace( "file://",QString("" ) );
    if( arturl.isNull() )
189 190 191 192 193 194
    {
        if( QDate::currentDate().dayOfYear() >= 354 )
            label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
        else
            label->setPixmap( QPixmap( ":/vlc128.png" ) );
    }
195
    else
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
196
    {
197 198
        label->setPixmap( QPixmap( arturl ) );
        msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
199
    }
200
    free( psz_arturl );
201 202
}

203 204
QSize BackgroundWidget::sizeHint() const
{
205
    return label->size();
206 207
}

208 209
void BackgroundWidget::resizeEvent( QResizeEvent *e )
{
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
210 211 212 213 214 215
    if( e->size().height() < MAX_BG_SIZE -1 )
    {
        label->setMaximumWidth( e->size().height() );
        label->setMaximumHeight( e->size().width() );
    }
    else
216
    {
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
217 218
        label->setMaximumHeight( MAX_BG_SIZE );
        label->setMaximumWidth( MAX_BG_SIZE );
219
    }
220
}
221

222 223 224 225
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
{
    QVLCMenu::PopupMenu( p_intf, true );
}
226

Clément Stenac's avatar
Clément Stenac committed
227 228 229 230
/**********************************************************************
 * Visualization selector panel
 **********************************************************************/
VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
231
                                QFrame( NULL ), p_intf( _p_i )
Clément Stenac's avatar
Clément Stenac committed
232 233
{
    QHBoxLayout *layout = new QHBoxLayout( this );
234
    layout->setMargin( 0 );
Clément Stenac's avatar
Clément Stenac committed
235
    QPushButton *prevButton = new QPushButton( "Prev" );
236
    QPushButton *nextButton = new QPushButton( "Next" );
Clément Stenac's avatar
Clément Stenac committed
237 238
    layout->addWidget( prevButton );
    layout->addWidget( nextButton );
Clément Stenac's avatar
Clément Stenac committed
239 240

    layout->addItem( new QSpacerItem( 40,20,
241 242
                              QSizePolicy::Expanding, QSizePolicy::Minimum ) );
    layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
Clément Stenac's avatar
Clément Stenac committed
243 244 245 246 247 248 249

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

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

Clément Stenac's avatar
Clément Stenac committed
250
    setLayout( layout );
251
    setMaximumHeight( 35 );
Clément Stenac's avatar
Clément Stenac committed
252 253 254 255 256 257
}

VisualSelector::~VisualSelector()
{
}

Clément Stenac's avatar
Clément Stenac committed
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
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 );
    }
}

/**********************************************************************
279
 * TEH controls
Clément Stenac's avatar
Clément Stenac committed
280
 **********************************************************************/
281 282 283 284 285 286

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

287
AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
Clément Stenac's avatar
Clément Stenac committed
288 289
                                           QFrame( NULL ), p_intf( _p_i )
{
290 291 292
    QHBoxLayout *advLayout = new QHBoxLayout( this );
    advLayout->setMargin( 0 );
    advLayout->setSpacing( 0 );
Clément Stenac's avatar
Clément Stenac committed
293

294
    /* A to B Button */
295 296 297 298
    ABButton = new QPushButton( "AB" );
    ABButton->setMaximumSize( QSize( 26, 26 ) );
    ABButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( ABButton );
299
    BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
300
    timeA = timeB = 0;
301 302
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
             this, AtoBLoop( float, int, int ) );
Clément Stenac's avatar
Clément Stenac committed
303

304 305 306 307 308 309 310 311 312 313
    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() );

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

317
    /* Snapshot Button */
318 319 320 321 322
    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
323 324
}

325
AdvControlsWidget::~AdvControlsWidget()
326
{}
Clément Stenac's avatar
Clément Stenac committed
327

328
void AdvControlsWidget::enableInput( bool enable )
Clément Stenac's avatar
Clément Stenac committed
329
{
330 331
    ABButton->setEnabled( enable );
    recordButton->setEnabled( enable );
Clément Stenac's avatar
Clément Stenac committed
332
}
333

334
void AdvControlsWidget::enableVideo( bool enable )
Clément Stenac's avatar
Clément Stenac committed
335 336
{
    snapshotButton->setEnabled( enable );
337
    frameButton->setEnabled( enable );
Clément Stenac's avatar
Clément Stenac committed
338 339
}

340
void AdvControlsWidget::snapshot()
Clément Stenac's avatar
Clément Stenac committed
341
{
342 343
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
344
    if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
Clément Stenac's avatar
Clément Stenac committed
345 346
}

347
/* Function called when the button is clicked() */
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
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" );
}
367

368
/* Function called regularly when in an AtoB loop */
369 370 371 372
void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
{
    if( timeB )
    {
373
        if( i_time >= (int)(timeB/1000000) )
374 375 376
            var_SetTime( THEMIM->getInput(), "time" , timeA );
    }
}
377

378
/* FIXME Record function */
379
void AdvControlsWidget::record(){}
380 381

//FIXME Frame by frame function
382 383
void AdvControlsWidget::frame(){}

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

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

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

413
    /** Slower and faster Buttons **/
414
    slowerButton = new QPushButton;
415
    slowerButton->setFlat( true );
416
    slowerButton->setMaximumSize( QSize( 26, 20 ) );
417

418
    BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
419 420
    controlLayout->addWidget( slowerButton, 0, 0 );

421
    fasterButton = new QPushButton;
422
    fasterButton->setFlat( true );
423
    fasterButton->setMaximumSize( QSize( 26, 20 ) );
424

425
    BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
426
    controlLayout->addWidget( fasterButton, 0, 17 );
427

428 429 430 431
    /* advanced Controls handling */
    b_advancedVisible = b_advControls;

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

435
    /** Disc and Menus handling */
436
    discFrame = new QWidget( this );
437

438 439 440
    QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
    discLayout->setSpacing( 0 );
    discLayout->setMargin( 0 );
441

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

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

450
    nextSectionButton = new QPushButton( discFrame );
451
    setupSmallButton( nextSectionButton );
452 453
    discLayout->addWidget( nextSectionButton );

454
    controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
455 456 457 458 459

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

460
    discFrame->hide();
461 462 463

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

492
    QSpinBox *telexPage = new QSpinBox;
493
    telexPage->setRange( 0, 999 );
494
    telexPage->setValue( 100 );
495 496 497 498
    telexPage->setAlignment( Qt::AlignRight );
    telexLayout->addWidget( telexPage );

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

    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 ) );
509
#endif
510

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

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

523
    controlLayout->addWidget( playButton, 2, 0, 2, 2 );
524

525 526
    controlLayout->setColumnMinimumWidth( 2, 20 );
    controlLayout->setColumnStretch( 2, 0 );
527 528 529 530 531 532 533 534

    /** 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 );
535
    setupSmallButton( prevButton );
536 537 538 539 540 541

    controlButLayout->addWidget( prevButton );

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

    controlButLayout->addWidget( stopButton );

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

    controlButLayout->addWidget( nextButton );

    /* Add this block to the main layout */
554
    controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
555

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

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

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

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

    /** extended Settings **/
    QPushButton *extSettingsButton = new QPushButton( "F" );
585
    BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
586
            extSettings() );
587
    setupSmallButton( extSettingsButton );
588
    controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
589

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

594
    /* Volume */
595
    VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
596

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

603 604 605
    if( b_shiny )
    {
        volumeSlider = new SoundSlider( this,
606 607
            config_GetInt( p_intf, "volume-step" ),
            config_GetInt( p_intf, "qt-volume-complete" ) );
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

    /* Volume control connection */
624
    //resize( QSize( 300, 60 ) );
625
    CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
626
    msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
627
}
628

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

632
/*
633 634 635 636
QSize ControlsWidget::sizeHint() const
{
    return QSize( 300, 50 );
}
637
*/
638

639 640 641 642 643 644 645
void ControlsWidget::stop()
{
    THEMIM->stop();
}

void ControlsWidget::play()
{
646
    if( THEPL->current.i_size == 0 )
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
    {
        /* 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 )
{
668 669 670 671 672
#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" )
673 674 675 676 677 678

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

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

void ControlsWidget::updateOnTimer()
{
708
    /* Audio part */
709 710
    audio_volume_t i_volume;
    aout_VolumeGet( p_intf, &i_volume );
711
    i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
712 713 714 715 716 717 718 719
    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;
    }
720

721
    /* Activate the interface buttons according to the presence of the input */
722
    enableInput( THEMIM->getIM()->hasInput() );
723
    //enableVideo( THEMIM->getIM()->hasVideo() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
724
    enableVideo( true );
725
}
726

727 728
void ControlsWidget::setStatus( int status )
{
729 730
    if( status == PLAYING_S ) // Playing
        playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
731
    else
732
        playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
733
}
734

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

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

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

    /* Advanced Buttons too */
    advControls->enableInput( enable );
775 776
}

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

    /* Advanced Buttons too */
    advControls->enableVideo( enable );
784 785
}

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

801

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

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

818
    speedSlider->setRange( -100, 100 );
819 820 821
    speedSlider->setSingleStep( 10 );
    speedSlider->setPageStep( 20 );
    speedSlider->setTickInterval( 20 );
822

823
    CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
824

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

831
    CONNECT( normalSpeedButton, clicked(), this, resetRate() );
832

833
    QVBoxLayout *speedControlLayout = new QVBoxLayout;
834 835 836
    speedControlLayout->addWidget( speedSlider );
    speedControlLayout->addWidget( normalSpeedButton );
    setLayout( speedControlLayout );
837 838 839
}

SpeedControlWidget::~SpeedControlWidget()
840
{}
841

842 843 844
#define RATE_SLIDER_MAXIMUM 3.0
#define RATE_SLIDER_MINIMUM 0.3
#define RATE_SLIDER_LENGTH 100.0
845 846 847

void SpeedControlWidget::updateControls( int rate )
{
848 849 850 851 852
    if( speedSlider->isSliderDown() )
    {
        //We don't want to change anything if the user is using the slider
        return;
    }
853

854 855
    int sliderValue;
    double speed = INPUT_RATE_DEFAULT / (double)rate;
856

857
    if( rate >= INPUT_RATE_DEFAULT )
858
    {
859 860 861 862 863 864 865
        if( speed < RATE_SLIDER_MINIMUM )
        {
            sliderValue = speedSlider->minimum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
866
                                        / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
867 868 869 870 871 872 873 874 875 876 877
        }
    }
    else
    {
        if( speed > RATE_SLIDER_MAXIMUM )
        {
            sliderValue = speedSlider->maximum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
878
                                        / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
879 880
        }
    }
881

882 883 884 885
    //Block signals to avoid feedback loop
    speedSlider->blockSignals( true );
    speedSlider->setValue( sliderValue );
    speedSlider->blockSignals( false );
886 887 888 889
}

void SpeedControlWidget::updateRate( int sliderValue )
{
890
    int rate;
891

892 893 894
    if( sliderValue < 0.0 )
    {
        rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
895
            ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
896 897 898
    }
    else
    {
899
        rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
900
            ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
901
    }