controller.cpp 38.8 KB
Newer Older
1
/*****************************************************************************
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
2
 * Controller.cpp : Controller for the main interface
3
 ****************************************************************************
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
4
 * Copyright ( C ) 2006-2008 the VideoLAN team
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
 * $Id$
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
 *          Jean-Baptiste Kempf <jb@videolan.org>
 *          Rafaël Carré <funman@videolanorg>
 *          Ilkka Ollakka <ileoo@videolan.org>
 *
 * 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
 * ( at your option ) any later version.
 *
 * 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.
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_vout.h>

#include "dialogs_provider.hpp"
#include "components/interface_widgets.hpp"
#include "main_interface.hpp"
#include "input_manager.hpp"
#include "menus.hpp"
#include "util/input_slider.hpp"
#include "util/customwidgets.hpp"

#include <QLabel>
#include <QSpacerItem>
#include <QCursor>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
44
#include <QToolButton>
45 46 47 48 49
#include <QHBoxLayout>
#include <QMenu>
#include <QPalette>
#include <QResizeEvent>
#include <QDate>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
50
#include <QSignalMapper>
51
#include <QTimer>
52 53 54 55 56 57 58

#define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media")

/**********************************************************************
 * TEH controls
 **********************************************************************/

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
59 60 61 62 63 64
/******
  * This is an abstract Toolbar/Controller
  * This has helper to create any toolbar, any buttons and to manage the actions
  *
  *****/
AbstractController::AbstractController( intf_thread_t * _p_i ) : QFrame( NULL )
65
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
66
    p_intf = _p_i;
67

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
68 69 70
    /* We need one layout. An controller without layout is stupid with 
       current architecture */
    controlLayout = new QGridLayout( this );
71

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
72
    /* Main action provider */
73
    toolbarActionsMapper = new QSignalMapper( this );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
74 75 76
    CONNECT( toolbarActionsMapper, mapped( int ),
             this, doAction( int ) );
    CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
77 78
}

79
/* Reemit some signals on status Change to activate some buttons */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
80
void AbstractController::setStatus( int status )
81
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
82 83 84
    bool b_hasInput = THEMIM->getIM()->hasInput();
    /* Activate the interface buttons according to the presence of the input */
    emit inputExists( b_hasInput );
85

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
86
    emit inputPlaying( status == PLAYING_S );
87

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
88 89
    emit inputIsRecordable( b_hasInput &&
                            var_GetBool( THEMIM->getInput(), "can-record" ) );
90 91
}

92
/* Generic button setup */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
93
void AbstractController::setupButton( QAbstractButton *aButton )
94
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
95 96 97
    static QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );
98

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
99 100 101 102
    aButton->setSizePolicy( sizePolicy );
    aButton->setFixedSize( QSize( 26, 26 ) );
    aButton->setIconSize( QSize( 20, 20 ) );
    aButton->setFocusPolicy( Qt::NoFocus );
103 104
}

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
/* Open the generic config line for the toolbar, parse it
 * and create the widgets accordingly */
void AbstractController::parseAndCreateLine( QString config, int i_line )
{
    int i_column = 0;
    QStringList list = config.split( ";" ) ;
    for( int i = 0; i < list.size(); i++ )
    {
         QStringList list2 = list.at( i ).split( "-" );
         if( list2.size() < 1 )
         {
             msg_Warn( p_intf, "Parsing error. Report this" );
             continue;
         }

         bool ok;
         int i_option = WIDGET_NORMAL;
         buttonType_e i_type = (buttonType_e)list2.at( 0 ).toInt( &ok );
         if( !ok )
         {
             msg_Warn( p_intf, "Parsing error 0. Please report this" );
             continue;
         }
         /* Special case for SPACERS, who aren't QWidgets */
         if( i_type == WIDGET_SPACER || i_type == WIDGET_SPACER_EXTEND )
         {
             controlLayout->setColumnMinimumWidth( i, 10 );
             i_column++;
             controlLayout->setColumnStretch( i,
                     ( i_type == WIDGET_SPACER ) ? 0 : 10 );
             continue;
         }

         if( list2.size() > 1 )
         {
             i_option = list2.at( 1 ).toInt( &ok );
             if( !ok )
             {
                 msg_Warn( p_intf, "Parsing error 1. Please report this" );
                 continue;
             }
         }

         int i_size;
         QWidget *widg = createWidget( i_type, &i_size, i_option );
         if( !widg ) continue;

         if( list2.size() > 2 )
         {
             i_size = list.at( 2 ).toInt( &ok );

             if( !ok )
             {
                 msg_Warn( p_intf, "Parsing error 2. Please report this" );
                 continue;
             }
         }

         controlLayout->addWidget( widg, i_line, i_column, 1, i_size );
         i_column += i_size;
    }
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
#define CONNECT_MAP( a ) CONNECT( a, clicked(),  toolbarActionsMapper, map() )
#define SET_MAPPING( a, b ) toolbarActionsMapper->setMapping( a , b )
#define CONNECT_MAP_SET( a, b ) \
    CONNECT_MAP( a ); \
    SET_MAPPING( a, b );
#define BUTTON_SET_BAR( button, image, tooltip ) \
    button->setToolTip( tooltip );          \
    button->setIcon( QIcon( ":/"#image ) );

#define ENABLE_ON_VIDEO( a ) \
    CONNECT( THEMIM->getIM(), voutChanged( bool ), a, setEnabled( bool ) ); \
    a->setEnabled( THEMIM->getIM()->hasVideo() ); /* TODO: is this necessary? when input is started before the interface? */

#define ENABLE_ON_INPUT( a ) \
    CONNECT( this, inputExists( bool ), a, setEnabled( bool ) ); \
    a->setEnabled( THEMIM->getIM()->hasInput() ); /* TODO: is this necessary? when input is started before the interface? */

185 186
QWidget *AbstractController::createWidget( buttonType_e button, int* i_size,
        int options )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
187
{
188 189 190 191 192 193 194
    assert( i_size );

    bool b_flat = options & WIDGET_FLAT;
    bool b_big = options & WIDGET_BIG;
    bool b_shiny = options & WIDGET_SHINY;
    *i_size = 1; 

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
    QWidget *widget = NULL;
    switch( button )
    {
    case PLAY_BUTTON: {
        PlayButton *playButton = new PlayButton;
        setupButton( playButton );
        BUTTON_SET_BAR( playButton, play_b, qtr( I_PLAY_TOOLTIP ) );
        CONNECT_MAP_SET( playButton, PLAY_ACTION );
        CONNECT( this, inputPlaying( bool ),
                 playButton, updateButton( bool ));
        widget = playButton;
        }
        break;
    case STOP_BUTTON:{
        QToolButton *stopButton = new QToolButton;
        setupButton( stopButton );
        CONNECT_MAP_SET( stopButton, STOP_ACTION );
        BUTTON_SET_BAR( stopButton, stop_b, qtr( "Stop playback" ) );
        widget = stopButton;
        }
        break;
    case PREVIOUS_BUTTON:{
        QToolButton *prevButton = new QToolButton;
        setupButton( prevButton );
        CONNECT_MAP_SET( prevButton, PREVIOUS_ACTION );
        BUTTON_SET_BAR( prevButton, previous_b,
                  qtr( "Previous media in the playlist" ) );
        widget = prevButton;
        }
        break;
    case NEXT_BUTTON:
        {
        QToolButton *nextButton = new QToolButton;
        setupButton( nextButton );
        CONNECT_MAP_SET( nextButton, NEXT_ACTION );
        BUTTON_SET_BAR( nextButton, next_b,
                qtr( "Next media in the playlist" ) );
        widget = nextButton;
        }
        break;
    case SLOWER_BUTTON:{
        QToolButton *slowerButton = new QToolButton;
        setupButton( slowerButton );
        CONNECT_MAP_SET( slowerButton, SLOWER_ACTION );
        BUTTON_SET_BAR( slowerButton, slower, qtr( "Slower" ) );
        ENABLE_ON_INPUT( slowerButton );
        widget = slowerButton;
        }
        break;
    case FASTER_BUTTON:{
        QToolButton *fasterButton = new QToolButton;
        setupButton( fasterButton );
247
        CONNECT_MAP_SET( fasterButton, FASTER_ACTION );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
248 249 250 251 252 253
        BUTTON_SET_BAR( fasterButton, faster, qtr( "Faster" ) );
        ENABLE_ON_INPUT( fasterButton );
        widget = fasterButton;
        }
        break;
    case FRAME_BUTTON: {
254
        QToolButton *frameButton = new QToolButton;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
255
        setupButton( frameButton );
256
        CONNECT_MAP_SET( frameButton, FRAME_ACTION );
257
        BUTTON_SET_BAR( frameButton, frame, qtr( "Frame by frame" ) );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
258 259 260 261 262 263 264 265 266 267 268 269 270 271
        ENABLE_ON_INPUT( frameButton );
        widget = frameButton;
        }
        break;
    case FULLSCREEN_BUTTON:{
        QToolButton *fullscreenButton = new QToolButton;
        setupButton( fullscreenButton );
        CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION );
        BUTTON_SET_BAR( fullscreenButton, fullscreen,
                qtr( "Toggle the video in fullscreen" ) );
        ENABLE_ON_VIDEO( fullscreenButton );
        widget = fullscreenButton;
        }
        break;
272 273 274 275 276 277 278 279 280 281
    case DEFULLSCREEN_BUTTON:{
        QToolButton *fullscreenButton = new QToolButton;
        setupButton( fullscreenButton );
        CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION );
        BUTTON_SET_BAR( fullscreenButton, defullscreen,
                qtr( "Toggle the video in fullscreen" ) );
        ENABLE_ON_VIDEO( fullscreenButton );
        widget = fullscreenButton;
        }
        break;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
    case EXTENDED_BUTTON:{
        QToolButton *extSettingsButton = new QToolButton;
        setupButton( extSettingsButton );
        CONNECT_MAP_SET( extSettingsButton, EXTENDED_ACTION );
        BUTTON_SET_BAR( extSettingsButton, extended,
                qtr( "Show extended settings" ) );
        widget = extSettingsButton;
        }
        break;
    case PLAYLIST_BUTTON:{
        QToolButton *playlistButton = new QToolButton;
        setupButton( playlistButton );
        CONNECT_MAP_SET( playlistButton, PLAYLIST_ACTION );
        BUTTON_SET_BAR( playlistButton, playlist,
                qtr( "Show playlist" ) );
        widget = playlistButton;
        }
        break;
    case SNAPSHOT_BUTTON:{
        QToolButton *snapshotButton = new QToolButton;
        setupButton( snapshotButton );
        CONNECT_MAP_SET( snapshotButton, SNAPSHOT_ACTION );
        BUTTON_SET_BAR( snapshotButton, snapshot, qtr( "Take a snapshot" ) );
        ENABLE_ON_VIDEO( snapshotButton );
        widget = snapshotButton;
        }
        break;
    case RECORD_BUTTON:{
        QToolButton *recordButton = new QToolButton;
        setupButton( recordButton );
        CONNECT_MAP_SET( recordButton, RECORD_ACTION );
        BUTTON_SET_BAR( recordButton, record, qtr( "Record" ) );
        ENABLE_ON_INPUT( recordButton );
        widget = recordButton;
        }
        break;
    case ATOB_BUTTON: {
        AtoB_Button *ABButton = new AtoB_Button;
        setupButton( ABButton );
        BUTTON_SET_BAR( ABButton, atob_nob, qtr( "Loop from point A to point "
                    "B continuously.\nClick to set point A" ) );
        ENABLE_ON_INPUT( ABButton );
        CONNECT_MAP_SET( ABButton, ATOB_ACTION );
        CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool),
                 ABButton, setIcons( bool, bool ) );
        widget = ABButton;
        }
        break;
    case INPUT_SLIDER: {
        InputSlider *slider = new InputSlider( Qt::Horizontal, NULL );
        /* Update the position when the IM has changed */
        CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
                slider, setPosition( float, int, int ) );
        /* And update the IM, when the position has changed */
        CONNECT( slider, sliderDragged( float ),
                THEMIM->getIM(), sliderUpdate( float ) );
338
        /* *i_size = -1; */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
339 340 341 342 343 344
        widget = slider;
        }
        break;
    case MENU_BUTTONS:
        widget = discFrame();
        widget->hide();
345
        *i_size = 3;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
346 347 348 349
        break;
    case TELETEXT_BUTTONS:
        widget = telexFrame();
        widget->hide();
350
        *i_size = 4;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
351 352 353 354 355
        break;
    case VOLUME:
        {
            SoundWidget *snd = new SoundWidget( p_intf, b_shiny );
            widget = snd;
356 357 358 359 360 361 362
            *i_size = 4;
        }
        break;
    case TIME_LABEL:
        {
            TimeLabel *timeLabel = new TimeLabel( p_intf );
            widget = timeLabel;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
363 364
        }
        break;
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
    case SPLITTER:
        {
            QFrame *line = new QFrame;
            line->setFrameShape( QFrame::VLine );
            line->setFrameShadow( QFrame::Raised );
            line->setLineWidth( 0 );
            line->setMidLineWidth( 1 );
            widget = line;
        }
        break;
    case ADVANCED_CONTROLLER:
        {
            advControls = new AdvControlsWidget( p_intf );
            widget = advControls;
            *i_size = advControls->getWidth();
        }
381
        break;
382 383 384 385 386 387 388 389 390
    case REVERSE_BUTTON:{
        QToolButton *reverseButton = new QToolButton;
        setupButton( reverseButton );
        CONNECT_MAP_SET( reverseButton, REVERSE_ACTION );
        BUTTON_SET_BAR( reverseButton, reverse, qtr( "Reverse" ) );
        ENABLE_ON_INPUT( reverseButton );
        widget = reverseButton;
        }
        break;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
391 392 393
    default:
        msg_Warn( p_intf, "This should not happen" );
        break;
394 395
    }

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
396 397
    /* Customize Buttons */
    if( b_flat || b_big )
398
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
399 400
        QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
        if( tmpButton )
401
        {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
402 403 404 405 406 407
            if( b_flat )
                tmpButton->setAutoRaise( b_flat );
            if( b_big )
            {
                tmpButton->setFixedSize( QSize( 32, 32 ) );
                tmpButton->setIconSize( QSize( 26, 26 ) );
408
                *i_size = 2;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
409
            }
410 411
        }
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
412
    return widget;
413 414
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
415
QWidget *AbstractController::discFrame()
416 417
{
    /** Disc and Menus handling */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
418
    QWidget *discFrame = new QWidget( this );
419 420

    QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
421
    discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
422

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
423 424 425 426
    QToolButton *prevSectionButton = new QToolButton( discFrame );
    setupButton( prevSectionButton );
    BUTTON_SET_BAR( prevSectionButton, dvd_prev,
            qtr("Previous Chapter/Title" ) );
427 428
    discLayout->addWidget( prevSectionButton );

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
429 430
    QToolButton *menuButton = new QToolButton( discFrame );
    setupButton( menuButton );
431
    discLayout->addWidget( menuButton );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
432
    BUTTON_SET_BAR( menuButton, dvd_menu, qtr( "Menu" ) );
433

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
434 435
    QToolButton *nextSectionButton = new QToolButton( discFrame );
    setupButton( nextSectionButton );
436
    discLayout->addWidget( nextSectionButton );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
437 438
    BUTTON_SET_BAR( nextSectionButton, dvd_next,
            qtr("Next Chapter/Title" ) );
439 440


Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
441 442 443 444 445 446
    /* Change the navigation button display when the IM
       navigation changes */
    CONNECT( THEMIM->getIM(), titleChanged( bool ),
            discFrame, setVisible( bool ) );
    CONNECT( THEMIM->getIM(), chapterChanged( bool ),
            menuButton, setVisible( bool ) );
447 448
    /* Changes the IM navigation when triggered on the nav buttons */
    CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
449
            sectionPrev() );
450
    CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
451
            sectionNext() );
452
    CONNECT( menuButton, clicked(), THEMIM->getIM(),
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
453 454 455 456
            sectionMenu() );

    return discFrame;
}
457

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
458 459
QWidget *AbstractController::telexFrame()
{
460 461 462
    /**
     * Telextext QFrame
     **/
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
463
    TeletextController *telexFrame = new TeletextController;
464
    QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
465 466 467 468 469 470 471 472 473
    telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
    CONNECT( THEMIM->getIM(), teletextPossible( bool ),
             telexFrame, setVisible( bool ) );

    /* On/Off button */
    QToolButton *telexOn = new QToolButton;
    telexFrame->telexOn = telexOn;
    setupButton( telexOn );
    BUTTON_SET_BAR( telexOn, tv, qtr( "Teletext Activation" ) );
474 475
    telexLayout->addWidget( telexOn );

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
476 477 478 479 480 481 482 483 484 485 486 487 488 489
    /* Teletext Activation and set */
    CONNECT( telexOn, clicked( bool ),
             THEMIM->getIM(), activateTeletext( bool ) );
    CONNECT( THEMIM->getIM(), teletextActivated( bool ),
             telexFrame, enableTeletextButtons( bool ) );


    /* Transparency button */
    QToolButton *telexTransparent = new QToolButton;
    telexFrame->telexTransparent = telexTransparent;
    setupButton( telexTransparent );
    BUTTON_SET_BAR( telexTransparent, tvtelx,
            qtr( "Toggle Transparency " ) );
    telexTransparent->setEnabled( false );
490 491
    telexLayout->addWidget( telexTransparent );

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
492 493 494 495 496 497 498 499 500 501
    /* Transparency change and set */
    CONNECT( telexTransparent, clicked( bool ),
            THEMIM->getIM(), telexSetTransparency( bool ) );
    CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
            telexFrame, toggleTeletextTransparency( bool ) );


    /* Page setting */
    QSpinBox *telexPage = new QSpinBox;
    telexFrame->telexPage = telexPage;
502 503 504 505 506 507 508
    telexPage->setRange( 0, 999 );
    telexPage->setValue( 100 );
    telexPage->setAccelerated( true );
    telexPage->setWrapping( true );
    telexPage->setAlignment( Qt::AlignRight );
    telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
    telexPage->setEnabled( false );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
509
    telexLayout->addWidget( telexPage );
510

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
511 512 513 514 515
    /* Page change and set */
    CONNECT( telexPage, valueChanged( int ),
            THEMIM->getIM(), telexSetPage( int ) );
    CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
            telexPage, setValue( int ) );
516

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
517 518 519 520
    return telexFrame;
}
#undef CONNECT_MAP
#undef SET_MAPPING
521
#undef CONNECT_MAP_SET
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
522
#undef BUTTON_SET_BAR
523 524
#undef ENABLE_ON_VIDEO
#undef ENABLE_ON_INPUT
525

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
526 527 528 529 530 531
SoundWidget::SoundWidget( intf_thread_t * _p_intf, bool b_shiny )
                         : b_my_volume( false )
{
    p_intf = _p_intf;
    QHBoxLayout *layout = new QHBoxLayout( this );
    layout->setSpacing( 0 ); layout->setMargin( 0 );
532 533 534 535 536
    hVolLabel = new VolumeClickHandler( p_intf, this );

    volMuteLabel = new QLabel;
    volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
    volMuteLabel->installEventFilter( hVolLabel );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
537
    layout->addWidget( volMuteLabel );
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553

    if( b_shiny )
    {
        volumeSlider = new SoundSlider( this,
            config_GetInt( p_intf, "volume-step" ),
            config_GetInt( p_intf, "qt-volume-complete" ),
            config_GetPsz( p_intf, "qt-slider-colours" ) );
    }
    else
    {
        volumeSlider = new QSlider( this );
        volumeSlider->setOrientation( Qt::Horizontal );
    }
    volumeSlider->setMaximumSize( QSize( 200, 40 ) );
    volumeSlider->setMinimumSize( QSize( 85, 30 ) );
    volumeSlider->setFocusPolicy( Qt::NoFocus );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
554
    layout->addWidget( volumeSlider );
555 556 557 558 559 560 561 562 563 564 565 566 567

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

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

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

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
568
void SoundWidget::updateVolume( int i_sliderVolume )
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
{
    if( !b_my_volume )
    {
        int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
        aout_VolumeSet( p_intf, i_res );
    }
    if( i_sliderVolume == 0 )
    {
        volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
        volMuteLabel->setToolTip( qtr( "Unmute" ) );
        return;
    }

    if( i_sliderVolume < VOLUME_MAX / 3 )
        volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
    else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
        volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
    else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
    volMuteLabel->setToolTip( qtr( "Mute" ) );
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
590
void SoundWidget::updateVolume()
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
{
    /* Audio part */
    audio_volume_t i_volume;
    aout_VolumeGet( p_intf, &i_volume );
    i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
    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;
    }
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
606
void TeletextController::toggleTeletextTransparency( bool b_transparent )
607
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
    telexTransparent->setIcon( b_transparent ? QIcon( ":/tvtelx" )
                                             : QIcon( ":/tvtelx-trans" ) );
}

void TeletextController::enableTeletextButtons( bool b_enabled )
{
    telexOn->setChecked( b_enabled );
    telexTransparent->setEnabled( b_enabled );
    telexPage->setEnabled( b_enabled );
}

void PlayButton::updateButton( bool b_playing )
{
    setIcon( b_playing ? QIcon( ":/pause_b" ) : QIcon( ":/play_b" ) );
    setToolTip( b_playing ? qtr( "Pause the playback" )
                          : qtr( I_PLAY_TOOLTIP ) );
624 625
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
626
void AtoB_Button::setIcons( bool timeA, bool timeB )
627
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
628
    if( !timeA && !timeB)
629
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
630 631 632
        setIcon( QIcon( ":/atob_nob" ) );
        setToolTip( qtr( "Loop from point A to point B continuously\n"
                         "Click to set point A" ) );
633
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
634
    else if( timeA && !timeB )
635
    {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
636 637
        setIcon( QIcon( ":/atob_noa" ) );
        setToolTip( qtr( "Click to set point B" ) );
638
    }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
    else if( timeA && timeB )
    {
        setIcon( QIcon( ":/atob" ) );
        setToolTip( qtr( "Stop the A to B loop" ) );
    }
}


//* Actions */
void AbstractController::doAction( int id_action )
{
    switch( id_action )
    {
        case PLAY_ACTION:
            play(); break;
        case PREVIOUS_ACTION:
            prev(); break;
        case NEXT_ACTION:
            next(); break;
        case STOP_ACTION:
            stop(); break;
        case SLOWER_ACTION:
            slower(); break;
        case FASTER_ACTION:
            faster(); break;
        case FULLSCREEN_ACTION:
            fullscreen(); break;
        case EXTENDED_ACTION:
            extSettings(); break;
        case PLAYLIST_ACTION:
            playlist(); break;
        case SNAPSHOT_ACTION:
            snapshot(); break;
        case RECORD_ACTION:
            record(); break;
        case ATOB_ACTION:
            THEMIM->getIM()->setAtoB(); break;
676 677
        case FRAME_ACTION:
            frame(); break;
678 679
        case REVERSE_ACTION:
            reverse(); break;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
        default:
            msg_Dbg( p_intf, "Action: %i", id_action );
            break;
    }
}

void AbstractController::stop()
{
    THEMIM->stop();
}

void AbstractController::play()
{
    if( THEPL->current.i_size == 0 )
    {
        /* The playlist is empty, open a file requester */
        THEDP->openFileDialog();
        return;
    }
    THEMIM->togglePlayPause();
}

void AbstractController::prev()
{
    THEMIM->prev();
}

void AbstractController::next()
{
    THEMIM->next();
710 711 712
}

/**
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
713
  * TODO
714 715 716 717
 * This functions toggle the fullscreen mode
 * If there is no video, it should first activate Visualisations...
 *  This has also to be fixed in enableVideo()
 */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
718
void AbstractController::fullscreen()
719 720
{
    vout_thread_t *p_vout =
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
721
      (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
722 723 724 725 726 727 728
    if( p_vout)
    {
        var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
        vlc_object_release( p_vout );
    }
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
729 730 731 732 733 734 735 736 737 738 739 740
void AbstractController::snapshot()
{
    vout_thread_t *p_vout =
      (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
    if( p_vout )
    {
        vout_Control( p_vout, VOUT_SNAPSHOT );
        vlc_object_release( p_vout );
    }
}

void AbstractController::extSettings()
741 742 743 744
{
    THEDP->extendedDialog();
}

745 746 747 748 749
void AbstractController::reverse()
{
    THEMIM->getIM()->reverse();
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
750
void AbstractController::slower()
751 752 753 754
{
    THEMIM->getIM()->slower();
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
755
void AbstractController::faster()
756 757 758 759
{
    THEMIM->getIM()->faster();
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
760
void AbstractController::playlist()
761
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
762 763
    if( p_intf->p_sys->p_mi ) p_intf->p_sys->p_mi->togglePlaylist();
}
764

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
void AbstractController::record()
{
    input_thread_t *p_input = THEMIM->getInput();
    if( p_input )
    {
        /* This method won't work fine if the stream can't be cut anywhere */
        const bool b_recording = var_GetBool( p_input, "record" );
        var_SetBool( p_input, "record", !b_recording );
#if 0
        else
        {
            /* 'record' access-filter is not loaded, we open Save dialog */
            input_item_t *p_item = input_GetItem( p_input );
            if( !p_item )
                return;

            char *psz = input_item_GetURI( p_item );
            if( psz )
                THEDP->streamingDialog( NULL, psz, true );
        }
#endif
    }
787 788
}

789 790 791 792 793 794
void AbstractController::frame()
{
    input_thread_t *p_input = THEMIM->getInput();
    if( p_input )
        var_SetVoid( p_input, "frame-next" );
}
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
795 796 797 798 799 800 801

/*****************************
 * DA Control Widget !
 *****************************/
ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
                                bool b_advControls ) :
                                AbstractController( _p_i )
802
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
803 804 805 806
    setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );

    /* advanced Controls handling */
    b_advancedVisible = b_advControls;
807
    advControls = NULL;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
808 809

    controlLayout->setSpacing( 0 );
810
    controlLayout->setLayoutMargins( 6, 4, 6, 2, 5 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
811

812 813 814
    QString line1 = getSettings()->value( "MainWindow/Controls2",
            "18;19;25" ).toString();
    parseAndCreateLine( line1, 0 );
815

816 817 818 819 820 821 822
/*    QString line2 = QString( "%1-2;%2;%3;%4;%5;%6;%6;%7;%8;%9;%6;%10;%11-4")
        .arg( PLAY_BUTTON )         .arg( WIDGET_SPACER )
        .arg( PREVIOUS_BUTTON )         .arg( STOP_BUTTON )
        .arg( NEXT_BUTTON )        .arg( WIDGET_SPACER )
        .arg( FULLSCREEN_BUTTON )        .arg( PLAYLIST_BUTTON )
        .arg( EXTENDED_BUTTON )        .arg( WIDGET_SPACER_EXTEND )
        .arg( VOLUME ); */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
823

824 825 826
    QString line2 = getSettings()->value( "MainWindow/Controls2",
            "0-2;21;21;4;2;5;21;21;8;11;10;21;22;20-4" ).toString();
    parseAndCreateLine( line2, 1 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
827

828
    if( !b_advancedVisible && advControls ) advControls->hide();
829 830
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
831 832 833
ControlsWidget::~ControlsWidget()
{}

834 835
void ControlsWidget::toggleAdvanced()
{
836 837 838
    if( !advControls ) return;

    if( !b_advancedVisible )
839 840 841 842 843 844 845 846 847 848 849 850
    {
        advControls->show();
        b_advancedVisible = true;
    }
    else
    {
        advControls->hide();
        b_advancedVisible = false;
    }
    emit advancedControlsToggled( b_advancedVisible );
}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
851 852 853 854 855 856
AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
                                     AbstractController( _p_i )
{
    controlLayout->setMargin( 0 );
    controlLayout->setSpacing( 0 );

857 858 859 860
    /* QString line = QString( "%1;%2;%3").arg( RECORD_BUTTON )
        .arg( SNAPSHOT_BUTTON )
        .arg( ATOB_BUTTON )
        .arg( FRAME_BUTTON ); */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
861

862 863 864 865
    QString line = getSettings()->value( "MainWindow/AdvControl",
            "12;13;14;15" ).toString();
    parseAndCreateLine( line, 0 );
}
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
866

867 868 869 870 871
InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i ) :
                                     AbstractController( _p_i )
{
    controlLayout->setMargin( 0 );
    controlLayout->setSpacing( 0 );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
872

873 874 875 876 877 878 879 880
    /*    QString line = QString( "%1-%2;%3;%4-%2")
        .arg( SLOWER_BUTTON ).arg( WIDGET_FLAT )
        .arg( INPUT_SLIDER )
        .arg( FASTER_BUTTON ); */
    QString line = getSettings()->value( "MainWindow/InputControl",
                   "6-1;16;7-1" ).toString();
    parseAndCreateLine( line, 0 );
}
881 882 883
/**********************************************************************
 * Fullscrenn control widget
 **********************************************************************/
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
884 885
FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i )
                           : AbstractController( _p_i )
886
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
887 888 889
    i_mouse_last_x      = -1;
    i_mouse_last_y      = -1;
    b_mouse_over        = false;
890 891
    i_mouse_last_move_x = -1;
    i_mouse_last_move_y = -1;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
892 893 894 895 896 897 898
#if HAVE_TRANSPARENCY
    b_slow_hide_begin   = false;
    i_slow_hide_timeout = 1;
#endif
    b_fullscreen        = false;
    i_hide_timeout      = 1;
    p_vout              = NULL;
899
    i_screennumber      = -1;
900 901 902 903 904 905 906 907

    setWindowFlags( Qt::ToolTip );
    setMinimumWidth( 600 );

    setFrameShape( QFrame::StyledPanel );
    setFrameStyle( QFrame::Sunken );
    setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
908
    controlLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
909 910

    /* First line */
911 912
    InputControlsWidget *inputC = new InputControlsWidget( p_intf );
    controlLayout->addWidget( inputC, 0, 0, 1, -1 );
913 914

    /* Second line */
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
    /* QString line2 = QString( "%1-2;%2;%3;%4;%5;%2;%6;%2;%7;%2;%8;%9;%10-4")
        .arg( PLAY_BUTTON )
        .arg( WIDGET_SPACER )
        .arg( PREVIOUS_BUTTON )
        .arg( STOP_BUTTON )
        .arg( NEXT_BUTTON )
        .arg( MENU_BUTTONS )
        .arg( TELETEXT_BUTTONS )
        .arg( DEFULLSCREEN_BUTTON )
        .arg( WIDGET_SPACER_EXTEND )
        .arg( TIME_LABEL )
        .arg( VOLUME ); */

    QString line = getSettings()->value( "MainWindow/FSCline",
            "0-2;21;4;2;5;21;18;21;19;21;9;22;23-4" ).toString();
    parseAndCreateLine( line, 1 );
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956

    /* hiding timer */
    p_hideTimer = new QTimer( this );
    CONNECT( p_hideTimer, timeout(), this, hideFSC() );
    p_hideTimer->setSingleShot( true );

    /* slow hiding timer */
#if HAVE_TRANSPARENCY
    p_slowHideTimer = new QTimer( this );
    CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
#endif

    adjustSize ();  /* need to get real width and height for moving */

#ifdef WIN32TRICK
    setWindowOpacity( 0.0 );
    b_fscHidden = true;
    adjustSize();
    show();
#endif

    vlc_mutex_init_recursive( &lock );
}

FullscreenControllerWidget::~FullscreenControllerWidget()
{
957
    getSettings()->setValue( "FullScreen/pos", pos() );
958 959 960 961 962 963 964 965 966 967
    detachVout();
    vlc_mutex_destroy( &lock );
}

/**
 * Show fullscreen controller
 */
void FullscreenControllerWidget::showFSC()
{
    adjustSize();
968 969
    /* center down */
    int number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
970
    if( number != i_screennumber )
971
    {
972 973 974
        msg_Dbg( p_intf, "Calculation fullscreen controllers center");
        /* screen has changed, calculate new position */
        QRect screenRes = QApplication::desktop()->screenGeometry(number);
975 976
        QPoint pos = QPoint( screenRes.x() + (screenRes.width() / 2) - (width() / 2),
                             screenRes.y() + screenRes.height() - height());
977
        move( pos );
978
        i_screennumber = number;
979
    }
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
#ifdef WIN32TRICK
    // after quiting and going to fs, we need to call show()
    if( isHidden() )
        show();
    if( b_fscHidden )
    {
        b_fscHidden = false;
        setWindowOpacity( 1.0 );
    }
#else
    show();
#endif

#if HAVE_TRANSPARENCY
    setWindowOpacity( DEFAULT_OPACITY );
#endif
}

/**
 * Hide fullscreen controller
 * FIXME: under windows it have to be done by moving out of screen
 *        because hide() doesnt work
 */
void FullscreenControllerWidget::hideFSC()
{
#ifdef WIN32TRICK
    b_fscHidden = true;
    setWindowOpacity( 0.0 );    // simulate hidding
#else
    hide();
#endif
}

/**
 * Plane to hide fullscreen controller
 */
void FullscreenControllerWidget::planHideFSC()
{
    vlc_mutex_lock( &lock );
    int i_timeout = i_hide_timeout;
    vlc_mutex_unlock( &lock );

    p_hideTimer->start( i_timeout );

#if HAVE_TRANSPARENCY
    b_slow_hide_begin = true;
    i_slow_hide_timeout = i_timeout;
    p_slowHideTimer->start( i_slow_hide_timeout / 2 );
#endif
}

/**
 * Hidding fullscreen controller slowly
 * Linux: need composite manager
 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
 */
void FullscreenControllerWidget::slowHideFSC()
{
#if HAVE_TRANSPARENCY
    if( b_slow_hide_begin )
    {
        b_slow_hide_begin = false;

        p_slowHideTimer->stop();
        /* the last part of time divided to 100 pieces */
        p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );

    }
    else
    {
#ifdef WIN32TRICK
         if ( windowOpacity() > 0.0 && !b_fscHidden )
#else
         if ( windowOpacity() > 0.0 )
#endif
         {
             /* we should use 0.01 because of 100 pieces ^^^
                but than it cannt be done in time */
             setWindowOpacity( windowOpacity() - 0.02 );
         }

         if ( windowOpacity() <= 0.0 )
             p_slowHideTimer->stop();
    }
#endif
}

/**
 * event handling
 * events: show, hide, start timer for hidding
 */
void FullscreenControllerWidget::customEvent( QEvent *event )
{
    bool b_fs;

    switch( event->type() )
    {
        case FullscreenControlToggle_Type:
            vlc_mutex_lock( &lock );
            b_fs = b_fullscreen;
            vlc_mutex_unlock( &lock );
            if( b_fs )
#ifdef WIN32TRICK
                if( b_fscHidden )
#else
                if( isHidden() )
#endif
                {
                    p_hideTimer->stop();
                    showFSC();
                }
                else
                    hideFSC();
            break;
        case FullscreenControlShow_Type:
            vlc_mutex_lock( &lock );
            b_fs = b_fullscreen;
            vlc_mutex_unlock( &lock );

#ifdef WIN32TRICK
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
1100
            if( b_fs && b_fscHidden )
1101
#else
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
1102
            if( b_fs && !isVisible() )
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
#endif
                showFSC();
            break;
        case FullscreenControlHide_Type:
            hideFSC();
            break;
        case FullscreenControlPlanHide_Type:
            if( !b_mouse_over ) // Only if the mouse is not over FSC
                planHideFSC();
            break;
    }
}

/**
 * On mouse move
 * moving with FSC
 */
void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
{
    if ( event->buttons() == Qt::LeftButton )
    {
        int i_moveX = event->globalX() - i_mouse_last_x;
        int i_moveY = event->globalY() - i_mouse_last_y;

        move( x() + i_moveX, y() + i_moveY );

        i_mouse_last_x = event->globalX();
        i_mouse_last_y = event->globalY();
    }
}

/**
 * On mouse press
 * store position of cursor
 */
void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
{
    i_mouse_last_x = event->globalX();
    i_mouse_last_y = event->globalY();
}

/**
 * On mouse go above FSC
 */
void FullscreenControllerWidget::enterEvent( QEvent *event )
{
    b_mouse_over = true;

    p_hideTimer->stop();
#if HAVE_TRANSPARENCY
    p_slowHideTimer->stop();
#endif
}

/**
 * On mouse go out from FSC
 */
void FullscreenControllerWidget::leaveEvent( QEvent *event )
{
    planHideFSC();

    b_mouse_over = false;
}

/**
 * When you get pressed key, send it to video output
 * FIXME: clearing focus by clearFocus() to not getting
 * key press events didnt work
 */
void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
{
    int i_vlck = qtEventToVLCKey( event );
    if( i_vlck > 0 )
    {
        var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
        event->accept();
    }
    else
        event->ignore();
}

/* */
static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
                const char *variable, vlc_value_t old_val,
                vlc_value_t new_val,  void *data )
{
    vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
    msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
    FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;

    p_fs->fullscreenChanged( p_vout, new_val.b_bool,
            var_GetInteger( p_vout, "mouse-hide-timeout" ) );

    return VLC_SUCCESS;
}
/* */
static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
                                                 vlc_value_t old_val, vlc_value_t new_val,
                                                 void *data )
{
    FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;

    int i_mousex, i_mousey;
    bool b_toShow = false;

    /* Get the value from the Vout - Trust the vout more than Qt */
    i_mousex = var_GetInteger( p_fs->p_vout, "mouse-x" );
    i_mousey = var_GetInteger( p_fs->p_vout, "mouse-y" );

    /* First time */
    if( p_fs->i_mouse_last_move_x == -1 || p_fs->i_mouse_last_move_y == -1 )
    {
        p_fs->i_mouse_last_move_x = i_mousex;
        p_fs->i_mouse_last_move_y = i_mousey;
        b_toShow = true;
    }
    /* All other times */
    else
    {
        /* Trigger only if move > 3 px dans une direction */
        if( abs( p_fs->i_mouse_last_move_x - i_mousex ) > 2 ||
            abs( p_fs->i_mouse_last_move_y - i_mousey ) > 2 )
        {
            b_toShow = true;
            p_fs->i_mouse_last_move_x = i_mousex;
            p_fs->i_mouse_last_move_y = i_mousey;
        }
    }

    if( b_toShow )
    {
        /* Show event */
        IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
        QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );

        /* Plan hide event */
        IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
        QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
    }

    return VLC_SUCCESS;
}

/**
 * It is called when video start
 */
void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
{
    assert( p_nvout && !p_vout );

    p_vout = p_nvout;

    msg_Dbg( p_vout, "Qt FS: Attaching Vout" );
    vlc_mutex_lock( &lock );

    var_AddCallback( p_vout, "fullscreen",
            FullscreenControllerWidgetFullscreenChanged, this );
            /* I miss a add and fire */
    fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
                       var_GetInteger( p_vout, "mouse-hide-timeout" ) );
    vlc_mutex_unlock( &lock );
}
1265

1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
/**
 * It is called after turn off video.
 */
void FullscreenControllerWidget::detachVout()
{
    if( p_vout )
    {
        msg_Dbg( p_vout, "Qt FS: Detaching Vout" );
        var_DelCallback( p_vout, "fullscreen",
                FullscreenControllerWidgetFullscreenChanged, this );
        vlc_mutex_lock( &lock );
        fullscreenChanged( p_vout, false, 0 );
        vlc_mutex_unlock( &lock );
        p_vout = NULL;
    }
}

/**
 * Register and unregister callback for mouse moving
 */
void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
        bool b_fs, int i_timeout )
{
    msg_Dbg( p_vout, "Qt: Entering Fullscreen" );

    vlc_mutex_lock( &lock );
    /* Entering fullscreen, register callback */
    if( b_fs && !b_fullscreen )
    {
        b_fullscreen = true;
        i_hide_timeout = i_timeout;
        var_AddCallback( p_vout, "mouse-moved",
                FullscreenControllerWidgetMouseMoved, this );
    }
    /* Quitting fullscreen, unregistering callback */
    else if( !b_fs && b_fullscreen )
    {
        b_fullscreen = false;
        i_hide_timeout = i_timeout;
        var_DelCallback( p_vout, "mouse-moved",
                FullscreenControllerWidgetMouseMoved, this );

        /* Force fs hidding */
        IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
        QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
    }
    vlc_mutex_unlock( &lock );
}