Skip to content

Commit

Permalink
Add Drag & Drop support
Browse files Browse the repository at this point in the history
  • Loading branch information
SeppNel committed Aug 2, 2021
1 parent d5e2dbb commit ff135c4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
30 changes: 30 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QStringList>
#include <QSignalMapper>
#include <regex>
#include <QMimeData>

using namespace std;
string ruta;
Expand All @@ -30,9 +31,38 @@ MainWindow::MainWindow(QWidget *parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setAcceptDrops(true);
}

void MainWindow::dragEnterEvent(QDragEnterEvent *e)
{
if (e->mimeData()->hasUrls()) {
e->acceptProposedAction();
}
}

void MainWindow::dropEvent(QDropEvent *e)
{
foreach (const QUrl &url, e->mimeData()->urls()) {
ruta = url.toLocalFile().toStdString();
cout << "Dropped file: " << ruta << endl;
string ext = ruta.substr(ruta.find_last_of(".") + 1);
if(ext == "ftd" || ext == "ctd") {
ui->list->clear();
openfile(ruta);
fileopen = true;
}
else {
QMessageBox msgBox;
msgBox.setText("Only .ftd and .ctd files");
msgBox.exec();
}
}
}




MainWindow::~MainWindow()
{
delete ui;
Expand Down
6 changes: 6 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MainWindow : public QMainWindow
{
Q_OBJECT


public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
Expand All @@ -30,12 +31,17 @@ private slots:


void on_save_clicked();
void on_delete_element_clicked();

private:
Ui::MainWindow *ui;

protected:
void keyPressEvent(QKeyEvent* pe);
void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override;

signals:
void changed(const QMimeData *mimeData = nullptr);
};
#endif // MAINWINDOW_H

0 comments on commit ff135c4

Please sign in to comment.