More spanner bits.

This commit is contained in:
Andrzej Kapolka 2014-02-18 13:58:44 -08:00
parent 5513524705
commit 55e2ebd92f
8 changed files with 117 additions and 19 deletions

View file

@ -1088,6 +1088,7 @@ void Menu::showMetavoxelEditor() {
_MetavoxelEditor = new MetavoxelEditor();
}
_MetavoxelEditor->raise();
_MetavoxelEditor->activateWindow();
}
void Menu::audioMuteToggled() {

View file

@ -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);

View file

@ -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<SharedObjectPointer>();
const float SPANNER_ALPHA = 1.0f;
static_cast<Spanner*>(spanner.data())->getRenderer()->render(SPANNER_ALPHA);
Spanner* spanner = static_cast<Spanner*>(_editor->getValue().value<SharedObjectPointer>().data());
Transformable* transformable = qobject_cast<Transformable*>(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 {

View file

@ -9,8 +9,8 @@
#ifndef __interface__MetavoxelEditor__
#define __interface__MetavoxelEditor__
#include <QDialog>
#include <QList>
#include <QWidget>
#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:

View file

@ -8,7 +8,6 @@
#include <QByteArray>
#include <QColorDialog>
#include <QComboBox>
#include <QDoubleSpinBox>
#include <QFormLayout>
#include <QHBoxLayout>
@ -18,6 +17,7 @@
#include <QMetaType>
#include <QPushButton>
#include <QScriptEngine>
#include <QSettings>
#include <QVBoxLayout>
#include <QtDebug>
@ -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<QUrlEditor>();
getItemEditorFactory()->registerEditor(qMetaTypeId<QUrl>(), creator);
return creator;
}
static QItemEditorCreatorBase* createVec3EditorCreator() {
QItemEditorCreatorBase* creator = new LazyItemEditorCreator<Vec3Editor>();
getItemEditorFactory()->registerEditor(qMetaTypeId<glm::vec3>(), 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);
}

View file

@ -10,6 +10,7 @@
#define __interface__MetavoxelUtil__
#include <QColor>
#include <QComboBox>
#include <QSharedPointer>
#include <QUrl>
#include <QUuid>
@ -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<NetworkProgram> _program;
QLineEdit* _line;
QUrlEditor _urlEditor;
};
#endif /* defined(__interface__MetavoxelUtil__) */

View file

@ -130,13 +130,17 @@ void SharedObjectEditor::updateType() {
}
delete form;
}
QObject* oldObject = static_cast<SharedObject*>(_object.data());
const QMetaObject* oldMetaObject = NULL;
if (oldObject) {
oldMetaObject = oldObject->metaObject();
oldObject->disconnect(this);
}
const QMetaObject* metaObject = _type->itemData(_type->currentIndex()).value<const QMetaObject*>();
if (metaObject == NULL) {
_object.reset();
return;
}
QObject* oldObject = static_cast<SharedObject*>(_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<SharedObject*>(newObject);
@ -181,3 +189,16 @@ void SharedObjectEditor::propertyChanged() {
property.write(object, widget->property(valuePropertyName));
}
}
void SharedObjectEditor::updateProperty() {
QFormLayout* form = static_cast<QFormLayout*>(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()));
}
}

View file

@ -168,6 +168,7 @@ private slots:
void updateType();
void propertyChanged();
void updateProperty();
private: