Unsolved Navigation inside a QML page due to external inputs
-
I have several QML pages each one with custom objects that appears as "buttons" or other focusable items.
The target machine has no mouse nor keyboard and the navigation among items is provided by external devices. From them I received via serial or ethernet some events that I forward as signals to the QML pages.So I have signals like "click", "up", "down", "left" and "right".
Each custom object has a property that define its state: deselected, selected and clicked.
Whenever I receive such a signal I should update those properties according to the page layout.Let's suppose I have two "buttons" in a column and an icon in the upper-right corner of the page. On startup the focus is set on the first button, then:
- if I receive "up" go to the icon
- if I receive "down" go to the second button
- if I receive "click" execute the button function
then if I moved to the second button:
- if I receive "up" go to the first button
- if I receive "click" execute the button function
Of course it depends on the page layout and also by the customer's requirements (i.e. when on the second button a "down" would go back to the first button or even to the icon).
Defining all these conditions with a straight fsm would require a huge quantity of if..else statements.
Is there something smarter to achieve the same?In C/C++ I would define a list of struct bound together using pointers:
typedef struct { QString name; item_t *up; item_t *down; item_t *left; item_t *right; } item_t; item_t items[ITEMS_NUM]; int currItem;
Whenever I receive an event I look for the current item and if the related pointer is not
null
I move toward the target item.What do you suggest in QML?