}
void ListModel::move(QModelIndexList &indexes, bool up) {
-
QList<Video*> movedVideos;
foreach (QModelIndex index, indexes) {
movedVideos << video;
}
- int counter = 1;
+ int end=up ? -1 : rowCount()-1, mod=up ? -1 : 1;
foreach (Video *video, movedVideos) {
int row = rowForVideo(video);
+ if (row+mod==end) { end=row; continue; }
// qDebug() << "video row" << row;
removeRows(row, 1, QModelIndex());
videos.insert(row, video);
endInsertRows();
- counter++;
}
emit needSelectionFor(movedVideos);
void MediaView::moveUpSelected() {
if (!listView->selectionModel()->hasSelection()) return;
+
QModelIndexList indexes = listView->selectionModel()->selectedIndexes();
+ qStableSort(indexes.begin(), indexes.end());
listModel->move(indexes, true);
+
+ // set current index after row moves to something more intuitive
+ int row = indexes.first().row();
+ listView->selectionModel()->setCurrentIndex(listModel->index(row>1?row:1), QItemSelectionModel::NoUpdate);
}
void MediaView::moveDownSelected() {
if (!listView->selectionModel()->hasSelection()) return;
+
QModelIndexList indexes = listView->selectionModel()->selectedIndexes();
+ qStableSort(indexes.begin(), indexes.end(), qGreater<QModelIndex>());
listModel->move(indexes, false);
+
+ // set current index after row moves to something more intuitive (respect 1 static item on bottom)
+ int row = indexes.first().row()+1, max = listModel->rowCount() - 2;
+ listView->selectionModel()->setCurrentIndex(listModel->index(row>max?max:row), QItemSelectionModel::NoUpdate);
}
void MediaView::showVideoContextMenu(QPoint point) {