Commit bafc8f27 authored by Scott Wheeler's avatar Scott Wheeler

More changes from Lars. I did a number of cosmetic changes; Lars, can

you check to make sure that I didn't leave anything out (that needs to be
there)?

=== from the mail with the patch ===
 The following issues are corected:
- files moved in a lists always get moved below an item dropped on, but the
  ui shows insertion marks above when moving above the upper half of an item.
- files dropped or pasted at a specific position in a playlist get added
  on top
- new items get always added at top of a playlist. It should be better to add
  them at  the end, especially if someone adds items to a playing list.
- multiple items get added in reversed order.

Detailed changes:

- insert before an item when dropping on the upper half of an item.
- Playlist signalFilesDroped, decode and
  PlaylistSplitter slotAddToPlaylist, addImpl are extended by the item
  after which the files should be added.
- The slotAddToPlaylist method without insert position now add items at the
  end of a list.
- remove decode method from CollectionList, it's duplicated from Playlist.

CCMAIL:hel@admin.de

svn path=/trunk/kdemultimedia/juk/; revision=240632
parent 37c87806
......@@ -130,21 +130,6 @@ CollectionList::~CollectionList()
delete m_dirWatch;
}
void CollectionList::decode(QMimeSource *s)
{
KURL::List urls;
if(!KURLDrag::decode(s, urls) || urls.isEmpty())
return;
QStringList files;
for(KURL::List::Iterator it = urls.begin(); it != urls.end(); it++)
files.append((*it).path());
emit signalFilesDropped(files, this);
}
void CollectionList::contentsDropEvent(QDropEvent *e)
{
if(e->source() == this)
......
......@@ -85,7 +85,6 @@ protected:
CollectionList(QWidget *parent);
virtual ~CollectionList();
virtual void decode(QMimeSource *s);
virtual void contentsDropEvent(QDropEvent *e);
virtual void contentsDragMoveEvent(QDragMoveEvent *e);
......
......@@ -444,7 +444,7 @@ void Playlist::copy()
void Playlist::paste()
{
decode(kapp->clipboard()->data());
decode(kapp->clipboard()->data(), currentItem());
}
void Playlist::clear()
......@@ -559,7 +559,7 @@ bool Playlist::canDecode(QMimeSource *s)
return KURLDrag::decode(s, urls) && !urls.isEmpty();
}
void Playlist::decode(QMimeSource *s)
void Playlist::decode(QMimeSource *s, QListViewItem *after)
{
KURL::List urls;
......@@ -571,7 +571,7 @@ void Playlist::decode(QMimeSource *s)
for(KURL::List::Iterator it = urls.begin(); it != urls.end(); it++)
fileList.append((*it).path());
emit signalFilesDropped(fileList, this);
emit signalFilesDropped(fileList, this, after);
}
bool Playlist::eventFilter(QObject* watched, QEvent* e)
......@@ -594,11 +594,19 @@ bool Playlist::eventFilter(QObject* watched, QEvent* e)
void Playlist::contentsDropEvent(QDropEvent *e)
{
if(e->source() == this) {
QPoint vp = contentsToViewport(e->pos());
QListViewItem *moveAfter = itemAt(vp);
// When dropping on the upper half of an item, insert before this item.
// This is what the user expects, and also allows the insertion at
// top of the list
QListViewItem *moveAfter = itemAt(contentsToViewport(e->pos()));
if(!moveAfter)
moveAfter = lastItem();
if(!moveAfter)
moveAfter = lastItem();
else if(vp.y() < moveAfter->itemPos() + moveAfter->height() / 2)
moveAfter = moveAfter->itemAbove();
if(e->source() == this) {
// Since we're trying to arrange things manually, turn off sorting.
......@@ -607,12 +615,22 @@ void Playlist::contentsDropEvent(QDropEvent *e)
QPtrList<QListViewItem> items = KListView::selectedItems();
for(QPtrListIterator<QListViewItem> it(items); it.current(); ++it) {
it.current()->moveItem(moveAfter);
if(!moveAfter) {
// Insert the item at the top of the list. This is a bit ugly,
// but I don't see another way.
takeItem(it.current());
insertItem(it.current());
}
else
it.current()->moveItem(moveAfter);
moveAfter = it.current();
}
}
else
decode(e);
decode(e, moveAfter);
}
void Playlist::showEvent(QShowEvent *e)
......
......@@ -257,7 +257,7 @@ protected:
virtual QDragObject *dragObject(QWidget *parent);
virtual QDragObject *dragObject() { return dragObject(this); }
virtual bool canDecode(QMimeSource *s);
virtual void decode(QMimeSource *s);
virtual void decode(QMimeSource *s, QListViewItem *after = 0);
virtual void contentsDropEvent(QDropEvent *e);
virtual void showEvent(QShowEvent *e);
virtual bool acceptDrag(QDropEvent *e) const { return KURLDrag::canDecode(e); }
......@@ -320,7 +320,7 @@ signals:
/**
* This is emitted when \a files are dropped on a specific playlist.
*/
void signalFilesDropped(const QStringList &files, Playlist *);
void signalFilesDropped(const QStringList &files, Playlist *, QListViewItem *after);
/**
* Set the next item to be played in the current playlist. This is used by
......
......@@ -350,10 +350,13 @@ void PlaylistSplitter::slotDeleteSelectedItems()
p->slotRemoveSelectedItems();
}
void PlaylistSplitter::slotAddToPlaylist(const QString &file, Playlist *list)
void PlaylistSplitter::slotAddToPlaylist(const QString &file, Playlist *list, PlaylistItem *after)
{
if(!after)
after = static_cast<PlaylistItem *>(list->lastItem());
KApplication::setOverrideCursor(Qt::waitCursor);
addImpl(file, list);
addImpl(file, list, after);
list->emitCountChanged();
KApplication::restoreOverrideCursor();
......@@ -369,12 +372,18 @@ void PlaylistSplitter::slotDeletePlaylist()
m_playlistBox->deleteItems();
}
void PlaylistSplitter::slotAddToPlaylist(const QStringList &files, Playlist *list)
void PlaylistSplitter::slotAddToPlaylist(const QStringList &files, Playlist *list, PlaylistItem *after)
{
if(!after)
after = static_cast<PlaylistItem *>(list->lastItem());
KApplication::setOverrideCursor(Qt::waitCursor);
for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it)
addImpl(*it, list);
after = addImpl(*it, list, after);
list->emitCountChanged();
KApplication::restoreOverrideCursor();
if(m_editor)
......@@ -553,7 +562,7 @@ void PlaylistSplitter::saveConfig()
}
}
void PlaylistSplitter::addImpl(const QString &file, Playlist *list)
PlaylistItem *PlaylistSplitter::addImpl(const QString &file, Playlist *list, PlaylistItem *after)
{
processEvents();
QFileInfo fileInfo(QDir::cleanDirPath(file));
......@@ -563,15 +572,16 @@ void PlaylistSplitter::addImpl(const QString &file, Playlist *list)
QStringList dirContents = dir.entryList();
for(QStringList::Iterator it = dirContents.begin(); it != dirContents.end(); ++it)
if(*it != "." && *it != "..")
addImpl(fileInfo.filePath() + QDir::separator() + *it, list);
after = addImpl(fileInfo.filePath() + QDir::separator() + *it, list, after);
}
else {
if(MediaFiles::isMediaFile(file))
list->createItem(fileInfo, QString::null, 0, false);
after = list->createItem(fileInfo, QString::null, after, false);
else if(MediaFiles::isPlaylistFile(file))
openPlaylist(fileInfo.absFilePath());
}
}
return after;
}
void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon, bool sortedFirst)
......@@ -591,8 +601,8 @@ void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon,
connect(p, SIGNAL(signalAboutToRemove(PlaylistItem *)),
this, SLOT(slotPlaylistItemRemoved(PlaylistItem *)));
connect(p, SIGNAL(signalFilesDropped(const QStringList &, Playlist *)),
this, SLOT(slotAddToPlaylist(const QStringList &, Playlist *)));
connect(p, SIGNAL(signalFilesDropped(const QStringList &, Playlist *, PlaylistItem *)),
this, SLOT(slotAddToPlaylist(const QStringList &, Playlist *, PlaylistItem *)));
connect(p, SIGNAL(signalSetNext(PlaylistItem *)),
this, SLOT(slotSetNextItem(PlaylistItem *)));
......
......@@ -238,14 +238,16 @@ public slots:
void slotSetSearchVisible(bool visible);
/**
* Add the file to the playlist.
* Add the file to the playlist. If \a after is null the items will be
* inserted at the end of the list.
*/
void slotAddToPlaylist(const QString &file, Playlist *list);
void slotAddToPlaylist(const QString &file, Playlist *list, PlaylistItem *after = 0);
/**
* Adds the files to the playlist.
* Adds the files to the playlist. If \a after is null the items will be
* inserted at the end of the list.
*/
void slotAddToPlaylist(const QStringList &files, Playlist *list);
void slotAddToPlaylist(const QStringList &files, Playlist *list, PlaylistItem *after = 0);
// PlaylistBox forwarding slots
......@@ -279,9 +281,16 @@ private:
void setupLayout();
void readConfig();
void saveConfig();
void addImpl(const QString &file, Playlist *list);
/**
* Adds the file or directory \a file to the Playlist \a list. If \a after
* is not null the items will be inserted after it. Returns a pointer to the
* last item inserted.
*/
PlaylistItem *addImpl(const QString &file, Playlist *list, PlaylistItem *after = 0);
/**
* If NULL is passed for the icon, no entry is created in the PlaylistBox
* If null is passed for the icon, no entry is created in the PlaylistBox
*/
void setupPlaylist(Playlist *p, bool raise = false, const char *icon = "midi", bool sortedFirst = false);
......
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