partial old-style drag support
This commit is contained in:
parent
714d629752
commit
149b9a6766
2 changed files with 20 additions and 47 deletions
|
|
@ -24,6 +24,7 @@
|
|||
#include "skin.h"
|
||||
#include "skinmanager.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QColor>
|
||||
#include <QMenu>
|
||||
#include <QPaintEvent>
|
||||
|
|
@ -31,6 +32,7 @@
|
|||
#include <QPalette>
|
||||
#include <QSettings>
|
||||
#include <QFontMetrics>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include <QSizePolicy>
|
||||
|
||||
|
|
@ -123,7 +125,7 @@ PlaylistView::PlaylistView (QWidget *parent) : QListView (parent)
|
|||
|
||||
setSelectionMode (QAbstractItemView::ExtendedSelection);
|
||||
setUniformItemSizes(true);
|
||||
//setDragEnabled(true);
|
||||
setDragEnabled(true);
|
||||
setAcceptDrops(true);
|
||||
|
||||
// TODO make sure delegate gets deleted
|
||||
|
|
@ -326,16 +328,18 @@ PlaylistView::mouseMoveEvent (QMouseEvent *event)
|
|||
if (mouseIndex.row () < 0 || sel.empty())
|
||||
return;
|
||||
|
||||
if (mouseIndex != currentIndex () && m_old_selection.empty()) {
|
||||
if (mouseIndex != currentIndex () && m_old_selection.isEmpty()) {
|
||||
m_old_current_index = currentIndex ().row();
|
||||
|
||||
qSort(sel);
|
||||
|
||||
int diff = mouseIndex.row () - currentIndex ().row ();
|
||||
if (!(sel.first().row () + diff >= 0) ||
|
||||
if (!(sel.first ().row () + diff >= 0) ||
|
||||
!(sel.last ().row () + diff < model ()->rowCount ()))
|
||||
return;
|
||||
|
||||
m_prev_scroll_pos = verticalScrollBar ()->value();
|
||||
|
||||
if (diff < 0 ) {
|
||||
// move selection up
|
||||
for (int i = 0; i < sel.size (); i++) {
|
||||
|
|
@ -355,46 +359,7 @@ PlaylistView::mouseMoveEvent (QMouseEvent *event)
|
|||
m_old_selection.insert(row);
|
||||
}
|
||||
}
|
||||
setSelectionMode (QAbstractItemView::NoSelection);
|
||||
setCurrentIndex(mouseIndex);
|
||||
setSelectionMode (QAbstractItemView::ExtendedSelection);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
QRect r = visualRect(currentIndex ());
|
||||
int y = event->pos ().y();
|
||||
if (!(y >= r.y () &&
|
||||
y <= r.y () + r.height ())) {
|
||||
|
||||
m_old_selection.clear();
|
||||
m_old_current_index = currentIndex ().row();
|
||||
|
||||
QModelIndexList sel = selectedIndexes ();
|
||||
qSort(sel);
|
||||
|
||||
if (y < r.y ()) {
|
||||
// move selection up
|
||||
for (int i = 0; i < sel.size (); i++) {
|
||||
int row = sel[i].row();
|
||||
//qDebug() << "moving " << row << "to" << row - 1;
|
||||
App->client ()->playlist ()->moveEntry (row, row - 1);
|
||||
|
||||
m_old_selection.insert(row);
|
||||
}
|
||||
} else {
|
||||
// move selection down
|
||||
for (int i = sel.size () - 1; i >= 0; i--) {
|
||||
int row = sel[i].row();
|
||||
//qDebug() << "moving " << row << "to" << row + 1;
|
||||
App->client ()->playlist ()->moveEntry (row, row + 1);
|
||||
|
||||
m_old_selection.insert(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -402,11 +367,18 @@ PlaylistView::entryMoved(QModelIndex a, QModelIndex b)
|
|||
{
|
||||
if (m_old_selection.contains (a.row())) {
|
||||
selectionModel ()->select (b, QItemSelectionModel::Select);
|
||||
m_old_selection.remove (a.row());
|
||||
m_old_selection.remove (a.row ());
|
||||
if (m_old_current_index == a.row ()) {
|
||||
setSelectionMode (QAbstractItemView::NoSelection);
|
||||
setCurrentIndex (b);
|
||||
setSelectionMode (QAbstractItemView::ExtendedSelection);
|
||||
// update currentIndex without losing the selection
|
||||
selectionModel ()->setCurrentIndex(b,
|
||||
QItemSelectionModel::NoUpdate);
|
||||
|
||||
// restore the previous scroll position
|
||||
scrollTo(model ()->index (m_prev_scroll_pos, 0),
|
||||
QAbstractItemView::PositionAtTop);
|
||||
|
||||
// ensure the new one is visible
|
||||
scrollTo (b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ class PlaylistView : public QListView {
|
|||
|
||||
QSet<int> m_old_selection;
|
||||
int m_old_current_index;
|
||||
int m_prev_scroll_pos;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue