mirror of
https://github.com/libretro/RetroArch
synced 2025-02-22 03:40:43 +00:00
Qt: only allow dropping files onto center list/grid view
This commit is contained in:
parent
489601fadb
commit
c883a81c42
@ -32,6 +32,8 @@
|
|||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
|
#include <QDragEnterEvent>
|
||||||
|
#include <QDropEvent>
|
||||||
#include <QtConcurrentRun>
|
#include <QtConcurrentRun>
|
||||||
|
|
||||||
#include "../ui_qt.h"
|
#include "../ui_qt.h"
|
||||||
@ -143,6 +145,40 @@ inline static bool comp_hash_label_key_lower(const QHash<QString, QString> &lhs,
|
|||||||
return lhs.value("label").toLower() < rhs.value("label").toLower();
|
return lhs.value("label").toLower() < rhs.value("label").toLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void addDirectoryFilesToList(QStringList &list, QDir &dir)
|
||||||
|
{
|
||||||
|
QStringList dirList = dir.entryList(QStringList(), QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System, QDir::Name);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < dirList.count(); i++)
|
||||||
|
{
|
||||||
|
QString path(dir.path() + "/" + dirList.at(i));
|
||||||
|
QFileInfo fileInfo(path);
|
||||||
|
|
||||||
|
if (fileInfo.isDir())
|
||||||
|
{
|
||||||
|
QDir fileInfoDir(path);
|
||||||
|
|
||||||
|
addDirectoryFilesToList(list, fileInfoDir);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileInfo.isFile())
|
||||||
|
{
|
||||||
|
list.append(fileInfo.absoluteFilePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* https://gist.github.com/andrey-str/0f9c7709cbf0c9c49ef9 */
|
||||||
|
static void setElidedText(QLabel *label, QWidget *clipWidget, int padding, const QString &text)
|
||||||
|
{
|
||||||
|
QFontMetrics metrix(label->font());
|
||||||
|
int width = clipWidget->width() - padding;
|
||||||
|
QString clippedText = metrix.elidedText(text, Qt::ElideRight, width);
|
||||||
|
label->setText(clippedText);
|
||||||
|
}
|
||||||
|
|
||||||
GridItem::GridItem() :
|
GridItem::GridItem() :
|
||||||
QObject()
|
QObject()
|
||||||
,widget(NULL)
|
,widget(NULL)
|
||||||
@ -155,15 +191,6 @@ GridItem::GridItem() :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/* https://gist.github.com/andrey-str/0f9c7709cbf0c9c49ef9 */
|
|
||||||
static void setElidedText(QLabel *label, QWidget *clipWidget, int padding, const QString &text)
|
|
||||||
{
|
|
||||||
QFontMetrics metrix(label->font());
|
|
||||||
int width = clipWidget->width() - padding;
|
|
||||||
QString clippedText = metrix.elidedText(text, Qt::ElideRight, width);
|
|
||||||
label->setText(clippedText);
|
|
||||||
}
|
|
||||||
|
|
||||||
TreeView::TreeView(QWidget *parent) :
|
TreeView::TreeView(QWidget *parent) :
|
||||||
QTreeView(parent)
|
QTreeView(parent)
|
||||||
{
|
{
|
||||||
@ -183,6 +210,41 @@ void TreeView::selectionChanged(const QItemSelection &selected, const QItemSelec
|
|||||||
emit itemsSelected(list);
|
emit itemsSelected(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileDropWidget::FileDropWidget(QWidget *parent) :
|
||||||
|
QWidget(parent)
|
||||||
|
{
|
||||||
|
setAcceptDrops(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDropWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
const QMimeData *data = event->mimeData();
|
||||||
|
|
||||||
|
if (data->hasUrls())
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileDropWidget::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
const QMimeData *data = event->mimeData();
|
||||||
|
|
||||||
|
if (data->hasUrls())
|
||||||
|
{
|
||||||
|
QList<QUrl> urls = data->urls();
|
||||||
|
QStringList files;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < urls.count(); i++)
|
||||||
|
{
|
||||||
|
QString path(urls.at(i).toLocalFile());
|
||||||
|
|
||||||
|
files.append(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit filesDropped(files);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TableWidget::TableWidget(QWidget *parent) :
|
TableWidget::TableWidget(QWidget *parent) :
|
||||||
QTableWidget(parent)
|
QTableWidget(parent)
|
||||||
{
|
{
|
||||||
@ -714,7 +776,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
,m_gridWidget(new QWidget(this))
|
,m_gridWidget(new QWidget(this))
|
||||||
,m_gridScrollArea(new QScrollArea(m_gridWidget))
|
,m_gridScrollArea(new QScrollArea(m_gridWidget))
|
||||||
,m_gridItems()
|
,m_gridItems()
|
||||||
,m_gridLayoutWidget(new QWidget())
|
,m_gridLayoutWidget(new FileDropWidget())
|
||||||
,m_zoomSlider(NULL)
|
,m_zoomSlider(NULL)
|
||||||
,m_lastZoomSliderValue(0)
|
,m_lastZoomSliderValue(0)
|
||||||
,m_pendingItemUpdates()
|
,m_pendingItemUpdates()
|
||||||
@ -746,8 +808,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
|
|
||||||
qRegisterMetaType<QPointer<ThumbnailWidget> >("ThumbnailWidget");
|
qRegisterMetaType<QPointer<ThumbnailWidget> >("ThumbnailWidget");
|
||||||
|
|
||||||
setAcceptDrops(true);
|
|
||||||
|
|
||||||
m_gridProgressWidget = new QWidget();
|
m_gridProgressWidget = new QWidget();
|
||||||
gridProgressLabel = new QLabel(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_PROGRESS), m_gridProgressWidget);
|
gridProgressLabel = new QLabel(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_PROGRESS), m_gridProgressWidget);
|
||||||
|
|
||||||
@ -935,6 +995,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(onZoomValueChanged(int)));
|
connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(onZoomValueChanged(int)));
|
||||||
connect(viewTypeIconsAction, SIGNAL(triggered()), this, SLOT(onIconViewClicked()));
|
connect(viewTypeIconsAction, SIGNAL(triggered()), this, SLOT(onIconViewClicked()));
|
||||||
connect(viewTypeListAction, SIGNAL(triggered()), this, SLOT(onListViewClicked()));
|
connect(viewTypeListAction, SIGNAL(triggered()), this, SLOT(onListViewClicked()));
|
||||||
|
connect(m_tableWidget, SIGNAL(filesDropped(QStringList)), this, SLOT(onPlaylistFilesDropped(QStringList)));
|
||||||
|
connect(m_gridLayoutWidget, SIGNAL(filesDropped(QStringList)), this, SLOT(onPlaylistFilesDropped(QStringList)));
|
||||||
|
|
||||||
/* make sure these use an auto connection so it will be queued if called from a different thread (some facilities in RA log messages from other threads) */
|
/* make sure these use an auto connection so it will be queued if called from a different thread (some facilities in RA log messages from other threads) */
|
||||||
connect(this, SIGNAL(gotLogMessage(const QString&)), this, SLOT(onGotLogMessage(const QString&)), Qt::AutoConnection);
|
connect(this, SIGNAL(gotLogMessage(const QString&)), this, SLOT(onGotLogMessage(const QString&)), Qt::AutoConnection);
|
||||||
@ -972,46 +1034,14 @@ MainWindow::~MainWindow()
|
|||||||
removeGridItems();
|
removeGridItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
|
void MainWindow::onPlaylistFilesDropped(QStringList files)
|
||||||
{
|
{
|
||||||
const QMimeData *data = event->mimeData();
|
addFilesToPlaylist(files);
|
||||||
|
|
||||||
if (data->hasUrls())
|
|
||||||
event->acceptProposedAction();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addDirectoryFilesToList(QStringList &list, QDir &dir)
|
/* Takes a list of files and folders and adds them to the currently selected playlist. Folders will have their contents added recursively. */
|
||||||
|
void MainWindow::addFilesToPlaylist(QStringList files)
|
||||||
{
|
{
|
||||||
QStringList dirList = dir.entryList(QStringList(), QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System, QDir::Name);
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < dirList.count(); i++)
|
|
||||||
{
|
|
||||||
QString path(dir.path() + "/" + dirList.at(i));
|
|
||||||
QFileInfo fileInfo(path);
|
|
||||||
|
|
||||||
if (fileInfo.isDir())
|
|
||||||
{
|
|
||||||
QDir fileInfoDir(path);
|
|
||||||
|
|
||||||
addDirectoryFilesToList(list, fileInfoDir);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileInfo.isFile())
|
|
||||||
{
|
|
||||||
list.append(fileInfo.absoluteFilePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::dropEvent(QDropEvent *event)
|
|
||||||
{
|
|
||||||
const QMimeData *data = event->mimeData();
|
|
||||||
|
|
||||||
if (data->hasUrls())
|
|
||||||
{
|
|
||||||
QList<QUrl> urls = data->urls();
|
|
||||||
QStringList list;
|
QStringList list;
|
||||||
QString currentPlaylistPath;
|
QString currentPlaylistPath;
|
||||||
QListWidgetItem *currentItem = m_listWidget->currentItem();
|
QListWidgetItem *currentItem = m_listWidget->currentItem();
|
||||||
@ -1044,9 +1074,9 @@ void MainWindow::dropEvent(QDropEvent *event)
|
|||||||
dialog.reset(new QProgressDialog(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_GATHERING_LIST_OF_FILES), "Cancel", 0, 0, this));
|
dialog.reset(new QProgressDialog(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_GATHERING_LIST_OF_FILES), "Cancel", 0, 0, this));
|
||||||
dialog->setWindowModality(Qt::ApplicationModal);
|
dialog->setWindowModality(Qt::ApplicationModal);
|
||||||
|
|
||||||
for (i = 0; i < urls.count(); i++)
|
for (i = 0; i < files.count(); i++)
|
||||||
{
|
{
|
||||||
QString path(urls.at(i).toLocalFile());
|
QString path(files.at(i));
|
||||||
QFileInfo fileInfo(path);
|
QFileInfo fileInfo(path);
|
||||||
|
|
||||||
if (dialog->wasCanceled())
|
if (dialog->wasCanceled())
|
||||||
@ -1157,7 +1187,6 @@ void MainWindow::dropEvent(QDropEvent *event)
|
|||||||
playlist_free(playlist);
|
playlist_free(playlist);
|
||||||
|
|
||||||
reloadPlaylists();
|
reloadPlaylists();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onGridItemClicked()
|
void MainWindow::onGridItemClicked()
|
||||||
|
@ -275,9 +275,11 @@ static void* ui_companion_qt_init(void)
|
|||||||
|
|
||||||
listWidget = mainwindow->playlistListWidget();
|
listWidget = mainwindow->playlistListWidget();
|
||||||
|
|
||||||
widget = new QWidget(mainwindow);
|
widget = new FileDropWidget(mainwindow);
|
||||||
widget->setObjectName("tableWidget");
|
widget->setObjectName("tableWidget");
|
||||||
|
|
||||||
|
QObject::connect(widget, SIGNAL(filesDropped(QStringList)), mainwindow, SLOT(onPlaylistFilesDropped(QStringList)));
|
||||||
|
|
||||||
layout = new QVBoxLayout();
|
layout = new QVBoxLayout();
|
||||||
layout->addWidget(mainwindow->contentTableWidget());
|
layout->addWidget(mainwindow->contentTableWidget());
|
||||||
layout->addWidget(mainwindow->contentGridWidget());
|
layout->addWidget(mainwindow->contentGridWidget());
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QProgressBar>
|
#include <QProgressBar>
|
||||||
#include <QDragEnterEvent>
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <retro_assert.h>
|
#include <retro_assert.h>
|
||||||
@ -65,6 +64,8 @@ class QFormLayout;
|
|||||||
class QStyle;
|
class QStyle;
|
||||||
class QScrollArea;
|
class QScrollArea;
|
||||||
class QSlider;
|
class QSlider;
|
||||||
|
class QDragEnterEvent;
|
||||||
|
class QDropEvent;
|
||||||
class LoadCoreWindow;
|
class LoadCoreWindow;
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
class ThumbnailWidget;
|
class ThumbnailWidget;
|
||||||
@ -139,6 +140,18 @@ protected slots:
|
|||||||
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class FileDropWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
FileDropWidget(QWidget *parent = 0);
|
||||||
|
signals:
|
||||||
|
void filesDropped(QStringList files);
|
||||||
|
protected:
|
||||||
|
void dragEnterEvent(QDragEnterEvent *event);
|
||||||
|
void dropEvent(QDropEvent *event);
|
||||||
|
};
|
||||||
|
|
||||||
class TableWidget : public QTableWidget
|
class TableWidget : public QTableWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -146,7 +159,7 @@ public:
|
|||||||
TableWidget(QWidget *parent = 0);
|
TableWidget(QWidget *parent = 0);
|
||||||
signals:
|
signals:
|
||||||
void enterPressed();
|
void enterPressed();
|
||||||
protected slots:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -322,6 +335,7 @@ public:
|
|||||||
void setAllPlaylistsListMaxCount(int count);
|
void setAllPlaylistsListMaxCount(int count);
|
||||||
void setAllPlaylistsGridMaxCount(int count);
|
void setAllPlaylistsGridMaxCount(int count);
|
||||||
PlaylistEntryDialog* playlistEntryDialog();
|
PlaylistEntryDialog* playlistEntryDialog();
|
||||||
|
void addFilesToPlaylist(QStringList files);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void thumbnailChanged(const QPixmap &pixmap);
|
void thumbnailChanged(const QPixmap &pixmap);
|
||||||
@ -389,6 +403,7 @@ private slots:
|
|||||||
void onPendingItemUpdates();
|
void onPendingItemUpdates();
|
||||||
void onGridItemDoubleClicked();
|
void onGridItemDoubleClicked();
|
||||||
void onGridItemClicked();
|
void onGridItemClicked();
|
||||||
|
void onPlaylistFilesDropped(QStringList files);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setCurrentCoreLabel();
|
void setCurrentCoreLabel();
|
||||||
@ -461,8 +476,6 @@ private:
|
|||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
void dragEnterEvent(QDragEnterEvent *event);
|
|
||||||
void dropEvent(QDropEvent *event);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(ThumbnailWidget)
|
Q_DECLARE_METATYPE(ThumbnailWidget)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user