mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 20:36:49 +02:00
Store button list in the resources section of fake item instead of C++ space
This commit is contained in:
parent
012f65a87f
commit
79f9b54f6a
3 changed files with 22 additions and 58 deletions
|
@ -30,21 +30,26 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//fake invisible item for initial buttons creations
|
//fake invisible item for initial buttons creations.
|
||||||
|
//Also used as a holder for buttons list
|
||||||
Item {
|
Item {
|
||||||
id: fakeParent
|
id: fakeParent
|
||||||
visible: false
|
visible: false
|
||||||
}
|
}
|
||||||
|
|
||||||
function doRecreateGrids() {
|
function doRecreateGrids() {
|
||||||
var tabletProxy = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
|
||||||
var tabletButtons = tabletProxy.getButtonsList();
|
|
||||||
|
|
||||||
if (tabletButtons.length <= 0) {
|
if (fakeParent.resources.length <= 0) {
|
||||||
console.warn("Tablet buttons list is empty");
|
console.warn("Tablet buttons list is empty", fakeParent.resources.length);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//copy buttons list to JS array to be able to sort it
|
||||||
|
var tabletButtons = [];
|
||||||
|
for (var btnIndex = 0; btnIndex < fakeParent.resources.length; btnIndex++) {
|
||||||
|
tabletButtons.push(fakeParent.resources[btnIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = swipeView.count - 1; i >= 0; i--) {
|
for (var i = swipeView.count - 1; i >= 0; i--) {
|
||||||
swipeView.removeItem(i);
|
swipeView.removeItem(i);
|
||||||
}
|
}
|
||||||
|
@ -53,7 +58,6 @@ Item {
|
||||||
swipeView.setCurrentIndex(-1);
|
swipeView.setCurrentIndex(-1);
|
||||||
sortButtons(tabletButtons);
|
sortButtons(tabletButtons);
|
||||||
|
|
||||||
var pagesNum = Math.ceil(tabletButtons.length / 12);
|
|
||||||
var currentPage = 0;
|
var currentPage = 0;
|
||||||
gridPages.push(pageComponent.createObject(null));
|
gridPages.push(pageComponent.createObject(null));
|
||||||
|
|
||||||
|
@ -87,10 +91,8 @@ Item {
|
||||||
if (!uuid) {
|
if (!uuid) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
var tabletProxy = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
for (var i in fakeParent.resources) {
|
||||||
var tabletButtons = tabletProxy.getButtonsList();
|
var child = fakeParent.resources[i];
|
||||||
for (var i in tabletButtons) {
|
|
||||||
var child = tabletButtons[i];
|
|
||||||
if (child.uuid === uuid) {
|
if (child.uuid === uuid) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
@ -129,6 +131,7 @@ Item {
|
||||||
}
|
}
|
||||||
button.flickable = swipeView.contentItem;
|
button.flickable = swipeView.contentItem;
|
||||||
tablet.count++
|
tablet.count++
|
||||||
|
fakeParent.resources.push(button);
|
||||||
gridsRecreateTimer.restart();
|
gridsRecreateTimer.restart();
|
||||||
|
|
||||||
return button;
|
return button;
|
||||||
|
@ -163,6 +166,7 @@ Item {
|
||||||
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 {
|
||||||
tablet.count--;
|
tablet.count--;
|
||||||
|
fakeParent.resources[index] = null;
|
||||||
//redraw grids
|
//redraw grids
|
||||||
gridsRecreateTimer.restart();
|
gridsRecreateTimer.restart();
|
||||||
}
|
}
|
||||||
|
|
|
@ -716,11 +716,7 @@ TabletButtonProxy* TabletProxy::addButton(const QVariant& properties) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));
|
auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));
|
||||||
{
|
_tabletButtonProxies.push_back(tabletButtonProxy);
|
||||||
QMutexLocker locker(&_tabletButtonsListMutex);
|
|
||||||
_tabletButtonProxies.push_back(tabletButtonProxy);
|
|
||||||
|
|
||||||
}
|
|
||||||
if (!_toolbarMode && _qmlTabletRoot) {
|
if (!_toolbarMode && _qmlTabletRoot) {
|
||||||
auto tablet = getQmlTablet();
|
auto tablet = getQmlTablet();
|
||||||
if (tablet) {
|
if (tablet) {
|
||||||
|
@ -768,10 +764,7 @@ void TabletProxy::removeButton(TabletButtonProxy* tabletButtonProxy) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
buttonProxy = *iter;
|
buttonProxy = *iter;
|
||||||
{
|
_tabletButtonProxies.erase(iter);
|
||||||
QMutexLocker locker(&_tabletButtonsListMutex);
|
|
||||||
_tabletButtonProxies.erase(iter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_toolbarMode && _qmlTabletRoot) {
|
if (!_toolbarMode && _qmlTabletRoot) {
|
||||||
|
@ -821,11 +814,8 @@ void TabletProxy::addButtonsToHomeScreen() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
for (auto& buttonProxy : _tabletButtonProxies) {
|
||||||
QMutexLocker locker(&_tabletButtonsListMutex);
|
addButtonProxyToQmlTablet(tablet, buttonProxy.data());
|
||||||
for (auto& buttonProxy : _tabletButtonProxies) {
|
|
||||||
addButtonProxyToQmlTablet(tablet, buttonProxy.data());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
|
auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
|
||||||
QObject::disconnect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()));
|
QObject::disconnect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()));
|
||||||
|
@ -852,12 +842,9 @@ void TabletProxy::desktopWindowClosed() {
|
||||||
void TabletProxy::addButtonsToToolbar() {
|
void TabletProxy::addButtonsToToolbar() {
|
||||||
Q_ASSERT(QThread::currentThread() == thread());
|
Q_ASSERT(QThread::currentThread() == thread());
|
||||||
ToolbarProxy* toolbarProxy = DependencyManager::get<TabletScriptingInterface>()->getSystemToolbarProxy();
|
ToolbarProxy* toolbarProxy = DependencyManager::get<TabletScriptingInterface>()->getSystemToolbarProxy();
|
||||||
{
|
for (auto& buttonProxy : _tabletButtonProxies) {
|
||||||
QMutexLocker locker(&_tabletButtonsListMutex);
|
// copy properties from tablet button proxy to toolbar button proxy.
|
||||||
for (auto& buttonProxy : _tabletButtonProxies) {
|
buttonProxy->setToolbarButtonProxy(toolbarProxy->addButton(buttonProxy->getProperties()));
|
||||||
// copy properties from tablet button proxy to toolbar button proxy.
|
|
||||||
buttonProxy->setToolbarButtonProxy(toolbarProxy->addButton(buttonProxy->getProperties()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make the toolbar visible
|
// make the toolbar visible
|
||||||
|
@ -914,19 +901,6 @@ QQuickItem* TabletProxy::getQmlMenu() const {
|
||||||
return menuList;
|
return menuList;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QObject *> TabletProxy::getButtonsList() const {
|
|
||||||
QList<QObject *> buttonsList;
|
|
||||||
QMutexLocker locker(&_tabletButtonsListMutex);
|
|
||||||
|
|
||||||
for (auto& buttonProxy : _tabletButtonProxies) {
|
|
||||||
if (buttonProxy->getQmlButton()) {
|
|
||||||
buttonsList.append(buttonProxy->getQmlButton());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return buttonsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// TabletButtonProxy
|
// TabletButtonProxy
|
||||||
//
|
//
|
||||||
|
@ -1007,7 +981,3 @@ 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointer<QQuickItem> TabletButtonProxy::getQmlButton() const {
|
|
||||||
return _qmlButton;
|
|
||||||
}
|
|
||||||
|
|
|
@ -204,13 +204,6 @@ 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
|
||||||
|
@ -270,7 +263,6 @@ protected:
|
||||||
std::pair<QVariant, bool> _initialWebPathParams;
|
std::pair<QVariant, bool> _initialWebPathParams;
|
||||||
bool _landscape { false };
|
bool _landscape { false };
|
||||||
bool _showRunningScripts { false };
|
bool _showRunningScripts { false };
|
||||||
mutable QMutex _tabletButtonsListMutex;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(TabletProxy*);
|
Q_DECLARE_METATYPE(TabletProxy*);
|
||||||
|
@ -305,8 +297,6 @@ public:
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void editProperties(const QVariantMap& properties);
|
Q_INVOKABLE void editProperties(const QVariantMap& properties);
|
||||||
|
|
||||||
QPointer<QQuickItem> getQmlButton() const;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void clickedSlot() { emit clicked(); }
|
void clickedSlot() { emit clicked(); }
|
||||||
|
|
||||||
|
@ -321,7 +311,7 @@ signals:
|
||||||
protected:
|
protected:
|
||||||
QUuid _uuid;
|
QUuid _uuid;
|
||||||
int _stableOrder;
|
int _stableOrder;
|
||||||
QPointer<QQuickItem> _qmlButton;
|
QQuickItem* _qmlButton { nullptr };
|
||||||
QObject* _toolbarButtonProxy { nullptr };
|
QObject* _toolbarButtonProxy { nullptr };
|
||||||
QVariantMap _properties;
|
QVariantMap _properties;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue