partial old-style drag support

This commit is contained in:
Brian Hrebec 2010-10-02 21:41:59 -05:00
parent 714d629752
commit 149b9a6766
2 changed files with 20 additions and 47 deletions

View file

@ -24,6 +24,7 @@
#include "skin.h" #include "skin.h"
#include "skinmanager.h" #include "skinmanager.h"
#include <QDebug>
#include <QColor> #include <QColor>
#include <QMenu> #include <QMenu>
#include <QPaintEvent> #include <QPaintEvent>
@ -31,6 +32,7 @@
#include <QPalette> #include <QPalette>
#include <QSettings> #include <QSettings>
#include <QFontMetrics> #include <QFontMetrics>
#include <QScrollBar>
#include <QSizePolicy> #include <QSizePolicy>
@ -123,7 +125,7 @@ PlaylistView::PlaylistView (QWidget *parent) : QListView (parent)
setSelectionMode (QAbstractItemView::ExtendedSelection); setSelectionMode (QAbstractItemView::ExtendedSelection);
setUniformItemSizes(true); setUniformItemSizes(true);
//setDragEnabled(true); setDragEnabled(true);
setAcceptDrops(true); setAcceptDrops(true);
// TODO make sure delegate gets deleted // TODO make sure delegate gets deleted
@ -326,7 +328,7 @@ PlaylistView::mouseMoveEvent (QMouseEvent *event)
if (mouseIndex.row () < 0 || sel.empty()) if (mouseIndex.row () < 0 || sel.empty())
return; return;
if (mouseIndex != currentIndex () && m_old_selection.empty()) { if (mouseIndex != currentIndex () && m_old_selection.isEmpty()) {
m_old_current_index = currentIndex ().row(); m_old_current_index = currentIndex ().row();
qSort(sel); qSort(sel);
@ -336,6 +338,8 @@ PlaylistView::mouseMoveEvent (QMouseEvent *event)
!(sel.last ().row () + diff < model ()->rowCount ())) !(sel.last ().row () + diff < model ()->rowCount ()))
return; return;
m_prev_scroll_pos = verticalScrollBar ()->value();
if (diff < 0 ) { if (diff < 0 ) {
// move selection up // move selection up
for (int i = 0; i < sel.size (); i++) { for (int i = 0; i < sel.size (); i++) {
@ -355,46 +359,7 @@ PlaylistView::mouseMoveEvent (QMouseEvent *event)
m_old_selection.insert(row); 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 void
@ -404,9 +369,16 @@ PlaylistView::entryMoved(QModelIndex a, QModelIndex b)
selectionModel ()->select (b, QItemSelectionModel::Select); selectionModel ()->select (b, QItemSelectionModel::Select);
m_old_selection.remove (a.row ()); m_old_selection.remove (a.row ());
if (m_old_current_index == a.row ()) { if (m_old_current_index == a.row ()) {
setSelectionMode (QAbstractItemView::NoSelection); // update currentIndex without losing the selection
setCurrentIndex (b); selectionModel ()->setCurrentIndex(b,
setSelectionMode (QAbstractItemView::ExtendedSelection); 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);
} }
} }
} }

View file

@ -91,6 +91,7 @@ class PlaylistView : public QListView {
QSet<int> m_old_selection; QSet<int> m_old_selection;
int m_old_current_index; int m_old_current_index;
int m_prev_scroll_pos;
}; };