mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 10:43:21 +02:00
Retreive buttons list from tablet proxy
This commit is contained in:
parent
c9f86e4b6b
commit
9b3db0725b
3 changed files with 51 additions and 74 deletions
|
@ -12,51 +12,54 @@ Item {
|
||||||
property int rowIndex: 6 // by default
|
property int rowIndex: 6 // by default
|
||||||
property int columnIndex: 1 // point to 'go to location'
|
property int columnIndex: 1 // point to 'go to location'
|
||||||
property int count: 0
|
property int count: 0
|
||||||
property var tabletButtons: new Array()
|
|
||||||
|
|
||||||
onTabletButtonsChanged: console.warn("tablet buttons", tabletButtons)
|
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: gridsRecreateTimer
|
id: gridsRecreateTimer
|
||||||
interval: 100
|
interval: 200
|
||||||
repeat: false
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
console.warn("timer triggered", tabletButtons.length)
|
|
||||||
doRecreateGrids()
|
doRecreateGrids()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fake invisible item for initial buttons creations
|
||||||
Item {
|
Item {
|
||||||
id: fakeParent
|
id: fakeParent
|
||||||
visible: parent
|
visible: parent
|
||||||
}
|
}
|
||||||
|
|
||||||
function doRecreateGrids() {
|
function doRecreateGrids() {
|
||||||
console.warn("buttons length", tabletButtons.length)
|
var tabletProxy = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
|
var tabletButtons = tabletProxy.getButtonsList();
|
||||||
for (var i = 0; i < swipeView.count; i++) {
|
for (var i = 0; i < swipeView.count; i++) {
|
||||||
var gridOuter = swipeView.itemAt(i);
|
var gridOuter = swipeView.itemAt(i);
|
||||||
gridOuter.destroy();
|
gridOuter.destroy();
|
||||||
swipeView.removeItem(i);
|
swipeView.removeItem(i);
|
||||||
}
|
}
|
||||||
|
sortButtons(tabletButtons);
|
||||||
|
|
||||||
for (var buttonIndex = 0; buttonIndex < tabletButtons.length; buttonIndex++) {
|
for (var buttonIndex = 0; buttonIndex < tabletButtons.length; buttonIndex++) {
|
||||||
console.warn("button index", buttonIndex)
|
|
||||||
var grid = swipeView.itemAt(swipeView.count - 1);
|
|
||||||
if (grid === null || grid.children[0].children.length === 12) {
|
|
||||||
grid = pageComponent.createObject(swipeView);
|
|
||||||
console.warn("grid index", swipeView.count)
|
|
||||||
//swipeView.addItem(grid);
|
|
||||||
}
|
|
||||||
var button = tabletButtons[buttonIndex]
|
var button = tabletButtons[buttonIndex]
|
||||||
button.parent = grid.children[0]
|
if (button !== null) {
|
||||||
grid.children[0].children.push(button);
|
var grid = swipeView.itemAt(swipeView.count - 1);
|
||||||
|
if (grid === null || grid.children[0].children.length === 12) {
|
||||||
|
grid = pageComponent.createObject(swipeView);
|
||||||
|
}
|
||||||
|
//reparent to actual grid
|
||||||
|
|
||||||
|
button.parent = grid.children[0]
|
||||||
|
grid.children[0].children.push(button);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// used to look up a button by its uuid
|
// used to look up a button by its uuid
|
||||||
function findButtonIndex(uuid) {
|
function findButtonIndex(uuid) {
|
||||||
if (!uuid) {
|
if (!uuid) {
|
||||||
return -1;//{ page: -1, index: -1};
|
return -1;
|
||||||
}
|
}
|
||||||
|
var tabletProxy = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
|
var tabletButtons = tabletProxy.getButtonsList();
|
||||||
for (var i in tabletButtons) {
|
for (var i in tabletButtons) {
|
||||||
var child = tabletButtons[i];
|
var child = tabletButtons[i];
|
||||||
if (child.uuid === uuid) {
|
if (child.uuid === uuid) {
|
||||||
|
@ -64,28 +67,14 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (var gridIndex = 0; gridIndex < swipeView.count; gridIndex++) {
|
return -1;
|
||||||
// var grid = swipeView.itemAt(gridIndex).children[0]
|
|
||||||
// for (var i in grid.children) {
|
|
||||||
// var child = grid.children[i];
|
|
||||||
// if (child.uuid === uuid) {
|
|
||||||
// return { page: gridIndex, index: i};
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
return -1;//{ page: -1, index: -1};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortButtons(/*gridIndex*/) {
|
function sortButtons(tabletButtons) {
|
||||||
//var children = [];
|
|
||||||
|
|
||||||
// var grid = swipeView.itemAt(gridIndex).children[0]
|
|
||||||
|
|
||||||
// for (var i = 0; i < grid.children.length; i++) {
|
|
||||||
// children[i] = grid.children[i];
|
|
||||||
// }
|
|
||||||
|
|
||||||
tabletButtons.sort(function (a, b) {
|
tabletButtons.sort(function (a, b) {
|
||||||
|
if (a === null || b === null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (a.sortOrder === b.sortOrder) {
|
if (a.sortOrder === b.sortOrder) {
|
||||||
// subsort by stableOrder, because JS sort is not stable in qml.
|
// subsort by stableOrder, because JS sort is not stable in qml.
|
||||||
return a.stableOrder - b.stableOrder;
|
return a.stableOrder - b.stableOrder;
|
||||||
|
@ -93,12 +82,10 @@ Item {
|
||||||
return a.sortOrder - b.sortOrder;
|
return a.sortOrder - b.sortOrder;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//grid.children = children;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function doAddButton(/*grid, gridIndex,*/ component, properties) {
|
function doAddButton(component, properties) {
|
||||||
var button = component.createObject(/*swipeView.itemAt(0).children[0]*/fakeParent);
|
var button = component.createObject(fakeParent);
|
||||||
|
|
||||||
// copy all properites to button
|
// copy all properites to button
|
||||||
var keys = Object.keys(properties).forEach(function (key) {
|
var keys = Object.keys(properties).forEach(function (key) {
|
||||||
|
@ -112,15 +99,8 @@ Item {
|
||||||
button.tabletRoot = parent.parent;
|
button.tabletRoot = parent.parent;
|
||||||
}
|
}
|
||||||
button.flickable = swipeView.contentItem
|
button.flickable = swipeView.contentItem
|
||||||
tabletButtons.push(button)
|
|
||||||
|
|
||||||
//sortButtons(/*gridIndex*/);
|
|
||||||
|
|
||||||
tablet.count++
|
tablet.count++
|
||||||
//redraw pages
|
gridsRecreateTimer.restart()
|
||||||
doRecreateGrids()
|
|
||||||
// console.warn("timer restarted", tabletButtons.length)
|
|
||||||
// gridsRecreateTimer.restart()
|
|
||||||
|
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
@ -144,14 +124,7 @@ Item {
|
||||||
// called by C++ code when a button should be added to the tablet
|
// called by C++ code when a button should be added to the tablet
|
||||||
function addButtonProxy(properties) {
|
function addButtonProxy(properties) {
|
||||||
var component = Qt.createComponent("TabletButton.qml");
|
var component = Qt.createComponent("TabletButton.qml");
|
||||||
// var grid = swipeView.itemAt(swipeView.count - 1)
|
return doAddButton(component, properties)
|
||||||
// if (grid === null || grid.children[0].children.length === 12) {
|
|
||||||
// grid = pageComponent.createObject(swipeView)
|
|
||||||
// swipeView.addItem(grid)
|
|
||||||
// }
|
|
||||||
console.warn("component status", component.status);
|
|
||||||
|
|
||||||
return doAddButton(/*grid, swipeView.count - 1,*/ component, properties)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// called by C++ code when a button should be removed from the tablet
|
// called by C++ code when a button should be removed from the tablet
|
||||||
|
@ -160,10 +133,6 @@ Item {
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
console.log("Warning: Tablet.qml could not find button with uuid = " + properties.uuid);
|
console.log("Warning: Tablet.qml could not find button with uuid = " + properties.uuid);
|
||||||
} else {
|
} else {
|
||||||
// var grid = swipeView.itemAt(index.page).children[0]
|
|
||||||
// grid.children[index.index].destroy();
|
|
||||||
console.warn("remove button proxy");
|
|
||||||
tabletButtons.slice(index, 1);
|
|
||||||
tablet.count--
|
tablet.count--
|
||||||
//redraw grids
|
//redraw grids
|
||||||
gridsRecreateTimer.restart();
|
gridsRecreateTimer.restart();
|
||||||
|
@ -245,19 +214,6 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
console.warn("Tablet created")
|
|
||||||
//pageComponent.createObject(swipeView)
|
|
||||||
// var tabletq = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
|
||||||
// if (tabletq) {
|
|
||||||
// // Tablet/toolbar button.
|
|
||||||
// for (var i = 0; i < 1; i++) {
|
|
||||||
// tabletq.addButton({ icon: "icons/tablet-icons/avatar-record-i.svg", activeIcon: "icons/tablet-icons/avatar-record-i.svg",
|
|
||||||
// text: "App " + i, isActive: false });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: bgMain
|
id: bgMain
|
||||||
gradient: Gradient {
|
gradient: Gradient {
|
||||||
|
@ -281,8 +237,6 @@ Item {
|
||||||
clip: false
|
clip: false
|
||||||
currentIndex: pageIndicator.currentIndex
|
currentIndex: pageIndicator.currentIndex
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onHoveredChanged: console.warn("swipe hovered", hovered)
|
|
||||||
onCurrentIndexChanged: console.warn("swipe currentIndex", currentIndex)
|
|
||||||
anchors {
|
anchors {
|
||||||
left: parent.left
|
left: parent.left
|
||||||
right: parent.right
|
right: parent.right
|
||||||
|
|
|
@ -900,6 +900,16 @@ QQuickItem* TabletProxy::getQmlMenu() const {
|
||||||
return menuList;
|
return menuList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QObject *> TabletProxy::getButtonsList() const {
|
||||||
|
QList<QObject *> buttonsList;
|
||||||
|
for (auto& buttonProxy : _tabletButtonProxies) {
|
||||||
|
if (buttonProxy->getQmlButton()) {
|
||||||
|
buttonsList.append(buttonProxy->getQmlButton());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buttonsList;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// TabletButtonProxy
|
// TabletButtonProxy
|
||||||
//
|
//
|
||||||
|
@ -980,3 +990,7 @@ void TabletButtonProxy::editProperties(const QVariantMap& properties) {
|
||||||
QMetaObject::invokeMethod(_toolbarButtonProxy, "editProperties", Qt::AutoConnection, Q_ARG(QVariantMap, properties));
|
QMetaObject::invokeMethod(_toolbarButtonProxy, "editProperties", Qt::AutoConnection, Q_ARG(QVariantMap, properties));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QQuickItem *TabletButtonProxy::getQmlButton() const {
|
||||||
|
return _qmlButton;
|
||||||
|
}
|
||||||
|
|
|
@ -204,6 +204,13 @@ public:
|
||||||
|
|
||||||
QQuickItem* getQmlMenu() const;
|
QQuickItem* getQmlMenu() const;
|
||||||
|
|
||||||
|
/**jsdoc
|
||||||
|
* Returns a list of currently created button items.
|
||||||
|
* @function TabletProxy#getButtonsList
|
||||||
|
* @returns {QList<QQuickItem*>}
|
||||||
|
*/
|
||||||
|
Q_INVOKABLE QList<QObject*> getButtonsList() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Signaled when this tablet receives an event from the html/js embedded in the tablet
|
* Signaled when this tablet receives an event from the html/js embedded in the tablet
|
||||||
|
@ -297,6 +304,8 @@ public:
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void editProperties(const QVariantMap& properties);
|
Q_INVOKABLE void editProperties(const QVariantMap& properties);
|
||||||
|
|
||||||
|
QQuickItem *getQmlButton() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void clickedSlot() { emit clicked(); }
|
void clickedSlot() { emit clicked(); }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue