|
36 | 36 | #include <QDesktopServices> // for QDesktopServices |
37 | 37 | #include <QDialog> // for QDialog, QDialog::Accepted |
38 | 38 | #include <QDir> // for QDir, operator|, QDir::Files, QDir::Hidden, QDir::Name, QDir::NoSymLinks |
| 39 | +#include <QDragEnterEvent> // for QDragEnterEvent |
| 40 | +#include <QDropEvent> // for QDropEvent |
39 | 41 | #include <QEvent> // for QEvent, QEvent::ToolTip |
40 | 42 | #include <QFile> // for QFile |
41 | 43 | #include <QFileDialog> // for QFileDialog, QFileDialog::DontConfirmOverwrite |
|
60 | 62 | #include <QMenu> // for QMenu |
61 | 63 | #include <QMenuBar> // for QMenuBar |
62 | 64 | #include <QMessageBox> // for QMessageBox, operator|, QMessageBox::Save, QMessageBox::Discard, QMess... |
| 65 | +#include <QMimeData> // for QMimeData |
63 | 66 | #include <QModelIndex> // for QModelIndex |
64 | 67 | #include <QModelIndexList> // for QModelIndexList |
65 | 68 | #include <QObject> // for SIGNAL, SLOT, qobject_cast, emit |
@@ -158,6 +161,7 @@ GCodeWorkShop::GCodeWorkShop(Medium* medium) |
158 | 161 |
|
159 | 162 | ui = new Ui::GCodeWorkShop(); |
160 | 163 | ui->setupUi(this); |
| 164 | + setAcceptDrops(true); |
161 | 165 |
|
162 | 166 | findToolBar = nullptr; |
163 | 167 | serialToolBar = nullptr; |
@@ -288,6 +292,30 @@ void GCodeWorkShop::moveEvent(QMoveEvent* event) |
288 | 292 | QMainWindow::moveEvent(event); |
289 | 293 | } |
290 | 294 |
|
| 295 | +void GCodeWorkShop::dragEnterEvent(QDragEnterEvent* event) |
| 296 | +{ |
| 297 | + if (!event->mimeData()->hasUrls()) { |
| 298 | + QMainWindow::dragEnterEvent(event); |
| 299 | + return; |
| 300 | + } |
| 301 | + |
| 302 | + event->acceptProposedAction(); |
| 303 | +} |
| 304 | + |
| 305 | +void GCodeWorkShop::dropEvent(QDropEvent* event) |
| 306 | +{ |
| 307 | + if (!event->mimeData()->hasUrls()) { |
| 308 | + QMainWindow::dropEvent(event); |
| 309 | + return; |
| 310 | + } |
| 311 | + |
| 312 | + for (QUrl url : event->mimeData()->urls()) { |
| 313 | + openFile(url.toString(QUrl::PreferLocalFile)); |
| 314 | + } |
| 315 | + |
| 316 | + event->acceptProposedAction(); |
| 317 | +} |
| 318 | + |
291 | 319 | Addons::Actions* GCodeWorkShop::addonsActions() |
292 | 320 | { |
293 | 321 | return m_addonsActions; |
|
0 commit comments