mirror of
https://github.com/libretro/RetroArch
synced 2025-01-31 15:32:59 +00:00
70 lines
1.3 KiB
C++
70 lines
1.3 KiB
C++
|
#include <QDragEnterEvent>
|
||
|
#include <QDropEvent>
|
||
|
#include <QKeyEvent>
|
||
|
#include <QPaintEvent>
|
||
|
#include <QStyle>
|
||
|
#include <QStyleOption>
|
||
|
#include <QMimeData>
|
||
|
#include <QPainter>
|
||
|
#include "filedropwidget.h"
|
||
|
|
||
|
FileDropWidget::FileDropWidget(QWidget *parent) :
|
||
|
QWidget(parent)
|
||
|
{
|
||
|
setAcceptDrops(true);
|
||
|
}
|
||
|
|
||
|
void FileDropWidget::paintEvent(QPaintEvent *event)
|
||
|
{
|
||
|
QStyleOption o;
|
||
|
QPainter p;
|
||
|
o.initFrom(this);
|
||
|
p.begin(this);
|
||
|
style()->drawPrimitive(
|
||
|
QStyle::PE_Widget, &o, &p, this);
|
||
|
p.end();
|
||
|
|
||
|
QWidget::paintEvent(event);
|
||
|
}
|
||
|
|
||
|
void FileDropWidget::keyPressEvent(QKeyEvent *event)
|
||
|
{
|
||
|
if (event->key() == Qt::Key_Delete)
|
||
|
{
|
||
|
event->accept();
|
||
|
emit deletePressed();
|
||
|
}
|
||
|
else
|
||
|
QWidget::keyPressEvent(event);
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
|