Changeset 126


Ignore:
Timestamp:
10/18/08 14:37:23 (4 years ago)
Author:
roeland
Message:

Moving with 1 item works
This is work on ticket #9

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • gui/main_window.cpp

    r125 r126  
    6868    libraryTreeView->sortByColumn(0, Qt::AscendingOrder); 
    6969 
     70    // Playlist table view 
    7071    playlistTableView->setModel(&playlistModel); 
    7172    playlistTableView->verticalHeader()->hide(); 
    7273    playlistTableView->horizontalHeader()->setResizeMode(QHeaderView::Interactive); 
     74    playlistTableView->setDragEnabled(true); 
     75    playlistTableView->setAcceptDrops(true); 
     76    playlistTableView->setDropIndicatorShown(true); 
    7377 
    7478    // MPD 
     
    111115    connect(&musicLibraryModel, SIGNAL(xmlWriten(QDateTime)), this, SLOT(databaseSaved(QDateTime))); 
    112116 
     117    // Playlist 
     118    connect(&playlistModel, SIGNAL(moveInPlaylist(quint32, quint32)), this, SLOT(movePlaylistItems(quint32, quint32))); 
     119 
    113120    // Timer 
    114121    fetchStatsFactor = 0; 
     
    506513    settings.setValue("database/db_update",db_update); 
    507514} 
     515 
     516void MainWindow::movePlaylistItems(quint32 from, quint32 to) 
     517{ 
     518    mpd.move(from, to); 
     519} 
  • gui/main_window.h

    r125 r126  
    108108 
    109109        void databaseSaved(QDateTime db_update); 
     110 
     111        void movePlaylistItems(quint32 from, quint32 to); 
    110112}; 
    111113 
  • gui/main_window.ui

    r125 r126  
    589589          <property name="dragEnabled" > 
    590590           <bool>true</bool> 
     591          </property> 
     592          <property name="dragDropOverwriteMode" > 
     593           <bool>false</bool> 
    591594          </property> 
    592595          <property name="dragDropMode" > 
  • gui/playlisttablemodel.cpp

    r107 r126  
    22#include <QModelIndex> 
    33#include <QStringListModel> 
     4#include <QMimeData> 
     5#include <QDebug> 
    46 
    57#include "playlisttablemodel.h" 
     
    134136} 
    135137 
     138qint32 PlaylistTableModel::getPosByRow(qint32 row) const 
     139{ 
     140    if(songs->size() <= row) { 
     141        return -1; 
     142    } 
     143 
     144    return songs->at(row)->pos; 
     145} 
     146 
    136147Qt::DropActions PlaylistTableModel::supportedDropActions() const 
    137148{ 
    138     return Qt::CopyAction | Qt::MoveAction; 
     149    return Qt::MoveAction; 
    139150} 
    140151 
     
    142153{ 
    143154    if (index.isValid()) 
    144         return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled; 
     155        return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled; 
    145156    else 
    146157        return Qt::ItemIsDropEnabled; 
     158} 
     159 
     160/** 
     161 * @return A QStringList with the mimetypes we support 
     162 */ 
     163QStringList PlaylistTableModel::mimeTypes() const 
     164{ 
     165    QStringList types; 
     166    types << "application/qtmpc_song_move_text"; 
     167    return types; 
     168} 
     169 
     170/** 
     171 * Convert the data at indexes into mimedata ready for transport 
     172 * 
     173 * @param indexes The indexes to pack into mimedata 
     174 * @return The mimedata 
     175 */ 
     176QMimeData *PlaylistTableModel::mimeData(const QModelIndexList &indexes) const 
     177{ 
     178    QMimeData *mimeData = new QMimeData(); 
     179    QByteArray encodedData; 
     180 
     181    QDataStream stream(&encodedData, QIODevice::WriteOnly); 
     182 
     183    /* 
     184     * Loop over all our indexes. However we have rows*columns indexes 
     185     * We pack per row so ingore the columns 
     186     */ 
     187    int lastrow = -1; 
     188    foreach (QModelIndex index, indexes) { 
     189        if (index.isValid()) { 
     190            if (index.row() == lastrow) 
     191                continue; 
     192 
     193            QString text = QString::number(getPosByRow(index.row())); 
     194            stream << text; 
     195            lastrow = index.row(); 
     196        } 
     197    } 
     198 
     199    mimeData->setData("application/qtmpc_song_move_text", encodedData); 
     200    return mimeData; 
     201} 
     202 
     203bool PlaylistTableModel::dropMimeData(const QMimeData *data, 
     204     Qt::DropAction action, int row, int column, const QModelIndex &parent) 
     205{ 
     206    if (action == Qt::IgnoreAction) 
     207        return true; 
     208 
     209    if (data->hasFormat("application/qtmpc_song_move_text")) { 
     210        QByteArray encodedData = data->data("application/qtmpc_song_move_text"); 
     211        QDataStream stream(&encodedData, QIODevice::ReadOnly); 
     212        QStringList newItems; 
     213 
     214        while (!stream.atEnd()) { 
     215            QString text; 
     216            stream >> text; 
     217 
     218            //We only do real moves 
     219            if (row < 0) { 
     220                continue; 
     221            } 
     222 
     223            quint32 from = text.toUInt(); 
     224            quint32 to = row; 
     225 
     226            //Fix for the counting in qtableview 
     227            if (from < to) { 
     228                to -= 1; 
     229            } 
     230 
     231            //Don't do useless moves 
     232            if (from == to) { 
     233                continue; 
     234            } 
     235 
     236            emit moveInPlaylist(from, to); 
     237        } 
     238 
     239    } 
     240 
     241    return false; 
    147242} 
    148243 
  • gui/playlisttablemodel.h

    r107 r126  
    2121        void updateCurrentSong(quint32 id); 
    2222        qint32 getIdByRow(qint32 row) const; 
     23        qint32 getPosByRow(qint32 row) const; 
    2324 
    2425        Qt::DropActions supportedDropActions() const; 
    25         Qt::ItemFlags flags(const QModelIndex &index) const;     
     26        Qt::ItemFlags flags(const QModelIndex &index) const; 
     27        QStringList mimeTypes() const; 
     28        QMimeData *mimeData(const QModelIndexList &indexes) const; 
     29        bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); 
    2630 
    2731    public slots: 
    2832        void updateSongs(QList<Song *> *); 
     33 
     34    signals: 
     35        void moveInPlaylist(quint32 from, quint32 to); 
    2936 
    3037    private: 
  • lib/mpdconnection.cpp

    r120 r126  
    254254} 
    255255 
     256void MPDConnection::move(const quint32 from, const quint32 to) 
     257{ 
     258    QByteArray send = "move " + QByteArray::number(from) + " " + QByteArray::number(to); 
     259 
     260    sendCommand(send); 
     261 
     262    if(!commandOk()) 
     263        qDebug("Couldn't move files around in playlist"); 
     264} 
     265 
    256266void MPDConnection::currentSong() 
    257267{ 
  • lib/mpdconnection.h

    r120 r126  
    3939        void playListInfo(); 
    4040        void removeSongs(const QList<qint32> &items); 
     41        void move(const quint32 from, const quint32 to); 
    4142        // TODO 
    4243 
  • lib/mpdparseutils.cpp

    r118 r126  
    116116            song->track = value.toInt(); 
    117117        } else if(element == "Pos") { 
     118            song->pos = value.toInt(); 
    118119        } else if(element == "Id") { 
    119120            song->id = value.toUInt(); 
Note: See TracChangeset for help on using the changeset viewer.