aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2013-08-13 16:41:14 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2013-08-13 16:41:14 +0000
commit14ff3ad8079147ef188270eb10631c0c2962435d (patch)
treebe428491ac41b06c8c8c85df8c5ddaefb761e76c /src
parent48a0ee1fcdac69def507f6d3a31ff6ee32b19480 (diff)
downloadqmmp-14ff3ad8079147ef188270eb10631c0c2962435d.tar.gz
qmmp-14ff3ad8079147ef188270eb10631c0c2962435d.tar.bz2
qmmp-14ff3ad8079147ef188270eb10631c0c2962435d.zip
enabled item moving feature
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3592 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
-rw-r--r--src/qmmpui/playlistcontainer.cpp49
-rw-r--r--src/qmmpui/playlistcontainer.h2
-rw-r--r--src/qmmpui/playlistgroup.cpp5
-rw-r--r--src/qmmpui/playlistgroup.h2
-rw-r--r--src/qmmpui/playlistmodel.cpp52
5 files changed, 91 insertions, 19 deletions
diff --git a/src/qmmpui/playlistcontainer.cpp b/src/qmmpui/playlistcontainer.cpp
index 4cde4d195..6f0297061 100644
--- a/src/qmmpui/playlistcontainer.cpp
+++ b/src/qmmpui/playlistcontainer.cpp
@@ -197,6 +197,55 @@ void PlayListContainer::removeTracks(QList<PlayListTrack *> tracks)
removeTrack(t);
}
+void PlayListContainer::move(QList<int> indexes, int from, int to)
+{
+ PlayListGroup *group = 0;
+
+ foreach (PlayListGroup *g, m_groups)
+ {
+ if(from > g->firstIndex && from <= g->lastIndex &&
+ to > g->firstIndex && to <= g->lastIndex)
+ {
+ group = g;
+ break;
+ }
+ }
+
+ if(!group)
+ return;
+
+ foreach (int i, indexes)
+ {
+ if(i <= group->firstIndex || i > group->lastIndex)
+ return;
+ }
+
+ if (from > to)
+ foreach(int i, indexes)
+ {
+ if (i + to - from < 0)
+ break;
+ else
+ {
+ m_items.move(i,i + to - from);
+ group->move(i - group->firstIndex - 1,
+ i + to - from - group->firstIndex - 1);
+ }
+ }
+ else
+ for (int i = indexes.count() - 1; i >= 0; i--)
+ {
+ if (indexes[i] + to - from >= m_items.count())
+ break;
+ else
+ {
+ m_items.move(indexes[i], indexes[i] + to - from);
+ group->move(indexes[i] - group->firstIndex - 1,
+ indexes[i] + to - from - group->firstIndex - 1);
+ }
+ }
+}
+
void PlayListContainer::clear()
{
while(!m_groups.isEmpty())
diff --git a/src/qmmpui/playlistcontainer.h b/src/qmmpui/playlistcontainer.h
index bbbf4d3df..159a64b6c 100644
--- a/src/qmmpui/playlistcontainer.h
+++ b/src/qmmpui/playlistcontainer.h
@@ -55,6 +55,8 @@ public:
void removeTrack(PlayListTrack *track);
void removeTracks(QList<PlayListTrack *> tracks);
+ void move(QList<int> indexes, int from, int to);
+
void clear();
private:
diff --git a/src/qmmpui/playlistgroup.cpp b/src/qmmpui/playlistgroup.cpp
index f6c7c943a..f0ddf8470 100644
--- a/src/qmmpui/playlistgroup.cpp
+++ b/src/qmmpui/playlistgroup.cpp
@@ -78,3 +78,8 @@ int PlayListGroup::count() const
{
return m_tracks.count();
}
+
+void PlayListGroup::move(int from, int to)
+{
+ m_tracks.move(from, to);
+}
diff --git a/src/qmmpui/playlistgroup.h b/src/qmmpui/playlistgroup.h
index e6c5b119a..4f37fd381 100644
--- a/src/qmmpui/playlistgroup.h
+++ b/src/qmmpui/playlistgroup.h
@@ -53,6 +53,8 @@ public:
virtual bool isGroup() const { return true; }
+ void move(int from, int to);
+
private:
QList<PlayListTrack *> m_tracks;
QString m_name;
diff --git a/src/qmmpui/playlistmodel.cpp b/src/qmmpui/playlistmodel.cpp
index 7f0b67dd8..ab97fae0c 100644
--- a/src/qmmpui/playlistmodel.cpp
+++ b/src/qmmpui/playlistmodel.cpp
@@ -39,7 +39,7 @@
#include "tagupdater_p.h"
#include "playlistmodel.h"
-#define INVALID_ROW -1
+#define INVALID_INDEX -1
PlayListModel::PlayListModel(const QString &name, QObject *parent)
: QObject(parent) , m_selection()
@@ -128,7 +128,6 @@ void PlayListModel::add(const QString &path)
m_loader->loadFile(path);
loadPlaylist(path);
}
-
}
void PlayListModel::add(const QStringList &paths)
@@ -477,33 +476,48 @@ int PlayListModel::totalLength() const
void PlayListModel::moveItems(int from, int to)
{
// Get rid of useless work
- /*if (from == to)
+ if (from == to)
return;
- QList<int> selected_rows = selectedIndexes();
+ QList<int> selected_indexes = selectedIndexes();
+
+ if(selected_indexes.isEmpty())
+ return;
- if (!(bottommostInSelection(from) == INVALID_ROW ||
- from == INVALID_ROW ||
- topmostInSelection(from) == INVALID_ROW)
- )
+ foreach(int i, selected_indexes) //do no move groups
{
- if (from > to)
- foreach(int i, selected_rows)
+ if(!isTrack(i))
+ return;
+ }
+
+ if (bottommostInSelection(from) == INVALID_INDEX ||
+ from == INVALID_INDEX ||
+ topmostInSelection(from) == INVALID_INDEX)
+ return;
+
+ m_container.move(selected_indexes, from, to);
+
+ /*if (from > to)
+ foreach(int i, selected_indexes)
+ {
if (i + to - from < 0)
break;
+
else
m_items.move(i,i + to - from);
- else
- for (int i = selected_rows.count() - 1; i >= 0; i--)
- if (selected_rows[i] + to -from >= m_items.count())
- break;
- else
- m_items.move(selected_rows[i],selected_rows[i] + to - from);
-
- m_current = m_items.indexOf(m_currentItem);
+ }
+ else
- emit listChanged();
+ for (int i = selected_indexes.count() - 1; i >= 0; i--)
+ {
+ if (selected_indexes[i] + to -from >= m_items.count())
+ break;
+ else
+ m_items.move(selected_indexes[i],selected_indexes[i] + to - from);
}*/
+
+ m_current = m_container.indexOf(m_current_track);
+ emit listChanged();
}
int PlayListModel::topmostInSelection(int row)