mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 09:53:24 +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
interface/resources/qml/hifi/tablet
libraries/ui/src/ui
|
@ -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 {
|
||||
id: fakeParent
|
||||
visible: false
|
||||
}
|
||||
|
||||
function doRecreateGrids() {
|
||||
var tabletProxy = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||
var tabletButtons = tabletProxy.getButtonsList();
|
||||
|
||||
if (tabletButtons.length <= 0) {
|
||||
console.warn("Tablet buttons list is empty");
|
||||
if (fakeParent.resources.length <= 0) {
|
||||
console.warn("Tablet buttons list is empty", fakeParent.resources.length);
|
||||
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--) {
|
||||
swipeView.removeItem(i);
|
||||
}
|
||||
|
@ -53,7 +58,6 @@ Item {
|
|||
swipeView.setCurrentIndex(-1);
|
||||
sortButtons(tabletButtons);
|
||||
|
||||
var pagesNum = Math.ceil(tabletButtons.length / 12);
|
||||
var currentPage = 0;
|
||||
gridPages.push(pageComponent.createObject(null));
|
||||
|
||||
|
@ -87,10 +91,8 @@ Item {
|
|||
if (!uuid) {
|
||||
return -1;
|
||||
}
|
||||
var tabletProxy = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||
var tabletButtons = tabletProxy.getButtonsList();
|
||||
for (var i in tabletButtons) {
|
||||
var child = tabletButtons[i];
|
||||
for (var i in fakeParent.resources) {
|
||||
var child = fakeParent.resources[i];
|
||||
if (child.uuid === uuid) {
|
||||
return i;
|
||||
}
|
||||
|
@ -129,6 +131,7 @@ Item {
|
|||
}
|
||||
button.flickable = swipeView.contentItem;
|
||||
tablet.count++
|
||||
fakeParent.resources.push(button);
|
||||
gridsRecreateTimer.restart();
|
||||
|
||||
return button;
|
||||
|
@ -163,6 +166,7 @@ Item {
|
|||
console.log("Warning: Tablet.qml could not find button with uuid = " + properties.uuid);
|
||||
} else {
|
||||
tablet.count--;
|
||||
fakeParent.resources[index] = null;
|
||||
//redraw grids
|
||||
gridsRecreateTimer.restart();
|
||||
}
|
||||
|
|
|
@ -716,11 +716,7 @@ TabletButtonProxy* TabletProxy::addButton(const QVariant& properties) {
|
|||
}
|
||||
|
||||
auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));
|
||||
{
|
||||
QMutexLocker locker(&_tabletButtonsListMutex);
|
||||
_tabletButtonProxies.push_back(tabletButtonProxy);
|
||||
|
||||
}
|
||||
_tabletButtonProxies.push_back(tabletButtonProxy);
|
||||
if (!_toolbarMode && _qmlTabletRoot) {
|
||||
auto tablet = getQmlTablet();
|
||||
if (tablet) {
|
||||
|
@ -768,10 +764,7 @@ void TabletProxy::removeButton(TabletButtonProxy* tabletButtonProxy) {
|
|||
return;
|
||||
}
|
||||
buttonProxy = *iter;
|
||||
{
|
||||
QMutexLocker locker(&_tabletButtonsListMutex);
|
||||
_tabletButtonProxies.erase(iter);
|
||||
}
|
||||
_tabletButtonProxies.erase(iter);
|
||||
}
|
||||
|
||||
if (!_toolbarMode && _qmlTabletRoot) {
|
||||
|
@ -821,11 +814,8 @@ void TabletProxy::addButtonsToHomeScreen() {
|
|||
return;
|
||||
}
|
||||
|
||||
{
|
||||
QMutexLocker locker(&_tabletButtonsListMutex);
|
||||
for (auto& buttonProxy : _tabletButtonProxies) {
|
||||
addButtonProxyToQmlTablet(tablet, buttonProxy.data());
|
||||
}
|
||||
for (auto& buttonProxy : _tabletButtonProxies) {
|
||||
addButtonProxyToQmlTablet(tablet, buttonProxy.data());
|
||||
}
|
||||
auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
|
||||
QObject::disconnect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()));
|
||||
|
@ -852,12 +842,9 @@ void TabletProxy::desktopWindowClosed() {
|
|||
void TabletProxy::addButtonsToToolbar() {
|
||||
Q_ASSERT(QThread::currentThread() == thread());
|
||||
ToolbarProxy* toolbarProxy = DependencyManager::get<TabletScriptingInterface>()->getSystemToolbarProxy();
|
||||
{
|
||||
QMutexLocker locker(&_tabletButtonsListMutex);
|
||||
for (auto& buttonProxy : _tabletButtonProxies) {
|
||||
// copy properties from tablet button proxy to toolbar button proxy.
|
||||
buttonProxy->setToolbarButtonProxy(toolbarProxy->addButton(buttonProxy->getProperties()));
|
||||
}
|
||||
for (auto& buttonProxy : _tabletButtonProxies) {
|
||||
// copy properties from tablet button proxy to toolbar button proxy.
|
||||
buttonProxy->setToolbarButtonProxy(toolbarProxy->addButton(buttonProxy->getProperties()));
|
||||
}
|
||||
|
||||
// make the toolbar visible
|
||||
|
@ -914,19 +901,6 @@ QQuickItem* TabletProxy::getQmlMenu() const {
|
|||
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
|
||||
//
|
||||
|
@ -1007,7 +981,3 @@ void TabletButtonProxy::editProperties(const 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;
|
||||
|
||||
/**jsdoc
|
||||
* Returns a list of currently created button items.
|
||||
* @function TabletProxy#getButtonsList
|
||||
* @returns {QList<QQuickItem*>}
|
||||
*/
|
||||
Q_INVOKABLE QList<QObject*> getButtonsList() const;
|
||||
|
||||
signals:
|
||||
/**jsdoc
|
||||
* 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;
|
||||
bool _landscape { false };
|
||||
bool _showRunningScripts { false };
|
||||
mutable QMutex _tabletButtonsListMutex;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(TabletProxy*);
|
||||
|
@ -305,8 +297,6 @@ public:
|
|||
*/
|
||||
Q_INVOKABLE void editProperties(const QVariantMap& properties);
|
||||
|
||||
QPointer<QQuickItem> getQmlButton() const;
|
||||
|
||||
public slots:
|
||||
void clickedSlot() { emit clicked(); }
|
||||
|
||||
|
@ -321,7 +311,7 @@ signals:
|
|||
protected:
|
||||
QUuid _uuid;
|
||||
int _stableOrder;
|
||||
QPointer<QQuickItem> _qmlButton;
|
||||
QQuickItem* _qmlButton { nullptr };
|
||||
QObject* _toolbarButtonProxy { nullptr };
|
||||
QVariantMap _properties;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue