interface_widgets.cpp 26.6 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 62
{
    vlc_mutex_init( p_intf, &lock );
    p_vout = NULL;
63
    hide(); setMinimumSize( 16, 16 );
64

65 66
   // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
    CONNECT( this, askVideoWidgetToShow(), this, show() );
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    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 );
}

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

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

115
void VideoWidget::release( void *p_win )
116
{
117
    p_vout = NULL;
118
}
119 120


121 122
/**********************************************************************
 * Background Widget. Show a simple image background. Currently,
123
 * it's album art if present or cone.
124
 **********************************************************************/
125 126 127 128
#define ICON_SIZE 128
#define MAX_BG_SIZE 400
#define MIN_BG_SIZE 64

129
BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
130
                                        QWidget( NULL ), p_intf( _p_i )
131
{
132
    /* We should use that one to take the more size it can */
133
    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
134

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

142
    /* A cone in the middle */
143
    label = new QLabel;
144
    label->setMargin( 5 );
145 146
    label->setMaximumHeight( MAX_BG_SIZE );
    label->setMaximumWidth( MAX_BG_SIZE );
147 148
    label->setMinimumHeight( MIN_BG_SIZE );
    label->setMinimumWidth( MIN_BG_SIZE );
149 150 151 152
    if( QDate::currentDate().dayOfYear() >= 354 )
        label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
    else
        label->setPixmap( QPixmap( ":/vlc128.png" ) );
153

154 155 156 157
    QGridLayout *backgroundLayout = new QGridLayout( this );
    backgroundLayout->addWidget( label, 0, 1 );
    backgroundLayout->setColumnStretch( 0, 1 );
    backgroundLayout->setColumnStretch( 2, 1 );
158

159
    CONNECT( THEMIM->getIM(), artChanged( QString ), this, update( QString ) );
160
    resize( 300, 150 );
161 162
}

Clément Stenac's avatar
Clément Stenac committed
163
BackgroundWidget::~BackgroundWidget()
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
164 165 166
{
}

167
void BackgroundWidget::update( QString url )
168
{
169
    if( url.isNull() )
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
170
    {
171 172 173 174
        if( QDate::currentDate().dayOfYear() >= 354 )
            label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
        else
            label->setPixmap( QPixmap( ":/vlc128.png" ) );
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
175 176
        return;
    }
177
    else
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
178
    {
179
        label->setPixmap( QPixmap( url ) );
180
        msg_Dbg( p_intf, "changing input b_need_update done ");
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
181
    }
182 183
}

184 185 186 187
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
{
    QVLCMenu::PopupMenu( p_intf, true );
}
188

Clément Stenac's avatar
Clément Stenac committed
189 190 191 192
/**********************************************************************
 * Visualization selector panel
 **********************************************************************/
VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
193
                                QFrame( NULL ), p_intf( _p_i )
Clément Stenac's avatar
Clément Stenac committed
194 195
{
    QHBoxLayout *layout = new QHBoxLayout( this );
196
    layout->setMargin( 0 );
Clément Stenac's avatar
Clément Stenac committed
197
    QPushButton *prevButton = new QPushButton( "Prev" );
198
    QPushButton *nextButton = new QPushButton( "Next" );
Clément Stenac's avatar
Clément Stenac committed
199 200
    layout->addWidget( prevButton );
    layout->addWidget( nextButton );
Clément Stenac's avatar
Clément Stenac committed
201 202

    layout->addItem( new QSpacerItem( 40,20,
203 204
                              QSizePolicy::Expanding, QSizePolicy::Minimum ) );
    layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
Clément Stenac's avatar
Clément Stenac committed
205 206 207 208 209 210 211

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

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

Clément Stenac's avatar
Clément Stenac committed
212
    setLayout( layout );
213
    setMaximumHeight( 35 );
Clément Stenac's avatar
Clément Stenac committed
214 215 216 217 218 219
}

VisualSelector::~VisualSelector()
{
}

Clément Stenac's avatar
Clément Stenac committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
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 );
    }
}

/**********************************************************************
241
 * TEH controls
Clément Stenac's avatar
Clément Stenac committed
242
 **********************************************************************/
243 244 245 246 247 248

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

249
AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
Clément Stenac's avatar
Clément Stenac committed
250 251
                                           QFrame( NULL ), p_intf( _p_i )
{
252 253 254
    QHBoxLayout *advLayout = new QHBoxLayout( this );
    advLayout->setMargin( 0 );
    advLayout->setSpacing( 0 );
Clément Stenac's avatar
Clément Stenac committed
255

256
    /* A to B Button */
257 258 259 260
    ABButton = new QPushButton( "AB" );
    ABButton->setMaximumSize( QSize( 26, 26 ) );
    ABButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( ABButton );
261
    BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
262
    timeA = timeB = 0;
263 264
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
             this, AtoBLoop( float, int, int ) );
265
#if 0
266 267 268 269 270
    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() );
271
#endif
272 273 274 275 276

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

280
    /* Snapshot Button */
281 282 283 284 285
    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
286 287
}

288
AdvControlsWidget::~AdvControlsWidget()
289
{}
Clément Stenac's avatar
Clément Stenac committed
290

291
void AdvControlsWidget::enableInput( bool enable )
Clément Stenac's avatar
Clément Stenac committed
292
{
293 294
    ABButton->setEnabled( enable );
    recordButton->setEnabled( enable );
Clément Stenac's avatar
Clément Stenac committed
295
}
296

297
void AdvControlsWidget::enableVideo( bool enable )
Clément Stenac's avatar
Clément Stenac committed
298 299
{
    snapshotButton->setEnabled( enable );
300
#if 0
301
    frameButton->setEnabled( enable );
302
#endif
Clément Stenac's avatar
Clément Stenac committed
303 304
}

305
void AdvControlsWidget::snapshot()
Clément Stenac's avatar
Clément Stenac committed
306
{
307 308
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
309
    if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
Clément Stenac's avatar
Clément Stenac committed
310 311
}

312
/* Function called when the button is clicked() */
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
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" );
}
332

333
/* Function called regularly when in an AtoB loop */
334 335 336 337
void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
{
    if( timeB )
    {
338
        if( i_time >= (int)(timeB/1000000) )
339 340 341
            var_SetTime( THEMIM->getInput(), "time" , timeA );
    }
}
342

343
/* FIXME Record function */
344
void AdvControlsWidget::record(){}
345

346
#if 0
347
//FIXME Frame by frame function
348
void AdvControlsWidget::frame(){}
349
#endif
350

351 352 353
/*****************************
 * DA Control Widget !
 *****************************/
354
ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
355
                                MainInterface *_p_mi,
356 357
                                bool b_advControls,
                                bool b_shiny ) :
358
                                QFrame( NULL ), p_intf( _p_i )
359 360
{
    controlLayout = new QGridLayout( this );
361
    controlLayout->setSpacing( 0 );
362 363 364 365 366
#if QT43
    controlLayout->setContentsMargins( 9, 6, 9, 6 );
#else
    controlLayout->setMargin( 6 );
#endif
367 368

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

370 371
    /** The main Slider **/
    slider = new InputSlider( Qt::Horizontal, NULL );
372
    controlLayout->addWidget( slider, 0, 1, 1, 16 );
373 374
    /* Update the position when the IM has changed */
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
375
             slider, setPosition( float, int, int ) );
376 377 378 379
    /* And update the IM, when the position has changed */
    CONNECT( slider, sliderDragged( float ),
             THEMIM->getIM(), sliderUpdate( float ) );

380
    /** Slower and faster Buttons **/
381 382
    slowerButton = new QToolButton;
    slowerButton->setAutoRaise( true );
383
    slowerButton->setMaximumSize( QSize( 26, 20 ) );
384

385
    BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
386 387
    controlLayout->addWidget( slowerButton, 0, 0 );

388 389
    fasterButton = new QToolButton;
    fasterButton->setAutoRaise( true );
390
    fasterButton->setMaximumSize( QSize( 26, 20 ) );
391

392
    BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
393
    controlLayout->addWidget( fasterButton, 0, 17 );
394

395 396 397 398
    /* advanced Controls handling */
    b_advancedVisible = b_advControls;

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

402
    /** Disc and Menus handling */
403
    discFrame = new QWidget( this );
404

405 406 407
    QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
    discLayout->setSpacing( 0 );
    discLayout->setMargin( 0 );
408

409
    prevSectionButton = new QPushButton( discFrame );
410
    setupSmallButton( prevSectionButton );
411 412
    discLayout->addWidget( prevSectionButton );

413
    menuButton = new QPushButton( discFrame );
414 415 416
    setupSmallButton( menuButton );
    discLayout->addWidget( menuButton );

417
    nextSectionButton = new QPushButton( discFrame );
418
    setupSmallButton( nextSectionButton );
419 420
    discLayout->addWidget( nextSectionButton );

421
    controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
422 423 424 425 426

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

427
    discFrame->hide();
428 429 430

    /* Change the navigation button display when the IM navigation changes */
    CONNECT( THEMIM->getIM(), navigationChanged( int ),
431
             this, setNavigation( int ) );
432 433 434 435 436 437 438
    /* 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() );
439
    /**
440
     * Telextext QFrame
441
     * TODO: Merge with upper menu in a StackLayout
442
     **/
443
#ifdef ZVBI_COMPILED
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
    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 );

459
    QSpinBox *telexPage = new QSpinBox;
460
    telexPage->setRange( 0, 999 );
461
    telexPage->setValue( 100 );
462 463 464 465
    telexPage->setAlignment( Qt::AlignRight );
    telexLayout->addWidget( telexPage );

    controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
466
    telexFrame->hide();
467 468 469 470 471 472 473 474 475

    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 ) );
476
#endif
477

478
    /** Play Buttons **/
479
    QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
480 481 482 483
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );

    /* Play */
484
    playButton = new QPushButton;
485
    playButton->setSizePolicy( sizePolicy );
486 487
    playButton->setMaximumSize( QSize( 36, 36 ) );
    playButton->setMinimumSize( QSize( 36, 36 ) );
488
    playButton->setIconSize( QSize( 30, 30 ) );
489

490
    controlLayout->addWidget( playButton, 2, 0, 2, 2 );
491

492 493
    controlLayout->setColumnMinimumWidth( 2, 20 );
    controlLayout->setColumnStretch( 2, 0 );
494 495 496 497 498 499 500 501

    /** 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 );
502
    setupSmallButton( prevButton );
503 504 505 506 507 508

    controlButLayout->addWidget( prevButton );

    /* Stop */
    QPushButton *stopButton = new QPushButton;
    stopButton->setSizePolicy( sizePolicy );
509
    setupSmallButton( stopButton );
510 511 512 513 514 515

    controlButLayout->addWidget( stopButton );

    /* next */
    QPushButton *nextButton = new QPushButton;
    nextButton->setSizePolicy( sizePolicy );
516
    setupSmallButton( nextButton );
517 518 519 520

    controlButLayout->addWidget( nextButton );

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

523
    BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
524
    BUTTON_SET_ACT_I( prevButton, "" , previous.png,
525 526 527
                      qtr( "Previous" ), prev() );
    BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
    BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
528

529 530 531 532
    controlLayout->setColumnMinimumWidth( 7, 20 );
    controlLayout->setColumnStretch( 7, 0 );
    controlLayout->setColumnStretch( 8, 0 );
    controlLayout->setColumnStretch( 9, 0 );
533

534 535 536
    /*
     * Other first Line buttons
     */
537 538 539
    /** Fullscreen/Visualisation **/
    fullscreenButton = new QPushButton( "F" );
    BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
540
    setupSmallButton( fullscreenButton );
541
    controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
542

543 544
    /** Playlist Button **/
    playlistButton = new QPushButton;
545
    setupSmallButton( playlistButton );
546
    controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
547
    BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
548
    CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
549 550 551

    /** extended Settings **/
    QPushButton *extSettingsButton = new QPushButton( "F" );
552
    BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
553
            extSettings() );
554
    setupSmallButton( extSettingsButton );
555
    controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
556

557
    controlLayout->setColumnStretch( 13, 0 );
558
    controlLayout->setColumnMinimumWidth( 13, 24 );
559
    controlLayout->setColumnStretch( 14, 5 );
560

561
    /* Volume */
562
    VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
563

564
    volMuteLabel = new QLabel;
565
    volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
566
    volMuteLabel->setToolTip( qtr( "Mute" ) );
567
    volMuteLabel->installEventFilter( hVolLabel );
568
    controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
569

570 571 572
    if( b_shiny )
    {
        volumeSlider = new SoundSlider( this,
573 574
            config_GetInt( p_intf, "volume-step" ),
            config_GetInt( p_intf, "qt-volume-complete" ) );
575 576 577 578 579 580
    }
    else
    {
        volumeSlider = new QSlider( this );
        volumeSlider->setOrientation( Qt::Horizontal );
    }
581
    volumeSlider->setMaximumSize( QSize( 200, 40 ) );
582
    volumeSlider->setMinimumSize( QSize( 106, 30 ) );
583
    volumeSlider->setFocusPolicy( Qt::NoFocus );
584
    controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
585

586
    /* Set the volume from the config */
587 588
    volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
                              VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
589 590 591

    /* Volume control connection */
    CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
592
    CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
593 594 595 596

    CONNECT( THEMIM->getIM(), statusChanged( int ), this, updateInput() );

    updateInput();
597
}
598

599
ControlsWidget::~ControlsWidget()
600
{}
601

602 603 604 605 606 607 608
void ControlsWidget::stop()
{
    THEMIM->stop();
}

void ControlsWidget::play()
{
609
    if( THEPL->current.i_size == 0 )
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
    {
        /* 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 )
{
631 632 633 634 635
#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" )
636 637 638 639 640 641

    // 1 = chapter, 2 = title, 0 = no
    if( navigation == 0 )
    {
        discFrame->hide();
    } else if( navigation == 1 ) {
642 643
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
644 645 646
        menuButton->show();
        discFrame->show();
    } else {
647 648
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
649 650 651 652 653 654
        menuButton->hide();
        discFrame->show();
    }
}

static bool b_my_volume;
655
void ControlsWidget::updateVolume( int i_sliderVolume )
656 657 658
{
    if( !b_my_volume )
    {
659
        int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
660 661
        aout_VolumeSet( p_intf, i_res );
    }
662 663
    if( i_sliderVolume == 0 )
        volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
664
    else if( i_sliderVolume < VOLUME_MAX / 3 )
665
        volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
666 667 668
    else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
        volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
    else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
669 670
}

671
void ControlsWidget::updateVolume()
672
{
673
    /* Audio part */
674 675
    audio_volume_t i_volume;
    aout_VolumeGet( p_intf, &i_volume );
676
    i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
677 678 679 680 681 682 683 684
    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;
    }
685
}
686

687 688
void ControlsWidget::updateInput()
{
689
    /* Activate the interface buttons according to the presence of the input */
690
    enableInput( THEMIM->getIM()->hasInput() );
691
    enableVideo( THEMIM->getIM()->hasVideo() );
692
}
693

694 695
void ControlsWidget::setStatus( int status )
{
696 697
    if( status == PLAYING_S ) // Playing
        playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
698
    else
699
        playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
700
}
701

702 703
/**
 * TODO
704
 * This functions toggle the fullscreen mode
705
 * If there is no video, it should first activate Visualisations...
706
 *  This has also to be fixed in enableVideo()
707
 */
Clément Stenac's avatar
Clément Stenac committed
708 709
void ControlsWidget::fullscreen()
{
710 711
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
712
    if( p_vout)
713
    {
714
        var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
715
        vlc_object_release( p_vout );
716
    }
717 718 719 720 721 722
}

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

724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
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 );
739 740 741

    /* Advanced Buttons too */
    advControls->enableInput( enable );
742 743
}

744
void ControlsWidget::enableVideo( bool enable )
745
{
746 747
    // TODO Later make the fullscreenButton toggle Visualisation and so on.
    fullscreenButton->setEnabled( enable );
748 749 750

    /* Advanced Buttons too */
    advControls->enableVideo( enable );
751 752
}

753 754 755 756 757 758 759 760 761 762 763 764
void ControlsWidget::toggleAdvanced()
{
    if( !VISIBLE( advControls ) )
    {
        advControls->show();
        b_advancedVisible = true;
    }
    else
    {
        advControls->hide();
        b_advancedVisible = false;
    }
765
    emit advancedControlsToggled( b_advancedVisible );
766
}
767

768

769 770 771 772 773
/**********************************************************************
 * Speed control widget
 **********************************************************************/
SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
                             QFrame( NULL ), p_intf( _p_i )
774
{
775
    QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
776 777
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );
778

779 780 781 782 783 784
    speedSlider = new QSlider;
    speedSlider->setSizePolicy( sizePolicy );
    speedSlider->setMaximumSize( QSize( 80, 200 ) );
    speedSlider->setOrientation( Qt::Vertical );
    speedSlider->setTickPosition( QSlider::TicksRight );

785
    speedSlider->setRange( -100, 100 );
786 787 788
    speedSlider->setSingleStep( 10 );
    speedSlider->setPageStep( 20 );
    speedSlider->setTickInterval( 20 );
789

790
    CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
791

792
    QToolButton *normalSpeedButton = new QToolButton( this );
793
    normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
794 795
    normalSpeedButton->setAutoRaise( true );
    normalSpeedButton->setText( "N" );
796
    normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
797

798
    CONNECT( normalSpeedButton, clicked(), this, resetRate() );
799

800
    QVBoxLayout *speedControlLayout = new QVBoxLayout;
801 802 803
    speedControlLayout->addWidget( speedSlider );
    speedControlLayout->addWidget( normalSpeedButton );
    setLayout( speedControlLayout );
804 805 806
}

SpeedControlWidget::~SpeedControlWidget()
807
{}
808

809 810 811
#define RATE_SLIDER_MAXIMUM 3.0
#define RATE_SLIDER_MINIMUM 0.3
#define RATE_SLIDER_LENGTH 100.0
812 813 814

void SpeedControlWidget::updateControls( int rate )
{
815 816 817 818 819
    if( speedSlider->isSliderDown() )
    {
        //We don't want to change anything if the user is using the slider
        return;
    }
820

821 822
    int sliderValue;
    double speed = INPUT_RATE_DEFAULT / (double)rate;
823

824
    if( rate >= INPUT_RATE_DEFAULT )
825
    {
826 827 828 829 830 831 832
        if( speed < RATE_SLIDER_MINIMUM )
        {
            sliderValue = speedSlider->minimum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
833
                                        / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
834 835 836 837 838 839 840 841 842 843 844
        }
    }
    else
    {
        if( speed > RATE_SLIDER_MAXIMUM )
        {
            sliderValue = speedSlider->maximum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
845
                                        / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
846 847
        }
    }
848

849 850 851 852
    //Block signals to avoid feedback loop
    speedSlider->blockSignals( true );
    speedSlider->setValue( sliderValue );
    speedSlider->blockSignals( false );
853 854 855 856
}

void SpeedControlWidget::updateRate( int sliderValue )
{
857
    int rate;
858

859 860
    if( sliderValue < 0.0 )
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
861 862
        rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
            ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
863 864 865
    }
    else
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
866 867
        rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
            ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
868
    }
869

870
    THEMIM->getIM()->setRate(rate);
871 872 873 874
}

void SpeedControlWidget::resetRate()
{
875
    THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
876
}