From 55e2ebd92f60de93a647d2c55026a063c4587f4c Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 18 Feb 2014 13:58:44 -0800 Subject: [PATCH] More spanner bits. --- interface/src/Menu.cpp | 1 + interface/src/renderer/Model.cpp | 4 +- interface/src/ui/MetavoxelEditor.cpp | 19 ++++++-- interface/src/ui/MetavoxelEditor.h | 4 +- libraries/metavoxels/src/MetavoxelUtil.cpp | 51 +++++++++++++++++++--- libraries/metavoxels/src/MetavoxelUtil.h | 31 +++++++++++-- libraries/metavoxels/src/SharedObject.cpp | 25 ++++++++++- libraries/metavoxels/src/SharedObject.h | 1 + 8 files changed, 117 insertions(+), 19 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index c61b4cbdaf..a836d462c1 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -1088,6 +1088,7 @@ void Menu::showMetavoxelEditor() { _MetavoxelEditor = new MetavoxelEditor(); } _MetavoxelEditor->raise(); + _MetavoxelEditor->activateWindow(); } void Menu::audioMuteToggled() { diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 48e1d0f70c..d8188dab63 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -276,7 +276,7 @@ bool Model::render(float alpha) { // render opaque meshes with alpha testing glEnable(GL_ALPHA_TEST); - glAlphaFunc(GL_GREATER, 0.5f); + glAlphaFunc(GL_GREATER, 0.5f * alpha); renderMeshes(alpha, false); @@ -916,7 +916,7 @@ void Model::renderMeshes(float alpha, bool translucent) { if (!mesh.colors.isEmpty()) { glEnableClientState(GL_COLOR_ARRAY); } else { - glColor3f(1.0f, 1.0f, 1.0f); + glColor4f(1.0f, 1.0f, 1.0f, alpha); } if (!mesh.texCoords.isEmpty()) { glEnableClientState(GL_TEXTURE_COORD_ARRAY); diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index 003d283795..3b3333e267 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -29,7 +29,7 @@ enum GridPlane { const glm::vec2 INVALID_VECTOR(FLT_MAX, FLT_MAX); MetavoxelEditor::MetavoxelEditor() : - QDialog(Application::getInstance()->getGLWidget()) { + QWidget(Application::getInstance()->getGLWidget(), Qt::Tool | Qt::WindowStaysOnTopHint) { setWindowTitle("Metavoxel Editor"); setAttribute(Qt::WA_DeleteOnClose); @@ -519,9 +519,20 @@ void InsertSpannerTool::simulate(float deltaTime) { } void InsertSpannerTool::render() { - SharedObjectPointer spanner = _editor->getValue().value(); - const float SPANNER_ALPHA = 1.0f; - static_cast(spanner.data())->getRenderer()->render(SPANNER_ALPHA); + Spanner* spanner = static_cast(_editor->getValue().value().data()); + Transformable* transformable = qobject_cast(spanner); + if (transformable) { + // find the intersection of the mouse ray with the grid and place the transformable there + glm::quat rotation = _editor->getGridRotation(); + glm::quat inverseRotation = glm::inverse(rotation); + glm::vec3 rayOrigin = inverseRotation * Application::getInstance()->getMouseRayOrigin(); + glm::vec3 rayDirection = inverseRotation * Application::getInstance()->getMouseRayDirection(); + float position = _editor->getGridPosition(); + float distance = (position - rayOrigin.z) / rayDirection.z; + transformable->setTranslation(rotation * glm::vec3(glm::vec2(rayOrigin + rayDirection * distance), position)); + } + const float SPANNER_ALPHA = 0.25f; + spanner->getRenderer()->render(SPANNER_ALPHA); } bool InsertSpannerTool::appliesTo(const AttributePointer& attribute) const { diff --git a/interface/src/ui/MetavoxelEditor.h b/interface/src/ui/MetavoxelEditor.h index a688a01cec..1709d07497 100644 --- a/interface/src/ui/MetavoxelEditor.h +++ b/interface/src/ui/MetavoxelEditor.h @@ -9,8 +9,8 @@ #ifndef __interface__MetavoxelEditor__ #define __interface__MetavoxelEditor__ -#include #include +#include #include "renderer/ProgramObject.h" @@ -24,7 +24,7 @@ class QScrollArea; class MetavoxelTool; /// Allows editing metavoxels. -class MetavoxelEditor : public QDialog { +class MetavoxelEditor : public QWidget { Q_OBJECT public: diff --git a/libraries/metavoxels/src/MetavoxelUtil.cpp b/libraries/metavoxels/src/MetavoxelUtil.cpp index f7c2a92b75..22c17abf12 100644 --- a/libraries/metavoxels/src/MetavoxelUtil.cpp +++ b/libraries/metavoxels/src/MetavoxelUtil.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -18,6 +17,7 @@ #include #include #include +#include #include #include @@ -54,6 +54,7 @@ public: DoubleEditor::DoubleEditor(QWidget* parent) : QDoubleSpinBox(parent) { setMinimum(-FLT_MAX); + setMaximum(FLT_MAX); } DelegatingItemEditorFactory::DelegatingItemEditorFactory() : @@ -117,6 +118,12 @@ static QItemEditorCreatorBase* createQColorEditorCreator() { return creator; } +static QItemEditorCreatorBase* createQUrlEditorCreator() { + QItemEditorCreatorBase* creator = new LazyItemEditorCreator(); + getItemEditorFactory()->registerEditor(qMetaTypeId(), creator); + return creator; +} + static QItemEditorCreatorBase* createVec3EditorCreator() { QItemEditorCreatorBase* creator = new LazyItemEditorCreator(); getItemEditorFactory()->registerEditor(qMetaTypeId(), creator); @@ -132,6 +139,7 @@ static QItemEditorCreatorBase* createParameterizedURLEditorCreator() { static QItemEditorCreatorBase* doubleEditorCreator = createDoubleEditorCreator(); static QItemEditorCreatorBase* qMetaObjectEditorCreator = createQMetaObjectEditorCreator(); static QItemEditorCreatorBase* qColorEditorCreator = createQColorEditorCreator(); +static QItemEditorCreatorBase* qUrlEditorCreator = createQUrlEditorCreator(); static QItemEditorCreatorBase* vec3EditorCreator = createVec3EditorCreator(); static QItemEditorCreatorBase* parameterizedURLEditorCreator = createParameterizedURLEditorCreator(); @@ -211,6 +219,36 @@ void QColorEditor::selectColor() { } } +QUrlEditor::QUrlEditor(QWidget* parent) : + QComboBox(parent) { + + setEditable(true); + setInsertPolicy(InsertAtTop); + + // populate initial URL list from settings + addItems(QSettings().value("editorURLs").toStringList()); + + connect(this, SIGNAL(activated(const QString&)), SLOT(updateURL(const QString&))); + connect(model(), SIGNAL(rowsInserted(const QModelIndex&,int,int)), SLOT(updateSettings())); +} + +void QUrlEditor::setURL(const QUrl& url) { + setCurrentText((_url = url).toString()); +} + +void QUrlEditor::updateURL(const QString& text) { + emit urlChanged(_url = text); +} + +void QUrlEditor::updateSettings() { + QStringList urls; + const int MAX_STORED_URLS = 10; + for (int i = 0, size = qMin(MAX_STORED_URLS, count()); i < size; i++) { + urls.append(itemText(i)); + } + QSettings().setValue("editorURLs", urls); +} + Vec3Editor::Vec3Editor(QWidget* parent) : QWidget(parent) { QHBoxLayout* layout = new QHBoxLayout(); layout->setContentsMargins(QMargins()); @@ -235,6 +273,7 @@ void Vec3Editor::updateVector() { QDoubleSpinBox* Vec3Editor::createComponentBox() { QDoubleSpinBox* box = new QDoubleSpinBox(); box->setMinimum(-FLT_MAX); + box->setMaximum(FLT_MAX); box->setMaximumWidth(100); connect(box, SIGNAL(valueChanged(double)), SLOT(updateVector())); return box; @@ -287,8 +326,9 @@ ParameterizedURLEditor::ParameterizedURLEditor(QWidget* parent) : lineContainer->setLayout(lineLayout); lineLayout->setContentsMargins(QMargins()); - lineLayout->addWidget(_line = new QLineEdit(), 1); - connect(_line, SIGNAL(textChanged(const QString&)), SLOT(updateURL())); + lineLayout->addWidget(&_urlEditor, 1); + connect(&_urlEditor, SIGNAL(urlChanged(const QUrl&)), SLOT(updateURL())); + connect(&_urlEditor, SIGNAL(urlChanged(const QUrl&)), SLOT(updateParameters())); QPushButton* refresh = new QPushButton("..."); connect(refresh, SIGNAL(clicked(bool)), SLOT(updateParameters())); @@ -296,8 +336,7 @@ ParameterizedURLEditor::ParameterizedURLEditor(QWidget* parent) : } void ParameterizedURLEditor::setURL(const ParameterizedURL& url) { - _url = url; - _line->setText(url.getURL().toString()); + _urlEditor.setURL((_url = url).getURL()); updateParameters(); } @@ -314,7 +353,7 @@ void ParameterizedURLEditor::updateURL() { widget->property("parameterName").toString()), widgetProperty.read(widget)); } } - emit urlChanged(_url = ParameterizedURL(_line->text(), parameters)); + emit urlChanged(_url = ParameterizedURL(_urlEditor.getURL(), parameters)); if (_program) { _program->disconnect(this); } diff --git a/libraries/metavoxels/src/MetavoxelUtil.h b/libraries/metavoxels/src/MetavoxelUtil.h index 37a6c8bcda..19fd41e826 100644 --- a/libraries/metavoxels/src/MetavoxelUtil.h +++ b/libraries/metavoxels/src/MetavoxelUtil.h @@ -10,6 +10,7 @@ #define __interface__MetavoxelUtil__ #include +#include #include #include #include @@ -21,9 +22,7 @@ #include "Bitstream.h" class QByteArray; -class QComboBox; class QDoubleSpinBox; -class QLineEdit; class QPushButton; class HifiSockAddr; @@ -107,6 +106,32 @@ private: QColor _color; }; +/// Editor for URL values. +class QUrlEditor : public QComboBox { + Q_OBJECT + Q_PROPERTY(QUrl url READ getURL WRITE setURL NOTIFY urlChanged USER true) + +public: + + QUrlEditor(QWidget* parent = NULL); + + void setURL(const QUrl& url); + const QUrl& getURL() { return _url; } + +signals: + + void urlChanged(const QUrl& url); + +private slots: + + void updateURL(const QString& text); + void updateSettings(); + +private: + + QUrl _url; +}; + /// Editor for vector values. class Vec3Editor : public QWidget { Q_OBJECT @@ -200,7 +225,7 @@ private: ParameterizedURL _url; QSharedPointer _program; - QLineEdit* _line; + QUrlEditor _urlEditor; }; #endif /* defined(__interface__MetavoxelUtil__) */ diff --git a/libraries/metavoxels/src/SharedObject.cpp b/libraries/metavoxels/src/SharedObject.cpp index 7482d0efb6..2393785702 100644 --- a/libraries/metavoxels/src/SharedObject.cpp +++ b/libraries/metavoxels/src/SharedObject.cpp @@ -130,13 +130,17 @@ void SharedObjectEditor::updateType() { } delete form; } + QObject* oldObject = static_cast(_object.data()); + const QMetaObject* oldMetaObject = NULL; + if (oldObject) { + oldMetaObject = oldObject->metaObject(); + oldObject->disconnect(this); + } const QMetaObject* metaObject = _type->itemData(_type->currentIndex()).value(); if (metaObject == NULL) { _object.reset(); return; } - QObject* oldObject = static_cast(_object.data()); - const QMetaObject* oldMetaObject = oldObject ? oldObject->metaObject() : NULL; QObject* newObject = metaObject->newInstance(); QFormLayout* form = new QFormLayout(); @@ -162,6 +166,10 @@ void SharedObjectEditor::updateType() { if (widgetProperty.hasNotifySignal()) { connect(widget, signal(widgetProperty.notifySignal().methodSignature()), SLOT(propertyChanged())); } + if (property.hasNotifySignal()) { + widget->setProperty("notifySignalIndex", property.notifySignalIndex()); + connect(newObject, signal(property.notifySignal().methodSignature()), SLOT(updateProperty())); + } } } _object = static_cast(newObject); @@ -181,3 +189,16 @@ void SharedObjectEditor::propertyChanged() { property.write(object, widget->property(valuePropertyName)); } } + +void SharedObjectEditor::updateProperty() { + QFormLayout* form = static_cast(layout()->itemAt(1)); + for (int i = 0; i < form->rowCount(); i++) { + QWidget* widget = form->itemAt(i, QFormLayout::FieldRole)->widget(); + if (widget->property("notifySignalIndex").toInt() != senderSignalIndex()) { + continue; + } + QMetaProperty property = _object->metaObject()->property(widget->property("propertyIndex").toInt()); + QByteArray valuePropertyName = QItemEditorFactory::defaultFactory()->valuePropertyName(property.userType()); + widget->setProperty(valuePropertyName, property.read(_object.data())); + } +} diff --git a/libraries/metavoxels/src/SharedObject.h b/libraries/metavoxels/src/SharedObject.h index 5a33b64e3d..008ea02e4b 100644 --- a/libraries/metavoxels/src/SharedObject.h +++ b/libraries/metavoxels/src/SharedObject.h @@ -168,6 +168,7 @@ private slots: void updateType(); void propertyChanged(); + void updateProperty(); private: