diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -220,6 +220,7 @@ m_gcodeEditor = new GCodeEditorWidget(this); connect(m_gcodeEditor, &GCodeEditorWidget::updateClientFactory, this, &MainWindow::updateClientFactory); + connect(m_gcodeEditor, &GCodeEditorWidget::droppedUrls, this, &MainWindow::processDropEvent); connect(m_gcodeEditor, &GCodeEditorWidget::fileClosed, this, [this](const QUrl & file) { m_openFiles.removeAll(file); }); diff --git a/src/widgets/gcodeeditorwidget.h b/src/widgets/gcodeeditorwidget.h --- a/src/widgets/gcodeeditorwidget.h +++ b/src/widgets/gcodeeditorwidget.h @@ -50,4 +50,8 @@ void currentFileChanged(const QUrl &file); void updateClientFactory(KTextEditor::View *view); void fileClosed(const QUrl &file); + void droppedUrls(QList fileList); + +private slots: + void dropCatch(QDropEvent *event); }; diff --git a/src/widgets/gcodeeditorwidget.cpp b/src/widgets/gcodeeditorwidget.cpp --- a/src/widgets/gcodeeditorwidget.cpp +++ b/src/widgets/gcodeeditorwidget.cpp @@ -17,14 +17,17 @@ along with this program. If not, see . */ #include +#include #include +#include #include #include "gcodeeditorwidget.h" GCodeEditorWidget::GCodeEditorWidget(QWidget *parent) : QWidget(parent) , m_tabwidget(new QTabWidget()) { + setAcceptDrops(true); m_editor = KTextEditor::Editor::instance(); setupTabWidget(); QVBoxLayout *layout = new QVBoxLayout(); @@ -80,6 +83,11 @@ KTextEditor::View *GCodeEditorWidget::newView(KTextEditor::Document *doc) { auto view = doc->createView(this); + // Connection is a hack using undocumented parts of KTextEditor::View. + // One day this may break, KTextEditor::View needs this added correcty as a real slot to the API. + // Hopefully we can get that added and use it in the future. + // This must be the older style connect string or it will not work. + connect(view, SIGNAL(dropEventPass(QDropEvent *)), this, SLOT(dropCatch(QDropEvent *))); setupInterface(view); return view; } @@ -101,3 +109,10 @@ emit currentFileChanged(urlTab.key(m_tabwidget->widget(index))); emit updateClientFactory(qobject_cast(m_tabwidget->widget(index))); } + +void GCodeEditorWidget::dropCatch(QDropEvent *event) +{ + if (event->mimeData()->hasUrls()) { + emit droppedUrls(event->mimeData()->urls()); + } +}