Changeset ac471f21023adf4d3784ab3856b9a6040689d65c

Show
Ignore:
Timestamp:
14/10/06 18:44:55 (2 years ago)
Author:
Clément Stenac <zorglub@videolan.org>
git-committer:
Clément Stenac <zorglub@videolan.org> 1160844295 +0000
git-parent:

[85f6dac57eff2d455420d1f4bbb4d7f41bae0ec0]

git-author:
Clément Stenac <zorglub@videolan.org> 1160844295 +0000
Message:

Initial drag and drop support for Qt

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/gui/qt4/components/playlist/selector.cpp

    r6523dc2 rac471f2  
    3939    view->setModel( model ); 
    4040 
     41    view->setDragEnabled(true); 
     42    view->setAcceptDrops(true); 
     43    view->setDropIndicatorShown(true); 
     44 
    4145    CONNECT( view, activated( const QModelIndex& ), 
    4246             this, setSource( const QModelIndex& ) ); 
  • modules/gui/qt4/components/playlist/standardpanel.cpp

    ra01c61f rac471f2  
    5757    view->header()->setSortIndicatorShown( true ); 
    5858    view->header()->setClickable( true ); 
     59 
    5960    view->setSelectionMode( QAbstractItemView::ExtendedSelection ); 
     61    view->setDragEnabled(true); 
     62    view->setAcceptDrops(true); 
     63    view->setDropIndicatorShown(true); 
    6064 
    6165    CONNECT( view, activated( const QModelIndex& ) , 
  • modules/gui/qt4/dialogs/playlist.cpp

    ra01c61f rac471f2  
    3131#include "menus.hpp" 
    3232 
     33#include <QUrl> 
    3334#include <QHBoxLayout> 
    3435#include <QSignalMapper> 
     
    7677    QApplication::postEvent( p_intf->p_sys->p_mi, event ); 
    7778} 
     79 
     80 
     81void PlaylistDialog::dropEvent(QDropEvent *event) 
     82{ 
     83     const QMimeData *mimeData = event->mimeData(); 
     84     foreach( QUrl url, mimeData->urls() ) { 
     85        QString s = url.toString(); 
     86        if( s.length() > 0 ) { 
     87            playlist_PlaylistAdd( THEPL, qtu(s), NULL, 
     88                                  PLAYLIST_APPEND, PLAYLIST_END ); 
     89        } 
     90     } 
     91     event->acceptProposedAction(); 
     92} 
     93void PlaylistDialog::dragEnterEvent(QDragEnterEvent *event) 
     94{ 
     95     event->acceptProposedAction(); 
     96} 
     97void PlaylistDialog::dragMoveEvent(QDragMoveEvent *event) 
     98{ 
     99     event->acceptProposedAction(); 
     100} 
     101void PlaylistDialog::dragLeaveEvent(QDragLeaveEvent *event) 
     102{ 
     103     event->accept(); 
     104} 
     105 
     106 
  • modules/gui/qt4/dialogs/playlist.hpp

    r7f994b8 rac471f2  
    5050    void createPlMenuBar( QMenuBar *bar, intf_thread_t *p_intf ); 
    5151    PlaylistDialog( intf_thread_t * ); 
     52 
     53    void dropEvent( QDropEvent *); 
     54    void dragEnterEvent( QDragEnterEvent * ); 
     55    void dragMoveEvent( QDragMoveEvent * ); 
     56    void dragLeaveEvent( QDragLeaveEvent * ); 
     57 
    5258    static PlaylistDialog *instance; 
    5359 
  • modules/gui/qt4/main_interface.cpp

    r141dd1d rac471f2  
    3737#include <QStatusBar> 
    3838#include <QKeyEvent> 
     39#include <QUrl> 
    3940 
    4041#include <assert.h> 
     
    8485    settings = new QSettings( "VideoLAN", "VLC" ); 
    8586    settings->beginGroup( "MainWindow" ); 
     87 
     88    setAcceptDrops(true); 
    8689 
    8790    need_components_update = false; 
     
    138141} 
    139142 
     143void MainInterface::dropEvent(QDropEvent *event) 
     144{ 
     145     const QMimeData *mimeData = event->mimeData(); 
     146 
     147     /* D&D of a subtitles file, add it on the fly */ 
     148     if( mimeData->urls().size() == 1 ) 
     149     { 
     150        if( THEMIM->getIM()->hasInput() ) 
     151        { 
     152            if( input_AddSubtitles( THEMIM->getInput(), 
     153                                    qtu( mimeData->urls()[0].toString() ), 
     154                                    VLC_TRUE ) ) 
     155            { 
     156                event->acceptProposedAction(); 
     157                return; 
     158            } 
     159        } 
     160     } 
     161     bool first = true; 
     162     foreach( QUrl url, mimeData->urls() ) { 
     163        QString s = url.toString(); 
     164        if( s.length() > 0 ) { 
     165            playlist_PlaylistAdd( THEPL, qtu(s), NULL, 
     166                                  PLAYLIST_APPEND | (first ? PLAYLIST_GO:0), 
     167                                  PLAYLIST_END ); 
     168            first = false; 
     169        } 
     170     } 
     171     event->acceptProposedAction(); 
     172} 
     173void MainInterface::dragEnterEvent(QDragEnterEvent *event) 
     174{ 
     175     event->acceptProposedAction(); 
     176} 
     177void MainInterface::dragMoveEvent(QDragMoveEvent *event) 
     178{ 
     179     event->acceptProposedAction(); 
     180} 
     181void MainInterface::dragLeaveEvent(QDragLeaveEvent *event) 
     182{ 
     183     event->accept(); 
     184} 
     185 
     186 
     187 
    140188MainInterface::~MainInterface() 
    141189{ 
  • modules/gui/qt4/main_interface.hpp

    r141dd1d rac471f2  
    5858protected: 
    5959    void resizeEvent( QResizeEvent * ); 
     60    void dropEvent( QDropEvent *); 
     61    void dragEnterEvent( QDragEnterEvent * ); 
     62    void dragMoveEvent( QDragMoveEvent * ); 
     63    void dragLeaveEvent( QDragLeaveEvent * ); 
    6064    void closeEvent( QCloseEvent *); 
    6165    Ui::MainInterfaceUI ui; 
  • modules/gui/qt4/playlist_model.cpp

    r7810e78 rac471f2  
    2121 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 
    2222 *****************************************************************************/ 
     23#define PLI_NAME( p ) p ? p->p_input->psz_name : "null" 
    2324 
    2425#include <assert.h> 
     
    99100    if( signal ) 
    100101        model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos ); 
    101     children.append( item ); 
     102    children.insert( i_pos, item ); 
    102103    if( signal ) 
    103104        model->endInsertRows(); 
     
    182183} 
    183184 
     185Qt::DropActions PLModel::supportedDropActions() const 
     186{ 
     187    return Qt::CopyAction; 
     188} 
     189 
     190Qt::ItemFlags PLModel::flags(const QModelIndex &index) const 
     191{ 
     192    Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index); 
     193    if( index.isValid() ) 
     194        return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; 
     195    else 
     196        return Qt::ItemIsDropEnabled | defaultFlags; 
     197} 
     198 
     199QStringList PLModel::mimeTypes() const 
     200{ 
     201    QStringList types; 
     202    types << "vlc/playlist-item-id"; 
     203    return types; 
     204} 
     205 
     206QMimeData *PLModel::mimeData(const QModelIndexList &indexes) const 
     207{ 
     208    QMimeData *mimeData = new QMimeData(); 
     209    QByteArray encodedData; 
     210    QDataStream stream(&encodedData, QIODevice::WriteOnly); 
     211 
     212    foreach (QModelIndex index, indexes) { 
     213        if (index.isValid() && index.column() == 0 ) 
     214            stream << itemId(index); 
     215    } 
     216    mimeData->setData("vlc/playlist-item-id", encodedData); 
     217    return mimeData; 
     218} 
     219 
     220bool PLModel::dropMimeData(const QMimeData *data, Qt::DropAction action, 
     221                           int row, int column, const QModelIndex &target) 
     222{ 
     223    if ( data->hasFormat("vlc/playlist-item-id") ) 
     224    { 
     225        if (action == Qt::IgnoreAction) 
     226            return true; 
     227 
     228        PLItem *targetItem; 
     229        if( target.isValid() ) 
     230            targetItem = static_cast<PLItem*>( target.internalPointer() ); 
     231        else 
     232            targetItem = rootItem; 
     233 
     234        QByteArray encodedData = data->data("vlc/playlist-item-id"); 
     235        QDataStream stream(&encodedData, QIODevice::ReadOnly); 
     236 
     237        PLItem *newParentItem; 
     238        while (!stream.atEnd()) 
     239        { 
     240            int i; 
     241            int srcId; 
     242            stream >> srcId; 
     243 
     244            PL_LOCK; 
     245            playlist_item_t *p_target = 
     246                        playlist_ItemGetById( p_playlist, targetItem->i_id ); 
     247            playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId ); 
     248 
     249            if( !p_target || !p_src ) 
     250            { 
     251                PL_UNLOCK; 
     252                return false; 
     253            } 
     254 
     255            if( p_target->i_children == -1 ) /* A leaf */ 
     256            { 
     257                PLItem *parentItem = targetItem->parent(); 
     258                assert( parentItem ); 
     259                playlist_item_t *p_parent = 
     260                         playlist_ItemGetById( p_playlist, parentItem->i_id ); 
     261                if( !p_parent ) 
     262                { 
     263                    PL_UNLOCK; 
     264                    return false; 
     265                } 
     266                for( i = 0 ; i< p_parent->i_children ; i++ ) 
     267                    if( p_parent->pp_children[i] == p_target ) break; 
     268                playlist_TreeMove( p_playlist, p_src, p_parent, i ); 
     269                newParentItem = parentItem; 
     270            } 
     271            else 
     272            { 
     273                /* \todo: if we drop on a top-level node, use copy instead ? */ 
     274                playlist_TreeMove( p_playlist, p_src, p_target, 0 ); 
     275                i = 0; 
     276                newParentItem = targetItem; 
     277            } 
     278            /* Remove from source */ 
     279            PLItem *srcItem = FindByInput( rootItem, p_src->p_input->i_id ); 
     280            srcItem->remove( srcItem ); 
     281            /* Display at new destination */ 
     282            PLItem *newItem = new PLItem( p_src, newParentItem, this ); 
     283            newParentItem->insertChild( newItem, i, true ); 
     284            UpdateTreeItem( p_src, newItem, true ); 
     285            if( p_src->i_children != -1 ) 
     286                UpdateNodeChildren( newItem ); 
     287            PL_UNLOCK; 
     288        } 
     289    } 
     290    return true; 
     291 } 
     292 
     293 
    184294void PLModel::addCallbacks() 
    185295{ 
     
    230340QVariant PLModel::data(const QModelIndex &index, int role) const 
    231341{ 
    232     assert( index.isValid() ); 
     342    if(!index.isValid() ) return QVariant(); 
    233343    PLItem *item = static_cast<PLItem*>(index.internalPointer()); 
    234344    if( role == Qt::DisplayRole ) 
     
    261371    assert( index.isValid() ); 
    262372    return static_cast<PLItem*>(index.internalPointer())->i_id; 
    263 } 
    264  
    265 Qt::ItemFlags PLModel::flags(const QModelIndex &index) const 
    266 { 
    267     if( !index.isValid() ) return Qt::ItemIsEnabled; 
    268     return Qt::ItemIsEnabled | Qt::ItemIsSelectable; 
    269373} 
    270374 
     
    450554    int type = event->type(); 
    451555    if( type != ItemUpdate_Type && type != ItemAppend_Type && 
    452         type != ItemDelete_Type
     556        type != ItemDelete_Type && type != PLUpdate_Type
    453557        return; 
    454558 
     
    459563    else if( type == ItemAppend_Type ) 
    460564        ProcessItemAppend( ple->p_add ); 
     565    else if( type == ItemDelete_Type ) 
     566        ProcessItemRemoval( ple->i_id ); 
    461567    else 
    462         ProcessItemRemoval( ple->i_id ); 
     568        rebuild(); 
    463569} 
    464570 
     
    670776    case 1: i_mode = SORT_ARTIST;break; 
    671777    case 2: i_mode = SORT_DURATION; break; 
     778    default: i_mode = SORT_TITLE_NODES_FIRST; break; 
    672779    } 
    673780    if( p_root ) 
     
    757864{ 
    758865    PLModel *p_model = (PLModel *) param; 
    759 //    p_model->b_need_update = VLC_TRUE; 
     866    PLEvent *event = new PLEvent( PLUpdate_Type, 0 ); 
     867    QApplication::postEvent( p_model, static_cast<QEvent*>(event) ); 
    760868    return VLC_SUCCESS; 
    761869} 
  • modules/gui/qt4/playlist_model.hpp

    r48f7e0b rac471f2  
    2828#include <QObject> 
    2929#include <QEvent> 
     30#include <QMimeData> 
    3031 
    3132#include <vlc/vlc.h> 
     
    7374static int ItemDelete_Type = QEvent::User + 3; 
    7475static int ItemAppend_Type = QEvent::User + 4; 
     76static int PLUpdate_Type = QEvent::User + 5; 
    7577 
    7678class PLEvent : public QEvent 
     
    122124    void search( QString search ); 
    123125    void sort( int column, Qt::SortOrder order ); 
     126 
     127    /* DnD handling */ 
     128    Qt::DropActions supportedDropActions() const; 
     129    QMimeData* mimeData(const QModelIndexList &indexes) const; 
     130    bool dropMimeData(const QMimeData *data, Qt::DropAction action, 
     131                      int row, int column, const QModelIndex &target); 
     132    QStringList mimeTypes() const; 
    124133 
    125134    void sendArt( QString url ); 
  • src/playlist/item.c

    r2e0102d rac471f2  
    483483    /* Attach to new parent */ 
    484484    INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item ); 
     485    p_item->p_parent = p_node; 
    485486 
    486487    return VLC_SUCCESS; 
  • src/playlist/tree.c

    radb0d2e rac471f2  
    431431        vlc_bool_t b_ena_ok = VLC_TRUE, b_unplayed_ok = VLC_TRUE; 
    432432        p_next = GetNextItem( p_playlist, p_root, p_next ); 
     433        PL_DEBUG( "Got next item %s, testing suitability", PLI_NAME(p_next) ); 
    433434        if( !p_next || p_next == p_root ) 
    434435            break; 
     
    521522    else 
    522523        p_parent = p_root; 
    523  
     524    PL_DEBUG( "Parent %s has %i children", PLI_NAME(p_parent), 
     525                                           p_parent->i_children ); 
    524526    for( i= 0 ; i < p_parent->i_children ; i++ ) 
    525527    {