interface_widgets.cpp 35.7 KB
Newer Older
1
/*****************************************************************************
2
 * interface_widgets.cpp : Custom widgets for the main interface
3
 ****************************************************************************
4
 * Copyright ( C ) 2006 the VideoLAN team
5
 * $Id$
6 7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Jean-Baptiste Kempf <jb@videolan.org>
9
 *          Rafaël Carré <funman@videolanorg>
10
 *          Ilkka Ollakka <ileoo@videolan.org>
11 12 13 14
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
15
 * ( at your option ) any later version.
16 17 18 19 20 21 22 23 24 25
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
26

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

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

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

51 52 53 54
/**********************************************************************
 * Video Widget. A simple frame on which video is drawn
 * This class handles resize issues
 **********************************************************************/
55

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

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

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

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

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

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

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

135 136 137 138
QSize VideoWidget::sizeHint() const
{
    return videoSize;
}
139

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

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

154
    /* A dark background */
zorglub's avatar
zorglub committed
155
    setAutoFillBackground( true );
156 157 158 159 160
    plt =  palette();
    plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
    plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
    setPalette( plt );

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

173 174 175 176
    QGridLayout *backgroundLayout = new QGridLayout( this );
    backgroundLayout->addWidget( label, 0, 1 );
    backgroundLayout->setColumnStretch( 0, 1 );
    backgroundLayout->setColumnStretch( 2, 1 );
177

178
    CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
179 180
}

zorglub's avatar
zorglub committed
181
BackgroundWidget::~BackgroundWidget()
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
182 183 184
{
}

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

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

209 210 211 212
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
{
    QVLCMenu::PopupMenu( p_intf, true );
}
213

zorglub's avatar
zorglub committed
214 215 216 217
/**********************************************************************
 * Visualization selector panel
 **********************************************************************/
VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
218
                                QFrame( NULL ), p_intf( _p_i )
zorglub's avatar
zorglub committed
219 220
{
    QHBoxLayout *layout = new QHBoxLayout( this );
221
    layout->setMargin( 0 );
zorglub's avatar
zorglub committed
222
    QPushButton *prevButton = new QPushButton( "Prev" );
223
    QPushButton *nextButton = new QPushButton( "Next" );
zorglub's avatar
zorglub committed
224 225
    layout->addWidget( prevButton );
    layout->addWidget( nextButton );
zorglub's avatar
zorglub committed
226 227

    layout->addItem( new QSpacerItem( 40,20,
228 229
                              QSizePolicy::Expanding, QSizePolicy::Minimum ) );
    layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
zorglub's avatar
zorglub committed
230 231 232 233 234 235 236

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

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

zorglub's avatar
zorglub committed
237
    setLayout( layout );
238
    setMaximumHeight( 35 );
zorglub's avatar
zorglub committed
239 240 241 242 243 244
}

VisualSelector::~VisualSelector()
{
}

zorglub's avatar
zorglub committed
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
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 );
    }
}

/**********************************************************************
266
 * TEH controls
zorglub's avatar
zorglub committed
267
 **********************************************************************/
268 269 270 271 272 273

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

274
AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
zorglub's avatar
zorglub committed
275 276
                                           QFrame( NULL ), p_intf( _p_i )
{
277 278 279
    QHBoxLayout *advLayout = new QHBoxLayout( this );
    advLayout->setMargin( 0 );
    advLayout->setSpacing( 0 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
280
    advLayout->setAlignment( Qt::AlignBottom );
zorglub's avatar
zorglub committed
281

282
    /* A to B Button */
283
    ABButton = new QPushButton( "AB" );
lukas.durfina's avatar
lukas.durfina committed
284
    setupSmallButton( ABButton );
285
    advLayout->addWidget( ABButton );
286
    BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
287
    timeA = timeB = 0;
288 289
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
             this, AtoBLoop( float, int, int ) );
290
#if 0
291 292 293 294 295
    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() );
296
#endif
297 298

    recordButton = new QPushButton( "R" );
lukas.durfina's avatar
lukas.durfina committed
299
    setupSmallButton( recordButton );
300
    advLayout->addWidget( recordButton );
301
    BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
302
            qtr( "Record" ), record() );
303

304
    /* Snapshot Button */
305
    snapshotButton = new QPushButton( "S" );
lukas.durfina's avatar
lukas.durfina committed
306
    setupSmallButton( snapshotButton );
307 308
    advLayout->addWidget( snapshotButton );
    BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
zorglub's avatar
zorglub committed
309 310
}

311
AdvControlsWidget::~AdvControlsWidget()
312
{}
zorglub's avatar
zorglub committed
313

314
void AdvControlsWidget::enableInput( bool enable )
zorglub's avatar
zorglub committed
315
{
316 317
    ABButton->setEnabled( enable );
    recordButton->setEnabled( enable );
zorglub's avatar
zorglub committed
318
}
319

320
void AdvControlsWidget::enableVideo( bool enable )
zorglub's avatar
zorglub committed
321 322
{
    snapshotButton->setEnabled( enable );
323
#if 0
324
    frameButton->setEnabled( enable );
325
#endif
zorglub's avatar
zorglub committed
326 327
}

328
void AdvControlsWidget::snapshot()
zorglub's avatar
zorglub committed
329
{
330 331
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
332
    if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
zorglub's avatar
zorglub committed
333 334
}

335
/* Function called when the button is clicked() */
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
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" );
}
355

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

366
/* FIXME Record function */
367
void AdvControlsWidget::record(){}
368

369
#if 0
370
//FIXME Frame by frame function
371
void AdvControlsWidget::frame(){}
372
#endif
373

374 375 376
/*****************************
 * DA Control Widget !
 *****************************/
377
ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
378
                                MainInterface *_p_mi,
379
                                bool b_advControls,
lukas.durfina's avatar
lukas.durfina committed
380 381 382
                                bool b_shiny,
                                bool b_fsCreation) :
                                QFrame( _p_mi ), p_intf( _p_i )
383
{
lukas.durfina's avatar
lukas.durfina committed
384 385
    controlLayout = new QGridLayout( );

386
    controlLayout->setSpacing( 0 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
387
    controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
388

lukas.durfina's avatar
lukas.durfina committed
389 390 391
    if( !b_fsCreation )
        setLayout( controlLayout );

392
    setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
393

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

404
    /** Slower and faster Buttons **/
405 406
    slowerButton = new QToolButton;
    slowerButton->setAutoRaise( true );
407
    slowerButton->setMaximumSize( QSize( 26, 20 ) );
408

409
    BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
410 411
    controlLayout->addWidget( slowerButton, 0, 0 );

412 413
    fasterButton = new QToolButton;
    fasterButton->setAutoRaise( true );
414
    fasterButton->setMaximumSize( QSize( 26, 20 ) );
415

416
    BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
417
    controlLayout->addWidget( fasterButton, 0, 17 );
418

419 420 421 422
    /* advanced Controls handling */
    b_advancedVisible = b_advControls;

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

426
    /** Disc and Menus handling */
427
    discFrame = new QWidget( this );
428

429 430 431
    QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
    discLayout->setSpacing( 0 );
    discLayout->setMargin( 0 );
432

433
    prevSectionButton = new QPushButton( discFrame );
434
    setupSmallButton( prevSectionButton );
435 436
    discLayout->addWidget( prevSectionButton );

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

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

445
    controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
446 447 448 449 450

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

451
    discFrame->hide();
452 453 454

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

482
    QSpinBox *telexPage = new QSpinBox;
483
    telexPage->setRange( 0, 999 );
484
    telexPage->setValue( 100 );
485 486
    telexPage->setAccelerated( true );
    telexPage->setWrapping( true );
487
    telexPage->setAlignment( Qt::AlignRight );
488
    telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
489 490 491
    telexLayout->addWidget( telexPage );

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

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

503
    /** Play Buttons **/
504
    QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
505 506 507 508
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );

    /* Play */
509
    playButton = new QPushButton;
510
    playButton->setSizePolicy( sizePolicy );
511 512
    playButton->setMaximumSize( QSize( 36, 36 ) );
    playButton->setMinimumSize( QSize( 36, 36 ) );
513
    playButton->setIconSize( QSize( 30, 30 ) );
514

515
    controlLayout->addWidget( playButton, 2, 0, 2, 2 );
516

517 518
    controlLayout->setColumnMinimumWidth( 2, 20 );
    controlLayout->setColumnStretch( 2, 0 );
519 520

    /** Prev + Stop + Next Block **/
lukas.durfina's avatar
lukas.durfina committed
521
    controlButLayout = new QHBoxLayout;
522 523 524 525 526
    controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */

    /* Prev */
    QPushButton *prevButton = new QPushButton;
    prevButton->setSizePolicy( sizePolicy );
527
    setupSmallButton( prevButton );
528 529 530 531 532 533

    controlButLayout->addWidget( prevButton );

    /* Stop */
    QPushButton *stopButton = new QPushButton;
    stopButton->setSizePolicy( sizePolicy );
534
    setupSmallButton( stopButton );
535 536 537 538 539 540

    controlButLayout->addWidget( stopButton );

    /* next */
    QPushButton *nextButton = new QPushButton;
    nextButton->setSizePolicy( sizePolicy );
541
    setupSmallButton( nextButton );
542 543 544 545

    controlButLayout->addWidget( nextButton );

    /* Add this block to the main layout */
lukas.durfina's avatar
lukas.durfina committed
546 547
    if( !b_fsCreation )
        controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
548

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

555 556 557 558
    controlLayout->setColumnMinimumWidth( 7, 20 );
    controlLayout->setColumnStretch( 7, 0 );
    controlLayout->setColumnStretch( 8, 0 );
    controlLayout->setColumnStretch( 9, 0 );
559

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

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

    /** extended Settings **/
lukas.durfina's avatar
lukas.durfina committed
577
    extSettingsButton = new QPushButton;
578
    BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
579
            extSettings() );
580
    setupSmallButton( extSettingsButton );
581
    controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
582

583
    controlLayout->setColumnStretch( 13, 0 );
584
    controlLayout->setColumnMinimumWidth( 13, 24 );
585
    controlLayout->setColumnStretch( 14, 5 );
586

587
    /* Volume */
lukas.durfina's avatar
lukas.durfina committed
588
    hVolLabel = new VolumeClickHandler( p_intf, this );
589

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

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

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

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

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

    updateInput();
625
}
626

627
ControlsWidget::~ControlsWidget()
628
{}
629

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

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

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

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

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

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

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

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

void ControlsWidget::extSettings()
{
    THEDP->extendedDialog();
}
zorglub's avatar
zorglub committed
757

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

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

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

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

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

802

lukas.durfina's avatar
lukas.durfina committed
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
/**********************************************************************
 * Fullscrenn control widget
 **********************************************************************/
FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
        MainInterface *_p_mi, bool b_advControls, bool b_shiny )
        : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
        i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
        b_mouseIsOver( false )
{
    setWindowFlags( Qt::ToolTip );

    setFrameShape( QFrame::StyledPanel );