mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-21 14:00:29 +00:00
Allow file selection by drag & drop (#173)
This commit is contained in:
parent
496cbcfd4d
commit
a729568a51
@ -65,6 +65,7 @@ NewFileDialog::NewFileDialog(QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
|
||||
setAcceptDrops(true);
|
||||
ui->recentsListWidget->addAction(ui->actionRemove_item);
|
||||
ui->recentsListWidget->addAction(ui->actionClear_all);
|
||||
|
||||
@ -218,6 +219,27 @@ void NewFileDialog::on_actionClear_all_triggered()
|
||||
ui->newFileEdit->clear();
|
||||
}
|
||||
|
||||
void NewFileDialog::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
// Accept drag & drop events only if they provide a URL
|
||||
if(event->mimeData()->hasUrls())
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void NewFileDialog::dropEvent(QDropEvent *event)
|
||||
{
|
||||
// Accept drag & drop events only if they provide a URL
|
||||
if(event->mimeData()->urls().count() == 0) {
|
||||
qWarning() << "No URL in drop event, ignoring it.";
|
||||
return;
|
||||
}
|
||||
|
||||
event->acceptProposedAction();
|
||||
loadFile(event->mimeData()->urls().first().path());
|
||||
}
|
||||
|
||||
bool NewFileDialog::fillRecentFilesList()
|
||||
{
|
||||
// Fill list with recent opened files
|
||||
|
@ -38,6 +38,10 @@ private slots:
|
||||
void on_actionRemove_item_triggered();
|
||||
void on_actionClear_all_triggered();
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void dropEvent(QDropEvent *event);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui::NewFileDialog> ui;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user