~siretart/vlc/ubuntu

« back to all changes in this revision

Viewing changes to modules/gui/qt4/components/interface_widgets.cpp

  • Committer: Reinhard Tartler
  • Date: 2008-09-26 06:45:40 UTC
  • mto: (21.2.1 vlc-0.9.3)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: siretart@tauware.de-20080926064540-0sd8zwmig33ksmy4
Tags: upstream-ubuntu-0.9.3
Import upstream version 0.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * interface_widgets.cpp : Custom widgets for the main interface
3
3
 ****************************************************************************
4
4
 * Copyright ( C ) 2006 the VideoLAN team
5
 
 * $Id: 777da1627ca9135518d195acbe0424a4822facb2 $
 
5
 * $Id: fd2430ca23390a13eec8e3ef85ce5e91b04dc60b $
6
6
 *
7
7
 * Authors: Clément Stenac <zorglub@videolan.org>
8
8
 *          Jean-Baptiste Kempf <jb@videolan.org>
317
317
#define setupSmallButton( aButton ){  \
318
318
    aButton->setMaximumSize( QSize( 26, 26 ) ); \
319
319
    aButton->setMinimumSize( QSize( 26, 26 ) ); \
320
 
    aButton->setIconSize( QSize( 20, 20 ) ); }
 
320
    aButton->setIconSize( QSize( 20, 20 ) ); \
 
321
    aButton->setFocusPolicy( Qt::NoFocus ); \
 
322
}
321
323
 
322
324
/* init static variables in advanced controls */
323
325
mtime_t AdvControlsWidget::timeA = 0;
527
529
    slowerButton = new QToolButton;
528
530
    slowerButton->setAutoRaise( true );
529
531
    slowerButton->setMaximumSize( QSize( 26, 20 ) );
 
532
    slowerButton->setFocusPolicy( Qt::NoFocus );
530
533
 
531
 
    BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
 
534
    BUTTON_SET_ACT_I( slowerButton, "", slower, qtr( "Slower" ), slower() );
532
535
 
533
536
    fasterButton = new QToolButton;
534
537
    fasterButton->setAutoRaise( true );
535
538
    fasterButton->setMaximumSize( QSize( 26, 20 ) );
 
539
    fasterButton->setFocusPolicy( Qt::NoFocus );
536
540
 
537
 
    BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
 
541
    BUTTON_SET_ACT_I( fasterButton, "", faster, qtr( "Faster" ), faster() );
538
542
 
539
543
    /* advanced Controls handling */
540
544
    b_advancedVisible = b_advControls;
640
644
    /* Play */
641
645
    playButton = new QPushButton;
642
646
    playButton->setSizePolicy( sizePolicy );
643
 
    playButton->setMaximumSize( QSize( 36, 36 ) );
644
 
    playButton->setMinimumSize( QSize( 36, 36 ) );
645
 
    playButton->setIconSize( QSize( 30, 30 ) );
646
 
 
 
647
    playButton->setMaximumSize( QSize( 32, 32 ) );
 
648
    playButton->setMinimumSize( QSize( 32, 32 ) );
 
649
    playButton->setIconSize( QSize( 26, 26 ) );
 
650
    playButton->setFocusPolicy( Qt::NoFocus );
647
651
 
648
652
    /** Prev + Stop + Next Block **/
649
653
    controlButLayout = new QHBoxLayout;
1017
1021
          b_slow_hide_begin(false), i_slow_hide_timeout(1),
1018
1022
          b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
1019
1023
{
 
1024
    i_mouse_last_move_x = -1;
 
1025
    i_mouse_last_move_y = -1;
 
1026
 
1020
1027
    setWindowFlags( Qt::ToolTip );
 
1028
    setMinimumWidth( 600 );
1021
1029
 
1022
1030
    setFrameShape( QFrame::StyledPanel );
1023
1031
    setFrameStyle( QFrame::Sunken );
1028
1036
 
1029
1037
    /* First line */
1030
1038
    slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1031
 
    slider->setMinimumWidth( 220 );
1032
1039
    fsLayout->addWidget( slowerButton, 0, 0 );
1033
 
    fsLayout->addWidget( slider, 0, 1, 1, 9 );
1034
 
    fsLayout->addWidget( fasterButton, 0, 10 );
 
1040
    fsLayout->addWidget( slider, 0, 1, 1, 11 );
 
1041
    fsLayout->addWidget( fasterButton, 0, 12 );
1035
1042
 
 
1043
    /* Second line */
1036
1044
    fsLayout->addWidget( playButton, 1, 0, 1, 2 );
1037
1045
    fsLayout->addLayout( controlButLayout, 1, 2 );
1038
1046
 
1042
1050
    fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
1043
1051
 
1044
1052
    fsLayout->setColumnStretch( 7, 10 );
1045
 
    fsLayout->addWidget( volMuteLabel, 1, 8 );
1046
 
    fsLayout->addWidget( volumeSlider, 1, 9, 1, 2 );
 
1053
 
 
1054
    TimeLabel *timeLabel = new TimeLabel( p_intf );
 
1055
 
 
1056
    fsLayout->addWidget( timeLabel, 1, 8 );
 
1057
    fsLayout->addWidget( volMuteLabel, 1, 9 );
 
1058
    fsLayout->addWidget( volumeSlider, 1, 10, 1, 2 );
1047
1059
 
1048
1060
    /* hiding timer */
1049
1061
    p_hideTimer = new QTimer( this );
1059
1071
    adjustSize ();  /* need to get real width and height for moving */
1060
1072
 
1061
1073
    /* center down */
1062
 
    QDesktopWidget * p_desktop = QApplication::desktop();
 
1074
    QWidget * p_desktop = QApplication::desktop()->screen(
 
1075
                QApplication::desktop()->screenNumber( _p_mi ) );
1063
1076
 
1064
 
    move( p_desktop->width() / 2 - width() / 2,
 
1077
    QPoint pos = QPoint( p_desktop->width() / 2 - width() / 2,
1065
1078
          p_desktop->height() - height() );
1066
1079
 
 
1080
    getSettings()->beginGroup( "FullScreen" );
 
1081
    move( getSettings()->value( "pos", pos ).toPoint() );
 
1082
    getSettings()->endGroup();
 
1083
 
1067
1084
#ifdef WIN32TRICK
1068
1085
    setWindowOpacity( 0.0 );
1069
1086
    b_fscHidden = true;
1078
1095
 
1079
1096
FullscreenControllerWidget::~FullscreenControllerWidget()
1080
1097
{
 
1098
    getSettings()->beginGroup( "FullScreen" );
 
1099
    getSettings()->setValue( "pos", pos() );
 
1100
    getSettings()->endGroup();
1081
1101
    detachVout();
1082
1102
    vlc_mutex_destroy( &lock );
1083
1103
}
1208
1228
            b_fs = b_fullscreen;
1209
1229
            vlc_mutex_unlock( &lock );
1210
1230
 
1211
 
            if( b_fs )  // FIXME I am not sure about that one
 
1231
#ifdef WIN32TRICK
 
1232
            if( b_fs && b_fscHidden )  // FIXME I am not sure about that one
 
1233
#else
 
1234
            if( b_fs && !isVisible() )  // FIXME I am not sure about that one
 
1235
#endif
1212
1236
                showFSC();
1213
1237
            break;
1214
1238
        case FullscreenControlHide_Type:
1290
1314
}
1291
1315
 
1292
1316
/* */
1293
 
static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1294
 
                                                        vlc_value_t old_val, vlc_value_t new_val,
1295
 
                                                        void *data )
 
1317
static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
 
1318
                const char *variable, vlc_value_t old_val,
 
1319
                vlc_value_t new_val,  void *data )
1296
1320
{
1297
1321
    vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
 
1322
    msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
1298
1323
    FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1299
1324
 
1300
 
    p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
 
1325
    p_fs->fullscreenChanged( p_vout, new_val.b_bool,
 
1326
            var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1301
1327
 
1302
1328
    return VLC_SUCCESS;
1303
1329
}
1308
1334
{
1309
1335
    FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1310
1336
 
1311
 
    /* Show event */
1312
 
    IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1313
 
    QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1314
 
 
1315
 
    /* Plan hide event */
1316
 
    IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1317
 
    QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
 
1337
    int i_mousex, i_mousey;
 
1338
    bool b_toShow = false;
 
1339
 
 
1340
    /* Get the value from the Vout - Trust the vout more than Qt */
 
1341
    i_mousex = var_GetInteger( p_fs->p_vout, "mouse-x" );
 
1342
    i_mousey = var_GetInteger( p_fs->p_vout, "mouse-y" );
 
1343
 
 
1344
    /* First time */
 
1345
    if( p_fs->i_mouse_last_move_x == -1 || p_fs->i_mouse_last_move_y == -1 )
 
1346
    {
 
1347
        p_fs->i_mouse_last_move_x = i_mousex;
 
1348
        p_fs->i_mouse_last_move_y = i_mousey;
 
1349
        b_toShow = true;
 
1350
    }
 
1351
    /* All other times */
 
1352
    else
 
1353
    {
 
1354
        /* Trigger only if move > 3 px dans une direction */
 
1355
        if( abs( p_fs->i_mouse_last_move_x - i_mousex ) > 2 ||
 
1356
            abs( p_fs->i_mouse_last_move_y - i_mousey ) > 2 )
 
1357
        {
 
1358
            b_toShow = true;
 
1359
            p_fs->i_mouse_last_move_x = i_mousex;
 
1360
            p_fs->i_mouse_last_move_y = i_mousey;
 
1361
        }
 
1362
    }
 
1363
 
 
1364
    if( b_toShow )
 
1365
    {
 
1366
        /* Show event */
 
1367
        IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
 
1368
        QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
 
1369
 
 
1370
        /* Plan hide event */
 
1371
        IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
 
1372
        QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
 
1373
    }
1318
1374
 
1319
1375
    return VLC_SUCCESS;
1320
1376
}
1329
1385
 
1330
1386
    p_vout = p_nvout;
1331
1387
 
 
1388
    msg_Dbg( p_vout, "Qt FS: Attaching Vout" );
1332
1389
    vlc_mutex_lock( &lock );
1333
 
    var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1334
 
    fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
 
1390
 
 
1391
    var_AddCallback( p_vout, "fullscreen",
 
1392
            FullscreenControllerWidgetFullscreenChanged, this );
 
1393
            /* I miss a add and fire */
 
1394
    fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
 
1395
                       var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1335
1396
    vlc_mutex_unlock( &lock );
1336
1397
}
1337
1398
/**
1341
1402
{
1342
1403
    if( p_vout )
1343
1404
    {
1344
 
        var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
 
1405
        msg_Dbg( p_vout, "Qt FS: Detaching Vout" );
 
1406
        var_DelCallback( p_vout, "fullscreen",
 
1407
                FullscreenControllerWidgetFullscreenChanged, this );
1345
1408
        vlc_mutex_lock( &lock );
1346
1409
        fullscreenChanged( p_vout, false, 0 );
1347
1410
        vlc_mutex_unlock( &lock );
1352
1415
/**
1353
1416
 * Register and unregister callback for mouse moving
1354
1417
 */
1355
 
void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
 
1418
void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
 
1419
        bool b_fs, int i_timeout )
1356
1420
{
 
1421
    msg_Dbg( p_vout, "Qt: Changing Fullscreen Mode" );
 
1422
 
1357
1423
    vlc_mutex_lock( &lock );
 
1424
    /* Entering fullscreen, register callback */
1358
1425
    if( b_fs && !b_fullscreen )
1359
1426
    {
1360
1427
        b_fullscreen = true;
1361
1428
        i_hide_timeout = i_timeout;
1362
 
        var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
 
1429
        var_AddCallback( p_vout, "mouse-moved",
 
1430
                FullscreenControllerWidgetMouseMoved, this );
1363
1431
    }
 
1432
    /* Quitting fullscreen, unregistering callback */
1364
1433
    else if( !b_fs && b_fullscreen )
1365
1434
    {
1366
1435
        b_fullscreen = false;
1367
1436
        i_hide_timeout = i_timeout;
1368
 
        var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
 
1437
        var_DelCallback( p_vout, "mouse-moved",
 
1438
                FullscreenControllerWidgetMouseMoved, this );
1369
1439
 
1370
1440
        /* Force fs hidding */
1371
1441
        IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1372
1442
        QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
 
1443
#ifdef WIN32
 
1444
        /* This is a big, a huge HACK around the windows Video Output,
 
1445
         Since the Vout fusion the Vout Windows, with the main windows
 
1446
         (very nice indeed for Alt-Tab), at the end of the film, when Vout quits
 
1447
         fullscreen, MI isn't properly put in the good state again...
 
1448
         (hidden still)...
 
1449
         Of course this is not good, but we will have to live with it temporarly
 
1450
         */
 
1451
        p_intf->p_sys->p_mi->hide();
 
1452
        p_intf->p_sys->p_mi->show();
 
1453
#endif
1373
1454
    }
1374
1455
    vlc_mutex_unlock( &lock );
1375
1456
}
1562
1643
    }
1563
1644
}
1564
1645
 
 
1646
TimeLabel::TimeLabel( intf_thread_t *_p_intf  ) :QLabel(), p_intf( _p_intf )
 
1647
{
 
1648
   b_remainingTime = false;
 
1649
   setText( " --:--/--:-- " );
 
1650
   setAlignment( Qt::AlignRight | Qt::AlignVCenter );
 
1651
   setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
 
1652
 
 
1653
 
 
1654
   CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
 
1655
             this, setDisplayPosition( float, int, int ) );
 
1656
}
 
1657
 
 
1658
void TimeLabel::setDisplayPosition( float pos, int time, int length )
 
1659
{
 
1660
    char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
 
1661
    secstotimestr( psz_length, length );
 
1662
    secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
 
1663
                                                           : time );
 
1664
 
 
1665
    QString timestr;
 
1666
    timestr.sprintf( "%s/%s", psz_time,
 
1667
                            ( !length && time ) ? "--:--" : psz_length );
 
1668
 
 
1669
    /* Add a minus to remaining time*/
 
1670
    if( b_remainingTime && length ) setText( " -"+timestr+" " );
 
1671
    else setText( " "+timestr+" " );
 
1672
}
 
1673
 
 
1674
void TimeLabel::toggleTimeDisplay()
 
1675
{
 
1676
    b_remainingTime = !b_remainingTime;
 
1677
}
 
1678
 
 
1679