⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interface_widgets.cpp

📁 VLC Player Source Code
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/***************************************************************************** * interface_widgets.cpp : Custom widgets for the main interface **************************************************************************** * Copyright ( C ) 2006 the VideoLAN team * $Id: 777da1627ca9135518d195acbe0424a4822facb2 $ * * 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>#include <QPushButton>#include <QToolButton>#include <QHBoxLayout>#include <QMenu>#include <QPalette>#include <QResizeEvent>#include <QDate>#ifdef Q_WS_X11# include <X11/Xlib.h># include <qx11info_x11.h>#endif#include <math.h>#define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media")/********************************************************************** * Video Widget. A simple frame on which video is drawn * This class handles resize issues **********************************************************************/VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i ){    /* Init */    i_vout = 0;    videoSize.rwidth() = -1;    videoSize.rheight() = -1;    hide();    /* Set the policy to expand in both directions *///    setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );    /* Black background is more coherent for a Video Widget */    QPalette plt =  palette();    plt.setColor( QPalette::Window, Qt::black );    setPalette( plt );    setAutoFillBackground(true);    /* Indicates that the widget wants to draw directly onto the screen.       Widgets with this attribute set do not participate in composition       management */    setAttribute( Qt::WA_PaintOnScreen, true );    /* The core can ask through a callback to show the video. */#if HAS_QT43    connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),             this, SLOT(SetSizing(unsigned int, unsigned int )),             Qt::BlockingQueuedConnection );#else#warning This is broken. Fix it with a QEventLoop with a processEvents ()    connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),             this, SLOT(SetSizing(unsigned int, unsigned int )) );#endif}void VideoWidget::paintEvent(QPaintEvent *ev){    QFrame::paintEvent(ev);#ifdef Q_WS_X11    XFlush( QX11Info::display() );#endif}/* Kill the vout at Destruction */VideoWidget::~VideoWidget(){    vout_thread_t *p_vout = i_vout ?        (vout_thread_t *)vlc_object_get( i_vout ) : NULL;    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_object_release( p_vout );    }}/** * Request the video to avoid the conflicts **/void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,                            unsigned int *pi_width, unsigned int *pi_height ){    msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );    emit askVideoWidgetToShow( *pi_width, *pi_height );    if( i_vout )    {        msg_Dbg( p_intf, "embedded video already in use" );        return NULL;    }    i_vout = p_nvout->i_object_id;#ifndef NDEBUG    msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );#endif    return ( void* )winId();}/* Set the Widget to the correct Size *//* Function has to be called by the parent   Parent has to care about resizing himself*/void VideoWidget::SetSizing( unsigned int w, unsigned int h ){    msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );    videoSize.rwidth() = w;    videoSize.rheight() = h;    if( isHidden() ) show();    updateGeometry(); // Needed for deinterlace}void VideoWidget::release( void *p_win ){    msg_Dbg( p_intf, "Video is not needed anymore" );    i_vout = 0;    videoSize.rwidth() = 0;    videoSize.rheight() = 0;    updateGeometry();    hide();}QSize VideoWidget::sizeHint() const{    return videoSize;}/********************************************************************** * Background Widget. Show a simple image background. Currently, * it's album art if present or cone. **********************************************************************/#define ICON_SIZE 128#define MAX_BG_SIZE 400#define MIN_BG_SIZE 128BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )                 :QWidget( NULL ), p_intf( _p_i ){    /* We should use that one to take the more size it can */    setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);    /* A dark background */    setAutoFillBackground( true );    plt = palette();    plt.setColor( QPalette::Active, QPalette::Window , Qt::black );    plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );    setPalette( plt );    /* A cone in the middle */    label = new QLabel;    label->setMargin( 5 );    label->setMaximumHeight( MAX_BG_SIZE );    label->setMaximumWidth( MAX_BG_SIZE );    label->setMinimumHeight( MIN_BG_SIZE );    label->setMinimumWidth( MIN_BG_SIZE );    if( QDate::currentDate().dayOfYear() >= 354 )        label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );    else        label->setPixmap( QPixmap( ":/vlc128.png" ) );    QGridLayout *backgroundLayout = new QGridLayout( this );    backgroundLayout->addWidget( label, 0, 1 );    backgroundLayout->setColumnStretch( 0, 1 );    backgroundLayout->setColumnStretch( 2, 1 );    CONNECT( THEMIM->getIM(), artChanged( input_item_t* ),             this, updateArt( input_item_t* ) );}BackgroundWidget::~BackgroundWidget(){}void BackgroundWidget::resizeEvent( QResizeEvent * event ){    if( event->size().height() <= MIN_BG_SIZE )        label->hide();    else        label->show();}void BackgroundWidget::updateArt( input_item_t *p_item ){    QString url;    if( p_item )    {        char *psz_art = input_item_GetArtURL( p_item );        url = psz_art;        free( psz_art );    }    if( url.isEmpty() )    {        if( QDate::currentDate().dayOfYear() >= 354 )            label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );        else            label->setPixmap( QPixmap( ":/vlc128.png" ) );    }    else    {        url = url.replace( "file://", QString("" ) );        /* Taglib seems to define a attachment://, It won't work yet */        url = url.replace( "attachment://", QString("" ) );        label->setPixmap( QPixmap( url ) );    }}void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event ){    QVLCMenu::PopupMenu( p_intf, true );}#if 0/********************************************************************** * Visualization selector panel **********************************************************************/VisualSelector::VisualSelector( intf_thread_t *_p_i ) :                                QFrame( NULL ), p_intf( _p_i ){    QHBoxLayout *layout = new QHBoxLayout( this );    layout->setMargin( 0 );    QPushButton *prevButton = new QPushButton( "Prev" );    QPushButton *nextButton = new QPushButton( "Next" );    layout->addWidget( prevButton );    layout->addWidget( nextButton );    layout->addStretch( 10 );    layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );    current = new QLabel( qtr( "None" ) );    layout->addWidget( current );    BUTTONACT( prevButton, prev() );    BUTTONACT( nextButton, next() );    setLayout( layout );    setMaximumHeight( 35 );}VisualSelector::~VisualSelector(){}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 );    }}#endif/********************************************************************** * TEH controls **********************************************************************/#define setupSmallButton( aButton ){  \    aButton->setMaximumSize( QSize( 26, 26 ) ); \    aButton->setMinimumSize( QSize( 26, 26 ) ); \    aButton->setIconSize( QSize( 20, 20 ) ); }/* init static variables in advanced controls */mtime_t AdvControlsWidget::timeA = 0;mtime_t AdvControlsWidget::timeB = 0;AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, bool b_fsCreation = false ) :                                           QFrame( NULL ), p_intf( _p_i ){    QHBoxLayout *advLayout = new QHBoxLayout( this );    advLayout->setMargin( 0 );    advLayout->setSpacing( 0 );    advLayout->setAlignment( Qt::AlignBottom );    /* A to B Button */    ABButton = new QPushButton;    setupSmallButton( ABButton );    advLayout->addWidget( ABButton );    BUTTON_SET_ACT_I( ABButton, "", atob_nob,      qtr( "Loop from point A to point B continuously.\nClick to set point A" ),      fromAtoB() );    timeA = timeB = 0;    i_last_input_id = 0;    /* in FS controller we skip this, because we dont want to have it double       controlled */    if( !b_fsCreation )        CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),                 this, AtoBLoop( float, int, int ) );    /* set up synchronization between main controller and fs controller */    CONNECT( THEMIM->getIM(), advControlsSetIcon(), this, setIcon() );    connect( this, SIGNAL( timeChanged() ),        THEMIM->getIM(), SIGNAL( advControlsSetIcon()));#if 0    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() );#endif    /* Record Button */    recordButton = new QPushButton;    setupSmallButton( recordButton );    advLayout->addWidget( recordButton );    BUTTON_SET_ACT_I( recordButton, "", record,            qtr( "Record" ), record() );    /* Snapshot Button */    snapshotButton = new QPushButton;    setupSmallButton( snapshotButton );    advLayout->addWidget( snapshotButton );    BUTTON_SET_ACT_I( snapshotButton, "", snapshot,            qtr( "Take a snapshot" ), snapshot() );}AdvControlsWidget::~AdvControlsWidget(){}void AdvControlsWidget::enableInput( bool enable ){    int i_input_id = 0;    if( THEMIM->getInput() != NULL )    {        input_item_t *p_item = input_GetItem( THEMIM->getInput() );        i_input_id = p_item->i_id;        if( var_Type( THEMIM->getInput(), "record-toggle" ) == VLC_VAR_VOID )            recordButton->setVisible( true );        else            recordButton->setVisible( false );    }    else        recordButton->setVisible( false );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -