#include #include #include #include #include #include #include #include #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 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); } }