WIP drag and drop
This commit is contained in:
parent
2087f10681
commit
5015c5c3a4
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <QKeyEvent>
|
||||
#include <QVBoxLayout>
|
||||
#include <QMimeData>
|
||||
|
||||
#include <qtk/input.h>
|
||||
#include <qtk/scene.h>
|
||||
|
@ -31,6 +32,7 @@ QtkWidget::QtkWidget(QWidget * parent, const QString & name) :
|
|||
QtkWidget::QtkWidget(QWidget * parent, const QString & name, Scene * scene) :
|
||||
QOpenGLWidget(parent), mDebugLogger(Q_NULLPTR),
|
||||
mConsole(new DebugConsole(this, name)), mScene(Q_NULLPTR) {
|
||||
setAcceptDrops(true);
|
||||
setScene(scene);
|
||||
setObjectName(name);
|
||||
QSurfaceFormat format;
|
||||
|
@ -77,6 +79,9 @@ void QtkWidget::initializeGL() {
|
|||
connect(
|
||||
mDebugLogger, SIGNAL(messageLogged(QOpenGLDebugMessage)), this,
|
||||
SLOT(messageLogged(QOpenGLDebugMessage)));
|
||||
// connect(
|
||||
// mDebugLogger, SIGNAL(messageLogged(QOpenGLDebugMessage)), mConsole,
|
||||
// SLOT(sendLog(QOpenGLDebugMessage)));
|
||||
mDebugLogger->startLogging();
|
||||
}
|
||||
|
||||
|
@ -140,6 +145,34 @@ void QtkWidget::toggleConsole() {
|
|||
* Protected Methods
|
||||
******************************************************************************/
|
||||
|
||||
void QtkWidget::dragEnterEvent(QDragEnterEvent * event) {
|
||||
if(event->mimeData()->hasFormat("text/plain")) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::dropEvent(QDropEvent * event) {
|
||||
mConsole->sendLog(event->mimeData()->text());
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
auto urls = event->mimeData()->urls();
|
||||
// if (urls.size() > 1) {
|
||||
// qDebug() << "Cannot accept drop of multiple files.\n";
|
||||
// event->ignore();
|
||||
// }
|
||||
auto url = urls.front();
|
||||
if (url.fileName().endsWith(".obj")) {
|
||||
auto fileName = url.fileName().replace(".obj", "").toStdString();
|
||||
auto filePath = url.toLocalFile().toStdString();
|
||||
mScene->blockSignals(true);
|
||||
mScene->addObject(new Qtk::Model(url.fileName().replace(".obj", "").toStdString().c_str(), ":/models/models/scythe/scythe.obj"));
|
||||
mScene->blockSignals(false);
|
||||
mScene->sceneUpdated(mScene->getSceneName());
|
||||
// mScene->mModels.push_back(new Qtk::Model(url.fileName().replace(".obj", "").toStdString().c_str(), url.path().toStdString().c_str()));
|
||||
// event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QtkWidget::keyPressEvent(QKeyEvent * event) {
|
||||
if(event->isAutoRepeat()) {
|
||||
// Do not repeat input while a key is held down
|
||||
|
|
|
@ -136,6 +136,10 @@ namespace Qtk {
|
|||
* Protected Methods
|
||||
************************************************************************/
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent * event) override;
|
||||
|
||||
void dropEvent(QDropEvent * event) override;
|
||||
|
||||
/**
|
||||
* @param event Key press event to update camera input manager.
|
||||
*/
|
||||
|
@ -175,6 +179,10 @@ namespace Qtk {
|
|||
/*************************************************************************
|
||||
* Private Methods
|
||||
************************************************************************/
|
||||
inline void loadModel(const QString & path) {
|
||||
auto * model = new Model("loadedModel", path.toStdString().c_str());
|
||||
mScene->mModels.push_back(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deconstruct any resources we have allocated for this widget.
|
||||
|
|
Loading…
Reference in New Issue