add drag and drop support

This commit is contained in:
Anakin 2017-01-03 11:47:27 +01:00
parent ae84c55559
commit 0fefc6168b
2 changed files with 15 additions and 1 deletions

View File

@ -21,6 +21,9 @@ public:
explicit OglViewerWidget(QWidget *parent = 0);
~OglViewerWidget();
signals:
void loadFile(const char*);
private:
struct {
bool left = false;
@ -40,6 +43,7 @@ protected:
void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE;
void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE;

View File

@ -93,9 +93,18 @@ void OglViewerWidget::wheelEvent(QWheelEvent *e)
update();
}
void OglViewerWidget::dragEnterEvent(QDragEnterEvent *e)
{
if (e->mimeData()->hasUrls())
if(e->mimeData()->urls().size() == 1)
if(e->mimeData()->urls().first().toLocalFile().endsWith(".msh"))
e->acceptProposedAction();
}
void OglViewerWidget::dropEvent(QDropEvent * e)
{
std::cout << e->mimeData()->text().toStdString() << std::endl;
emit loadFile(e->mimeData()->urls().first().toLocalFile().toStdString().c_str());
}
void OglViewerWidget::keyPressEvent(QKeyEvent *e)
@ -127,6 +136,7 @@ void OglViewerWidget::initializeGL()
m_dataEngine = new GeometryEngine;
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView);
connect(parentWidget(), SIGNAL(loadFile(const char*)), m_dataEngine, SLOT(loadFile(const char*)));
connect(this, SIGNAL(loadFile(const char*)), m_dataEngine, SLOT(loadFile(const char*)));
}