Right click menu for the file view
This commit is contained in:
parent
15158805af
commit
66478974cd
Binary file not shown.
After Width: | Height: | Size: 485 B |
|
@ -1,5 +1,5 @@
|
||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/">
|
<qresource prefix="/" >
|
||||||
<file>clear.png</file>
|
<file>clear.png</file>
|
||||||
<file>go-home.png</file>
|
<file>go-home.png</file>
|
||||||
<file>go-next.png</file>
|
<file>go-next.png</file>
|
||||||
|
@ -31,5 +31,7 @@
|
||||||
<file>folder.png</file>
|
<file>folder.png</file>
|
||||||
<file>configure.png</file>
|
<file>configure.png</file>
|
||||||
<file>exit.png</file>
|
<file>exit.png</file>
|
||||||
|
<file>copy.png</file>
|
||||||
|
<file>move.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 426 B |
|
@ -24,6 +24,9 @@ FileView::FileView(QWidget* parent)
|
||||||
|
|
||||||
connect(ui_.list, SIGNAL(activated(QModelIndex)), SLOT(ItemActivated(QModelIndex)));
|
connect(ui_.list, SIGNAL(activated(QModelIndex)), SLOT(ItemActivated(QModelIndex)));
|
||||||
connect(ui_.list, SIGNAL(doubleClicked(QModelIndex)), SLOT(ItemDoubleClick(QModelIndex)));
|
connect(ui_.list, SIGNAL(doubleClicked(QModelIndex)), SLOT(ItemDoubleClick(QModelIndex)));
|
||||||
|
connect(ui_.list, SIGNAL(AddToPlaylist(QList<QUrl>)), SIGNAL(Queue(QList<QUrl>)));
|
||||||
|
connect(ui_.list, SIGNAL(CopyToLibrary(QList<QUrl>)), SIGNAL(CopyToLibrary(QList<QUrl>)));
|
||||||
|
connect(ui_.list, SIGNAL(MoveToLibrary(QList<QUrl>)), SIGNAL(MoveToLibrary(QList<QUrl>)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileView::SetPath(const QString& path) {
|
void FileView::SetPath(const QString& path) {
|
||||||
|
@ -83,5 +86,5 @@ void FileView::ItemDoubleClick(const QModelIndex& index) {
|
||||||
if (model_->isDir(index))
|
if (model_->isDir(index))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
emit PlayFile(model_->filePath(index));
|
emit Queue(QList<QUrl>() << QUrl::fromLocalFile(model_->filePath(index)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,9 @@ class FileView : public QWidget {
|
||||||
signals:
|
signals:
|
||||||
void PathChanged(const QString& path);
|
void PathChanged(const QString& path);
|
||||||
|
|
||||||
void PlayFile(const QString& path);
|
void Queue(const QList<QUrl>& urls);
|
||||||
void PlayDirectory(const QString& path);
|
void CopyToLibrary(const QList<QUrl>& urls);
|
||||||
|
void MoveToLibrary(const QList<QUrl>& urls);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void FileUp();
|
void FileUp();
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset resource="../data/data.qrc">
|
||||||
<normaloff>:/go-previous.png</normaloff>:/go-previous.png</iconset>
|
<normaloff>:/go-previous.png</normaloff>:/go-previous.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="autoRaise">
|
<property name="autoRaise">
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
<string>...</string>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset resource="../data/data.qrc">
|
||||||
<normaloff>:/go-next.png</normaloff>:/go-next.png</iconset>
|
<normaloff>:/go-next.png</normaloff>:/go-next.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="autoRaise">
|
<property name="autoRaise">
|
||||||
|
@ -62,7 +62,7 @@
|
||||||
<string>...</string>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset resource="../data/data.qrc">
|
||||||
<normaloff>:/go-up.png</normaloff>:/go-up.png</iconset>
|
<normaloff>:/go-up.png</normaloff>:/go-up.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="autoRaise">
|
<property name="autoRaise">
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
<string>...</string>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset resource="../data/data.qrc">
|
||||||
<normaloff>:/go-home.png</normaloff>:/go-home.png</iconset>
|
<normaloff>:/go-home.png</normaloff>:/go-home.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="autoRaise">
|
<property name="autoRaise">
|
||||||
|
@ -90,7 +90,7 @@
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListView" name="list">
|
<widget class="FileViewList" name="list">
|
||||||
<property name="dragEnabled">
|
<property name="dragEnabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
@ -107,6 +107,15 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>FileViewList</class>
|
||||||
|
<extends>QListView</extends>
|
||||||
|
<header>fileviewlist.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources>
|
||||||
|
<include location="../data/data.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
#include "fileviewlist.h"
|
||||||
|
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QContextMenuEvent>
|
||||||
|
#include <QFileSystemModel>
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
|
FileViewList::FileViewList(QWidget* parent)
|
||||||
|
: QListView(parent),
|
||||||
|
menu_(new QMenu(this))
|
||||||
|
{
|
||||||
|
menu_->addAction(QIcon(":media-playback-start.png"), "Add to playlist",
|
||||||
|
this, SLOT(AddToPlaylistSlot()));
|
||||||
|
menu_->addSeparator();
|
||||||
|
menu_->addAction(QIcon(":copy.png"), "Copy to library...",
|
||||||
|
this, SLOT(CopyToLibrarySlot()));
|
||||||
|
menu_->addAction(QIcon(":move.png"),"Move to library...",
|
||||||
|
this, SLOT(MoveToLibrarySlot()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileViewList::contextMenuEvent(QContextMenuEvent* e) {
|
||||||
|
menu_selection_ = selectionModel()->selection();
|
||||||
|
|
||||||
|
menu_->popup(e->globalPos());
|
||||||
|
e->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QUrl> FileViewList::UrlListFromSelection() const {
|
||||||
|
QList<QUrl> urls;
|
||||||
|
foreach (const QModelIndex& index, menu_selection_.indexes()) {
|
||||||
|
if (index.column() == 0)
|
||||||
|
urls << QUrl::fromLocalFile(
|
||||||
|
static_cast<QFileSystemModel*>(model())->filePath(index));
|
||||||
|
}
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileViewList::AddToPlaylistSlot() {
|
||||||
|
emit AddToPlaylist(UrlListFromSelection());
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileViewList::CopyToLibrarySlot() {
|
||||||
|
emit CopyToLibrary(UrlListFromSelection());
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileViewList::MoveToLibrarySlot() {
|
||||||
|
emit MoveToLibrary(UrlListFromSelection());
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
#ifndef FILEVIEWLIST_H
|
||||||
|
#define FILEVIEWLIST_H
|
||||||
|
|
||||||
|
#include <QListView>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
class FileViewList : public QListView {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
FileViewList(QWidget* parent = 0);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void AddToPlaylist(const QList<QUrl>& urls);
|
||||||
|
void CopyToLibrary(const QList<QUrl>& urls);
|
||||||
|
void MoveToLibrary(const QList<QUrl>& urls);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void contextMenuEvent(QContextMenuEvent* e);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void AddToPlaylistSlot();
|
||||||
|
void CopyToLibrarySlot();
|
||||||
|
void MoveToLibrarySlot();
|
||||||
|
|
||||||
|
QList<QUrl> UrlListFromSelection() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QMenu* menu_;
|
||||||
|
QItemSelection menu_selection_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FILEVIEWLIST_H
|
|
@ -48,7 +48,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
ui_.library_view->SetLibrary(library_);
|
ui_.library_view->SetLibrary(library_);
|
||||||
|
|
||||||
// File view connections
|
// File view connections
|
||||||
connect(ui_.file_view, SIGNAL(PlayFile(QString)), SLOT(PlayFile(QString)));
|
connect(ui_.file_view, SIGNAL(Queue(QList<QUrl>)), SLOT(QueueFiles(QList<QUrl>)));
|
||||||
connect(ui_.file_view, SIGNAL(PathChanged(QString)), SLOT(FilePathChanged(QString)));
|
connect(ui_.file_view, SIGNAL(PathChanged(QString)), SLOT(FilePathChanged(QString)));
|
||||||
|
|
||||||
// Action connections
|
// Action connections
|
||||||
|
@ -176,14 +176,8 @@ MainWindow::~MainWindow() {
|
||||||
SaveGeometry();
|
SaveGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::PlayFile(const QString& path) {
|
void MainWindow::QueueFiles(const QList<QUrl>& urls) {
|
||||||
Song song;
|
QModelIndex playlist_index = playlist_->InsertPaths(urls);
|
||||||
song.InitFromFile(path, -1);
|
|
||||||
|
|
||||||
if (!song.is_valid())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QModelIndex playlist_index = playlist_->InsertSongs(SongList() << song);
|
|
||||||
|
|
||||||
if (playlist_index.isValid() && player_->GetState() != Engine::Playing)
|
if (playlist_index.isValid() && player_->GetState() != Engine::Playing)
|
||||||
player_->PlayAt(playlist_index.row());
|
player_->PlayAt(playlist_index.row());
|
||||||
|
|
|
@ -28,7 +28,7 @@ class MainWindow : public QMainWindow {
|
||||||
void closeEvent(QCloseEvent* event);
|
void closeEvent(QCloseEvent* event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void PlayFile(const QString& path);
|
void QueueFiles(const QList<QUrl>& urls);
|
||||||
void FilePathChanged(const QString& path);
|
void FilePathChanged(const QString& path);
|
||||||
|
|
||||||
void ReportError(const QString& message);
|
void ReportError(const QString& message);
|
||||||
|
|
|
@ -158,48 +158,52 @@ bool Playlist::dropMimeData(const QMimeData* data, Qt::DropAction action, int ro
|
||||||
layoutChanged();
|
layoutChanged();
|
||||||
|
|
||||||
} else if (data->hasUrls()) {
|
} else if (data->hasUrls()) {
|
||||||
// URL list dragged from some other app probably
|
// URL list dragged from the file list or some other app
|
||||||
SongList songs;
|
InsertPaths(data->urls(), row);
|
||||||
foreach (const QUrl& url, data->urls()) {
|
}
|
||||||
if (url.scheme() != "file")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
QString filename(url.toLocalFile());
|
return true;
|
||||||
QFileInfo info(filename);
|
}
|
||||||
|
|
||||||
if (!info.exists())
|
QModelIndex Playlist::InsertPaths(const QList<QUrl>& urls, int after) {
|
||||||
continue;
|
SongList songs;
|
||||||
|
foreach (const QUrl& url, urls) {
|
||||||
|
if (url.scheme() != "file")
|
||||||
|
continue;
|
||||||
|
|
||||||
if (info.isDir()) {
|
QString filename(url.toLocalFile());
|
||||||
// Add all the songs in the directory
|
QFileInfo info(filename);
|
||||||
QDirIterator it(filename,
|
|
||||||
QDir::Files | QDir::NoDotAndDotDot | QDir::Readable,
|
|
||||||
QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
|
|
||||||
|
|
||||||
while (it.hasNext()) {
|
if (!info.exists())
|
||||||
QString path(it.next());
|
continue;
|
||||||
|
|
||||||
Song song;
|
if (info.isDir()) {
|
||||||
song.InitFromFile(path, -1);
|
// Add all the songs in the directory
|
||||||
if (!song.is_valid())
|
QDirIterator it(filename,
|
||||||
continue;
|
QDir::Files | QDir::NoDotAndDotDot | QDir::Readable,
|
||||||
|
QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
|
||||||
|
|
||||||
|
while (it.hasNext()) {
|
||||||
|
QString path(it.next());
|
||||||
|
|
||||||
songs << song;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Song song;
|
Song song;
|
||||||
song.InitFromFile(filename, -1);
|
song.InitFromFile(path, -1);
|
||||||
if (!song.is_valid())
|
if (!song.is_valid())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
songs << song;
|
songs << song;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
Song song;
|
||||||
|
song.InitFromFile(filename, -1);
|
||||||
|
if (!song.is_valid())
|
||||||
|
continue;
|
||||||
|
|
||||||
InsertSongs(songs, row);
|
songs << song;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return InsertSongs(songs, after);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex Playlist::InsertItems(const QList<PlaylistItem*>& items, int after) {
|
QModelIndex Playlist::InsertItems(const QList<PlaylistItem*>& items, int after) {
|
||||||
|
|
|
@ -49,6 +49,7 @@ class Playlist : public QAbstractListModel {
|
||||||
// Changing the playlist
|
// Changing the playlist
|
||||||
QModelIndex InsertItems(const QList<PlaylistItem*>& items, int after = -1);
|
QModelIndex InsertItems(const QList<PlaylistItem*>& items, int after = -1);
|
||||||
QModelIndex InsertSongs(const SongList& items, int after = -1);
|
QModelIndex InsertSongs(const SongList& items, int after = -1);
|
||||||
|
QModelIndex InsertPaths(const QList<QUrl>& urls, int after = -1);
|
||||||
void StopAfter(int row);
|
void StopAfter(int row);
|
||||||
|
|
||||||
// QAbstractListModel
|
// QAbstractListModel
|
||||||
|
|
|
@ -31,7 +31,8 @@ SOURCES += main.cpp \
|
||||||
libraryconfig.cpp \
|
libraryconfig.cpp \
|
||||||
systemtrayicon.cpp \
|
systemtrayicon.cpp \
|
||||||
libraryquery.cpp \
|
libraryquery.cpp \
|
||||||
fileview.cpp
|
fileview.cpp \
|
||||||
|
fileviewlist.cpp
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
player.h \
|
player.h \
|
||||||
library.h \
|
library.h \
|
||||||
|
@ -59,7 +60,8 @@ HEADERS += mainwindow.h \
|
||||||
libraryconfig.h \
|
libraryconfig.h \
|
||||||
systemtrayicon.h \
|
systemtrayicon.h \
|
||||||
libraryquery.h \
|
libraryquery.h \
|
||||||
fileview.h
|
fileview.h \
|
||||||
|
fileviewlist.h
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
libraryconfig.ui \
|
libraryconfig.ui \
|
||||||
fileview.ui
|
fileview.ui
|
||||||
|
|
Loading…
Reference in New Issue