Commit 7d5c42bf authored by Kacper Kasper's avatar Kacper Kasper

Initial drag and drop support.

* Needs cleanup.
parent 17c1e4d1
......@@ -375,20 +375,19 @@ CollectionList::~CollectionList()
m_columnTags.clear();
}
void CollectionList::contentsDropEvent(QDropEvent *e)
void CollectionList::dropEvent(QDropEvent *e)
{
if(e->source() == this)
return; // Don't rearrange in the CollectionList.
else
Playlist::contentsDropEvent(e);
Playlist::dropEvent(e);
}
void CollectionList::contentsDragMoveEvent(QDragMoveEvent *e)
void CollectionList::dragMoveEvent(QDragMoveEvent *e)
{
// FIXME drag
/*if(e->source() != this)
Playlist::contentsDragMoveEvent(e);
else*/
if(e->source() != this)
Playlist::dragMoveEvent(e);
else
e->setAccepted(false);
}
......@@ -473,7 +472,7 @@ void CollectionListItem::refresh()
data()->cachedWidths.resize(columns);
for(int i = offset; i < columns; i++) {
setData(i, Qt::DisplayRole, text(i));
setText(i, text(i));
int id = i - offset;
if(id != TrackNumberColumn && id != LengthColumn) {
// All columns other than track num and length need local-encoded data for sorting
......
......@@ -142,8 +142,8 @@ protected:
CollectionList(PlaylistCollection *collection);
virtual ~CollectionList();
virtual void contentsDropEvent(QDropEvent *e);
virtual void contentsDragMoveEvent(QDragMoveEvent *e);
virtual void dropEvent(QDropEvent *e);
virtual void dragMoveEvent(QDragMoveEvent *e);
// These methods are used by CollectionListItem, which is a friend class.
......
......@@ -240,10 +240,11 @@ void Playlist::SharedSettings::apply(Playlist *l) const
int offset = l->columnOffset();
int i = 0;
bool oldState = l->header()->blockSignals(true);
//bool oldState = l->header()->blockSignals(true);
foreach(int column, m_columnOrder)
l->header()->moveSection(l->header()->visualIndex(i++ + offset), column + offset); // FIXME mismatch with setColumnOrder
l->header()->blockSignals(oldState);
// FIXME this is broken
l->header()->moveSection(i++ + offset, column + offset); // FIXME mismatch with setColumnOrder
//l->header()->blockSignals(oldState);
for(int i = 0; i < m_columnsVisible.size(); i++) {
if(m_columnsVisible[i] && l->isColumnHidden(i + offset))
......@@ -1019,37 +1020,18 @@ void Playlist::removeFromDisk(const PlaylistItemList &items)
}
}
// FIXME drag
/*Q3DragObject *Playlist::dragObject(QWidget *parent)
void Playlist::dragEnterEvent(QDragEnterEvent *e)
{
PlaylistItemList items = selectedItems();
KUrl::List urls;
foreach(PlaylistItem *item, items) {
urls << KUrl::fromPath(item->file().absFilePath());
}
K3URLDrag *urlDrag = new K3URLDrag(urls, parent);
urlDrag->setPixmap(BarIcon("audio-x-generic"));
return urlDrag;
}
void Playlist::contentsDragEnterEvent(QDragEnterEvent *e)
{
K3ListView::contentsDragEnterEvent(e);
if(CoverDrag::isCover(e->mimeData())) {
setDropHighlighter(true);
setDropVisualizer(false);
//setDropHighlighter(true);
setDropIndicatorShown(false);
e->accept();
return;
}
setDropHighlighter(false);
setDropVisualizer(true);
//setDropHighlighter(false);
setDropIndicatorShown(true);
const KUrl::List urls = KUrl::List::fromMimeData(e->mimeData());
......@@ -1058,9 +1040,10 @@ void Playlist::contentsDragEnterEvent(QDragEnterEvent *e)
return;
}
e->accept();
if(e->mimeData()->hasUrls())
e->acceptProposedAction();
return;
}*/
}
bool Playlist::acceptDrag(QDropEvent *e) const
{
......@@ -1156,7 +1139,7 @@ void Playlist::keyPressEvent(QKeyEvent *event)
if(*selected) {
QTreeWidgetItemIterator visible(this, QTreeWidgetItemIterator::NotHidden);
if(*selected == *visible)
KApplication::postEvent(parent(), new FocusUpEvent);
QApplication::postEvent(parent(), new FocusUpEvent);
}
}
......@@ -1164,10 +1147,34 @@ void Playlist::keyPressEvent(QKeyEvent *event)
QTreeWidget::keyPressEvent(event);
}
void Playlist::contentsDropEvent(QDropEvent *e)
QStringList Playlist::mimeTypes() const
{
// FIXME drag
/*QPoint vp = contentsToViewport(e->pos());
return QStringList("text/uri-list");
}
QMimeData* Playlist::mimeData(const QList<QTreeWidgetItem *> items) const
{
KUrl::List urls;
foreach(QTreeWidgetItem *item, items) {
urls << KUrl::fromPath(static_cast<PlaylistItem*>(item)->file().absFilePath());
}
QMimeData *urlDrag = new QMimeData();
urlDrag->setUrls(urls);
return urlDrag;
}
bool Playlist::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action)
{
qDebug() << index;
return true;
}
void Playlist::dropEvent(QDropEvent *e)
{
QPoint vp = e->pos();
PlaylistItem *item = static_cast<PlaylistItem *>(itemAt(vp));
// First see if we're dropping a cover, if so we can get it out of the
......@@ -1197,9 +1204,10 @@ void Playlist::contentsDropEvent(QDropEvent *e)
// This is what the user expects, and also allows the insertion at
// top of the list
QRect rect = visualItemRect(item);
if(!item)
item = static_cast<PlaylistItem *>(lastItem());
else if(vp.y() < item->itemPos() + item->height() / 2)
item = static_cast<PlaylistItem *>(topLevelItem(topLevelItemCount() - 1));
else if(vp.y() < rect.y() + rect.height() / 2)
item = static_cast<PlaylistItem *>(item->itemAbove());
m_blockDataChanged = true;
......@@ -1221,8 +1229,8 @@ void Playlist::contentsDropEvent(QDropEvent *e)
takeItem(listViewItem);
insertItem(listViewItem);
}
else
listViewItem->moveItem(item);
//else
// listViewItem->moveItem(item);
item = static_cast<PlaylistItem *>(listViewItem);
}
......@@ -1234,7 +1242,7 @@ void Playlist::contentsDropEvent(QDropEvent *e)
dataChanged();
emit signalPlaylistItemsDropped(this);
QTreeWidget::contentsDropEvent(e);*/
QTreeWidget::dropEvent(e);
}
void Playlist::showEvent(QShowEvent *e)
......@@ -1525,7 +1533,6 @@ void Playlist::slotInitialize()
setAllColumnsShowFocus(true);
setSelectionMode(QTreeWidget::ExtendedSelection);
header()->setSortIndicatorShown(true);
//setDropVisualizer(true);
m_columnFixedWidths.resize(columnCount());
......@@ -1581,8 +1588,9 @@ void Playlist::slotInitialize()
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
setAcceptDrops(true);
//setDropVisualizer(true);
viewport()->setAcceptDrops(true);
setDropIndicatorShown(true);
setDragEnabled(true);
m_disableColumnWidthUpdates = false;
......@@ -1693,6 +1701,8 @@ void Playlist::setup()
m_headerMenu = m_columnVisibleAction->menu();
header()->installEventFilter(this);
// TODO: Determine if other stuff in setup must happen before slotInitialize().
// Explicitly call slotInitialize() so that the columns are added before
......@@ -1784,10 +1794,10 @@ bool Playlist::playing() const
int Playlist::leftMostVisibleColumn() const
{
int i = 0;
while(isColumnHidden(header()->sectionPosition(i)) && i < PlaylistItem::lastColumn())
while(isColumnHidden(header()->visualIndex(i)) && i < PlaylistItem::lastColumn())
i++;
return header()->sectionPosition(i);
return header()->visualIndex(i);
}
PlaylistItemList Playlist::items(QTreeWidgetItemIterator::IteratorFlags flags)
......@@ -2176,7 +2186,7 @@ void Playlist::slotShowRMBMenu(const QPoint &point)
action("viewCover")->setEnabled(file.coverInfo()->hasCover());
action("removeCover")->setEnabled(file.coverInfo()->coverId() != CoverManager::NoMatch);
m_rmbMenu->popup(window()->mapToGlobal(mapToGlobal(point)));
m_rmbMenu->popup(mapToGlobal(point));
m_currentColumn = column + columnOffset();
}
......@@ -2392,7 +2402,7 @@ bool processEvents()
if(time.elapsed() > 100) {
time.restart();
kapp->processEvents();
qApp->processEvents();
return true;
}
return false;
......
......@@ -38,7 +38,6 @@ class KActionMenu;
class QFileInfo;
class QMimeData;
class QDrag;
class QAction;
class WebImageFetcher;
......@@ -425,11 +424,12 @@ protected:
virtual bool eventFilter(QObject *watched, QEvent *e);
virtual void keyPressEvent(QKeyEvent *e);
//virtual Q3DragObject *dragObject(QWidget *parent);
//virtual Q3DragObject *dragObject() { return dragObject(this); }
virtual void decode(const QMimeData *s, PlaylistItem *item = 0);
virtual void contentsDropEvent(QDropEvent *e);
//virtual void contentsDragEnterEvent(QDragEnterEvent *e);
QStringList mimeTypes() const;
QMimeData* mimeData(const QList<QTreeWidgetItem *> items) const;
virtual bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action);
virtual void dropEvent(QDropEvent *e);
virtual void dragEnterEvent(QDragEnterEvent *e);
virtual void showEvent(QShowEvent *e);
virtual bool acceptDrag(QDropEvent *e) const;
virtual void paintEvent(QPaintEvent *pe);
......
......@@ -78,6 +78,7 @@ PlaylistBox::PlaylistBox(PlayerManager *player, QWidget *parent, QStackedWidget
setHeaderLabel("Playlists");
setRootIsDecorated(false);
setContextMenuPolicy(Qt::CustomContextMenu);
setDropIndicatorShown(true);
header()->blockSignals(true);
header()->hide();
......@@ -87,8 +88,8 @@ PlaylistBox::PlaylistBox(PlayerManager *player, QWidget *parent, QStackedWidget
// FIXME ?
//setFullWidth(true);
// FIXME drag
//setAcceptDrops(true);
viewport()->setAcceptDrops(true);
setDropIndicatorShown(true);
setSelectionMode(QAbstractItemView::ExtendedSelection);
m_contextMenu = new KMenu(this);
......@@ -487,22 +488,27 @@ void PlaylistBox::decode(const QMimeData *s, Item *item)
}
}
void PlaylistBox::contentsDropEvent(QDropEvent *e)
void PlaylistBox::dropEvent(QDropEvent *e)
{
m_showTimer->stop();
// FIXME drag
/*Item *i = static_cast<Item *>(itemAt(contentsToViewport(e->pos())));
Item *i = static_cast<Item *>(itemAt(e->pos()));
decode(e->mimeData(), i);
if(m_dropItem) {
Item *old = m_dropItem;
m_dropItem = 0;
old->repaint();
}*/
//old->repaint();
}
e->acceptProposedAction();
}
void PlaylistBox::dragEnterEvent(QDragEnterEvent *e)
{
e->acceptProposedAction();
}
void PlaylistBox::contentsDragMoveEvent(QDragMoveEvent *e)
void PlaylistBox::dragMoveEvent(QDragMoveEvent *e)
{
// If we can decode the input source, there is a non-null item at the "move"
// position, the playlist for that Item is non-null, is not the
......@@ -510,13 +516,12 @@ void PlaylistBox::contentsDragMoveEvent(QDragMoveEvent *e)
//
// Otherwise, do not accept the event.
// FIXME drag
/*if (!KUrl::List::canDecode(e->mimeData())) {
if (!e->mimeData()->hasUrls()) {
e->setAccepted(false);
return;
}
Item *target = static_cast<Item *>(itemAt(contentsToViewport(e->pos())));
Item *target = static_cast<Item *>(itemAt(e->pos()));
if(target) {
......@@ -530,8 +535,8 @@ void PlaylistBox::contentsDragMoveEvent(QDragMoveEvent *e)
if(dynamic_cast<Playlist *>(e->source())) {
if(target->playlist() &&
target->playlist() != CollectionList::instance() &&
!target->isSelected())
target->playlist() != CollectionList::instance() /*&&
!target->isSelected()*/)
{
e->setAccepted(true);
}
......@@ -547,15 +552,15 @@ void PlaylistBox::contentsDragMoveEvent(QDragMoveEvent *e)
if(e->isAccepted()) {
m_dropItem = target;
target->repaint();
//target->repaint();
m_showTimer->setSingleShot(true);
m_showTimer->start(1500);
}
else
m_dropItem = 0;
if(old)
old->repaint();
/*if(old)
old->repaint();*/
}
}
else {
......@@ -564,18 +569,17 @@ void PlaylistBox::contentsDragMoveEvent(QDragMoveEvent *e)
// possible to create new lists.
e->setAccepted(true);
}*/
}
}
void PlaylistBox::contentsDragLeaveEvent(QDragLeaveEvent *e)
void PlaylistBox::dragLeaveEvent(QDragLeaveEvent *e)
{
// FIXME drag
/*if(m_dropItem) {
if(m_dropItem) {
Item *old = m_dropItem;
m_dropItem = 0;
old->repaint();
//old->repaint();
}
QTreeWidget::contentsDragLeaveEvent(e);*/
QTreeWidget::dragLeaveEvent(e);
}
void PlaylistBox::mousePressEvent(QMouseEvent *e)
......
......@@ -92,9 +92,10 @@ private:
void saveConfig();
virtual void decode(const QMimeData *s, Item *item);
virtual void contentsDropEvent(QDropEvent *e);
virtual void contentsDragMoveEvent(QDragMoveEvent *e);
virtual void contentsDragLeaveEvent(QDragLeaveEvent *e);
virtual void dropEvent(QDropEvent *e);
virtual void dragEnterEvent(QDragEnterEvent *e);
virtual void dragMoveEvent(QDragMoveEvent *e);
virtual void dragLeaveEvent(QDragLeaveEvent *e);
virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseReleaseEvent(QMouseEvent *e);
virtual void keyPressEvent(QKeyEvent *e);
......
......@@ -159,12 +159,6 @@ QString PlaylistItem::text(int column) const
void PlaylistItem::setText(int column, const QString &text)
{
int offset = playlist()->columnOffset();
if(column - offset >= 0 && column + offset <= lastColumn()) {
QTreeWidgetItem::setText(column, QString());
return;
}
QTreeWidgetItem::setText(column, text);
playlist()->slotWeightDirty(column);
}
......@@ -280,8 +274,7 @@ PlaylistItem::PlaylistItem(CollectionList *parent) :
{
d = new Data;
m_collectionItem = static_cast<CollectionListItem *>(this);
// FIXME drag
//setDragEnabled(true);
setFlags(flags() | Qt::ItemIsDragEnabled);
}
// FIXME paintCell
......@@ -414,8 +407,14 @@ void PlaylistItem::setup(CollectionListItem *item)
d = item->d;
item->addChildItem(this);
// FIXME drag
//setDragEnabled(true);
setFlags(flags() | Qt::ItemIsDragEnabled);
int offset = playlist()->columnOffset();
int columns = lastColumn() + offset + 1;
for(int i = offset; i < columns; i++) {
setText(i, text(i));
}
}
////////////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment