Merge pull request #3497 from ZappoMan/entityPropsRescale

add rescale support to entity properties UI
This commit is contained in:
Philip Rosedale 2014-09-26 16:42:15 -07:00
commit 9b228c9e37
3 changed files with 91 additions and 0 deletions

View file

@ -2794,6 +2794,7 @@ var editModelID = -1;
var dimensionX;
var dimensionY;
var dimensionZ;
var rescalePercentage;
function handeMenuEvent(menuItem) {
print("menuItemEvent() in JS... menuItem=" + menuItem);
@ -2896,6 +2897,11 @@ function handeMenuEvent(menuItem) {
index++;
array.push({ label: "", type: "inlineButton", buttonLabel: "Reset to Natural Dimensions", name: "resetDimensions" });
index++;
array.push({ label: "Rescale Percentage:", value: 100 });
rescalePercentage = index;
index++;
array.push({ label: "", type: "inlineButton", buttonLabel: "Rescale", name: "rescaleDimensions" });
index++;
array.push({ label: "Velocity:", type: "header" });
index++;
@ -3023,6 +3029,27 @@ Window.inlineButtonClicked.connect(function (name) {
{ value: propertiesForEditedEntity.naturalDimensions.z.toFixed(decimals), oldIndex: dimensionZ }
]);
}
if (name == "rescaleDimensions") {
var decimals = 3;
var peekValues = editEntityFormArray;
Window.peekNonBlockingFormResult(peekValues);
var peekX = peekValues[dimensionX].value;
var peekY = peekValues[dimensionY].value;
var peekZ = peekValues[dimensionZ].value;
var peekRescale = peekValues[rescalePercentage].value;
var rescaledX = peekX * peekRescale / 100.0;
var rescaledY = peekY * peekRescale / 100.0;
var rescaledZ = peekZ * peekRescale / 100.0;
Window.reloadNonBlockingForm([
{ value: rescaledX.toFixed(decimals), oldIndex: dimensionX },
{ value: rescaledY.toFixed(decimals), oldIndex: dimensionY },
{ value: rescaledZ.toFixed(decimals), oldIndex: dimensionZ },
{ value: 100, oldIndex: rescalePercentage }
]);
}
});
Window.nonBlockingFormClosed.connect(function() {
array = editEntityFormArray;
@ -3056,6 +3083,8 @@ Window.nonBlockingFormClosed.connect(function() {
properties.dimensions.y = array[index++].value;
properties.dimensions.z = array[index++].value;
index++; // skip reset button
index++; // skip rescale percentage
index++; // skip rescale button
index++; // skip header
properties.velocity.x = array[index++].value;

View file

@ -127,6 +127,14 @@ QScriptValue WindowScriptingInterface::getNonBlockingFormResult(QScriptValue for
return retVal;
}
QScriptValue WindowScriptingInterface::peekNonBlockingFormResult(QScriptValue form) {
QScriptValue retVal;
QMetaObject::invokeMethod(this, "doPeekNonBlockingFormResult", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(QScriptValue, retVal),
Q_ARG(QScriptValue, form));
return retVal;
}
/// Display an alert box
/// \param const QString& message message to display
@ -234,6 +242,58 @@ bool WindowScriptingInterface::nonBlockingFormActive() {
return _nonBlockingFormActive;
}
QScriptValue WindowScriptingInterface::doPeekNonBlockingFormResult(QScriptValue array) {
QScriptValue retVal;
int e = -1;
int d = -1;
int c = -1;
for (int i = 0; i < _form.property("length").toInt32(); ++i) {
QScriptValue item = _form.property(i);
QScriptValue value = item.property("value");
if (item.property("button").toString() != "") {
// Nothing to do
} else if (item.property("type").toString() == "inlineButton") {
// Nothing to do
} else if (item.property("type").toString() == "header") {
// Nothing to do
} else if (item.property("directory").toString() != "") {
d += 1;
value = _directories.at(d)->property("path").toString();
item.setProperty("directory", value);
_form.setProperty(i, item);
} else if (item.property("options").isArray()) {
c += 1;
item.setProperty("value", _combos.at(c)->currentText());
_form.setProperty(i, item);
} else {
e += 1;
bool ok = true;
if (value.isNumber()) {
value = _edits.at(e)->text().toDouble(&ok);
} else if (value.isString()) {
value = _edits.at(e)->text();
} else if (value.isBool()) {
if (_edits.at(e)->text() == "true") {
value = true;
} else if (_edits.at(e)->text() == "false") {
value = false;
} else {
ok = false;
}
}
if (ok) {
item.setProperty("value", value);
_form.setProperty(i, item);
}
}
}
array = _form;
return (_formResult == QDialog::Accepted);
}
QScriptValue WindowScriptingInterface::doGetNonBlockingFormResult(QScriptValue array) {
QScriptValue retVal;

View file

@ -46,6 +46,7 @@ public slots:
void nonBlockingForm(const QString& title, QScriptValue array);
void reloadNonBlockingForm(QScriptValue array);
QScriptValue getNonBlockingFormResult(QScriptValue array);
QScriptValue peekNonBlockingFormResult(QScriptValue array);
signals:
void inlineButtonClicked(const QString& name);
@ -64,6 +65,7 @@ private slots:
void doReloadNonBlockingForm(QScriptValue array);
bool nonBlockingFormActive();
QScriptValue doGetNonBlockingFormResult(QScriptValue array);
QScriptValue doPeekNonBlockingFormResult(QScriptValue array);
void chooseDirectory();
void inlineButtonClicked();