interface_widgets.cpp 8.64 KB
Newer Older
1
/*****************************************************************************
2
 * interface_widgets.cpp : Custom widgets for the main interface
3
 ****************************************************************************
4 5
 * Copyright (C) 2006 the VideoLAN team
 * $Id$
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * Authors: Clément Stenac <zorglub@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.
 *****************************************************************************/

zorglub's avatar
zorglub committed
24
#include "dialogs_provider.hpp"
25
#include "qt4.hpp"
26
#include "components/interface_widgets.hpp"
27
#include "main_interface.hpp"
28
#include "input_manager.hpp"
29

zorglub's avatar
zorglub committed
30
#include "pixmaps/art.xpm"
31 32
#include <vlc/vout.h>

zorglub's avatar
zorglub committed
33
#include <QCursor>
zorglub's avatar
zorglub committed
34
#include <QPushButton>
35
#include <QHBoxLayout>
zorglub's avatar
zorglub committed
36
#include <QMenu>
37

zorglub's avatar
zorglub committed
38 39
#define ICON_SIZE 128

40 41 42 43
/**********************************************************************
 * Video Widget. A simple frame on which video is drawn
 * This class handles resize issues
 **********************************************************************/
44 45 46 47 48
static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
                        unsigned int *, unsigned int * );
static void DoRelease( intf_thread_t *, void * );
static int DoControl( intf_thread_t *, void *, int, va_list );

49
VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
{
    vlc_mutex_init( p_intf, &lock );
    p_vout = NULL;

    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
}

VideoWidget::~VideoWidget()
{
    vlc_mutex_lock( &lock );
    if( p_vout )
    {
        if( !p_intf->psz_switch_intf )
        {
            if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
                vout_Control( p_vout, VOUT_REPARENT );
        }
        else
        {
            if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
                vout_Control( p_vout, VOUT_CLOSE );
        }
    }
    vlc_mutex_unlock( &lock );
    vlc_mutex_destroy( &lock );
}

QSize VideoWidget::sizeHint() const
{
79
    fprintf( stderr, "Video Size %ix%i\n", widgetSize.width(), widgetSize.height() );
80
    return widgetSize;
81 82
}

83
void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
84 85 86 87 88 89 90 91
                           unsigned int *pi_width, unsigned int *pi_height )
{
    if( p_vout )
    {
        msg_Dbg( p_intf, "embedded video already in use" );
        return NULL;
    }
    p_vout = p_nvout;
92
    setMinimumSize( 1,1 );
93
    return (void*)winId();
94 95
}

96
void VideoWidget::release( void *p_win )
97
{
98
    p_vout = NULL;
99
}
100 101 102 103 104 105 106
/**********************************************************************
 * Background Widget. Show a simple image background. Currently,
 * it's a static cone.
 **********************************************************************/
BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
                                        QFrame( NULL ), p_intf( _p_i )
{
107

zorglub's avatar
zorglub committed
108
    setAutoFillBackground( true );
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    plt =  palette();
    plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
    plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
    setPalette( plt );

    backgroundLayout = new QHBoxLayout;
    label = new QLabel( "" );
    label->setMaximumHeight( ICON_SIZE );
    label->setMaximumWidth( ICON_SIZE );
    label->setScaledContents( true );
    label->setPixmap( QPixmap( ":/vlc128.png" ) );
    backgroundLayout = new QHBoxLayout;
    backgroundLayout->addWidget( label );
    setLayout( backgroundLayout );
}

zorglub's avatar
zorglub committed
125
BackgroundWidget::~BackgroundWidget()
126 127 128 129 130
{
    backgroundLayout->takeAt(0);
    delete backgroundLayout;
}

131 132
QSize BackgroundWidget::sizeHint() const
{
133
    fprintf( stderr, "BG %ix%i\n", widgetSize.width(), widgetSize.height() );
134 135 136
    return widgetSize;
}

137 138 139 140 141 142 143
void BackgroundWidget::resizeEvent( QResizeEvent *e )
{
    if( e->size().height() < ICON_SIZE -1 )
        label->setMaximumWidth( e->size().height() );
    else
        label->setMaximumWidth( ICON_SIZE );
}
144

zorglub's avatar
zorglub committed
145 146 147 148 149 150 151
/**********************************************************************
 * Visualization selector panel
 **********************************************************************/
VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
                                                QFrame( NULL ), p_intf( _p_i )
{
    QHBoxLayout *layout = new QHBoxLayout( this );
152
    layout->setMargin( 0 );
zorglub's avatar
zorglub committed
153 154 155 156 157
    QPushButton *prevButton = new QPushButton( "Prev" );
    QPushButton *nextButton = new QPushButton( "Next");
    layout->addWidget( prevButton );
    layout->addWidget( nextButton );
    setLayout( layout );
158
    setMaximumHeight( 35 );
zorglub's avatar
zorglub committed
159 160 161 162 163 164
}

VisualSelector::~VisualSelector()
{
}

165 166 167 168 169 170 171 172 173
/**********************************************************************
 * Playlist Widget. The embedded playlist
 **********************************************************************/
#include "components/playlist/panels.hpp"
#include "components/playlist/selector.hpp"

PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : QFrame(NULL),
                                                            p_intf( _p_intf )
{
zorglub's avatar
zorglub committed
174 175 176
    QVBoxLayout *left = new QVBoxLayout( );
    QHBoxLayout *middle = new QHBoxLayout;

177 178
    selector = new PLSelector( this, p_intf, THEPL );
    selector->setMaximumWidth( 130 );
zorglub's avatar
zorglub committed
179 180 181 182 183
    left->addWidget( selector );

    QPushButton *undockButton = new QPushButton( "UN", this );
    undockButton->setMaximumWidth( 25 );
    undockButton->setToolTip( qtr( "Undock playlist for main interface" ) );
zorglub's avatar
zorglub committed
184
    BUTTONACT( undockButton, undock() );
zorglub's avatar
zorglub committed
185
    middle->addWidget( undockButton );
zorglub's avatar
zorglub committed
186 187 188 189 190 191

    addButton = new QPushButton( "+", this );
    addButton->setMaximumWidth( 25 );
    BUTTONACT( addButton, add() );
    middle->addWidget( addButton );

zorglub's avatar
zorglub committed
192 193 194 195 196 197 198 199
    left->addLayout( middle );

    QLabel *art = new QLabel( "" );
    art->setMaximumHeight( 128 );
    art->setMaximumWidth( 128 );
    art->setScaledContents( true );
    art->setPixmap( QPixmap( art_xpm ) ); //":/vlc128.png" ) );
    left->addWidget( art );
200 201 202

    playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
                                                THEPL->p_local_category );
zorglub's avatar
zorglub committed
203
    currentRootId = p_root->i_id;
204 205 206 207 208

    rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
                              p_intf, THEPL, p_root ) );

    CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
zorglub's avatar
zorglub committed
209
    CONNECT( selector, activated( int ), this, setCurrentRootId( int ) );
210

zorglub's avatar
zorglub committed
211 212
    QHBoxLayout *layout = new QHBoxLayout(this);
    layout->addLayout( left, 0 );
213 214 215 216 217 218 219 220
    layout->addWidget( rightPanel, 10 );
    setLayout( layout );
}

PlaylistWidget::~PlaylistWidget()
{
}

zorglub's avatar
zorglub committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
void PlaylistWidget::setCurrentRootId( int _new )
{
    currentRootId = _new;
    if( currentRootId == THEPL->p_local_category->i_id ||
        currentRootId == THEPL->p_local_onelevel->i_id  )
    {
        addButton->setEnabled( true );
        addButton->setToolTip( qtr("Add to playlist" ) );
    }
    else if( currentRootId == THEPL->p_ml_category->i_id ||
             currentRootId == THEPL->p_ml_onelevel->i_id )
    {
        addButton->setEnabled( true );
        addButton->setToolTip( qtr("Add to media library" ) );
    }
    else
        addButton->setEnabled( false );
}

240 241 242 243 244 245 246 247 248 249
void PlaylistWidget::undock()
{
    hide();
    THEDP->playlistDialog();
    deleteLater();

    QEvent *event = new QEvent( (QEvent::Type)(PLUndockEvent_Type) );
    QApplication::postEvent( p_intf->p_sys->p_mi, event );
}

zorglub's avatar
zorglub committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
void PlaylistWidget::add()
{
    QMenu *popup = new QMenu();
    if( currentRootId == THEPL->p_local_category->i_id ||
        currentRootId == THEPL->p_local_onelevel->i_id )
    {
        popup->addAction( "Add file", THEDP, SLOT( simplePLAppendDialog() ) );
        popup->addAction( "Advanced add", THEDP, SLOT( PLAppendDialog() ) );
    }
    else if( currentRootId == THEPL->p_ml_category->i_id ||
             currentRootId == THEPL->p_ml_onelevel->i_id )
    {
        popup->addAction( "Add file", THEDP, SLOT( simpleMLAppendDialog() ) );
        popup->addAction( "Advanced add", THEDP, SLOT( MLAppendDialog() ) );
        popup->addAction( "Directory", THEDP, SLOT( openMLDirectory() ) );
    }
    popup->popup( QCursor::pos() );
}

269 270 271 272 273
QSize PlaylistWidget::sizeHint() const
{
    return widgetSize;
}