From cb7472c27026856b742beea8206e54ca4a8a7f8e Mon Sep 17 00:00:00 2001 From: vladest Date: Mon, 25 Dec 2017 20:14:31 +0100 Subject: [PATCH] Selection consistency #1 --- .../resources/qml/hifi/tablet/TabletHome.qml | 51 ++++++++++++++----- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/TabletHome.qml b/interface/resources/qml/hifi/tablet/TabletHome.qml index 382e1f3f1e..5cf27151a7 100644 --- a/interface/resources/qml/hifi/tablet/TabletHome.qml +++ b/interface/resources/qml/hifi/tablet/TabletHome.qml @@ -129,8 +129,10 @@ Item { property TabletButtonsProxyModel proxyModel: TabletButtonsProxyModel {} GridView { - id: flickable + id: gridView keyNavigationEnabled: false + highlightFollowsCurrentItem: false + property int previousGridIndex: -1 anchors { fill: parent topMargin: 20 @@ -138,6 +140,25 @@ Item { rightMargin: 30 bottomMargin: 0 } + + function setButtonState(buttonIndex) { + var itemat = gridView.contentItem.children[buttonIndex]; + if (itemat.isActive) { + itemat.state = "active state"; + } else { + itemat.state = state; + } + } + + onCurrentIndexChanged: { + setButtonState(previousGridIndex) + rowIndex = Math.floor(currentIndex / TabletEnums.ButtonsColumnsOnPage); + columnIndex = currentIndex % TabletEnums.ButtonsColumnsOnPage + console.warn("current index", currentIndex, rowIndex, columnIndex) + setButtonState(currentIndex) + previousGridIndex = currentIndex + } + cellWidth: width/3 cellHeight: cellWidth flow: GridView.LeftToRight @@ -145,16 +166,20 @@ Item { delegate: Item { id: wrapper - width: flickable.cellWidth - height: flickable.cellHeight + width: gridView.cellWidth + height: gridView.cellHeight property var proxy: modelData TabletButton { id: tabletButton anchors.centerIn: parent + flickable: swipeView.contentItem; onClicked: modelData.clicked() - state: wrapper.GridView.isCurrentItem ? "hover state" : "base state" + onStateChanged: console.warn("state", state, uuid) +// Component.onCompleted: { +// state = Qt.binding(function() { return wrapper.GridView.isCurrentItem ? "hover state" : "base state"; }); +// } } Connections { @@ -231,14 +256,14 @@ 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; -// } -// } + 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: { @@ -253,7 +278,6 @@ Item { var index = currentGridItems.currentIndex; currentGridItems.moveCurrentIndexRight(); - console.warn("onRightPressed", index, currentGridItems.currentIndex, currentGridItems.count) if (index === currentGridItems.count - 1 && index === currentGridItems.currentIndex) { if (swipeView.currentIndex < swipeView.count - 1) { swipeView.incrementCurrentIndex(); @@ -268,7 +292,6 @@ Item { var index = currentGridItems.currentIndex; currentGridItems.moveCurrentIndexLeft(); - console.warn("onLeftPressed", index, currentGridItems.currentIndex, currentGridItems.count) if (index === 0 && index === currentGridItems.currentIndex) { if (swipeView.currentIndex > 0) { swipeView.decrementCurrentIndex();