예제 #1
0
void PointerEvent::fromScriptValue(const QScriptValue& object, PointerEvent& event) {
    if (object.isObject()) {
        QScriptValue type = object.property("type");
        QString typeStr = type.isString() ? type.toString() : "Move";
        if (typeStr == "Press") {
            event._type = Press;
        } else if (typeStr == "DoublePress") {
            event._type = DoublePress;
        } else if (typeStr == "Release") {
            event._type = Release;
        } else {
            event._type = Move;
        }

        QScriptValue id = object.property("id");
        event._id = id.isNumber() ? (uint32_t)id.toNumber() : 0;

        glm::vec2 pos2D;
        vec2FromScriptValue(object.property("pos2D"), event._pos2D);

        glm::vec3 pos3D;
        vec3FromScriptValue(object.property("pos3D"), event._pos3D);

        glm::vec3 normal;
        vec3FromScriptValue(object.property("normal"), event._normal);

        glm::vec3 direction;
        vec3FromScriptValue(object.property("direction"), event._direction);

        QScriptValue button = object.property("button");
        QString buttonStr = type.isString() ? button.toString() : "NoButtons";

        if (buttonStr == "Primary") {
            event._button = PrimaryButton;
        } else if (buttonStr == "Secondary") {
            event._button = SecondaryButton;
        } else if (buttonStr == "Tertiary") {
            event._button = TertiaryButton;
        } else {
            event._button = NoButtons;
        }

        bool primary = object.property("isPrimaryHeld").toBool();
        bool secondary = object.property("isSecondaryHeld").toBool();
        bool tertiary = object.property("isTertiaryHeld").toBool();
        event._buttons = 0;
        if (primary) {
            event._buttons |= PrimaryButton;
        }
        if (secondary) {
            event._buttons |= SecondaryButton;
        }
        if (tertiary) {
            event._buttons |= TertiaryButton;
        }

        event._keyboardModifiers = (Qt::KeyboardModifiers)(object.property("keyboardModifiers").toUInt32());
    }
}
예제 #2
0
void Web3DOverlay::setProperties(const QScriptValue &properties) {
    Billboard3DOverlay::setProperties(properties);

    QScriptValue urlValue = properties.property("url");
    if (urlValue.isValid()) {
        QString newURL = urlValue.toVariant().toString();
        if (newURL != _url) {
            setURL(newURL);
        }
    }

    QScriptValue resolution = properties.property("resolution");
    if (resolution.isValid()) {
        vec2FromScriptValue(resolution, _resolution);
    }


    QScriptValue dpi = properties.property("dpi");
    if (dpi.isValid()) {
        _dpi = dpi.toVariant().toFloat();
    }
}