Use buttons index

This commit is contained in:
vladest 2017-12-27 23:50:15 +01:00
parent ffcccacfa5
commit 35fee739c5
4 changed files with 27 additions and 41 deletions

View file

@ -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;

View file

@ -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();

View file

@ -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<TabletButtonListModel*>(sourceModel());
for (int i = 0; i < model->rowCount(); i++) {
TabletButtonProxy* bproxy = model->data(model->index(i), ButtonProxyRole).value<TabletButtonProxy*>();
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>("TabletScriptingInterface", 1, 0, "TabletEnums");
qmlRegisterType<TabletButtonsProxyModel>("TabletScriptingInterface", 1, 0, "TabletButtonsProxyModel");

View file

@ -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*);