From 35fee739c59132ade4054542ed75396aec1068e5 Mon Sep 17 00:00:00 2001 From: vladest Date: Wed, 27 Dec 2017 23:50:15 +0100 Subject: [PATCH] Use buttons index --- .../qml/hifi/tablet/TabletButton.qml | 13 ++++----- .../resources/qml/hifi/tablet/TabletHome.qml | 28 +++---------------- .../ui/src/ui/TabletScriptingInterface.cpp | 21 ++++++++++---- .../ui/src/ui/TabletScriptingInterface.h | 6 ++-- 4 files changed, 27 insertions(+), 41 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/TabletButton.qml b/interface/resources/qml/hifi/tablet/TabletButton.qml index 843f8706ed..4d443fb97c 100644 --- a/interface/resources/qml/hifi/tablet/TabletButton.qml +++ b/interface/resources/qml/hifi/tablet/TabletButton.qml @@ -24,9 +24,9 @@ Item { property int stableOrder: 0 property var tabletRoot; property var flickable: null + property var gridView: null - property int row: -1 - property int column: -1 + property int buttonIndex: -1 width: 129 height: 129 @@ -138,7 +138,8 @@ Item { enabled: true preventStealing: false onClicked: { - tablet.setCurrentItemState("base state"); + gridView.currentIndex = buttonIndex + if (tabletButton.inDebugMode) { if (tabletButton.isActive) { tabletButton.isActive = false; @@ -146,8 +147,6 @@ Item { tabletButton.isActive = true; } } - tablet.rowIndex = tabletButton.row - tablet.columnIndex = tabletButton.column tabletButton.clicked(); if (tabletRoot) { @@ -156,7 +155,7 @@ Item { } onEntered: { - tablet.setCurrentItemState("base state"); + gridView.currentIndex = buttonIndex tabletButton.isEntered = true; Tablet.playSound(TabletEnums.ButtonHover); @@ -165,8 +164,6 @@ Item { } else { tabletButton.state = "hover state"; } - tablet.rowIndex = tabletButton.row - tablet.columnIndex = tabletButton.column } onExited: { tabletButton.isEntered = false; diff --git a/interface/resources/qml/hifi/tablet/TabletHome.qml b/interface/resources/qml/hifi/tablet/TabletHome.qml index 0b450cc2e7..2064fb38fa 100644 --- a/interface/resources/qml/hifi/tablet/TabletHome.qml +++ b/interface/resources/qml/hifi/tablet/TabletHome.qml @@ -14,9 +14,6 @@ Item { objectName: "tablet" property var tabletProxy: Tablet.getTablet("com.highfidelity.interface.tablet.system"); - property int rowIndex: 6 // by default - property int columnIndex: 1 // point to 'go to location' - property var currentGridItems: null focus: true @@ -145,10 +142,9 @@ Item { if (buttonIndex < 0) { return; } + console.warn("changing item at", buttonIndex, buttonstate) var itemat = gridView.contentItem.children[buttonIndex].children[0]; - console.warn("changing item at", buttonIndex, state, itemat.objectName, - gridView.contentItem.children[buttonIndex].objectName) if (itemat.isActive) { itemat.state = "active state"; } else { @@ -158,9 +154,7 @@ Item { onCurrentIndexChanged: { setButtonState(previousGridIndex, "base state"); - rowIndex = Math.floor(currentIndex / TabletEnums.ButtonsColumnsOnPage); - columnIndex = currentIndex % TabletEnums.ButtonsColumnsOnPage - console.warn("current index", currentIndex, rowIndex, columnIndex) + console.warn("current index", currentIndex) setButtonState(currentIndex, "hover state"); previousGridIndex = currentIndex } @@ -181,12 +175,10 @@ Item { TabletButton { id: tabletButton anchors.centerIn: parent + gridView: wrapper.GridView.view + buttonIndex: page.proxyModel.buttonIndex(uuid); flickable: swipeView.contentItem; onClicked: modelData.clicked() - onStateChanged: console.warn("state", state, uuid) -// Component.onCompleted: { -// state = Qt.binding(function() { return wrapper.GridView.isCurrentItem ? "hover state" : "base state"; }); -// } } Connections { @@ -221,7 +213,6 @@ Item { currentGridItems.currentIndex = (previousIndex > swipeView.currentIndex ? currentGridItems.count - 1 : 0); previousIndex = currentIndex; - setButtonState(currentIndex, "hover state"); } hoverEnabled: true @@ -263,17 +254,6 @@ Item { } } - function setCurrentItemState(state) { - var buttonIndex = rowIndex * TabletEnums.ButtonsColumnsOnPage + columnIndex; - if (currentGridItems !== null && buttonIndex >= 0 && buttonIndex < currentGridItems.length) { - if (currentGridItems[buttonIndex].isActive) { - currentGridItems[buttonIndex].state = "active state"; - } else { - currentGridItems[buttonIndex].state = state; - } - } - } - Component.onCompleted: { focus = true; forceActiveFocus(); diff --git a/libraries/ui/src/ui/TabletScriptingInterface.cpp b/libraries/ui/src/ui/TabletScriptingInterface.cpp index 5e5b3f83ea..c69ec1ce84 100644 --- a/libraries/ui/src/ui/TabletScriptingInterface.cpp +++ b/libraries/ui/src/ui/TabletScriptingInterface.cpp @@ -93,13 +93,27 @@ void TabletButtonListModel::removeButton(TabletButtonProxy* button) { } TabletButtonsProxyModel::TabletButtonsProxyModel(QObject *parent) - : QSortFilterProxyModel(parent), _pageIndex(-1) { + : QSortFilterProxyModel(parent) { } int TabletButtonsProxyModel::pageIndex() const { return _pageIndex; } +int TabletButtonsProxyModel::buttonIndex(const QString &uuid) { + if (!sourceModel() || _pageIndex < 0) { + return -1; + } + TabletButtonListModel* model = static_cast(sourceModel()); + for (int i = 0; i < model->rowCount(); i++) { + TabletButtonProxy* bproxy = model->data(model->index(i), ButtonProxyRole).value(); + if (bproxy && bproxy->getUuid().toString().contains(uuid)) { + return i - (_pageIndex*TabletScriptingInterface::ButtonsOnPage); + } + } + return -1; +} + void TabletButtonsProxyModel::setPageIndex(int pageIndex) { if (_pageIndex == pageIndex) @@ -117,11 +131,6 @@ bool TabletButtonsProxyModel::filterAcceptsRow(int sourceRow, && sourceRow < (_pageIndex + 1)*TabletScriptingInterface::ButtonsOnPage); } -bool TabletButtonsProxyModel::lessThan(const QModelIndex &left, - const QModelIndex &right) const { - return true; -} - TabletScriptingInterface::TabletScriptingInterface() { qmlRegisterType("TabletScriptingInterface", 1, 0, "TabletEnums"); qmlRegisterType("TabletScriptingInterface", 1, 0, "TabletButtonsProxyModel"); diff --git a/libraries/ui/src/ui/TabletScriptingInterface.h b/libraries/ui/src/ui/TabletScriptingInterface.h index a69bcd2f75..56e3ae257b 100644 --- a/libraries/ui/src/ui/TabletScriptingInterface.h +++ b/libraries/ui/src/ui/TabletScriptingInterface.h @@ -129,8 +129,9 @@ class TabletButtonsProxyModel : public QSortFilterProxyModel Q_PROPERTY(int pageIndex READ pageIndex WRITE setPageIndex NOTIFY pageIndexChanged) public: - TabletButtonsProxyModel(QObject *parent = 0); + TabletButtonsProxyModel(QObject* parent = 0); int pageIndex() const; + Q_INVOKABLE int buttonIndex(const QString& uuid); public slots: void setPageIndex(int pageIndex); @@ -140,10 +141,9 @@ signals: protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; - bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; private: - int _pageIndex; + int _pageIndex { -1 }; }; Q_DECLARE_METATYPE(TabletButtonsProxyModel*);