diff --git a/interface/resources/qml/hifi/tablet/TabletButton.qml b/interface/resources/qml/hifi/tablet/TabletButton.qml index 6c2685f155..9ad8d1476c 100644 --- a/interface/resources/qml/hifi/tablet/TabletButton.qml +++ b/interface/resources/qml/hifi/tablet/TabletButton.qml @@ -125,7 +125,6 @@ Item { } } onEntered: { - console.log("Tablet Button Hovered!"); tabletButton.isEntered = true; if (tabletButton.isActive) { tabletButton.state = "hover active state"; @@ -134,7 +133,6 @@ Item { } } onExited: { - console.log("Tablet Button Unhovered!"); tabletButton.isEntered = false; if (tabletButton.isActive) { tabletButton.state = "active state"; diff --git a/interface/resources/qml/hifi/toolbars/StateImage.qml b/interface/resources/qml/hifi/toolbars/StateImage.qml index 44eaa6f7fd..ee0778626d 100644 --- a/interface/resources/qml/hifi/toolbars/StateImage.qml +++ b/interface/resources/qml/hifi/toolbars/StateImage.qml @@ -6,7 +6,7 @@ Item { property alias alpha: image.opacity property var subImage; property int yOffset: 0 - property int buttonState: 0 + property int buttonState: 1 property real size: 50 width: size; height: size property bool pinned: false diff --git a/interface/resources/qml/hifi/toolbars/ToolbarButton.qml b/interface/resources/qml/hifi/toolbars/ToolbarButton.qml index bc035ca19c..91c992bf0d 100644 --- a/interface/resources/qml/hifi/toolbars/ToolbarButton.qml +++ b/interface/resources/qml/hifi/toolbars/ToolbarButton.qml @@ -3,11 +3,34 @@ import QtQuick.Controls 1.4 StateImage { id: button - property int hoverState: -1 - property int defaultState: -1 + property bool isActive: false + property bool isEntered: false + + property int imageOffOut: 1 + property int imageOffIn: 3 + property int imageOnOut: 0 + property int imageOnIn: 2 signal clicked() + function changeProperty(key, value) { + button[key] = value; + } + + function updateState() { + if (!button.isEntered && !button.isActive) { + buttonState = imageOffOut; + } else if (!button.isEntered && button.isActive) { + buttonState = imageOnOut; + } else if (button.isEntered && !button.isActive) { + buttonState = imageOffIn; + } else { + buttonState = imageOnIn; + } + } + + onIsActiveChanged: updateState(); + Timer { id: asyncClickSender interval: 10 @@ -22,14 +45,12 @@ StateImage { anchors.fill: parent onClicked: asyncClickSender.start(); onEntered: { - if (hoverState >= 0) { - buttonState = hoverState; - } + button.isEntered = true; + updateState(); } onExited: { - if (defaultState >= 0) { - buttonState = defaultState; - } + button.isEntered = false; + updateState(); } } } diff --git a/interface/src/scripting/ToolbarScriptingInterface.cpp b/interface/src/scripting/ToolbarScriptingInterface.cpp index eb60ff0f67..2b4f64f35e 100644 --- a/interface/src/scripting/ToolbarScriptingInterface.cpp +++ b/interface/src/scripting/ToolbarScriptingInterface.cpp @@ -19,15 +19,33 @@ class ToolbarButtonProxy : public QmlWrapper { public: ToolbarButtonProxy(QObject* qmlObject, QObject* parent = nullptr) : QmlWrapper(qmlObject, parent) { + std::lock_guard guard(_mutex); + _qmlButton = qobject_cast(qmlObject); connect(qmlObject, SIGNAL(clicked()), this, SIGNAL(clicked())); } Q_INVOKABLE void editProperties(QVariantMap properties) { - qDebug() << "XXX WRITE TabletButtonProxy::editProperties"; + std::lock_guard guard(_mutex); + QVariantMap::const_iterator iter = properties.constBegin(); + while (iter != properties.constEnd()) { + _properties[iter.key()] = iter.value(); + if (_qmlButton) { + // [01/25 14:26:20] [WARNING] [default] QMetaObject::invokeMethod: No such method ToolbarButton_QMLTYPE_195::changeProperty(QVariant,QVariant) + + QMetaObject::invokeMethod(_qmlButton, "changeProperty", Qt::AutoConnection, + Q_ARG(QVariant, QVariant(iter.key())), Q_ARG(QVariant, iter.value())); + } + ++iter; + } } signals: void clicked(); + +protected: + mutable std::mutex _mutex; + QQuickItem* _qmlButton { nullptr }; + QVariantMap _properties; }; class ToolbarProxy : public QmlWrapper { diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 7a6f063077..7d5c1fed1a 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -244,8 +244,6 @@ var toolBar = (function () { imageURL: TOOLS_PATH + "edit.svg", visible: true, alpha: 0.9, - buttonState: 1, - hoverState: 3, defaultState: 1 }); } else { diff --git a/scripts/system/goto.js b/scripts/system/goto.js index 30f6ca255c..95bd05ae73 100644 --- a/scripts/system/goto.js +++ b/scripts/system/goto.js @@ -33,9 +33,6 @@ if (Settings.getValue("HUDUIEnabled")) { objectName: buttonName, imageURL: Script.resolvePath("assets/images/tools/directory.svg"), visible: true, - buttonState: 1, - defaultState: 1, - hoverState: 3, alpha: 0.9 }); } else { diff --git a/scripts/system/help.js b/scripts/system/help.js index f3f3007b65..7813780da3 100644 --- a/scripts/system/help.js +++ b/scripts/system/help.js @@ -24,9 +24,6 @@ objectName: buttonName, imageURL: Script.resolvePath("assets/images/tools/help.svg"), visible: true, - hoverState: 2, - defaultState: 1, - buttonState: 1, alpha: 0.9 }); } else { diff --git a/scripts/system/hmd.js b/scripts/system/hmd.js index bd525d7b14..794e348fd3 100644 --- a/scripts/system/hmd.js +++ b/scripts/system/hmd.js @@ -83,8 +83,6 @@ if (headset) { objectName: "hmdToggle", imageURL: Script.resolvePath("assets/images/tools/switch.svg"), visible: true, - hoverState: 2, - defaultState: 0, alpha: 0.9 }); } else { diff --git a/scripts/system/marketplaces/marketplaces.js b/scripts/system/marketplaces/marketplaces.js index 24eda5b6a3..8cb13cf27e 100644 --- a/scripts/system/marketplaces/marketplaces.js +++ b/scripts/system/marketplaces/marketplaces.js @@ -126,9 +126,6 @@ if (Settings.getValue("HUDUIEnabled")) { marketplaceButton = toolBar.addButton({ imageURL: toolIconUrl + "market.svg", objectName: "marketplace", - buttonState: 1, - defaultState: 1, - hoverState: 3, alpha: 0.9 }); } else { diff --git a/scripts/system/mute.js b/scripts/system/mute.js index f94dbc242c..3aec12ff59 100644 --- a/scripts/system/mute.js +++ b/scripts/system/mute.js @@ -32,9 +32,6 @@ if (Settings.getValue("HUDUIEnabled")) { objectName: buttonName, imageURL: Script.resolvePath("assets/images/tools/mic.svg"), visible: true, - buttonState: 1, - defaultState: 1, - hoverState: 3, alpha: 0.9 }); } else { diff --git a/scripts/system/pal.js b/scripts/system/pal.js index 92bc410404..a9d6d8b2e2 100644 --- a/scripts/system/pal.js +++ b/scripts/system/pal.js @@ -487,9 +487,6 @@ if (Settings.getValue("HUDUIEnabled")) { objectName: buttonName, imageURL: Script.resolvePath("assets/images/tools/people.svg"), visible: true, - hoverState: 2, - defaultState: 1, - buttonState: 1, alpha: 0.9 }); } else { diff --git a/scripts/system/snapshot.js b/scripts/system/snapshot.js index db0c7bd36e..fa2f2df7d3 100644 --- a/scripts/system/snapshot.js +++ b/scripts/system/snapshot.js @@ -28,9 +28,6 @@ if (Settings.getValue("HUDUIEnabled")) { objectName: buttonName, imageURL: Script.resolvePath("assets/images/tools/snap.svg"), visible: true, - buttonState: 1, - defaultState: 1, - hoverState: 2, alpha: 0.9, }); } else {