WIP drag and drop

This commit is contained in:
Shaun Reed 2023-03-11 21:14:48 -05:00
parent 2087f10681
commit 5015c5c3a4
2 changed files with 41 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QMimeData>
#include <qtk/input.h> #include <qtk/input.h>
#include <qtk/scene.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) : QtkWidget::QtkWidget(QWidget * parent, const QString & name, Scene * scene) :
QOpenGLWidget(parent), mDebugLogger(Q_NULLPTR), QOpenGLWidget(parent), mDebugLogger(Q_NULLPTR),
mConsole(new DebugConsole(this, name)), mScene(Q_NULLPTR) { mConsole(new DebugConsole(this, name)), mScene(Q_NULLPTR) {
setAcceptDrops(true);
setScene(scene); setScene(scene);
setObjectName(name); setObjectName(name);
QSurfaceFormat format; QSurfaceFormat format;
@ -77,6 +79,9 @@ void QtkWidget::initializeGL() {
connect( connect(
mDebugLogger, SIGNAL(messageLogged(QOpenGLDebugMessage)), this, mDebugLogger, SIGNAL(messageLogged(QOpenGLDebugMessage)), this,
SLOT(messageLogged(QOpenGLDebugMessage))); SLOT(messageLogged(QOpenGLDebugMessage)));
// connect(
// mDebugLogger, SIGNAL(messageLogged(QOpenGLDebugMessage)), mConsole,
// SLOT(sendLog(QOpenGLDebugMessage)));
mDebugLogger->startLogging(); mDebugLogger->startLogging();
} }
@ -140,6 +145,34 @@ void QtkWidget::toggleConsole() {
* Protected Methods * 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) { void QtkWidget::keyPressEvent(QKeyEvent * event) {
if(event->isAutoRepeat()) { if(event->isAutoRepeat()) {
// Do not repeat input while a key is held down // Do not repeat input while a key is held down

View File

@ -136,6 +136,10 @@ namespace Qtk {
* Protected Methods * Protected Methods
************************************************************************/ ************************************************************************/
void dragEnterEvent(QDragEnterEvent * event) override;
void dropEvent(QDropEvent * event) override;
/** /**
* @param event Key press event to update camera input manager. * @param event Key press event to update camera input manager.
*/ */
@ -175,6 +179,10 @@ namespace Qtk {
/************************************************************************* /*************************************************************************
* Private Methods * 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. * Deconstruct any resources we have allocated for this widget.