diff --git a/src/engine/QMLEngine.js b/src/engine/QMLEngine.js index 80d79f837..0c298c2e8 100644 --- a/src/engine/QMLEngine.js +++ b/src/engine/QMLEngine.js @@ -583,9 +583,24 @@ class QMLEngine { ${jsData.exports.map(sym => `$context.${sym} = ${sym};`).join("")} `); - this.js[file] = contextSetter; + if (jsData.pragma && jsData.pragma.indexOf("library") !== -1) { + // For .pragma library, execute the code once in a clean context and + // return a function that imports getters/setters to other contexts + const jsContext = {}; + contextSetter(jsContext); + this.js[file] = context => { + jsData.exports.forEach(sym => QmlWeb.setupGetterSetter(context, sym, + () => jsContext[sym], + val => { + jsContext[sym] = val; + } + )); + }; + } else { + this.js[file] = contextSetter; + } - return contextSetter; + return this.js[file]; } $registerStart(f) { diff --git a/src/modules/QtQml/Timer.js b/src/modules/QtQml/Timer.js index a1b154a9f..95a9edbbe 100644 --- a/src/modules/QtQml/Timer.js +++ b/src/modules/QtQml/Timer.js @@ -5,7 +5,7 @@ QmlWeb.registerQmlType({ baseClass: "QtObject", properties: { interval: { type: "int", initialValue: 1000 }, - parent: { type: "QtObject", readOnly: true }, + parent: { type: "QtObject" }, // TODO ro repeat: "bool", running: "bool", triggeredOnStart: "bool" diff --git a/src/modules/QtQuick/Item.js b/src/modules/QtQuick/Item.js index 7688b3453..0c112165e 100644 --- a/src/modules/QtQuick/Item.js +++ b/src/modules/QtQuick/Item.js @@ -3,6 +3,13 @@ QmlWeb.registerQmlType({ name: "Item", versions: /.*/, baseClass: "QtQml.QtObject", + enums: { + Item: { + TopLeft: 0, Top: 1, TopRight: 2, + Left: 3, Center: 4, Right: 5, + BottomLeft: 6, Bottom: 7, BottomRight: 8 + } + }, properties: { $opacity: { type: "real", initialValue: 1 }, parent: "Item", @@ -14,6 +21,7 @@ QmlWeb.registerQmlType({ children: "list", resources: "list", transform: "list", + transformOrigin: { type: "enum", initialValue: 4 }, // Item.Center x: "real", y: "real", z: "real", @@ -122,6 +130,7 @@ QmlWeb.registerQmlType({ this.rotationChanged.connect(this, this.$updateTransform); this.scaleChanged.connect(this, this.$updateTransform); this.transformChanged.connect(this, this.$updateTransform); + this.transformOriginChanged.connect(this, this.$onTransformOriginChanged); this.Component.completed.connect(this, this.Component$onCompleted_); this.opacityChanged.connect(this, this.$calculateOpacity); @@ -374,6 +383,20 @@ QmlWeb.registerQmlType({ this.dom.style.filter = filter; this.dom.style.webkitFilter = filter; // Chrome, Safari and Opera } + $onTransformOriginChanged(newVal) { + const map = [ + 'left top', // 0 - TopLeft + 'center top', // 1 - Top + 'right top', // 2 - TopRight + 'left center', // 3 - Left + '', // 4 - Center + 'right center', // 5 - Right + 'left bottom', // 6 - BottomLeft + 'center bottom', // 7 - Bottom + 'right bottom', // 8 - BottomRight + ]; + this.dom.style.transformOrigin = map[newVal]; + } Component$onCompleted_() { this.$calculateOpacity(); }