Changeset 126
- Timestamp:
- 10/18/08 14:37:23 (4 years ago)
- Files:
-
- 8 edited
-
gui/main_window.cpp (modified) (3 diffs)
-
gui/main_window.h (modified) (1 diff)
-
gui/main_window.ui (modified) (1 diff)
-
gui/playlisttablemodel.cpp (modified) (3 diffs)
-
gui/playlisttablemodel.h (modified) (1 diff)
-
lib/mpdconnection.cpp (modified) (1 diff)
-
lib/mpdconnection.h (modified) (1 diff)
-
lib/mpdparseutils.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
gui/main_window.cpp
r125 r126 68 68 libraryTreeView->sortByColumn(0, Qt::AscendingOrder); 69 69 70 // Playlist table view 70 71 playlistTableView->setModel(&playlistModel); 71 72 playlistTableView->verticalHeader()->hide(); 72 73 playlistTableView->horizontalHeader()->setResizeMode(QHeaderView::Interactive); 74 playlistTableView->setDragEnabled(true); 75 playlistTableView->setAcceptDrops(true); 76 playlistTableView->setDropIndicatorShown(true); 73 77 74 78 // MPD … … 111 115 connect(&musicLibraryModel, SIGNAL(xmlWriten(QDateTime)), this, SLOT(databaseSaved(QDateTime))); 112 116 117 // Playlist 118 connect(&playlistModel, SIGNAL(moveInPlaylist(quint32, quint32)), this, SLOT(movePlaylistItems(quint32, quint32))); 119 113 120 // Timer 114 121 fetchStatsFactor = 0; … … 506 513 settings.setValue("database/db_update",db_update); 507 514 } 515 516 void MainWindow::movePlaylistItems(quint32 from, quint32 to) 517 { 518 mpd.move(from, to); 519 } -
gui/main_window.h
r125 r126 108 108 109 109 void databaseSaved(QDateTime db_update); 110 111 void movePlaylistItems(quint32 from, quint32 to); 110 112 }; 111 113 -
gui/main_window.ui
r125 r126 589 589 <property name="dragEnabled" > 590 590 <bool>true</bool> 591 </property> 592 <property name="dragDropOverwriteMode" > 593 <bool>false</bool> 591 594 </property> 592 595 <property name="dragDropMode" > -
gui/playlisttablemodel.cpp
r107 r126 2 2 #include <QModelIndex> 3 3 #include <QStringListModel> 4 #include <QMimeData> 5 #include <QDebug> 4 6 5 7 #include "playlisttablemodel.h" … … 134 136 } 135 137 138 qint32 PlaylistTableModel::getPosByRow(qint32 row) const 139 { 140 if(songs->size() <= row) { 141 return -1; 142 } 143 144 return songs->at(row)->pos; 145 } 146 136 147 Qt::DropActions PlaylistTableModel::supportedDropActions() const 137 148 { 138 return Qt:: CopyAction | Qt::MoveAction;149 return Qt::MoveAction; 139 150 } 140 151 … … 142 153 { 143 154 if (index.isValid()) 144 return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIs DropEnabled | Qt::ItemIsEnabled;155 return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled; 145 156 else 146 157 return Qt::ItemIsDropEnabled; 158 } 159 160 /** 161 * @return A QStringList with the mimetypes we support 162 */ 163 QStringList 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 */ 176 QMimeData *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 203 bool 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; 147 242 } 148 243 -
gui/playlisttablemodel.h
r107 r126 21 21 void updateCurrentSong(quint32 id); 22 22 qint32 getIdByRow(qint32 row) const; 23 qint32 getPosByRow(qint32 row) const; 23 24 24 25 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); 26 30 27 31 public slots: 28 32 void updateSongs(QList<Song *> *); 33 34 signals: 35 void moveInPlaylist(quint32 from, quint32 to); 29 36 30 37 private: -
lib/mpdconnection.cpp
r120 r126 254 254 } 255 255 256 void 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 256 266 void MPDConnection::currentSong() 257 267 { -
lib/mpdconnection.h
r120 r126 39 39 void playListInfo(); 40 40 void removeSongs(const QList<qint32> &items); 41 void move(const quint32 from, const quint32 to); 41 42 // TODO 42 43 -
lib/mpdparseutils.cpp
r118 r126 116 116 song->track = value.toInt(); 117 117 } else if(element == "Pos") { 118 song->pos = value.toInt(); 118 119 } else if(element == "Id") { 119 120 song->id = value.toUInt();
Note: See TracChangeset
for help on using the changeset viewer.
