get button-states for toolbar buttons working again

This commit is contained in:
Seth Alves 2017-01-25 15:38:54 -08:00
parent 98f1664a46
commit ff8d13ecc7
12 changed files with 49 additions and 34 deletions

View file

@ -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";

View file

@ -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

View file

@ -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();
}
}
}

View file

@ -19,15 +19,33 @@ class ToolbarButtonProxy : public QmlWrapper {
public:
ToolbarButtonProxy(QObject* qmlObject, QObject* parent = nullptr) : QmlWrapper(qmlObject, parent) {
std::lock_guard<std::mutex> guard(_mutex);
_qmlButton = qobject_cast<QQuickItem*>(qmlObject);
connect(qmlObject, SIGNAL(clicked()), this, SIGNAL(clicked()));
}
Q_INVOKABLE void editProperties(QVariantMap properties) {
qDebug() << "XXX WRITE TabletButtonProxy::editProperties";
std::lock_guard<std::mutex> 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 {

View file

@ -244,8 +244,6 @@ var toolBar = (function () {
imageURL: TOOLS_PATH + "edit.svg",
visible: true,
alpha: 0.9,
buttonState: 1,
hoverState: 3,
defaultState: 1
});
} else {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {