interface_widgets.cpp 26.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
    hide(); setMinimumSize( 16, 16 );
61

62 63
   // 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
    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 );
}

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

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

112
void VideoWidget::release( void *p_win )
113
{
114
    p_vout = NULL;
115
}
116 117


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

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

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

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

151 152 153 154
    QGridLayout *backgroundLayout = new QGridLayout( this );
    backgroundLayout->addWidget( label, 0, 1 );
    backgroundLayout->setColumnStretch( 0, 1 );
    backgroundLayout->setColumnStretch( 2, 1 );
155

156
    CONNECT( THEMIM->getIM(), artChanged( QString ), this, update( QString ) );
157
    resize( 300, 150 );
158 159
}

Clément Stenac's avatar
Clément Stenac committed
160
BackgroundWidget::~BackgroundWidget()
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
161 162 163
{
}

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

181 182 183 184
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
{
    QVLCMenu::PopupMenu( p_intf, true );
}
185

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

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

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

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

Clément Stenac's avatar
Clément Stenac committed
209
    setLayout( layout );
210
    setMaximumHeight( 35 );
Clément Stenac's avatar
Clément Stenac committed
211 212 213 214 215 216
}

VisualSelector::~VisualSelector()
{
}

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

/**********************************************************************
238
 * TEH controls
Clément Stenac's avatar
Clément Stenac committed
239
 **********************************************************************/
240 241 242 243 244 245

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

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

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

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

277
    /* Snapshot Button */
278 279 280 281 282
    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
283 284
}

285
AdvControlsWidget::~AdvControlsWidget()
286
{}
Clément Stenac's avatar
Clément Stenac committed
287

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

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

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

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

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

340
/* FIXME Record function */
341
void AdvControlsWidget::record(){}
342

343
#if 0
344
//FIXME Frame by frame function
345
void AdvControlsWidget::frame(){}
346
#endif
347

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

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

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

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

382
    BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
383 384
    controlLayout->addWidget( slowerButton, 0, 0 );

385 386
    fasterButton = new QToolButton;
    fasterButton->setAutoRaise( true );
387
    fasterButton->setMaximumSize( QSize( 26, 20 ) );
388

389
    BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
390
    controlLayout->addWidget( fasterButton, 0, 17 );
391

392 393 394 395
    /* advanced Controls handling */
    b_advancedVisible = b_advControls;

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

399
    /** Disc and Menus handling */
400
    discFrame = new QWidget( this );
401

402 403 404
    QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
    discLayout->setSpacing( 0 );
    discLayout->setMargin( 0 );
405

406
    prevSectionButton = new QPushButton( discFrame );
407
    setupSmallButton( prevSectionButton );
408 409
    discLayout->addWidget( prevSectionButton );

410
    menuButton = new QPushButton( discFrame );
411 412 413
    setupSmallButton( menuButton );
    discLayout->addWidget( menuButton );

414
    nextSectionButton = new QPushButton( discFrame );
415
    setupSmallButton( nextSectionButton );
416 417
    discLayout->addWidget( nextSectionButton );

418
    controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
419 420 421 422 423

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

424
    discFrame->hide();
425 426 427

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

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

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

    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 ) );
473
#endif
474

475
    /** Play Buttons **/
476
    QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
477 478 479 480
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );

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

487
    controlLayout->addWidget( playButton, 2, 0, 2, 2 );
488

489 490
    controlLayout->setColumnMinimumWidth( 2, 20 );
    controlLayout->setColumnStretch( 2, 0 );
491 492 493 494 495 496 497 498

    /** 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 );
499
    setupSmallButton( prevButton );
500 501 502 503 504 505

    controlButLayout->addWidget( prevButton );

    /* Stop */
    QPushButton *stopButton = new QPushButton;
    stopButton->setSizePolicy( sizePolicy );
506
    setupSmallButton( stopButton );
507 508 509 510 511 512

    controlButLayout->addWidget( stopButton );

    /* next */
    QPushButton *nextButton = new QPushButton;
    nextButton->setSizePolicy( sizePolicy );
513
    setupSmallButton( nextButton );
514 515 516 517

    controlButLayout->addWidget( nextButton );

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

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

526 527 528 529
    controlLayout->setColumnMinimumWidth( 7, 20 );
    controlLayout->setColumnStretch( 7, 0 );
    controlLayout->setColumnStretch( 8, 0 );
    controlLayout->setColumnStretch( 9, 0 );
530

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

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

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

554
    controlLayout->setColumnStretch( 13, 0 );
555
    controlLayout->setColumnMinimumWidth( 13, 24 );
556
    controlLayout->setColumnStretch( 14, 5 );
557

558
    /* Volume */
559
    VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
560

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

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

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

    /* Volume control connection */
    CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
589
    CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
590
}
591

592
ControlsWidget::~ControlsWidget()
593
{}
594

595 596 597 598 599 600 601
void ControlsWidget::stop()
{
    THEMIM->stop();
}

void ControlsWidget::play()
{
602
    if( THEPL->current.i_size == 0 )
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
    {
        /* 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 )
{
624 625 626 627 628
#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" )
629 630 631 632 633 634

    // 1 = chapter, 2 = title, 0 = no
    if( navigation == 0 )
    {
        discFrame->hide();
    } else if( navigation == 1 ) {
635 636
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
637 638 639
        menuButton->show();
        discFrame->show();
    } else {
640 641
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
642 643 644 645 646 647
        menuButton->hide();
        discFrame->show();
    }
}

static bool b_my_volume;
648
void ControlsWidget::updateVolume( int i_sliderVolume )
649 650 651
{
    if( !b_my_volume )
    {
652
        int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
653 654
        aout_VolumeSet( p_intf, i_res );
    }
655 656
    if( i_sliderVolume == 0 )
        volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
657
    else if( i_sliderVolume < VOLUME_MAX / 3 )
658
        volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
659 660 661
    else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
        volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
    else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
662 663
}

664
void ControlsWidget::updateVolume()
665
{
666
    /* Audio part */
667 668
    audio_volume_t i_volume;
    aout_VolumeGet( p_intf, &i_volume );
669
    i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
670 671 672 673 674 675 676 677
    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;
    }
678

679
    /* Activate the interface buttons according to the presence of the input */
680
    enableInput( THEMIM->getIM()->hasInput() );
681
    //enableVideo( THEMIM->getIM()->hasVideo() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
682
    enableVideo( true );
683
}
684

685 686
void ControlsWidget::setStatus( int status )
{
687 688
    if( status == PLAYING_S ) // Playing
        playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
689
    else
690
        playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
691
}
692

693 694
/**
 * TODO
695
 * This functions toggle the fullscreen mode
696
 * If there is no video, it should first activate Visualisations...
697
 *  This has also to be fixed in enableVideo()
698
 */
Clément Stenac's avatar
Clément Stenac committed
699 700
void ControlsWidget::fullscreen()
{
701 702
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
703
    if( p_vout)
704
    {
705
        var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
706
        vlc_object_release( p_vout );
707
    }
708 709 710 711 712 713
}

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

715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
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 );
730 731 732

    /* Advanced Buttons too */
    advControls->enableInput( enable );
733 734
}

735
void ControlsWidget::enableVideo( bool enable )
736
{
737 738
    // TODO Later make the fullscreenButton toggle Visualisation and so on.
    fullscreenButton->setEnabled( enable );
739 740 741

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

744 745 746 747 748 749 750 751 752 753 754 755
void ControlsWidget::toggleAdvanced()
{
    if( !VISIBLE( advControls ) )
    {
        advControls->show();
        b_advancedVisible = true;
    }
    else
    {
        advControls->hide();
        b_advancedVisible = false;
    }
756
    emit advancedControlsToggled( b_advancedVisible );
757
}
758

759

760 761 762 763 764
/**********************************************************************
 * Speed control widget
 **********************************************************************/
SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
                             QFrame( NULL ), p_intf( _p_i )
765
{
766
    QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
767 768
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );
769

770 771 772 773 774 775
    speedSlider = new QSlider;
    speedSlider->setSizePolicy( sizePolicy );
    speedSlider->setMaximumSize( QSize( 80, 200 ) );
    speedSlider->setOrientation( Qt::Vertical );
    speedSlider->setTickPosition( QSlider::TicksRight );

776
    speedSlider->setRange( -100, 100 );
777 778 779
    speedSlider->setSingleStep( 10 );
    speedSlider->setPageStep( 20 );
    speedSlider->setTickInterval( 20 );
780

781
    CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
782

783
    QToolButton *normalSpeedButton = new QToolButton( this );
784
    normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
785 786
    normalSpeedButton->setAutoRaise( true );
    normalSpeedButton->setText( "N" );
787
    normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
788

789
    CONNECT( normalSpeedButton, clicked(), this, resetRate() );
790

791
    QVBoxLayout *speedControlLayout = new QVBoxLayout;
792 793 794
    speedControlLayout->addWidget( speedSlider );
    speedControlLayout->addWidget( normalSpeedButton );
    setLayout( speedControlLayout );
795 796 797
}

SpeedControlWidget::~SpeedControlWidget()
798
{}
799

800 801 802
#define RATE_SLIDER_MAXIMUM 3.0
#define RATE_SLIDER_MINIMUM 0.3
#define RATE_SLIDER_LENGTH 100.0
803 804 805

void SpeedControlWidget::updateControls( int rate )
{
806 807 808 809 810
    if( speedSlider->isSliderDown() )
    {
        //We don't want to change anything if the user is using the slider
        return;
    }
811

812 813
    int sliderValue;
    double speed = INPUT_RATE_DEFAULT / (double)rate;
814

815
    if( rate >= INPUT_RATE_DEFAULT )
816
    {
817 818 819 820 821 822 823
        if( speed < RATE_SLIDER_MINIMUM )
        {
            sliderValue = speedSlider->minimum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
824
                                        / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
825 826 827 828 829 830 831 832 833 834 835
        }
    }
    else
    {
        if( speed > RATE_SLIDER_MAXIMUM )
        {
            sliderValue = speedSlider->maximum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
836
                                        / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
837 838
        }
    }
839

840 841 842 843
    //Block signals to avoid feedback loop
    speedSlider->blockSignals( true );
    speedSlider->setValue( sliderValue );
    speedSlider->blockSignals( false );
844 845 846 847
}

void SpeedControlWidget::updateRate( int sliderValue )
{
848
    int rate;
849

850 851
    if( sliderValue < 0.0 )
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
852 853
        rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
            ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
854 855 856
    }
    else
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
857 858
        rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
            ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
859
    }
860

861
    THEMIM->getIM()->setRate(rate);
862 863 864 865
}

void SpeedControlWidget::resetRate()
{
866
    THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
867
}