diff --git a/mainwindow.cpp b/mainwindow.cpp index 0bbb359..1adc69b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -9,6 +9,7 @@ #include #include #include +#include using namespace std; string ruta; @@ -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; diff --git a/mainwindow.h b/mainwindow.h index 1810586..a639d69 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -18,6 +18,7 @@ class MainWindow : public QMainWindow { Q_OBJECT + public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); @@ -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