Instantiating a structure-enum - bixby

So I have a structure-enum that looks like:
integer (Id) {}
enum (Color) {
symbol (red)
symbol (orange)
symbol (yellow)
symbol (green)
symbol (blue)
symbol (indigo)
symbol (violet)
}
structure-enum (ColorId) {
property (color) {
type (Color)
min (Required)
max (One)
}
property (id) {
type (Id)
min (Required)
max (One)
}
constant: ColorId {
color: (red)
id: (1)
}
constant: ColorId {
color: (orange)
id: (2)
}
constant: ColorId {
color: (yellow)
id: (3)
}
constant: ColorId {
color: (green)
id: (4)
}
constant: ColorId {
color: (blue)
id: (5)
}
constant: ColorId {
color: (indigo)
id: (6)
}
constant: ColorId {
color: (violet)
id: (7)
}
}
And I want to have an action that looks something like:
action (SomeAction) {
collect {
input (colorId) {
type (ColorId)
min (Required)
max (One)
}
}
output (SomeOutput)
}
I want the user to be able to say one of the Colors (which I have vocab for) and have Bixby match that color to one of the structure-enums and input that into my actions. So for example, the user could say "yellow" and Bixby would match that to the structure-enum:
constant: ColorId {
color: (yellow)
id: (3)
}
And use that as an input to my action. Basically I want to know how to take a user utterance and instantiate that into a structure-enum. How do I go about this?

structure-enum does fit this usage case.
You may have the following constant and the syntax is still valid.
constant: ColorId {
color: (red)
id: (1)
}
constant: ColorId {
color: (red)
id: (11)
}
constant: ColorId {
color: (red)
id: (31)
}
Keep the enum Color and do a look up in JS file and return Id.

Related

QML naming confussion

I have a basic question about naming components in QML files. I have read that the top element should always get the id root and parent is always the reference to the next element above it.
I have a two qml files, one with a ListView and one with the listview delegate
Userlogon.qml
Item {
id: root
height: parent.height
width: parent.width
property var password: ['0', '1', '2', '3']
property int selectedField : mill.selectedIndex
property int selectedUser : 0
property string p_background: configuration.getColor(Colors.ContentBackground)
ColumnLayout { anchors.fill: parent
Rectangle { id: userlist; Layout.fillWidth: true; Layout.fillHeight: true; Layout.preferredHeight: 300; color: p_background
ColumnLayout { anchors.fill: parent
ListView { Layout.fillWidth: true; Layout.fillHeight: true
model: user.model
currentIndex: 1
onCurrentIndexChanged: { console.log("currentIndex changed") }
header: UserItemDelegate { p_index: -1; p_name: "Benutzeranmeldung"; p_icon: "password"; p_isHeader: true }
delegate: UserItemDelegate { p_index: index; p_name: name; p_icon: icon; p_isHeader: false }
spacing: 20
}
}
}
UserItemDelegate.qml
Item {
id: root
height: configuration.getSize(Sizes.ListItemHeight)
width: parent.width
property int p_index
property string p_name
property string p_icon
property bool p_isHeader
property bool p_isSelected: root.ListView.view.currentIndex == p_index
property string p_color: configuration.getColor(p_isHeader ? Colors.ListItemDisabled : (p_isSelected ? Colors.ListItemSelected : Colors.ListItemDefault))
Rectangle { anchors.fill: parent; Layout.fillWidth: true; Layout.fillHeight: true; color: p_color
RowLayout { anchors.verticalCenter: parent.verticalCenter;
Image { Layout.leftMargin: 10; sourceSize.height: root.height * 0.6; source: "image://iconprovider/" + p_icon }
Label { Layout.leftMargin: 10; text: p_name }
}
MouseArea{ enabled: !p_isHeader; anchors.fill: parent; onClicked: { root.ListView.view.currentIndex = p_index; } }
}
}
With root.Listview.view.currentIndex I can access the listview in the parent UserLogon.qml although root is the id of the current item?
And is it possible to access e.g. a timer defined in UserLogon.qml from the delegate. If so how would the referencing be?
First of all, you don't need to name every root object "root". I don't know where you read that, but you can use whatever name makes sense to you.
When you call root.ListView.view.currentIndex, the root in that case is the id of the delegate, not the list. QML's scoping rules guarantee that. The ListView.view attached property then allows you to reference back to the list without needing its id.
Your timer question is unclear. In general, yes you can have access to the ListView's properties from the delegate, but you should usually do it the other way around. The ListView should reference the delegate's properties. The reason is that you may have a need to use that delegate somewhere else and you don't necessarily want it tightly coupled with the ListView in that case. Here's an example:
MyList.qml
ListView {
id: contactList
Timer {
id: backgroundTimer
interval: 3000
running: true
}
model: 5
delegate: MyDelegate {
width: contactList.width
// ListView binds the delegate's 'timedOut' property to something
timedOut: backgroundTimer.running
}
}
MyDelegate.qml
Rectangle {
id: contact
property bool timedOut: false
height: 30
radius: height / 2
color: timedOut ? "red" : "blue"
}

How to color the stars of p:rating based on the rating value?

I'm trying to color the stars of the PrimeFaces rating component depending on the value. If the value is 1, the stars should be red, if the value is 5, the stars should be green.
The easy way would be adding a class based on the value of the rating and update it when the value changes:
<p:rating ... styleClass="stars-#{bean.ratingValue}">
<p:ajax update="#this"/>
</p:rating>
With this class, you can style the stars based on the set class:
body .ui-rating.stars-1 .ui-rating-star-on a {
color: red;
}
body .ui-rating.stars-2 .ui-rating-star-on a {
color: orange;
}
body .ui-rating.stars-3 .ui-rating-star-on a {
color: yellow;
}
body .ui-rating.stars-4 .ui-rating-star-on a {
color: greenyellow;
}
body .ui-rating.stars-5 .ui-rating-star-on a {
color: green;
}
See also:
How do I override default PrimeFaces CSS with custom styles?

How to make a color name not automatically convert to a hex value in Stylus?

I am iterating a for loop with stylus preprocessor. I need color class names and color values and the hex values I get are fine but my class names are not ideal.
$colors = red blue green orange;
for item in $colors {
.{"" + item} {
color: item;
}
}
and I get this compiled:
.#f00 {
color: #f00;
}
.#00f {
color: #00f;
}
.#008000 {
color: #008000;
}
.#ffa500 {
color: #ffa500;
}
but my expected result was:
.red {
color: #f00; // or red
}
.blue {
color: #00F // or blue
}
// .. etc
I can imagine that there is a function for the names to remain.
Any help appreciated.
If you can convert the original list of colors to a set of strings, this
$colors = 'red' 'blue' 'green' 'orange';
for item in $colors {
.{item} {
color: convert(item);
}
}
yields
.red {
color: #f00;
}
.blue {
color: #00f;
}
.green {
color: #008000;
}
.orange {
color: #ffa500;
}
if you change convert to unquote, the hex values will get replaced with the names you supply them in the list.

QML toggle PropertyChanges onclick

I try to toggle my navigation with a toggle function. I want to change "x" position.
So here is what i got so far. But don't work. I try to use a toggle function to chnage state on click. I set two different state one that the navigation is visible and one that the navigation is hidden.
I get this error "ReferenceError: toggle is not defined"
Item {
id: toggleswitch
width: 200
height: 200
property bool on: false
function toggle() {
if (toggleswitch.state == "on")
toggleswitch.state = "off";
else
toggleswitch.state = "on";
}
Rectangle {
id: open
width: parent.width
height: 35
color: "#33000000"
Text {
anchors.centerIn: parent
text: "open"
color: "white"
font.family: "Helvetica"
font.pixelSize: 25
}
MouseArea { anchors.fill: parent; onClicked: toggle() }
}
states: [
State {
name: "on"
PropertyChanges { target: navigation; x: 0 }
PropertyChanges { target: toggleswitch; on: true }
},
State {
name: "off"
PropertyChanges { target: navigation; x: -300 }
PropertyChanges { target: toggleswitch; on: false }
}
]
}
Some small slider example:
import QtQuick 2.2
Rectangle {
width: 360
height: 360
Rectangle {
anchors {
left: parent.left
top: parent.top
bottom: parent.bottom
}
id: slider
state: "close"
states: [
State {
name: "close"
PropertyChanges {
target: slider
width: 50
}
},
State {
name: "open"
PropertyChanges {
target: slider
width: 360
}
}
]
transitions: [
Transition {
NumberAnimation {
target: slider
property: "width"
duration: 500
easing.type: Easing.InOutBack
}
}
]
color: "green"
}
MouseArea {
anchors.fill: parent
onClicked: {
if (slider.state == "close")
slider.state = "open";
else
slider.state = "close";
}
}
}
transitions is optional here
You can say to QML which object is your function.
Item {
id: toggleswitch
width: 200
height: 200
state: "off" //INIT YOUR STATE !!
property bool on: false
function toggle() {
if (toggleswitch.state == "on")
toggleswitch.state = "off";
else
toggleswitch.state = "on";
}
Rectangle {
id: open
width: parent.width
height: 35
color: "#33000000"
Text {
anchors.centerIn: parent
text: "open"
color: "white"
font.family: "Helvetica"
font.pixelSize: 25
}
MouseArea { anchors.fill: parent; onClicked: toggleswitch.toggle() } //here
}
states: [
State {
name: "on"
PropertyChanges { target: navigation; x: 0 }
PropertyChanges { target: toggleswitch; on: true }
},
State {
name: "off"
PropertyChanges { target: navigation; x: -300 }
PropertyChanges { target: toggleswitch; on: false }
}
]
What I would do here is not manipulate the state directly but toggle on the property directly, and bind the states to that property.
To me it feels more readable, semantical and reduce the coupling between the object and its visual states.
This also has the advantage of having states always coherent with the on property and provides a better abstraction. When using this component you can freely change the on property programmatically and the component display will update accordingly.
That's what I would probably end up with :
Item {
id: toggleswitch
width: 200
height: 200
property bool on: false
function toggle() {
on = !on //simpler toggle function
}
Rectangle {
id: open
width: parent.width
height: 35
color: "#33000000"
Text {
anchors.centerIn: parent
text: "open"
color: "white"
font.family: "Helvetica"
font.pixelSize: 25
}
MouseArea { anchors.fill: parent; onClicked: toggleswitch.toggle() }
}
states: [
State {
name: "on"
when: toggleswith.on
PropertyChanges { target: navigation; x: 0 }
},
State {
name: "off"
when: !toggleswith.on
PropertyChanges { target: navigation; x: -300 }
}
]

highcharts: change color of pie slice on hover

when a slice of pie chart is hovered over i'd like it to change to the designated hover color, and then change back to its original color once the mouse is off that slice.
the documentation here (http://api.highcharts.com/highcharts#plotOptions.series.marker.states.hover) made it seem like the following would work, but i didn't have any luck:
http://jsfiddle.net/pixeloco/ztJkb/3/
plotOptions: {
series: {
marker: {
states: {
hover: {
fillColor: 'black'
}
}
}
}
},
i found this solution http://jsfiddle.net/r6p7E/6/, but it requires that all slices be the same color. is there a way to have a multi-colored chart with slices that change color on hover?
Looks like you need these options:
series: {
states: {
hover: {
enabled: false
}
},
point: {
events: {
mouseOver: function () {
this.options.oldColor = this.color;
this.graphic.attr("fill", "black");
},
mouseOut: function () {
this.graphic.attr("fill", this.options.oldColor);
}
}
},
}
FIDDLE EXAMPLE

Resources