mirror of
https://github.com/overte-org/overte.git
synced 2025-04-07 19:12:28 +02:00
Support for the ablity to change button properties from js.
This commit is contained in:
parent
0add5274ac
commit
5441d33a25
4 changed files with 45 additions and 2 deletions
|
@ -12,6 +12,10 @@ Item {
|
|||
|
||||
signal clicked()
|
||||
|
||||
function changeProperty(key, value) {
|
||||
tabletButton[key] = value;
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: buttonBg
|
||||
color: tabletButton.color
|
||||
|
|
|
@ -121,6 +121,21 @@ void TabletButtonProxy::setQmlButton(QQuickItem* qmlButton) {
|
|||
_qmlButton = qmlButton;
|
||||
}
|
||||
|
||||
// TABLET_UI_HACK TODO: add property accessors, and forward property changes to the _qmlButton if present.
|
||||
QVariantMap TabletButtonProxy::getProperties() const {
|
||||
std::lock_guard<std::mutex> guard(_mutex);
|
||||
return _properties;
|
||||
}
|
||||
|
||||
void TabletButtonProxy::editProperties(QVariantMap properties) {
|
||||
std::lock_guard<std::mutex> guard(_mutex);
|
||||
QVariantMap::const_iterator iter = properties.constBegin();
|
||||
while (iter != properties.constEnd()) {
|
||||
_properties[iter.key()] = iter.value();
|
||||
if (_qmlButton) {
|
||||
QMetaObject::invokeMethod(_qmlButton, "changeProperty", Qt::AutoConnection, Q_ARG(QVariant, QVariant(iter.key())), Q_ARG(QVariant, iter.value()));
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
#include "TabletScriptingInterface.moc"
|
||||
|
|
|
@ -90,7 +90,19 @@ public:
|
|||
|
||||
void setQmlButton(QQuickItem* qmlButton);
|
||||
|
||||
const QVariantMap& getProperties() const { return _properties; }
|
||||
/**jsdoc
|
||||
* Returns the current value of this button's properties
|
||||
* @function TabletButtonProxy#getProperties
|
||||
* @returns {object}
|
||||
*/
|
||||
Q_INVOKABLE QVariantMap getProperties() const;
|
||||
|
||||
/**jsdoc
|
||||
* Replace the values of some of this button's properties
|
||||
* @function TabletButtonProxy#editProperties
|
||||
* @param properties {object} set of properties to change
|
||||
*/
|
||||
Q_INVOKABLE void editProperties(QVariantMap properties);
|
||||
|
||||
public slots:
|
||||
void clickedSlot() { emit clicked(); }
|
||||
|
|
|
@ -17,6 +17,18 @@ var button = tablet.addButton({
|
|||
text: "BAM!!!"
|
||||
});
|
||||
|
||||
// change the color and name every second...
|
||||
var colors = ["#ff6f6f", "#6fff6f", "#6f6fff"];
|
||||
var names = ["BAM!", "BAM!!", "BAM!!!"];
|
||||
var colorIndex = 0;
|
||||
Script.setInterval(function () {
|
||||
colorIndex = (colorIndex + 1) % colors.length;
|
||||
button.editProperties({
|
||||
color: colors[colorIndex],
|
||||
text: names[colorIndex]
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
button.clicked.connect(function () {
|
||||
print("AJT: BAMM!!! CLICK from JS!");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue